]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ARM Packages: Fixed line endings
authoroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 25 Jan 2013 11:28:06 +0000 (11:28 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 25 Jan 2013 11:28:06 +0000 (11:28 +0000)
This large code change only modifies the line endings to be CRLF to be
compliant with the EDK2 coding convention document.

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

280 files changed:
ArmPkg/Application/LinuxLoader/LinuxConfig.c
ArmPkg/Application/LinuxLoader/LinuxInternal.h
ArmPkg/ArmPkg.dsc
ArmPkg/Drivers/CpuDxe/ArmV4/ExceptionSupport.S
ArmPkg/Drivers/CpuDxe/ArmV4/ExceptionSupport.asm
ArmPkg/Drivers/CpuDxe/ArmV6/ExceptionSupport.S
ArmPkg/Drivers/CpuPei/CpuPei.inf
ArmPkg/Drivers/PL390Gic/PL390GicDxe.c
ArmPkg/Drivers/PL390Gic/PL390GicDxe.inf
ArmPkg/Drivers/TimerDxe/TimerDxe.c
ArmPkg/Drivers/TimerDxe/TimerDxe.inf
ArmPkg/Filesystem/SemihostFs/SemihostFs.inf
ArmPkg/Include/Library/ArmCpuLib.h
ArmPkg/Include/Library/ArmDisassemblerLib.h
ArmPkg/Include/Library/ArmLib.h
ArmPkg/Include/Library/ArmV7ArchTimerLib.h
ArmPkg/Include/Library/DefaultExceptionHandlerLib.h
ArmPkg/Include/Library/SemihostLib.h
ArmPkg/Include/Library/UncachedMemoryAllocationLib.h
ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.c
ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf
ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
ArmPkg/Library/ArmLib/Arm11/Arm11LibMem.c
ArmPkg/Library/ArmLib/Arm11/Arm11Support.S
ArmPkg/Library/ArmLib/Arm11/Arm11Support.asm
ArmPkg/Library/ArmLib/Arm9/Arm9Lib.c
ArmPkg/Library/ArmLib/Arm9/Arm9Support.S
ArmPkg/Library/ArmLib/Arm9/Arm9Support.asm
ArmPkg/Library/ArmLib/ArmV7/ArmV7ArchTimer.c
ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.c
ArmPkg/Library/BaseMemoryLibStm/Arm/CopyMem.asm
ArmPkg/Library/BaseMemoryLibVstm/Arm/CopyMem.asm
ArmPkg/Library/BaseMemoryLibVstm/Arm/SetMem.S
ArmPkg/Library/BaseMemoryLibVstm/Arm/SetMem.asm
ArmPkg/Library/BdsLib/BdsAppLoader.c
ArmPkg/Library/BdsLib/BdsFilePath.c
ArmPkg/Library/BdsLib/BdsHelper.c
ArmPkg/Library/BdsLib/BdsInternal.h
ArmPkg/Library/BdsLib/BdsLib.inf
ArmPkg/Library/BdsLib/BdsLinuxAtag.c
ArmPkg/Library/BdsLib/BdsLinuxLoader.c
ArmPkg/Library/BdsLib/BdsLinuxLoader.h
ArmPkg/Library/BdsLib/BdsLoadOption.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/Llvm_int_lib.h
ArmPkg/Library/CompilerIntrinsicsLib/Arm/ashldi3.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/ashldi3.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/ashrdi3.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/ashrdi3.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/clzsi2.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/clzsi2.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/ctzsi2.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/ctzsi2.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/div.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/div.asm
ArmPkg/Library/CompilerIntrinsicsLib/Arm/divdi3.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/divdi3.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/divsi3.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/divsi3.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/lasr.asm
ArmPkg/Library/CompilerIntrinsicsLib/Arm/ldivmod.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/ldivmod.asm
ArmPkg/Library/CompilerIntrinsicsLib/Arm/llsl.asm
ArmPkg/Library/CompilerIntrinsicsLib/Arm/llsr.asm
ArmPkg/Library/CompilerIntrinsicsLib/Arm/lshrdi3.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/lshrdi3.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.asm
ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy4.asm
ArmPkg/Library/CompilerIntrinsicsLib/Arm/memmove.asm
ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.asm
ArmPkg/Library/CompilerIntrinsicsLib/Arm/moddi3.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/moddi3.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/modsi3.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/modsi3.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/muldi3.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/muldi3.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/mullu.asm
ArmPkg/Library/CompilerIntrinsicsLib/Arm/switch.asm
ArmPkg/Library/CompilerIntrinsicsLib/Arm/switch16.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/switch32.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/switch8.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/switchu8.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/ucmpdi2.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/ucmpdi2.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/udivdi3.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/udivdi3.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/udivmoddi4.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/udivmoddi4.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/udivsi3.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/udivsi3.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/uldiv.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/uldiv.asm
ArmPkg/Library/CompilerIntrinsicsLib/Arm/uldivmod.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/umoddi3.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/umoddi3.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/umodsi3.S
ArmPkg/Library/CompilerIntrinsicsLib/Arm/umodsi3.c
ArmPkg/Library/CompilerIntrinsicsLib/Arm/uwrite.asm
ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentException.S
ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.inf
ArmPkg/Library/DebugUncachedMemoryAllocationLib/DebugUncachedMemoryAllocationLib.inf
ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.inf
ArmPkg/Library/SemihostLib/Arm/GccSemihost.S
ArmPkg/Library/SemihostLib/Arm/SemihostPrivate.h
ArmPkg/Library/SemihostLib/SemihostLib.inf
ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf
ArmPlatformPkg/ArmPlatformPkg-2ndstage.dsc
ArmPlatformPkg/ArmPlatformPkg-2ndstage.fdf
ArmPlatformPkg/ArmPlatformPkg.fdf
ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb-RTSM-MPCore.fdf
ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEb.c
ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbSecLibRTSM/ArmRealViewEbSec.c
ArmPlatformPkg/ArmRealViewEbPkg/Library/NorFlashArmRealViewEbLib/NorFlashArmRealViewEbLib.inf
ArmPlatformPkg/ArmRealViewEbPkg/Library/PL111LcdArmRealViewEbLib/PL111LcdArmRealViewEbLib.inf
ArmPlatformPkg/ArmRealViewEbPkg/Library/SysConfigArmRealViewEbLib/SysConfigArmRealViewEbLib.inf
ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A15.fdf
ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A15_MPCore.fdf
ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/ArmVExpressLib.inf
ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4.c
ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/RTSM.c
ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/RTSMMem.c
ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibCTA9x4/CTA9x4Sec.c
ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/ArmVExpressSecLib.inf
ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/RTSMSec.c
ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf
ArmPlatformPkg/ArmVExpressPkg/Library/HdLcdArmVExpressLib/HdLcdArmVExpressLib.inf
ArmPlatformPkg/ArmVExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpressLib.inf
ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpressLib.inf
ArmPlatformPkg/ArmVExpressPkg/Library/ResetSystemLib/ResetSystemLib.c
ArmPlatformPkg/ArmVExpressPkg/Library/ResetSystemLib/ResetSystemLib.inf
ArmPlatformPkg/Bds/Bds.inf
ArmPlatformPkg/Bds/BdsHelper.c
ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/LcdGraphicsOutputBlt.c
ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/LcdGraphicsOutputDxe.c
ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c
ArmPlatformPkg/Drivers/PL061GpioDxe/PL061Gpio.c
ArmPlatformPkg/Drivers/PL061GpioDxe/PL061GpioDxe.inf
ArmPlatformPkg/Drivers/SP804TimerDxe/SP804Timer.c
ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf
ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805Watchdog.c
ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf
ArmPlatformPkg/Include/Drivers/PL111Lcd.h
ArmPlatformPkg/Include/Drivers/PL301Axi.h
ArmPlatformPkg/Include/Drivers/PL341Dmc.h
ArmPlatformPkg/Include/Guid/ArmGlobalVariableHob.h
ArmPlatformPkg/Include/Library/ArmPlatformGlobalVariableLib.h
ArmPlatformPkg/Include/Library/ArmPlatformLib.h
ArmPlatformPkg/Include/Library/ArmPlatformSecLib.h
ArmPlatformPkg/Include/Library/ArmPlatformSysConfigLib.h
ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.c
ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.inf
ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.c
ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf
ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.c
ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.c
ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNull.c
ArmPlatformPkg/Library/ArmPlatformSecLibNull/ArmPlatformLibNullSec.c
ArmPlatformPkg/Library/DebugSecExtraActionLib/DebugSecExtraActionLib.inf
ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.c
ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.c
ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.inf
ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf
ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf
ArmPlatformPkg/Scripts/Ds5/build_report.py
ArmPlatformPkg/Scripts/Ds5/edk2_debugger.py
ArmPlatformPkg/Scripts/Ds5/firmware_volume.py
ArmPlatformPkg/Scripts/Ds5/system_table.py
ArmPlatformPkg/Sec/Sec.c
BeagleBoardPkg/BeagleBoardPkg.dec
BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoard.c
BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoardLib.inf
BeagleBoardPkg/Library/GdbSerialLib/GdbSerialLib.c
BeagleBoardPkg/Library/GdbSerialLib/GdbSerialLib.inf
BeagleBoardPkg/Sec/Cache.c
BeagleBoardPkg/Sec/Sec.inf
BeagleBoardPkg/Tools/generate_image.c
EmbeddedPkg/Ebl/Ebl.h
EmbeddedPkg/EmbeddedPkg.dsc
EmbeddedPkg/GdbStub/GdbStub.c
EmbeddedPkg/GdbStub/GdbStubInternal.h
EmbeddedPkg/GdbStub/Ia32/Processor.c
EmbeddedPkg/GdbStub/SerialIo.c
EmbeddedPkg/Include/Library/DebugAgentTimerLib.h
EmbeddedPkg/Include/Library/DmaLib.h
EmbeddedPkg/Include/Library/EblAddExternalCommandLib.h
EmbeddedPkg/Include/Library/EblCmdLib.h
EmbeddedPkg/Include/Library/EblNetworkLib.h
EmbeddedPkg/Include/Library/GdbSerialLib.h
EmbeddedPkg/Include/Library/PrePiLib.h
EmbeddedPkg/Include/Library/SerialPortExtLib.h
EmbeddedPkg/Include/Protocol/EblAddCommand.h
EmbeddedPkg/Include/Protocol/EmbeddedExternalDevice.h
EmbeddedPkg/Include/Protocol/EmbeddedGpio.h
EmbeddedPkg/Include/fdt.h
EmbeddedPkg/Include/libfdt.h
EmbeddedPkg/Include/libfdt_env.h
EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLib.c
EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.inf
EmbeddedPkg/Library/EblCmdLibNull/EblCmdLibNull.inf
EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.c
EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.inf
EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c
EmbeddedPkg/Library/FdtLib/fdt.c
EmbeddedPkg/Library/FdtLib/fdt_empty_tree.c
EmbeddedPkg/Library/FdtLib/fdt_ro.c
EmbeddedPkg/Library/FdtLib/fdt_rw.c
EmbeddedPkg/Library/FdtLib/fdt_strerror.c
EmbeddedPkg/Library/FdtLib/fdt_sw.c
EmbeddedPkg/Library/FdtLib/fdt_wip.c
EmbeddedPkg/Library/FdtLib/libfdt_internal.h
EmbeddedPkg/Library/GdbDebugAgent/Arm/ExceptionSupport.ARMv6.S
EmbeddedPkg/Library/GdbDebugAgent/Arm/ExceptionSupport.ARMv6.asm
EmbeddedPkg/Library/GdbDebugAgent/Arm/Processor.c
EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.h
EmbeddedPkg/Library/GdbDebugAgent/Ia32/Processor.c
EmbeddedPkg/Library/NullDmaLib/NullDmaLib.inf
EmbeddedPkg/Library/PrePiHobLib/Hob.c
EmbeddedPkg/Library/PrePiHobListPointerLib/PrePiHobListPointer.c
EmbeddedPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf
EmbeddedPkg/Library/PrePiLib/FwVol.c
EmbeddedPkg/Library/PrePiLib/PrePi.h
EmbeddedPkg/Library/PrePiLib/PrePiLib.c
EmbeddedPkg/Library/PrePiLib/ReportStatusCode.c
EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf
EmbeddedPkg/Library/TemplateResetSystemLib/TemplateResetSystemLib.inf
EmbeddedPkg/TemplateSec/TemplateSec.inf
EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf
Omap35xxPkg/Flash/Flash.c
Omap35xxPkg/Flash/Flash.h
Omap35xxPkg/Flash/Flash.inf
Omap35xxPkg/Gpio/Gpio.c
Omap35xxPkg/Gpio/Gpio.inf
Omap35xxPkg/Include/Library/OmapDmaLib.h
Omap35xxPkg/Include/Library/OmapLib.h
Omap35xxPkg/Include/Omap3530/Omap3530.h
Omap35xxPkg/Include/Omap3530/Omap3530Dma.h
Omap35xxPkg/Include/Omap3530/Omap3530Gpio.h
Omap35xxPkg/Include/Omap3530/Omap3530Gpmc.h
Omap35xxPkg/Include/Omap3530/Omap3530I2c.h
Omap35xxPkg/Include/Omap3530/Omap3530Interrupt.h
Omap35xxPkg/Include/Omap3530/Omap3530MMCHS.h
Omap35xxPkg/Include/Omap3530/Omap3530PadConfiguration.h
Omap35xxPkg/Include/Omap3530/Omap3530Prcm.h
Omap35xxPkg/Include/Omap3530/Omap3530Timer.h
Omap35xxPkg/Include/Omap3530/Omap3530Usb.h
Omap35xxPkg/Include/TPS65950.h
Omap35xxPkg/LcdGraphicsOutputDxe/LcdGraphicsOutputBlt.c
Omap35xxPkg/LcdGraphicsOutputDxe/LcdGraphicsOutputDxe.c
Omap35xxPkg/LcdGraphicsOutputDxe/LcdGraphicsOutputDxe.h
Omap35xxPkg/LcdGraphicsOutputDxe/LcdGraphicsOutputDxe.inf
Omap35xxPkg/Library/DebugAgentTimerLib/DebugAgentTimerLib.c
Omap35xxPkg/Library/DebugAgentTimerLib/DebugAgentTimerLib.inf
Omap35xxPkg/Library/GdbSerialLib/GdbSerialLib.c
Omap35xxPkg/Library/GdbSerialLib/GdbSerialLib.inf
Omap35xxPkg/Library/OmapDmaLib/OmapDmaLib.inf
Omap35xxPkg/Library/RealTimeClockLib/RealTimeClockLib.c
Omap35xxPkg/Library/RealTimeClockLib/RealTimeClockLib.inf
Omap35xxPkg/MMCHSDxe/MMCHS.c
Omap35xxPkg/MMCHSDxe/MMCHS.h
Omap35xxPkg/MMCHSDxe/MMCHS.inf
Omap35xxPkg/MmcHostDxe/MmcHostDxe.c
Omap35xxPkg/MmcHostDxe/MmcHostDxe.h
Omap35xxPkg/MmcHostDxe/MmcHostDxe.inf
Omap35xxPkg/Omap35xxPkg.dsc
Omap35xxPkg/PciEmulation/PciEmulation.c
Omap35xxPkg/PciEmulation/PciEmulation.h
Omap35xxPkg/PciEmulation/PciEmulation.inf
Omap35xxPkg/SmbusDxe/Smbus.c
Omap35xxPkg/SmbusDxe/Smbus.inf
Omap35xxPkg/TPS65950Dxe/TPS65950.c
Omap35xxPkg/TPS65950Dxe/TPS65950.inf
Omap35xxPkg/TimerDxe/Timer.c
Omap35xxPkg/TimerDxe/TimerDxe.inf

index b95d0a4dc00f925d01f915cce5d1569c028c749e..0d0b8b47463318810d9e57bb95769478c810b0e1 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 "LinuxInternal.h"
-
-#define DEFAULT_BOOT_ENTRY_DESCRIPTION  L"Linux"
-#define MAX_STR_INPUT                   300
-#define MAX_ASCII_INPUT                 300
-
-typedef enum {
-  LINUX_LOADER_NEW = 1,
-  LINUX_LOADER_UPDATE
-} LINUX_LOADER_ACTION;
-
-STATIC
-EFI_STATUS
-EditHIInputStr (
-  IN OUT CHAR16  *CmdLine,
-  IN     UINTN   MaxCmdLine
-  )
-{
-  UINTN           CmdLineIndex;
-  UINTN           WaitIndex;
-  CHAR8           Char;
-  EFI_INPUT_KEY   Key;
-  EFI_STATUS      Status;
-
-  Print (CmdLine);
-
-  for (CmdLineIndex = StrLen (CmdLine); CmdLineIndex < MaxCmdLine; ) {
-    Status = gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &WaitIndex);
-    ASSERT_EFI_ERROR (Status);
-
-    Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
-    ASSERT_EFI_ERROR (Status);
-
-    // Unicode character is valid when Scancode is NUll
-    if (Key.ScanCode == SCAN_NULL) {
-      // Scan code is NUll, hence read Unicode character
-      Char = (CHAR8)Key.UnicodeChar;
-    } else {
-      Char = CHAR_NULL;
-    }
-
-    if ((Char == CHAR_LINEFEED) || (Char == CHAR_CARRIAGE_RETURN) || (Char == 0x7f)) {
-      CmdLine[CmdLineIndex] = '\0';
-      Print (L"\n\r");
-
-      return EFI_SUCCESS;
-    } else if ((Key.UnicodeChar == L'\b') || (Key.ScanCode == SCAN_LEFT) || (Key.ScanCode == SCAN_DELETE)){
-      if (CmdLineIndex != 0) {
-        CmdLineIndex--;
-        Print (L"\b \b");
-      }
-    } else if ((Key.ScanCode == SCAN_ESC) || (Char == 0x1B) || (Char == 0x0)) {
-      return EFI_INVALID_PARAMETER;
-    } else {
-      CmdLine[CmdLineIndex++] = Key.UnicodeChar;
-      Print (L"%c", Key.UnicodeChar);
-    }
-  }
-
-  return EFI_SUCCESS;
-}
-
-STATIC
-EFI_STATUS
-EditHIInputAscii (
-  IN OUT CHAR8   *CmdLine,
-  IN     UINTN   MaxCmdLine
-  )
-{
-  CHAR16*     Str;
-  EFI_STATUS  Status;
-
-  Str = (CHAR16*)AllocatePool (MaxCmdLine * sizeof(CHAR16));
-  AsciiStrToUnicodeStr (CmdLine, Str);
-
-  Status = EditHIInputStr (Str, MaxCmdLine);
-
-  UnicodeStrToAsciiStr (Str, CmdLine);
-  FreePool (Str);
-
-  return Status;
-}
-
-STATIC
-EFI_STATUS
-GetHIInputInteger (
-  OUT UINTN   *Integer
-  )
-{
-  CHAR16      CmdLine[255];
-  EFI_STATUS  Status;
-
-  CmdLine[0] = '\0';
-  Status = EditHIInputStr (CmdLine, 255);
-  if (!EFI_ERROR(Status)) {
-    *Integer = StrDecimalToUintn (CmdLine);
-  }
-
-  return Status;
-}
-
-#if 0
-EFI_STATUS
-GenerateDeviceDescriptionName (
-  IN  EFI_HANDLE  Handle,
-  IN OUT CHAR16*  Description
-  )
-{
-  EFI_STATUS                        Status;
-  EFI_COMPONENT_NAME_PROTOCOL*      ComponentName2Protocol;
-  EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;
-  EFI_DEVICE_PATH_PROTOCOL*         DevicePathProtocol;
-  CHAR16*                           DriverName;
-  CHAR16*                           DevicePathTxt;
-  EFI_DEVICE_PATH*                  DevicePathNode;
-
-  ComponentName2Protocol = NULL;
-  Status = gBS->HandleProtocol (Handle, &gEfiComponentName2ProtocolGuid, (VOID **)&ComponentName2Protocol);
-  if (!EFI_ERROR(Status)) {
-    //TODO: Fixme. we must find the best langague
-    Status = ComponentName2Protocol->GetDriverName (ComponentName2Protocol,"en",&DriverName);
-    if (!EFI_ERROR(Status)) {
-      StrnCpy (Description,DriverName,BOOT_DEVICE_DESCRIPTION_MAX);
-    }
-  }
-
-  if (EFI_ERROR(Status)) {
-    // Use the lastest non null entry of the Device path as a description
-    Status = gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **)&DevicePathProtocol);
-    if (EFI_ERROR(Status)) {
-      return Status;
-    }
-
-    // Convert the last non end-type Device Path Node in text for the description
-    DevicePathNode = GetLastDevicePathNode (DevicePathProtocol);
-    Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
-    ASSERT_EFI_ERROR(Status);
-    DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText(DevicePathNode,TRUE,TRUE);
-    StrnCpy (Description, DevicePathTxt, BOOT_DEVICE_DESCRIPTION_MAX);
-    FreePool (DevicePathTxt);
-  }
-
-  return EFI_SUCCESS;
-}
-#endif
-
-EFI_STATUS
-LinuxLoaderConfig (
-  IN EFI_LOADED_IMAGE_PROTOCOL   *LoadedImage
-  )
-{
-  EFI_STATUS                   Status;
-  LINUX_LOADER_ACTION          Choice;
-  UINTN                        BootOrderSize;
-  UINT16*                      BootOrder;
-  UINTN                        BootOrderCount;
-  UINTN                        Index;
-  CHAR16                       Description[MAX_ASCII_INPUT];
-  CHAR8                        CmdLine[MAX_ASCII_INPUT];
-  CHAR16                       Initrd[MAX_STR_INPUT];
-  UINT16                       InitrdPathListLength;
-  UINT16                       CmdLineLength;
-  BDS_LOAD_OPTION*             BdsLoadOption;
-  BDS_LOAD_OPTION**            SupportedBdsLoadOptions;
-  UINTN                        SupportedBdsLoadOptionCount;
-  LINUX_LOADER_OPTIONAL_DATA*  LinuxOptionalData;
-  EFI_DEVICE_PATH*             DevicePathRoot;
-
-  SupportedBdsLoadOptions = NULL;
-  SupportedBdsLoadOptionCount = 0;
-
-  do {
-    Print (L"[%d] Create new Linux Boot Entry\n",LINUX_LOADER_NEW);
-    Print (L"[%d] Update Linux Boot Entry\n",LINUX_LOADER_UPDATE);
-
-    Print (L"Option: ");
-    Status = GetHIInputInteger (&Choice);
-    if (Status == EFI_INVALID_PARAMETER) {
-      Print (L"\n");
-      return Status;
-    } else if ((Choice != LINUX_LOADER_NEW) && (Choice != LINUX_LOADER_UPDATE)) {
-      Print (L"Error: the option should be either '%d' or '%d'\n",LINUX_LOADER_NEW,LINUX_LOADER_UPDATE);
-      Status = EFI_INVALID_PARAMETER;
-    }
-  } while (EFI_ERROR(Status));
-
-  if (Choice == LINUX_LOADER_UPDATE) {
-    // If no compatible entry then we just create a new entry
-    Choice = LINUX_LOADER_NEW;
-
-    // Scan the OptionalData of every entry for the correct signature
-    Status = GetEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder);
-    if (!EFI_ERROR(Status)) {
-      BootOrderCount = BootOrderSize / sizeof(UINT16);
-
-      // Allocate an array to handle maximum number of supported Boot Entry
-      SupportedBdsLoadOptions = (BDS_LOAD_OPTION**)AllocatePool(sizeof(BDS_LOAD_OPTION*) * BootOrderCount);
-
-      SupportedBdsLoadOptionCount = 0;
-
-      // Check if the signature is present in the list of the current Boot entries
-      for (Index = 0; Index < BootOrderCount; Index++) {
-        Status = BootOptionFromLoadOptionIndex (BootOrder[Index], &BdsLoadOption);
-        if (!EFI_ERROR(Status)) {
-          if ((BdsLoadOption->OptionalDataSize >= sizeof(UINT32)) &&
-              (*(UINT32*)BdsLoadOption->OptionalData == LINUX_LOADER_SIGNATURE)) {
-            SupportedBdsLoadOptions[SupportedBdsLoadOptionCount++] = BdsLoadOption;
-            Choice = LINUX_LOADER_UPDATE;
-          }
-        }
-      }
-    }
-    FreePool (BootOrder);
-  }
-
-  if (Choice == LINUX_LOADER_NEW) {
-    Description[0] = '\0';
-    CmdLine[0]     = '\0';
-    Initrd[0]      = '\0';
-
-    BdsLoadOption = (BDS_LOAD_OPTION*)AllocateZeroPool (sizeof(BDS_LOAD_OPTION));
-
-    DEBUG_CODE_BEGIN();
-      CHAR16*                           DevicePathTxt;
-      EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;
-
-      Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
-      ASSERT_EFI_ERROR(Status);
-      DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (LoadedImage->FilePath, TRUE, TRUE);
-
-      Print(L"EFI OS Loader: %s\n",DevicePathTxt);
-
-      FreePool(DevicePathTxt);
-    DEBUG_CODE_END();
-
-    //
-    // Fill the known fields of BdsLoadOption
-    //
-
-    BdsLoadOption->Attributes = LOAD_OPTION_ACTIVE | LOAD_OPTION_CATEGORY_BOOT;
-
-    // Get the full Device Path for this file
-    Status = gBS->HandleProtocol (LoadedImage->DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&DevicePathRoot);
-    ASSERT_EFI_ERROR(Status);
-
-    BdsLoadOption->FilePathList = AppendDevicePath (DevicePathRoot, LoadedImage->FilePath);
-    BdsLoadOption->FilePathListLength = GetDevicePathSize (BdsLoadOption->FilePathList);
-  } else {
-    if (SupportedBdsLoadOptionCount > 1) {
-      for (Index = 0; Index < SupportedBdsLoadOptionCount; Index++) {
-        Print (L"[%d] %s\n",Index + 1,SupportedBdsLoadOptions[Index]->Description);
-      }
-
-      do {
-        Print (L"Update Boot Entry: ");
-        Status = GetHIInputInteger (&Choice);
-        if (Status == EFI_INVALID_PARAMETER) {
-          Print (L"\n");
-          return Status;
-        } else if ((Choice < 1) && (Choice > SupportedBdsLoadOptionCount)) {
-          Print (L"Choose entry from 1 to %d\n",SupportedBdsLoadOptionCount);
-          Status = EFI_INVALID_PARAMETER;
-        }
-      } while (EFI_ERROR(Status));
-      BdsLoadOption = SupportedBdsLoadOptions[Choice-1];
-    }
-    StrnCpy (Description, BdsLoadOption->Description, MAX_STR_INPUT);
-
-    LinuxOptionalData = (LINUX_LOADER_OPTIONAL_DATA*)BdsLoadOption->OptionalData;
-    if (LinuxOptionalData->CmdLineLength > 0) {
-      CopyMem (CmdLine, (CHAR8*)LinuxOptionalData + sizeof(LINUX_LOADER_OPTIONAL_DATA), LinuxOptionalData->CmdLineLength);
-    } else {
-      CmdLine[0] = '\0';
-    }
-
-    if (LinuxOptionalData->InitrdPathListLength > 0) {
-      CopyMem (Initrd, (CHAR8*)LinuxOptionalData + sizeof(LINUX_LOADER_OPTIONAL_DATA) + LinuxOptionalData->CmdLineLength, LinuxOptionalData->InitrdPathListLength);
-    } else {
-      Initrd[0] = L'\0';
-    }
-    DEBUG((EFI_D_ERROR,"L\n"));
-  }
-
-  // Description
-  Print (L"Description: ");
-  Status = EditHIInputStr (Description, MAX_STR_INPUT);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-  if (StrLen (Description) == 0) {
-    StrnCpy (Description, DEFAULT_BOOT_ENTRY_DESCRIPTION, MAX_STR_INPUT);
-  }
-  BdsLoadOption->Description = Description;
-
-  // CmdLine
-  Print (L"Command Line: ");
-  Status = EditHIInputAscii (CmdLine, MAX_ASCII_INPUT);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  // Initrd
-  Print (L"Initrd name: ");
-  Status = EditHIInputStr (Initrd, MAX_STR_INPUT);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  CmdLineLength = AsciiStrLen (CmdLine);
-  if (CmdLineLength > 0) {
-    CmdLineLength += sizeof(CHAR8);
-  }
-
-  InitrdPathListLength = StrLen (Initrd) * sizeof(CHAR16);
-  if (InitrdPathListLength > 0) {
-    InitrdPathListLength += sizeof(CHAR16);
-  }
-
-  BdsLoadOption->OptionalDataSize = sizeof(LINUX_LOADER_OPTIONAL_DATA) + CmdLineLength + InitrdPathListLength;
-
-  LinuxOptionalData = (LINUX_LOADER_OPTIONAL_DATA*)AllocatePool (BdsLoadOption->OptionalDataSize);
-  BdsLoadOption->OptionalData = LinuxOptionalData;
-
-  LinuxOptionalData->Signature = LINUX_LOADER_SIGNATURE;
-  LinuxOptionalData->CmdLineLength = CmdLineLength;
-  LinuxOptionalData->InitrdPathListLength = InitrdPathListLength;
-
-  if (CmdLineLength > 0) {
-    CopyMem (LinuxOptionalData + 1, CmdLine, CmdLineLength);
-  }
-  if (InitrdPathListLength > 0) {
-    CopyMem ((UINT8*)(LinuxOptionalData + 1) + CmdLineLength, Initrd, InitrdPathListLength);
-  }
-
-  // Create or Update the boot entry
-  Status = BootOptionToLoadOptionVariable (BdsLoadOption);
-
-  return Status;
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include "LinuxInternal.h"\r
+\r
+#define DEFAULT_BOOT_ENTRY_DESCRIPTION  L"Linux"\r
+#define MAX_STR_INPUT                   300\r
+#define MAX_ASCII_INPUT                 300\r
+\r
+typedef enum {\r
+  LINUX_LOADER_NEW = 1,\r
+  LINUX_LOADER_UPDATE\r
+} LINUX_LOADER_ACTION;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EditHIInputStr (\r
+  IN OUT CHAR16  *CmdLine,\r
+  IN     UINTN   MaxCmdLine\r
+  )\r
+{\r
+  UINTN           CmdLineIndex;\r
+  UINTN           WaitIndex;\r
+  CHAR8           Char;\r
+  EFI_INPUT_KEY   Key;\r
+  EFI_STATUS      Status;\r
+\r
+  Print (CmdLine);\r
+\r
+  for (CmdLineIndex = StrLen (CmdLine); CmdLineIndex < MaxCmdLine; ) {\r
+    Status = gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &WaitIndex);\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    // Unicode character is valid when Scancode is NUll\r
+    if (Key.ScanCode == SCAN_NULL) {\r
+      // Scan code is NUll, hence read Unicode character\r
+      Char = (CHAR8)Key.UnicodeChar;\r
+    } else {\r
+      Char = CHAR_NULL;\r
+    }\r
+\r
+    if ((Char == CHAR_LINEFEED) || (Char == CHAR_CARRIAGE_RETURN) || (Char == 0x7f)) {\r
+      CmdLine[CmdLineIndex] = '\0';\r
+      Print (L"\n\r");\r
+\r
+      return EFI_SUCCESS;\r
+    } else if ((Key.UnicodeChar == L'\b') || (Key.ScanCode == SCAN_LEFT) || (Key.ScanCode == SCAN_DELETE)){\r
+      if (CmdLineIndex != 0) {\r
+        CmdLineIndex--;\r
+        Print (L"\b \b");\r
+      }\r
+    } else if ((Key.ScanCode == SCAN_ESC) || (Char == 0x1B) || (Char == 0x0)) {\r
+      return EFI_INVALID_PARAMETER;\r
+    } else {\r
+      CmdLine[CmdLineIndex++] = Key.UnicodeChar;\r
+      Print (L"%c", Key.UnicodeChar);\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EditHIInputAscii (\r
+  IN OUT CHAR8   *CmdLine,\r
+  IN     UINTN   MaxCmdLine\r
+  )\r
+{\r
+  CHAR16*     Str;\r
+  EFI_STATUS  Status;\r
+\r
+  Str = (CHAR16*)AllocatePool (MaxCmdLine * sizeof(CHAR16));\r
+  AsciiStrToUnicodeStr (CmdLine, Str);\r
+\r
+  Status = EditHIInputStr (Str, MaxCmdLine);\r
+\r
+  UnicodeStrToAsciiStr (Str, CmdLine);\r
+  FreePool (Str);\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+GetHIInputInteger (\r
+  OUT UINTN   *Integer\r
+  )\r
+{\r
+  CHAR16      CmdLine[255];\r
+  EFI_STATUS  Status;\r
+\r
+  CmdLine[0] = '\0';\r
+  Status = EditHIInputStr (CmdLine, 255);\r
+  if (!EFI_ERROR(Status)) {\r
+    *Integer = StrDecimalToUintn (CmdLine);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+#if 0\r
+EFI_STATUS\r
+GenerateDeviceDescriptionName (\r
+  IN  EFI_HANDLE  Handle,\r
+  IN OUT CHAR16*  Description\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  EFI_COMPONENT_NAME_PROTOCOL*      ComponentName2Protocol;\r
+  EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
+  EFI_DEVICE_PATH_PROTOCOL*         DevicePathProtocol;\r
+  CHAR16*                           DriverName;\r
+  CHAR16*                           DevicePathTxt;\r
+  EFI_DEVICE_PATH*                  DevicePathNode;\r
+\r
+  ComponentName2Protocol = NULL;\r
+  Status = gBS->HandleProtocol (Handle, &gEfiComponentName2ProtocolGuid, (VOID **)&ComponentName2Protocol);\r
+  if (!EFI_ERROR(Status)) {\r
+    //TODO: Fixme. we must find the best langague\r
+    Status = ComponentName2Protocol->GetDriverName (ComponentName2Protocol,"en",&DriverName);\r
+    if (!EFI_ERROR(Status)) {\r
+      StrnCpy (Description,DriverName,BOOT_DEVICE_DESCRIPTION_MAX);\r
+    }\r
+  }\r
+\r
+  if (EFI_ERROR(Status)) {\r
+    // Use the lastest non null entry of the Device path as a description\r
+    Status = gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **)&DevicePathProtocol);\r
+    if (EFI_ERROR(Status)) {\r
+      return Status;\r
+    }\r
+\r
+    // Convert the last non end-type Device Path Node in text for the description\r
+    DevicePathNode = GetLastDevicePathNode (DevicePathProtocol);\r
+    Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
+    ASSERT_EFI_ERROR(Status);\r
+    DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText(DevicePathNode,TRUE,TRUE);\r
+    StrnCpy (Description, DevicePathTxt, BOOT_DEVICE_DESCRIPTION_MAX);\r
+    FreePool (DevicePathTxt);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+#endif\r
+\r
+EFI_STATUS\r
+LinuxLoaderConfig (\r
+  IN EFI_LOADED_IMAGE_PROTOCOL   *LoadedImage\r
+  )\r
+{\r
+  EFI_STATUS                   Status;\r
+  LINUX_LOADER_ACTION          Choice;\r
+  UINTN                        BootOrderSize;\r
+  UINT16*                      BootOrder;\r
+  UINTN                        BootOrderCount;\r
+  UINTN                        Index;\r
+  CHAR16                       Description[MAX_ASCII_INPUT];\r
+  CHAR8                        CmdLine[MAX_ASCII_INPUT];\r
+  CHAR16                       Initrd[MAX_STR_INPUT];\r
+  UINT16                       InitrdPathListLength;\r
+  UINT16                       CmdLineLength;\r
+  BDS_LOAD_OPTION*             BdsLoadOption;\r
+  BDS_LOAD_OPTION**            SupportedBdsLoadOptions;\r
+  UINTN                        SupportedBdsLoadOptionCount;\r
+  LINUX_LOADER_OPTIONAL_DATA*  LinuxOptionalData;\r
+  EFI_DEVICE_PATH*             DevicePathRoot;\r
+\r
+  SupportedBdsLoadOptions = NULL;\r
+  SupportedBdsLoadOptionCount = 0;\r
+\r
+  do {\r
+    Print (L"[%d] Create new Linux Boot Entry\n",LINUX_LOADER_NEW);\r
+    Print (L"[%d] Update Linux Boot Entry\n",LINUX_LOADER_UPDATE);\r
+\r
+    Print (L"Option: ");\r
+    Status = GetHIInputInteger (&Choice);\r
+    if (Status == EFI_INVALID_PARAMETER) {\r
+      Print (L"\n");\r
+      return Status;\r
+    } else if ((Choice != LINUX_LOADER_NEW) && (Choice != LINUX_LOADER_UPDATE)) {\r
+      Print (L"Error: the option should be either '%d' or '%d'\n",LINUX_LOADER_NEW,LINUX_LOADER_UPDATE);\r
+      Status = EFI_INVALID_PARAMETER;\r
+    }\r
+  } while (EFI_ERROR(Status));\r
+\r
+  if (Choice == LINUX_LOADER_UPDATE) {\r
+    // If no compatible entry then we just create a new entry\r
+    Choice = LINUX_LOADER_NEW;\r
+\r
+    // Scan the OptionalData of every entry for the correct signature\r
+    Status = GetEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder);\r
+    if (!EFI_ERROR(Status)) {\r
+      BootOrderCount = BootOrderSize / sizeof(UINT16);\r
+\r
+      // Allocate an array to handle maximum number of supported Boot Entry\r
+      SupportedBdsLoadOptions = (BDS_LOAD_OPTION**)AllocatePool(sizeof(BDS_LOAD_OPTION*) * BootOrderCount);\r
+\r
+      SupportedBdsLoadOptionCount = 0;\r
+\r
+      // Check if the signature is present in the list of the current Boot entries\r
+      for (Index = 0; Index < BootOrderCount; Index++) {\r
+        Status = BootOptionFromLoadOptionIndex (BootOrder[Index], &BdsLoadOption);\r
+        if (!EFI_ERROR(Status)) {\r
+          if ((BdsLoadOption->OptionalDataSize >= sizeof(UINT32)) &&\r
+              (*(UINT32*)BdsLoadOption->OptionalData == LINUX_LOADER_SIGNATURE)) {\r
+            SupportedBdsLoadOptions[SupportedBdsLoadOptionCount++] = BdsLoadOption;\r
+            Choice = LINUX_LOADER_UPDATE;\r
+          }\r
+        }\r
+      }\r
+    }\r
+    FreePool (BootOrder);\r
+  }\r
+\r
+  if (Choice == LINUX_LOADER_NEW) {\r
+    Description[0] = '\0';\r
+    CmdLine[0]     = '\0';\r
+    Initrd[0]      = '\0';\r
+\r
+    BdsLoadOption = (BDS_LOAD_OPTION*)AllocateZeroPool (sizeof(BDS_LOAD_OPTION));\r
+\r
+    DEBUG_CODE_BEGIN();\r
+      CHAR16*                           DevicePathTxt;\r
+      EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
+\r
+      Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
+      ASSERT_EFI_ERROR(Status);\r
+      DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (LoadedImage->FilePath, TRUE, TRUE);\r
+\r
+      Print(L"EFI OS Loader: %s\n",DevicePathTxt);\r
+\r
+      FreePool(DevicePathTxt);\r
+    DEBUG_CODE_END();\r
+\r
+    //\r
+    // Fill the known fields of BdsLoadOption\r
+    //\r
+\r
+    BdsLoadOption->Attributes = LOAD_OPTION_ACTIVE | LOAD_OPTION_CATEGORY_BOOT;\r
+\r
+    // Get the full Device Path for this file\r
+    Status = gBS->HandleProtocol (LoadedImage->DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&DevicePathRoot);\r
+    ASSERT_EFI_ERROR(Status);\r
+\r
+    BdsLoadOption->FilePathList = AppendDevicePath (DevicePathRoot, LoadedImage->FilePath);\r
+    BdsLoadOption->FilePathListLength = GetDevicePathSize (BdsLoadOption->FilePathList);\r
+  } else {\r
+    if (SupportedBdsLoadOptionCount > 1) {\r
+      for (Index = 0; Index < SupportedBdsLoadOptionCount; Index++) {\r
+        Print (L"[%d] %s\n",Index + 1,SupportedBdsLoadOptions[Index]->Description);\r
+      }\r
+\r
+      do {\r
+        Print (L"Update Boot Entry: ");\r
+        Status = GetHIInputInteger (&Choice);\r
+        if (Status == EFI_INVALID_PARAMETER) {\r
+          Print (L"\n");\r
+          return Status;\r
+        } else if ((Choice < 1) && (Choice > SupportedBdsLoadOptionCount)) {\r
+          Print (L"Choose entry from 1 to %d\n",SupportedBdsLoadOptionCount);\r
+          Status = EFI_INVALID_PARAMETER;\r
+        }\r
+      } while (EFI_ERROR(Status));\r
+      BdsLoadOption = SupportedBdsLoadOptions[Choice-1];\r
+    }\r
+    StrnCpy (Description, BdsLoadOption->Description, MAX_STR_INPUT);\r
+\r
+    LinuxOptionalData = (LINUX_LOADER_OPTIONAL_DATA*)BdsLoadOption->OptionalData;\r
+    if (LinuxOptionalData->CmdLineLength > 0) {\r
+      CopyMem (CmdLine, (CHAR8*)LinuxOptionalData + sizeof(LINUX_LOADER_OPTIONAL_DATA), LinuxOptionalData->CmdLineLength);\r
+    } else {\r
+      CmdLine[0] = '\0';\r
+    }\r
+\r
+    if (LinuxOptionalData->InitrdPathListLength > 0) {\r
+      CopyMem (Initrd, (CHAR8*)LinuxOptionalData + sizeof(LINUX_LOADER_OPTIONAL_DATA) + LinuxOptionalData->CmdLineLength, LinuxOptionalData->InitrdPathListLength);\r
+    } else {\r
+      Initrd[0] = L'\0';\r
+    }\r
+    DEBUG((EFI_D_ERROR,"L\n"));\r
+  }\r
+\r
+  // Description\r
+  Print (L"Description: ");\r
+  Status = EditHIInputStr (Description, MAX_STR_INPUT);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+  if (StrLen (Description) == 0) {\r
+    StrnCpy (Description, DEFAULT_BOOT_ENTRY_DESCRIPTION, MAX_STR_INPUT);\r
+  }\r
+  BdsLoadOption->Description = Description;\r
+\r
+  // CmdLine\r
+  Print (L"Command Line: ");\r
+  Status = EditHIInputAscii (CmdLine, MAX_ASCII_INPUT);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  // Initrd\r
+  Print (L"Initrd name: ");\r
+  Status = EditHIInputStr (Initrd, MAX_STR_INPUT);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  CmdLineLength = AsciiStrLen (CmdLine);\r
+  if (CmdLineLength > 0) {\r
+    CmdLineLength += sizeof(CHAR8);\r
+  }\r
+\r
+  InitrdPathListLength = StrLen (Initrd) * sizeof(CHAR16);\r
+  if (InitrdPathListLength > 0) {\r
+    InitrdPathListLength += sizeof(CHAR16);\r
+  }\r
+\r
+  BdsLoadOption->OptionalDataSize = sizeof(LINUX_LOADER_OPTIONAL_DATA) + CmdLineLength + InitrdPathListLength;\r
+\r
+  LinuxOptionalData = (LINUX_LOADER_OPTIONAL_DATA*)AllocatePool (BdsLoadOption->OptionalDataSize);\r
+  BdsLoadOption->OptionalData = LinuxOptionalData;\r
+\r
+  LinuxOptionalData->Signature = LINUX_LOADER_SIGNATURE;\r
+  LinuxOptionalData->CmdLineLength = CmdLineLength;\r
+  LinuxOptionalData->InitrdPathListLength = InitrdPathListLength;\r
+\r
+  if (CmdLineLength > 0) {\r
+    CopyMem (LinuxOptionalData + 1, CmdLine, CmdLineLength);\r
+  }\r
+  if (InitrdPathListLength > 0) {\r
+    CopyMem ((UINT8*)(LinuxOptionalData + 1) + CmdLineLength, Initrd, InitrdPathListLength);\r
+  }\r
+\r
+  // Create or Update the boot entry\r
+  Status = BootOptionToLoadOptionVariable (BdsLoadOption);\r
+\r
+  return Status;\r
+}\r
index e4862735207b804a9ef727b0ea00f10df8022a58..28673b561efb151a7079d439cb07400e57261d95 100644 (file)
@@ -1,49 +1,49 @@
-/** @file
-*
-*  Copyright (c) 2011, ARM Limited. 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.
-*
-**/
-
-#ifndef __LOADER_INTERNAL_H
-#define __LOADER_INTERNAL_H
-
-#include <Uefi.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/BdsLib.h>
-#include <Library/DebugLib.h>
-#include <Library/DevicePathLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiLib.h>
-
-#include <Protocol/LoadedImage.h>
-
-#define LINUX_KERNEL_NAME               L"zImage"
-#define FDT_NAME                        L"platform.dtb"
-
-#define LINUX_LOADER_SIGNATURE    SIGNATURE_32('l', 'i', 'l', 'o')
-
-typedef struct {
-  UINT32                        Signature;
-  UINT16                        CmdLineLength;
-  UINT16                        InitrdPathListLength;
-
-  // These following fields have variable length:
-  //CHAR8*                      CmdLine;
-  //CHAR16*                     Initrd;
-} LINUX_LOADER_OPTIONAL_DATA;
-
-EFI_STATUS
-LinuxLoaderConfig (
-  IN EFI_LOADED_IMAGE_PROTOCOL   *LoadedImage
-  );
-
-#endif
+/** @file\r
+*\r
+*  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+*\r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*\r
+**/\r
+\r
+#ifndef __LOADER_INTERNAL_H\r
+#define __LOADER_INTERNAL_H\r
+\r
+#include <Uefi.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/BdsLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+\r
+#include <Protocol/LoadedImage.h>\r
+\r
+#define LINUX_KERNEL_NAME               L"zImage"\r
+#define FDT_NAME                        L"platform.dtb"\r
+\r
+#define LINUX_LOADER_SIGNATURE    SIGNATURE_32('l', 'i', 'l', 'o')\r
+\r
+typedef struct {\r
+  UINT32                        Signature;\r
+  UINT16                        CmdLineLength;\r
+  UINT16                        InitrdPathListLength;\r
+\r
+  // These following fields have variable length:\r
+  //CHAR8*                      CmdLine;\r
+  //CHAR16*                     Initrd;\r
+} LINUX_LOADER_OPTIONAL_DATA;\r
+\r
+EFI_STATUS\r
+LinuxLoaderConfig (\r
+  IN EFI_LOADED_IMAGE_PROTOCOL   *LoadedImage\r
+  );\r
+\r
+#endif\r
index abc25a69ab0bf9007cbe17e42d0303c430a9f788..a2433df8692e2983f8766362e30dfa9f6bc9b08c 100644 (file)
-#/** @file
-# ARM processor package.
-#
-# Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>
-#
-#    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                  = ArmPkg
-  PLATFORM_GUID                  = 5CFBD99E-3C43-4E7F-8054-9CDEAFF7710F
-  PLATFORM_VERSION               = 0.1
-  DSC_SPECIFICATION              = 0x00010005
-  OUTPUT_DIRECTORY               = Build/Arm
-  SUPPORTED_ARCHITECTURES        = ARM
-  BUILD_TARGETS                  = DEBUG|RELEASE
-  SKUID_IDENTIFIER               = DEFAULT
-
-[BuildOptions]
-  XCODE:*_*_ARM_PLATFORM_FLAGS  == -arch armv7
-  XCODE:RELEASE_*_*_CC_FLAGS     = -DMDEPKG_NDEBUG 
-  
-  GCC:*_*_ARM_PLATFORM_FLAGS    == -march=armv7-a -mfpu=neon
-  GCC:RELEASE_*_*_CC_FLAGS     = -DMDEPKG_NDEBUG 
-
-  RVCT:*_*_ARM_PLATFORM_FLAGS  == --cpu Cortex-A8
-  RVCT:RELEASE_*_*_CC_FLAGS  = -DMDEPKG_NDEBUG 
-
-[LibraryClasses.common]
-  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
-  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
-  CacheMaintenanceLib|ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf
-  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
-  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
-  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
-  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
-  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
-  TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
-  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
-  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
-  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
-  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
-  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
-  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
-
-  SemihostLib|ArmPkg/Library/SemihostLib/SemihostLib.inf
-  UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf
-  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
-  DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf
-
-  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf
-  CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
-  ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf
-  DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
-  ArmTrustZoneLib|ArmPkg/Library/ArmTrustZoneLib/ArmTrustZoneLib.inf
-
-  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
-  PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf
-  # TODO: Check if we cannot remove this dependancy (Mayve using the SerialLibNull implementation makes the EFI application do not print)
-  SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf
-
-  BdsLib|ArmPkg/Library/BdsLib/BdsLib.inf
-  FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf
-  
-  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
-
-[LibraryClasses.common.PEIM]
-  HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
-  PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf
-  MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf
-  PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf
-  PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf
-
-[LibraryClasses.common.DXE_DRIVER]
-  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.inf
-
-[LibraryClasses.ARM]
-  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
-
-[Components.common]
-  ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf
-  ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf
-  ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
-#  ArmPkg/Library/ArmLib/Arm11/Arm11ArmLib.inf
-#  ArmPkg/Library/ArmLib/Arm11/Arm11ArmLibPrePi.inf
-#  ArmPkg/Library/ArmLib/Arm9/Arm9ArmLib.inf
-#  ArmPkg/Library/ArmLib/Arm9/Arm9ArmLibPrePi.inf
-  ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf
-  ArmPkg/Library/ArmLib/ArmV7/ArmV7LibPrePi.inf
-  ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf
-  ArmPkg/Library/ArmLib/Null/NullArmLib.inf
-  ArmPkg/Library/BaseMemoryLibStm/BaseMemoryLibStm.inf
-  ArmPkg/Library/BaseMemoryLibVstm/BaseMemoryLibVstm.inf
-  ArmPkg/Library/BasePeCoffLib/BasePeCoffLib.inf
-  ArmPkg/Library/BdsLib/BdsLib.inf
-  ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
-  ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.inf
-  ArmPkg/Library/DebugUncachedMemoryAllocationLib/DebugUncachedMemoryAllocationLib.inf
-  ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf
-  ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.inf
-  ArmPkg/Library/SemiHostingDebugLib/SemiHostingDebugLib.inf
-  ArmPkg/Library/SemiHostingSerialPortLib/SemiHostingSerialPortLib.inf
-  ArmPkg/Library/SemihostLib/SemihostLib.inf
-  ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf
-
-  ArmPkg/Drivers/ArmCpuLib/ArmCortexA8Lib/ArmCortexA8Lib.inf
-  ArmPkg/Drivers/ArmCpuLib/ArmCortexA9Lib/ArmCortexA9Lib.inf
-  ArmPkg/Drivers/ArmCpuLib/ArmCortexA15Lib/ArmCortexA15Lib.inf
-  ArmPkg/Drivers/CpuDxe/CpuDxe.inf
-  ArmPkg/Drivers/CpuPei/CpuPei.inf
-  ArmPkg/Drivers/PL390Gic/PL390GicDxe.inf
-  ArmPkg/Drivers/PL390Gic/PL390GicLib.inf
-  ArmPkg/Drivers/PL390Gic/PL390GicSecLib.inf
-  ArmPkg/Drivers/TimerDxe/TimerDxe.inf
-
-  ArmPkg/Filesystem/SemihostFs/SemihostFs.inf
-
-  ArmPkg/Application/LinuxLoader/LinuxAtagLoader.inf
-  ArmPkg/Application/LinuxLoader/LinuxFdtLoader.inf
+#/** @file\r
+# ARM processor package.\r
+#\r
+# Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>\r
+#\r
+#    This program and the accompanying materials\r
+#    are licensed and made available under the terms and conditions of the BSD License\r
+#    which accompanies this distribution. The full text of the license may be found at\r
+#    http://opensource.org/licenses/bsd-license.php\r
+#\r
+#    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  PLATFORM_NAME                  = ArmPkg\r
+  PLATFORM_GUID                  = 5CFBD99E-3C43-4E7F-8054-9CDEAFF7710F\r
+  PLATFORM_VERSION               = 0.1\r
+  DSC_SPECIFICATION              = 0x00010005\r
+  OUTPUT_DIRECTORY               = Build/Arm\r
+  SUPPORTED_ARCHITECTURES        = ARM\r
+  BUILD_TARGETS                  = DEBUG|RELEASE\r
+  SKUID_IDENTIFIER               = DEFAULT\r
+\r
+[BuildOptions]\r
+  XCODE:*_*_ARM_PLATFORM_FLAGS  == -arch armv7\r
+  XCODE:RELEASE_*_*_CC_FLAGS     = -DMDEPKG_NDEBUG \r
+  \r
+  GCC:*_*_ARM_PLATFORM_FLAGS    == -march=armv7-a -mfpu=neon\r
+  GCC:RELEASE_*_*_CC_FLAGS     = -DMDEPKG_NDEBUG \r
+\r
+  RVCT:*_*_ARM_PLATFORM_FLAGS  == --cpu Cortex-A8\r
+  RVCT:RELEASE_*_*_CC_FLAGS  = -DMDEPKG_NDEBUG \r
+\r
+[LibraryClasses.common]\r
+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf\r
+  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf\r
+  CacheMaintenanceLib|ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf\r
+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf\r
+  TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf\r
+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
+  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf\r
+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf\r
+\r
+  SemihostLib|ArmPkg/Library/SemihostLib/SemihostLib.inf\r
+  UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf\r
+  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
+  DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf\r
+\r
+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf\r
+  CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf\r
+  ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf\r
+  DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf\r
+  ArmTrustZoneLib|ArmPkg/Library/ArmTrustZoneLib/ArmTrustZoneLib.inf\r
+\r
+  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf\r
+  PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf\r
+  # TODO: Check if we cannot remove this dependancy (Mayve using the SerialLibNull implementation makes the EFI application do not print)\r
+  SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf\r
+\r
+  BdsLib|ArmPkg/Library/BdsLib/BdsLib.inf\r
+  FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf\r
+  \r
+  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf\r
+\r
+[LibraryClasses.common.PEIM]\r
+  HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
+  PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf\r
+  MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf\r
+  PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf\r
+  PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf\r
+\r
+[LibraryClasses.common.DXE_DRIVER]\r
+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.inf\r
+\r
+[LibraryClasses.ARM]\r
+  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf\r
+\r
+[Components.common]\r
+  ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf\r
+  ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf\r
+  ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf\r
+#  ArmPkg/Library/ArmLib/Arm11/Arm11ArmLib.inf\r
+#  ArmPkg/Library/ArmLib/Arm11/Arm11ArmLibPrePi.inf\r
+#  ArmPkg/Library/ArmLib/Arm9/Arm9ArmLib.inf\r
+#  ArmPkg/Library/ArmLib/Arm9/Arm9ArmLibPrePi.inf\r
+  ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf\r
+  ArmPkg/Library/ArmLib/ArmV7/ArmV7LibPrePi.inf\r
+  ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf\r
+  ArmPkg/Library/ArmLib/Null/NullArmLib.inf\r
+  ArmPkg/Library/BaseMemoryLibStm/BaseMemoryLibStm.inf\r
+  ArmPkg/Library/BaseMemoryLibVstm/BaseMemoryLibVstm.inf\r
+  ArmPkg/Library/BasePeCoffLib/BasePeCoffLib.inf\r
+  ArmPkg/Library/BdsLib/BdsLib.inf\r
+  ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf\r
+  ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.inf\r
+  ArmPkg/Library/DebugUncachedMemoryAllocationLib/DebugUncachedMemoryAllocationLib.inf\r
+  ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf\r
+  ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.inf\r
+  ArmPkg/Library/SemiHostingDebugLib/SemiHostingDebugLib.inf\r
+  ArmPkg/Library/SemiHostingSerialPortLib/SemiHostingSerialPortLib.inf\r
+  ArmPkg/Library/SemihostLib/SemihostLib.inf\r
+  ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf\r
+\r
+  ArmPkg/Drivers/ArmCpuLib/ArmCortexA8Lib/ArmCortexA8Lib.inf\r
+  ArmPkg/Drivers/ArmCpuLib/ArmCortexA9Lib/ArmCortexA9Lib.inf\r
+  ArmPkg/Drivers/ArmCpuLib/ArmCortexA15Lib/ArmCortexA15Lib.inf\r
+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf\r
+  ArmPkg/Drivers/CpuPei/CpuPei.inf\r
+  ArmPkg/Drivers/PL390Gic/PL390GicDxe.inf\r
+  ArmPkg/Drivers/PL390Gic/PL390GicLib.inf\r
+  ArmPkg/Drivers/PL390Gic/PL390GicSecLib.inf\r
+  ArmPkg/Drivers/TimerDxe/TimerDxe.inf\r
+\r
+  ArmPkg/Filesystem/SemihostFs/SemihostFs.inf\r
+\r
+  ArmPkg/Application/LinuxLoader/LinuxAtagLoader.inf\r
+  ArmPkg/Application/LinuxLoader/LinuxFdtLoader.inf\r
index 96bd68246f91a65fd0eb66e01df2c354ad654549..2b439f3331b63871a4e4e280dc8807d71faa4f33 100644 (file)
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-.text
-.align 3
-
-GCC_ASM_EXPORT(ExceptionHandlersStart)
-GCC_ASM_EXPORT(ExceptionHandlersEnd)
-GCC_ASM_EXPORT(CommonExceptionEntry)
-GCC_ASM_EXPORT(AsmCommonExceptionEntry)
-GCC_ASM_EXPORT(CommonCExceptionHandler)
-
-ASM_PFX(ExceptionHandlersStart):
-
-ASM_PFX(Reset):
-  b ASM_PFX(ResetEntry)
-
-ASM_PFX(UndefinedInstruction):
-  b ASM_PFX(UndefinedInstructionEntry)
-
-ASM_PFX(SoftwareInterrupt):
-  b ASM_PFX(SoftwareInterruptEntry)
-
-ASM_PFX(PrefetchAbort):
-  b ASM_PFX(PrefetchAbortEntry)
-
-ASM_PFX(DataAbort):
-  b ASM_PFX(DataAbortEntry)
-
-ASM_PFX(ReservedException):
-  b ASM_PFX(ReservedExceptionEntry)
-
-ASM_PFX(Irq):
-  b ASM_PFX(IrqEntry)
-
-ASM_PFX(Fiq):
-  b ASM_PFX(FiqEntry)
-
-ASM_PFX(ResetEntry):
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-  
-  mov       R0,#0
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(UndefinedInstructionEntry):
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       r0,#1
-  ldr       r1,ASM_PFX(CommonExceptionEntry)
-  bx        r1
-
-ASM_PFX(SoftwareInterruptEntry):
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       r0,#2
-  ldr       r1,ASM_PFX(CommonExceptionEntry)
-  bx        r1
-
-ASM_PFX(PrefetchAbortEntry):
-  sub       LR,LR,#4
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       r0,#3
-  ldr       r1,ASM_PFX(CommonExceptionEntry)
-  bx        r1
-
-ASM_PFX(DataAbortEntry):
-  sub       LR,LR,#8
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       r0,#4
-  ldr       r1,ASM_PFX(CommonExceptionEntry)
-  bx        r1
-
-ASM_PFX(ReservedExceptionEntry):
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       r0,#5
-  ldr       r1,ASM_PFX(CommonExceptionEntry)
-  bx        r1
-
-ASM_PFX(IrqEntry):
-  sub       LR,LR,#4
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       r0,#6
-  ldr       r1,ASM_PFX(CommonExceptionEntry)
-  bx        r1
-
-ASM_PFX(FiqEntry):
-  sub       LR,LR,#4
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       r0,#7
-  ldr       r1,ASM_PFX(CommonExceptionEntry)
-  bx        r1
-
-ASM_PFX(CommonExceptionEntry):
-  .byte       0x12
-  .byte       0x34
-  .byte       0x56
-  .byte       0x78
-
-ASM_PFX(ExceptionHandlersEnd):
-
-ASM_PFX(AsmCommonExceptionEntry):
-  mrc       p15, 0, R1, c6, c0, 2   @ Read IFAR
-  str       R1, [SP, #0x50]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFAR 
-  
-  mrc       p15, 0, R1, c5, c0, 1   @ Read IFSR
-  str       R1, [SP, #0x4c]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFSR
-  
-  mrc       p15, 0, R1, c6, c0, 0   @ Read DFAR
-  str       R1, [SP, #0x48]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFAR
-  
-  mrc       p15, 0, R1, c5, c0, 0   @ Read DFSR
-  str       R1, [SP, #0x44]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFSR
-  
-  ldr       R1, [SP, #0x5c]         @ srsdb saved pre-exception CPSR on the stack 
-  str       R1, [SP, #0x40]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.CPSR
-  and       r1, r1, #0x1f           @ Check to see if User or System Mode
-  cmp       r1, #0x1f
-  cmpne     r1, #0x10
-  add       R2, SP, #0x38           @ Store it in EFI_SYSTEM_CONTEXT_ARM.LR
-  ldmneed   r2, {lr}^               @ User or System mode, use unbanked register
-  ldmneed   r2, {lr}                @ All other modes used banked register
-
-  ldr       R1, [SP, #0x58]         @ PC is the LR pushed by srsdb 
-  str       R1, [SP, #0x3c]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.PC
-  
-  sub       R1, SP, #0x60           @ We pused 0x60 bytes on the stack 
-  str       R1, [SP, #0x34]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.SP
-  
-                                              @ R0 is exception type 
-  mov       R1,SP                             @ Prepare System Context pointer as an argument for the exception handler
-  blx       ASM_PFX(CommonCExceptionHandler)  @ Call exception handler
-  
-  ldr       R2,[SP,#0x40]           @ EFI_SYSTEM_CONTEXT_ARM.CPSR
-  str       R2,[SP,#0x5c]           @ Store it back to srsdb stack slot so it can be restored 
-
-  ldr       R2,[SP,#0x3c]           @ EFI_SYSTEM_CONTEXT_ARM.PC
-  str       R2,[SP,#0x58]           @ Store it back to srsdb stack slot so it can be restored 
-
-  ldmfd     SP!,{R0-R12}            @ Restore general purpose registers
-                                    @ Exception handler can not change SP or LR as we would blow chunks
-                                    
-  add       SP,SP,#0x20             @ Clear out the remaining stack space
-  ldmfd     SP!,{LR}                @ restore the link register for this context
-  rfefd     SP!                     @ return from exception via srsdb stack slot
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+.text\r
+.align 3\r
+\r
+GCC_ASM_EXPORT(ExceptionHandlersStart)\r
+GCC_ASM_EXPORT(ExceptionHandlersEnd)\r
+GCC_ASM_EXPORT(CommonExceptionEntry)\r
+GCC_ASM_EXPORT(AsmCommonExceptionEntry)\r
+GCC_ASM_EXPORT(CommonCExceptionHandler)\r
+\r
+ASM_PFX(ExceptionHandlersStart):\r
+\r
+ASM_PFX(Reset):\r
+  b ASM_PFX(ResetEntry)\r
+\r
+ASM_PFX(UndefinedInstruction):\r
+  b ASM_PFX(UndefinedInstructionEntry)\r
+\r
+ASM_PFX(SoftwareInterrupt):\r
+  b ASM_PFX(SoftwareInterruptEntry)\r
+\r
+ASM_PFX(PrefetchAbort):\r
+  b ASM_PFX(PrefetchAbortEntry)\r
+\r
+ASM_PFX(DataAbort):\r
+  b ASM_PFX(DataAbortEntry)\r
+\r
+ASM_PFX(ReservedException):\r
+  b ASM_PFX(ReservedExceptionEntry)\r
+\r
+ASM_PFX(Irq):\r
+  b ASM_PFX(IrqEntry)\r
+\r
+ASM_PFX(Fiq):\r
+  b ASM_PFX(FiqEntry)\r
+\r
+ASM_PFX(ResetEntry):\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+  \r
+  mov       R0,#0\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(UndefinedInstructionEntry):\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       r0,#1\r
+  ldr       r1,ASM_PFX(CommonExceptionEntry)\r
+  bx        r1\r
+\r
+ASM_PFX(SoftwareInterruptEntry):\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       r0,#2\r
+  ldr       r1,ASM_PFX(CommonExceptionEntry)\r
+  bx        r1\r
+\r
+ASM_PFX(PrefetchAbortEntry):\r
+  sub       LR,LR,#4\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       r0,#3\r
+  ldr       r1,ASM_PFX(CommonExceptionEntry)\r
+  bx        r1\r
+\r
+ASM_PFX(DataAbortEntry):\r
+  sub       LR,LR,#8\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       r0,#4\r
+  ldr       r1,ASM_PFX(CommonExceptionEntry)\r
+  bx        r1\r
+\r
+ASM_PFX(ReservedExceptionEntry):\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       r0,#5\r
+  ldr       r1,ASM_PFX(CommonExceptionEntry)\r
+  bx        r1\r
+\r
+ASM_PFX(IrqEntry):\r
+  sub       LR,LR,#4\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       r0,#6\r
+  ldr       r1,ASM_PFX(CommonExceptionEntry)\r
+  bx        r1\r
+\r
+ASM_PFX(FiqEntry):\r
+  sub       LR,LR,#4\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       r0,#7\r
+  ldr       r1,ASM_PFX(CommonExceptionEntry)\r
+  bx        r1\r
+\r
+ASM_PFX(CommonExceptionEntry):\r
+  .byte       0x12\r
+  .byte       0x34\r
+  .byte       0x56\r
+  .byte       0x78\r
+\r
+ASM_PFX(ExceptionHandlersEnd):\r
+\r
+ASM_PFX(AsmCommonExceptionEntry):\r
+  mrc       p15, 0, R1, c6, c0, 2   @ Read IFAR\r
+  str       R1, [SP, #0x50]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFAR \r
+  \r
+  mrc       p15, 0, R1, c5, c0, 1   @ Read IFSR\r
+  str       R1, [SP, #0x4c]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFSR\r
+  \r
+  mrc       p15, 0, R1, c6, c0, 0   @ Read DFAR\r
+  str       R1, [SP, #0x48]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFAR\r
+  \r
+  mrc       p15, 0, R1, c5, c0, 0   @ Read DFSR\r
+  str       R1, [SP, #0x44]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFSR\r
+  \r
+  ldr       R1, [SP, #0x5c]         @ srsdb saved pre-exception CPSR on the stack \r
+  str       R1, [SP, #0x40]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.CPSR\r
+  and       r1, r1, #0x1f           @ Check to see if User or System Mode\r
+  cmp       r1, #0x1f\r
+  cmpne     r1, #0x10\r
+  add       R2, SP, #0x38           @ Store it in EFI_SYSTEM_CONTEXT_ARM.LR\r
+  ldmneed   r2, {lr}^               @ User or System mode, use unbanked register\r
+  ldmneed   r2, {lr}                @ All other modes used banked register\r
+\r
+  ldr       R1, [SP, #0x58]         @ PC is the LR pushed by srsdb \r
+  str       R1, [SP, #0x3c]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.PC\r
+  \r
+  sub       R1, SP, #0x60           @ We pused 0x60 bytes on the stack \r
+  str       R1, [SP, #0x34]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.SP\r
+  \r
+                                              @ R0 is exception type \r
+  mov       R1,SP                             @ Prepare System Context pointer as an argument for the exception handler\r
+  blx       ASM_PFX(CommonCExceptionHandler)  @ Call exception handler\r
+  \r
+  ldr       R2,[SP,#0x40]           @ EFI_SYSTEM_CONTEXT_ARM.CPSR\r
+  str       R2,[SP,#0x5c]           @ Store it back to srsdb stack slot so it can be restored \r
+\r
+  ldr       R2,[SP,#0x3c]           @ EFI_SYSTEM_CONTEXT_ARM.PC\r
+  str       R2,[SP,#0x58]           @ Store it back to srsdb stack slot so it can be restored \r
+\r
+  ldmfd     SP!,{R0-R12}            @ Restore general purpose registers\r
+                                    @ Exception handler can not change SP or LR as we would blow chunks\r
+                                    \r
+  add       SP,SP,#0x20             @ Clear out the remaining stack space\r
+  ldmfd     SP!,{LR}                @ restore the link register for this context\r
+  rfefd     SP!                     @ return from exception via srsdb stack slot\r
index 4af58339b73fe1e844168a8338e329693318df7b..2ea8d65f156b2942b808d050438e28920c3fe868 100644 (file)
-//------------------------------------------------------------------------------ 
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-  EXPORT  ExceptionHandlersStart
-  EXPORT  ExceptionHandlersEnd
-  EXPORT  CommonExceptionEntry
-  EXPORT  AsmCommonExceptionEntry
-  IMPORT  CommonCExceptionHandler
-
-  PRESERVE8
-  AREA  DxeExceptionHandlers, CODE, READONLY
-  
-ExceptionHandlersStart
-
-Reset
-  b   ResetEntry
-
-UndefinedInstruction
-  b   UndefinedInstructionEntry
-
-SoftwareInterrupt
-  b   SoftwareInterruptEntry
-
-PrefetchAbort
-  b   PrefetchAbortEntry
-
-DataAbort
-  b   DataAbortEntry
-
-ReservedException
-  b   ReservedExceptionEntry
-
-Irq
-  b   IrqEntry
-
-Fiq
-  b   FiqEntry
-
-ResetEntry
-  stmfd     SP!,{R0-R1}
-  mov       R0,#0
-  ldr       R1,CommonExceptionEntry
-  bx        R1
-
-UndefinedInstructionEntry
-  stmfd     SP!,{R0-R1}
-  mov       R0,#1
-  ldr       R1,CommonExceptionEntry
-  bx        R1
-
-SoftwareInterruptEntry
-  stmfd     SP!,{R0-R1}
-  mov       R0,#2
-  ldr       R1,CommonExceptionEntry
-  bx        R1
-
-PrefetchAbortEntry
-  stmfd     SP!,{R0-R1}
-  mov       R0,#3
-  SUB       LR,LR,#4
-  ldr       R1,CommonExceptionEntry
-  bx        R1
-
-DataAbortEntry
-  stmfd     SP!,{R0-R1}
-  mov       R0,#4
-  SUB       LR,LR,#8
-  ldr       R1,CommonExceptionEntry
-  bx        R1
-
-ReservedExceptionEntry
-  stmfd     SP!,{R0-R1}
-  mov       R0,#5
-  ldr       R1,CommonExceptionEntry
-  bx        R1
-
-IrqEntry
-  stmfd     SP!,{R0-R1}
-  mov       R0,#6
-  SUB       LR,LR,#4
-  ldr       R1,CommonExceptionEntry
-  bx        R1
-
-FiqEntry
-  stmfd     SP!,{R0-R1}
-  mov       R0,#7
-  SUB       LR,LR,#4
-  ldr       R1,CommonExceptionEntry
-  bx        R1
-
-CommonExceptionEntry
-  dcd       0x12345678
-
-ExceptionHandlersEnd
-
-AsmCommonExceptionEntry
-  mrc       p15, 0, r1, c6, c0, 2   ; Read IFAR
-  stmfd     SP!,{R1}                ; Store the IFAR
-  
-  mrc       p15, 0, r1, c5, c0, 1   ; Read IFSR
-  stmfd     SP!,{R1}                ; Store the IFSR
-  
-  mrc       p15, 0, r1, c6, c0, 0   ; Read DFAR
-  stmfd     SP!,{R1}                ; Store the DFAR
-  
-  mrc       p15, 0, r1, c5, c0, 0   ; Read DFSR
-  stmfd     SP!,{R1}                ; Store the DFSR
-  
-  mrs       R1,SPSR                 ; Read SPSR (which is the pre-exception CPSR)
-  stmfd     SP!,{R1}                ; Store the SPSR
-  
-  stmfd     SP!,{LR}                ; Store the link register (which is the pre-exception PC)
-  stmfd     SP,{SP,LR}^             ; Store user/system mode stack pointer and link register
-  nop                               ; Required by ARM architecture
-  SUB       SP,SP,#0x08             ; Adjust stack pointer
-  stmfd     SP!,{R2-R12}            ; Store general purpose registers
-  
-  ldr       R3,[SP,#0x50]           ; Read saved R1 from the stack (it was saved by the exception entry routine)
-  ldr       R2,[SP,#0x4C]           ; Read saved R0 from the stack (it was saved by the exception entry routine)
-  stmfd     SP!,{R2-R3}             ; Store general purpose registers R0 and R1
-  
-  mov       R1,SP                   ; Prepare System Context pointer as an argument for the exception handler
-  
-  sub       SP,SP,#4                ; Adjust SP to preserve 8-byte alignment
-  blx       CommonCExceptionHandler ; Call exception handler
-  add       SP,SP,#4                ; Adjust SP back to where we were
-  
-  ldr       R2,[SP,#0x40]           ; Load CPSR from context, in case it has changed
-  MSR       SPSR_cxsf,R2            ; Store it back to the SPSR to be restored when exiting this handler
-
-  ldmfd     SP!,{R0-R12}            ; Restore general purpose registers
-  ldm       SP,{SP,LR}^             ; Restore user/system mode stack pointer and link register
-  nop                               ; Required by ARM architecture
-  add       SP,SP,#0x08             ; Adjust stack pointer
-  ldmfd     SP!,{LR}                ; Restore the link register (which is the pre-exception PC)
-  add       SP,SP,#0x1C             ; Clear out the remaining stack space
-  movs      PC,LR                   ; Return from exception
-  
-  END
-
-
+//------------------------------------------------------------------------------ \r
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+  EXPORT  ExceptionHandlersStart\r
+  EXPORT  ExceptionHandlersEnd\r
+  EXPORT  CommonExceptionEntry\r
+  EXPORT  AsmCommonExceptionEntry\r
+  IMPORT  CommonCExceptionHandler\r
+\r
+  PRESERVE8\r
+  AREA  DxeExceptionHandlers, CODE, READONLY\r
+  \r
+ExceptionHandlersStart\r
+\r
+Reset\r
+  b   ResetEntry\r
+\r
+UndefinedInstruction\r
+  b   UndefinedInstructionEntry\r
+\r
+SoftwareInterrupt\r
+  b   SoftwareInterruptEntry\r
+\r
+PrefetchAbort\r
+  b   PrefetchAbortEntry\r
+\r
+DataAbort\r
+  b   DataAbortEntry\r
+\r
+ReservedException\r
+  b   ReservedExceptionEntry\r
+\r
+Irq\r
+  b   IrqEntry\r
+\r
+Fiq\r
+  b   FiqEntry\r
+\r
+ResetEntry\r
+  stmfd     SP!,{R0-R1}\r
+  mov       R0,#0\r
+  ldr       R1,CommonExceptionEntry\r
+  bx        R1\r
+\r
+UndefinedInstructionEntry\r
+  stmfd     SP!,{R0-R1}\r
+  mov       R0,#1\r
+  ldr       R1,CommonExceptionEntry\r
+  bx        R1\r
+\r
+SoftwareInterruptEntry\r
+  stmfd     SP!,{R0-R1}\r
+  mov       R0,#2\r
+  ldr       R1,CommonExceptionEntry\r
+  bx        R1\r
+\r
+PrefetchAbortEntry\r
+  stmfd     SP!,{R0-R1}\r
+  mov       R0,#3\r
+  SUB       LR,LR,#4\r
+  ldr       R1,CommonExceptionEntry\r
+  bx        R1\r
+\r
+DataAbortEntry\r
+  stmfd     SP!,{R0-R1}\r
+  mov       R0,#4\r
+  SUB       LR,LR,#8\r
+  ldr       R1,CommonExceptionEntry\r
+  bx        R1\r
+\r
+ReservedExceptionEntry\r
+  stmfd     SP!,{R0-R1}\r
+  mov       R0,#5\r
+  ldr       R1,CommonExceptionEntry\r
+  bx        R1\r
+\r
+IrqEntry\r
+  stmfd     SP!,{R0-R1}\r
+  mov       R0,#6\r
+  SUB       LR,LR,#4\r
+  ldr       R1,CommonExceptionEntry\r
+  bx        R1\r
+\r
+FiqEntry\r
+  stmfd     SP!,{R0-R1}\r
+  mov       R0,#7\r
+  SUB       LR,LR,#4\r
+  ldr       R1,CommonExceptionEntry\r
+  bx        R1\r
+\r
+CommonExceptionEntry\r
+  dcd       0x12345678\r
+\r
+ExceptionHandlersEnd\r
+\r
+AsmCommonExceptionEntry\r
+  mrc       p15, 0, r1, c6, c0, 2   ; Read IFAR\r
+  stmfd     SP!,{R1}                ; Store the IFAR\r
+  \r
+  mrc       p15, 0, r1, c5, c0, 1   ; Read IFSR\r
+  stmfd     SP!,{R1}                ; Store the IFSR\r
+  \r
+  mrc       p15, 0, r1, c6, c0, 0   ; Read DFAR\r
+  stmfd     SP!,{R1}                ; Store the DFAR\r
+  \r
+  mrc       p15, 0, r1, c5, c0, 0   ; Read DFSR\r
+  stmfd     SP!,{R1}                ; Store the DFSR\r
+  \r
+  mrs       R1,SPSR                 ; Read SPSR (which is the pre-exception CPSR)\r
+  stmfd     SP!,{R1}                ; Store the SPSR\r
+  \r
+  stmfd     SP!,{LR}                ; Store the link register (which is the pre-exception PC)\r
+  stmfd     SP,{SP,LR}^             ; Store user/system mode stack pointer and link register\r
+  nop                               ; Required by ARM architecture\r
+  SUB       SP,SP,#0x08             ; Adjust stack pointer\r
+  stmfd     SP!,{R2-R12}            ; Store general purpose registers\r
+  \r
+  ldr       R3,[SP,#0x50]           ; Read saved R1 from the stack (it was saved by the exception entry routine)\r
+  ldr       R2,[SP,#0x4C]           ; Read saved R0 from the stack (it was saved by the exception entry routine)\r
+  stmfd     SP!,{R2-R3}             ; Store general purpose registers R0 and R1\r
+  \r
+  mov       R1,SP                   ; Prepare System Context pointer as an argument for the exception handler\r
+  \r
+  sub       SP,SP,#4                ; Adjust SP to preserve 8-byte alignment\r
+  blx       CommonCExceptionHandler ; Call exception handler\r
+  add       SP,SP,#4                ; Adjust SP back to where we were\r
+  \r
+  ldr       R2,[SP,#0x40]           ; Load CPSR from context, in case it has changed\r
+  MSR       SPSR_cxsf,R2            ; Store it back to the SPSR to be restored when exiting this handler\r
+\r
+  ldmfd     SP!,{R0-R12}            ; Restore general purpose registers\r
+  ldm       SP,{SP,LR}^             ; Restore user/system mode stack pointer and link register\r
+  nop                               ; Required by ARM architecture\r
+  add       SP,SP,#0x08             ; Adjust stack pointer\r
+  ldmfd     SP!,{LR}                ; Restore the link register (which is the pre-exception PC)\r
+  add       SP,SP,#0x1C             ; Clear out the remaining stack space\r
+  movs      PC,LR                   ; Return from exception\r
+  \r
+  END\r
+\r
+\r
index 86d2a7135fce84a62b8c90bc01ead955effa2f47..948ad69946ea513ae5582ebd54e3bef8d12c1d80 100644 (file)
-#------------------------------------------------------------------------------ 
-#
-# Use ARMv6 instruction to operate on a single stack
-#
-# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-#
-# 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 <Library/PcdLib.h>
-
-/*
-
-This is the stack constructed by the exception handler (low address to high address)
-                # R0 - IFAR is EFI_SYSTEM_CONTEXT for ARM
-  Reg   Offset
-  ===   ======              
-  R0    0x00    # stmfd     SP!,{R0-R12}
-  R1    0x04
-  R2    0x08
-  R3    0x0c
-  R4    0x10
-  R5    0x14
-  R6    0x18
-  R7    0x1c
-  R8    0x20
-  R9    0x24
-  R10   0x28
-  R11   0x2c
-  R12   0x30
-  SP    0x34    # reserved via adding 0x20 (32) to the SP
-  LR    0x38
-  PC    0x3c
-  CPSR  0x40
-  DFSR  0x44
-  DFAR  0x48
-  IFSR  0x4c
-  IFAR  0x50
-  
-  LR    0x54    # SVC Link register (we need to restore it)
-  
-  LR    0x58    # pushed by srsfd    
-  CPSR  0x5c    
-
- */
-
-GCC_ASM_EXPORT(ExceptionHandlersStart)
-GCC_ASM_EXPORT(ExceptionHandlersEnd)
-GCC_ASM_EXPORT(CommonExceptionEntry)
-GCC_ASM_EXPORT(AsmCommonExceptionEntry)
-GCC_ASM_EXPORT(CommonCExceptionHandler)
-
-.text
-#if !defined(__APPLE__)
-.fpu neon    @ makes vpush/vpop assemble
-#endif
-.align 5
-
-
-//
-// This code gets copied to the ARM vector table
-// ExceptionHandlersStart - ExceptionHandlersEnd gets copied
-//
-ASM_PFX(ExceptionHandlersStart):
-
-ASM_PFX(Reset):
-  b ASM_PFX(ResetEntry)
-
-ASM_PFX(UndefinedInstruction):
-  b ASM_PFX(UndefinedInstructionEntry)
-
-ASM_PFX(SoftwareInterrupt):
-  b ASM_PFX(SoftwareInterruptEntry)
-
-ASM_PFX(PrefetchAbort):
-  b ASM_PFX(PrefetchAbortEntry)
-
-ASM_PFX(DataAbort):
-  b ASM_PFX(DataAbortEntry)
-
-ASM_PFX(ReservedException):
-  b ASM_PFX(ReservedExceptionEntry)
-
-ASM_PFX(Irq):
-  b ASM_PFX(IrqEntry)
-
-ASM_PFX(Fiq):
-  b ASM_PFX(FiqEntry)
-
-ASM_PFX(ResetEntry):
-  srsdb     #0x13!                    @ Store return state on SVC stack
-                                      @ We are already in SVC mode
-
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-  
-  mov       R0,#0                     @ ExceptionType
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(UndefinedInstructionEntry):
-  sub       LR, LR, #4                @ Only -2 for Thumb, adjust in CommonExceptionEntry
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       R0,#1                     @ ExceptionType
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(SoftwareInterruptEntry):
-  sub       LR, LR, #4                @ Only -2 for Thumb, adjust in CommonExceptionEntry
-  srsdb     #0x13!                    @ Store return state on SVC stack
-                                      @ We are already in SVC mode
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       R0,#2                     @ ExceptionType
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(PrefetchAbortEntry):
-  sub       LR,LR,#4
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       R0,#3                     @ ExceptionType
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(DataAbortEntry):
-  sub       LR,LR,#8
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       R0,#4
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(ReservedExceptionEntry):
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       R0,#5
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(IrqEntry):
-  sub       LR,LR,#4
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       R0,#6                     @ ExceptionType
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(FiqEntry):
-  sub       LR,LR,#4
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-                                      @ Since we have already switch to SVC R8_fiq - R12_fiq
-                                      @ never get used or saved
-  mov       R0,#7                     @ ExceptionType
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-//
-// This gets patched by the C code that patches in the vector table
-//
-ASM_PFX(CommonExceptionEntry):
-  .word       ASM_PFX(AsmCommonExceptionEntry)
-
-ASM_PFX(ExceptionHandlersEnd):
-
-//
-// This code runs from CpuDxe driver loaded address. It is patched into 
-// CommonExceptionEntry.
-//
-ASM_PFX(AsmCommonExceptionEntry):
-  mrc       p15, 0, R1, c6, c0, 2   @ Read IFAR
-  str       R1, [SP, #0x50]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFAR 
-  
-  mrc       p15, 0, R1, c5, c0, 1   @ Read IFSR
-  str       R1, [SP, #0x4c]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFSR
-  
-  mrc       p15, 0, R1, c6, c0, 0   @ Read DFAR
-  str       R1, [SP, #0x48]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFAR
-  
-  mrc       p15, 0, R1, c5, c0, 0   @ Read DFSR
-  str       R1, [SP, #0x44]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFSR
-  
-  ldr       R1, [SP, #0x5c]         @ srsdb saved pre-exception CPSR on the stack 
-  str       R1, [SP, #0x40]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.CPSR
-
-  add       R2, SP, #0x38           @ Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR
-  and       R3, R1, #0x1f           @ Check CPSR to see if User or System Mode
-  cmp       R3, #0x1f               @ if ((CPSR == 0x10) || (CPSR == 0x1df))
-  cmpne     R3, #0x10               @   
-  stmeqed   R2, {lr}^               @   save unbanked lr
-                                    @ else 
-  stmneed   R2, {lr}                @   save SVC lr
-
-
-  ldr       R5, [SP, #0x58]         @ PC is the LR pushed by srsfd 
-                                    @ Check to see if we have to adjust for Thumb entry
-  sub       r4, r0, #1              @ if (ExceptionType == 1 || ExceptionType ==2)) {
-  cmp       r4, #1                  @   // UND & SVC have differnt LR adjust for Thumb 
-  bhi       NoAdjustNeeded
-  
-  tst       r1, #0x20               @   if ((CPSR & T)) == T) {  // Thumb Mode on entry 
-  addne     R5, R5, #2              @     PC += 2@
-  str       R5,[SP,#0x58]           @ Update LR value pused by srsfd 
-  
-NoAdjustNeeded:
-
-  str       R5, [SP, #0x3c]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.PC
-  
-  sub       R1, SP, #0x60           @ We pused 0x60 bytes on the stack 
-  str       R1, [SP, #0x34]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.SP
-  
-                                    @ R0 is ExceptionType 
-  mov       R1,SP                   @ R1 is SystemContext 
-
-#if (FixedPcdGet32(PcdVFPEnabled))
-  vpush     {d0-d15}                @ save vstm registers in case they are used in optimizations
-#endif
-
-/* 
-VOID
-EFIAPI
-CommonCExceptionHandler (
-  IN     EFI_EXCEPTION_TYPE           ExceptionType,   R0
-  IN OUT EFI_SYSTEM_CONTEXT           SystemContext    R1
-  )
-
-*/  
-  blx       ASM_PFX(CommonCExceptionHandler)  @ Call exception handler
-
-#if (FixedPcdGet32(PcdVFPEnabled))
-  vpop      {d0-d15}  
-#endif
-
-  ldr       R1, [SP, #0x4c]         @ Restore EFI_SYSTEM_CONTEXT_ARM.IFSR
-  mcr       p15, 0, R1, c5, c0, 1   @ Write IFSR
-
-  ldr       R1, [SP, #0x44]         @ sRestore EFI_SYSTEM_CONTEXT_ARM.DFSR
-  mcr       p15, 0, R1, c5, c0, 0   @ Write DFSR
-  
-  ldr       R1,[SP,#0x3c]           @ EFI_SYSTEM_CONTEXT_ARM.PC
-  str       R1,[SP,#0x58]           @ Store it back to srsfd stack slot so it can be restored 
-
-  ldr       R1,[SP,#0x40]           @ EFI_SYSTEM_CONTEXT_ARM.CPSR
-  str       R1,[SP,#0x5c]           @ Store it back to srsfd stack slot so it can be restored 
-  
-  add       R3, SP, #0x54           @ Make R3 point to SVC LR saved on entry
-  add       R2, SP, #0x38           @ Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR
-  and       R1, R1, #0x1f           @ Check to see if User or System Mode
-  cmp       R1, #0x1f               @ if ((CPSR == 0x10) || (CPSR == 0x1f))
-  cmpne     R1, #0x10               @   
-  ldmeqed   R2, {lr}^               @   restore unbanked lr
-                                    @ else
-  ldmneed   R3, {lr}                @   restore SVC lr, via ldmfd SP!, {LR}
-  
-  ldmfd     SP!,{R0-R12}            @ Restore general purpose registers
-                                    @ Exception handler can not change SP
-                                    
-  add       SP,SP,#0x20             @ Clear out the remaining stack space
-  ldmfd     SP!,{LR}                @ restore the link register for this context
-  rfefd     SP!                     @ return from exception via srsfd stack slot
-  
+#------------------------------------------------------------------------------ \r
+#\r
+# Use ARMv6 instruction to operate on a single stack\r
+#\r
+# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+#include <Library/PcdLib.h>\r
+\r
+/*\r
+\r
+This is the stack constructed by the exception handler (low address to high address)\r
+                # R0 - IFAR is EFI_SYSTEM_CONTEXT for ARM\r
+  Reg   Offset\r
+  ===   ======              \r
+  R0    0x00    # stmfd     SP!,{R0-R12}\r
+  R1    0x04\r
+  R2    0x08\r
+  R3    0x0c\r
+  R4    0x10\r
+  R5    0x14\r
+  R6    0x18\r
+  R7    0x1c\r
+  R8    0x20\r
+  R9    0x24\r
+  R10   0x28\r
+  R11   0x2c\r
+  R12   0x30\r
+  SP    0x34    # reserved via adding 0x20 (32) to the SP\r
+  LR    0x38\r
+  PC    0x3c\r
+  CPSR  0x40\r
+  DFSR  0x44\r
+  DFAR  0x48\r
+  IFSR  0x4c\r
+  IFAR  0x50\r
+  \r
+  LR    0x54    # SVC Link register (we need to restore it)\r
+  \r
+  LR    0x58    # pushed by srsfd    \r
+  CPSR  0x5c    \r
+\r
+ */\r
\r
+\r
+GCC_ASM_EXPORT(ExceptionHandlersStart)\r
+GCC_ASM_EXPORT(ExceptionHandlersEnd)\r
+GCC_ASM_EXPORT(CommonExceptionEntry)\r
+GCC_ASM_EXPORT(AsmCommonExceptionEntry)\r
+GCC_ASM_EXPORT(CommonCExceptionHandler)\r
+\r
+.text\r
+#if !defined(__APPLE__)\r
+.fpu neon    @ makes vpush/vpop assemble\r
+#endif\r
+.align 5\r
+\r
+\r
+//\r
+// This code gets copied to the ARM vector table\r
+// ExceptionHandlersStart - ExceptionHandlersEnd gets copied\r
+//\r
+ASM_PFX(ExceptionHandlersStart):\r
+\r
+ASM_PFX(Reset):\r
+  b ASM_PFX(ResetEntry)\r
+\r
+ASM_PFX(UndefinedInstruction):\r
+  b ASM_PFX(UndefinedInstructionEntry)\r
+\r
+ASM_PFX(SoftwareInterrupt):\r
+  b ASM_PFX(SoftwareInterruptEntry)\r
+\r
+ASM_PFX(PrefetchAbort):\r
+  b ASM_PFX(PrefetchAbortEntry)\r
+\r
+ASM_PFX(DataAbort):\r
+  b ASM_PFX(DataAbortEntry)\r
+\r
+ASM_PFX(ReservedException):\r
+  b ASM_PFX(ReservedExceptionEntry)\r
+\r
+ASM_PFX(Irq):\r
+  b ASM_PFX(IrqEntry)\r
+\r
+ASM_PFX(Fiq):\r
+  b ASM_PFX(FiqEntry)\r
+\r
+ASM_PFX(ResetEntry):\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+                                      @ We are already in SVC mode\r
+\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+  \r
+  mov       R0,#0                     @ ExceptionType\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(UndefinedInstructionEntry):\r
+  sub       LR, LR, #4                @ Only -2 for Thumb, adjust in CommonExceptionEntry\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       R0,#1                     @ ExceptionType\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(SoftwareInterruptEntry):\r
+  sub       LR, LR, #4                @ Only -2 for Thumb, adjust in CommonExceptionEntry\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+                                      @ We are already in SVC mode\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       R0,#2                     @ ExceptionType\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(PrefetchAbortEntry):\r
+  sub       LR,LR,#4\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       R0,#3                     @ ExceptionType\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(DataAbortEntry):\r
+  sub       LR,LR,#8\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       R0,#4\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(ReservedExceptionEntry):\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       R0,#5\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(IrqEntry):\r
+  sub       LR,LR,#4\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       R0,#6                     @ ExceptionType\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(FiqEntry):\r
+  sub       LR,LR,#4\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+                                      @ Since we have already switch to SVC R8_fiq - R12_fiq\r
+                                      @ never get used or saved\r
+  mov       R0,#7                     @ ExceptionType\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+//\r
+// This gets patched by the C code that patches in the vector table\r
+//\r
+ASM_PFX(CommonExceptionEntry):\r
+  .word       ASM_PFX(AsmCommonExceptionEntry)\r
+\r
+ASM_PFX(ExceptionHandlersEnd):\r
+\r
+//\r
+// This code runs from CpuDxe driver loaded address. It is patched into \r
+// CommonExceptionEntry.\r
+//\r
+ASM_PFX(AsmCommonExceptionEntry):\r
+  mrc       p15, 0, R1, c6, c0, 2   @ Read IFAR\r
+  str       R1, [SP, #0x50]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFAR \r
+  \r
+  mrc       p15, 0, R1, c5, c0, 1   @ Read IFSR\r
+  str       R1, [SP, #0x4c]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFSR\r
+  \r
+  mrc       p15, 0, R1, c6, c0, 0   @ Read DFAR\r
+  str       R1, [SP, #0x48]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFAR\r
+  \r
+  mrc       p15, 0, R1, c5, c0, 0   @ Read DFSR\r
+  str       R1, [SP, #0x44]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFSR\r
+  \r
+  ldr       R1, [SP, #0x5c]         @ srsdb saved pre-exception CPSR on the stack \r
+  str       R1, [SP, #0x40]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.CPSR\r
+\r
+  add       R2, SP, #0x38           @ Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR\r
+  and       R3, R1, #0x1f           @ Check CPSR to see if User or System Mode\r
+  cmp       R3, #0x1f               @ if ((CPSR == 0x10) || (CPSR == 0x1df))\r
+  cmpne     R3, #0x10               @   \r
+  stmeqed   R2, {lr}^               @   save unbanked lr\r
+                                    @ else \r
+  stmneed   R2, {lr}                @   save SVC lr\r
+\r
+\r
+  ldr       R5, [SP, #0x58]         @ PC is the LR pushed by srsfd \r
+                                    @ Check to see if we have to adjust for Thumb entry\r
+  sub       r4, r0, #1              @ if (ExceptionType == 1 || ExceptionType ==2)) {\r
+  cmp       r4, #1                  @   // UND & SVC have differnt LR adjust for Thumb \r
+  bhi       NoAdjustNeeded\r
+  \r
+  tst       r1, #0x20               @   if ((CPSR & T)) == T) {  // Thumb Mode on entry \r
+  addne     R5, R5, #2              @     PC += 2@\r
+  str       R5,[SP,#0x58]           @ Update LR value pused by srsfd \r
+  \r
+NoAdjustNeeded:\r
+\r
+  str       R5, [SP, #0x3c]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.PC\r
+  \r
+  sub       R1, SP, #0x60           @ We pused 0x60 bytes on the stack \r
+  str       R1, [SP, #0x34]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.SP\r
+  \r
+                                    @ R0 is ExceptionType \r
+  mov       R1,SP                   @ R1 is SystemContext \r
+\r
+#if (FixedPcdGet32(PcdVFPEnabled))\r
+  vpush     {d0-d15}                @ save vstm registers in case they are used in optimizations\r
+#endif\r
+\r
+/* \r
+VOID\r
+EFIAPI\r
+CommonCExceptionHandler (\r
+  IN     EFI_EXCEPTION_TYPE           ExceptionType,   R0\r
+  IN OUT EFI_SYSTEM_CONTEXT           SystemContext    R1\r
+  )\r
+\r
+*/  \r
+  blx       ASM_PFX(CommonCExceptionHandler)  @ Call exception handler\r
+\r
+#if (FixedPcdGet32(PcdVFPEnabled))\r
+  vpop      {d0-d15}  \r
+#endif\r
+\r
+  ldr       R1, [SP, #0x4c]         @ Restore EFI_SYSTEM_CONTEXT_ARM.IFSR\r
+  mcr       p15, 0, R1, c5, c0, 1   @ Write IFSR\r
+\r
+  ldr       R1, [SP, #0x44]         @ sRestore EFI_SYSTEM_CONTEXT_ARM.DFSR\r
+  mcr       p15, 0, R1, c5, c0, 0   @ Write DFSR\r
+  \r
+  ldr       R1,[SP,#0x3c]           @ EFI_SYSTEM_CONTEXT_ARM.PC\r
+  str       R1,[SP,#0x58]           @ Store it back to srsfd stack slot so it can be restored \r
+\r
+  ldr       R1,[SP,#0x40]           @ EFI_SYSTEM_CONTEXT_ARM.CPSR\r
+  str       R1,[SP,#0x5c]           @ Store it back to srsfd stack slot so it can be restored \r
+  \r
+  add       R3, SP, #0x54           @ Make R3 point to SVC LR saved on entry\r
+  add       R2, SP, #0x38           @ Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR\r
+  and       R1, R1, #0x1f           @ Check to see if User or System Mode\r
+  cmp       R1, #0x1f               @ if ((CPSR == 0x10) || (CPSR == 0x1f))\r
+  cmpne     R1, #0x10               @   \r
+  ldmeqed   R2, {lr}^               @   restore unbanked lr\r
+                                    @ else\r
+  ldmneed   R3, {lr}                @   restore SVC lr, via ldmfd SP!, {LR}\r
+  \r
+  ldmfd     SP!,{R0-R12}            @ Restore general purpose registers\r
+                                    @ Exception handler can not change SP\r
+                                    \r
+  add       SP,SP,#0x20             @ Clear out the remaining stack space\r
+  ldmfd     SP!,{LR}                @ restore the link register for this context\r
+  rfefd     SP!                     @ return from exception via srsfd stack slot\r
+  \r
index 3d1665aabdb9b241d9c4e7b5dbc15c24a95ad366..ec8b9f5c533cb36e6a524fa1a0089be58b82dafb 100755 (executable)
@@ -53,7 +53,7 @@
   gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize\r
   gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize\r
 \r
   gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize\r
   gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize\r
 \r
-[FeaturePcd]  
+[FeaturePcd]  \r
   gEmbeddedTokenSpaceGuid.PcdCacheEnable  \r
 \r
 [depex]\r
   gEmbeddedTokenSpaceGuid.PcdCacheEnable  \r
 \r
 [depex]\r
index 1a8239e73a5e9bc07f2f468cf334cc9a366ad3aa..590cdb7056f593f9caeae01ec2a43ec5674a82a5 100644 (file)
-/*++
-
-Copyright (c) 2009, Hewlett-Packard Company. All rights reserved.<BR>
-Portions copyright (c) 2010, Apple Inc. All rights reserved.<BR>
-Portions copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR> 
-
-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:
-
-  Gic.c
-
-Abstract:
-
-  Driver implementing the GIC interrupt controller protocol
-
---*/
-
-#include <PiDxe.h>
-
-#include <Library/BaseLib.h>
-#include <Library/DebugLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiLib.h>
-#include <Library/PcdLib.h>
-#include <Library/IoLib.h>
-#include <Library/ArmGicLib.h>
-
-#include <Protocol/Cpu.h>
-#include <Protocol/HardwareInterrupt.h>
-
-#define ARM_GIC_DEFAULT_PRIORITY  0x80
-
-extern EFI_HARDWARE_INTERRUPT_PROTOCOL gHardwareInterruptProtocol;
-
-//
-// Notifications
-//
-EFI_EVENT EfiExitBootServicesEvent      = (EFI_EVENT)NULL;
-
-// Maximum Number of Interrupts
-UINTN mGicNumInterrupts                 = 0;
-
-HARDWARE_INTERRUPT_HANDLER  *gRegisteredInterruptHandlers = NULL;
-
-/**
-  Register Handler for the specified interrupt source.
-
-  @param This     Instance pointer for this protocol
-  @param Source   Hardware source of the interrupt
-  @param Handler  Callback for interrupt. NULL to unregister
-
-  @retval EFI_SUCCESS Source was updated to support Handler.
-  @retval EFI_DEVICE_ERROR  Hardware could not be programmed.
-
-**/
-EFI_STATUS
-EFIAPI
-RegisterInterruptSource (
-  IN EFI_HARDWARE_INTERRUPT_PROTOCOL    *This,
-  IN HARDWARE_INTERRUPT_SOURCE          Source,
-  IN HARDWARE_INTERRUPT_HANDLER         Handler
-  )
-{
-  if (Source > mGicNumInterrupts) {
-    ASSERT(FALSE);
-    return EFI_UNSUPPORTED;
-  }
-  
-  if ((Handler == NULL) && (gRegisteredInterruptHandlers[Source] == NULL)) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  if ((Handler != NULL) && (gRegisteredInterruptHandlers[Source] != NULL)) {
-    return EFI_ALREADY_STARTED;
-  }
-
-  gRegisteredInterruptHandlers[Source] = Handler;
-
-  // If the interrupt handler is unregistered then disable the interrupt
-  if (NULL == Handler){
-       return This->DisableInterruptSource (This, Source);
-  } else {
-       return This->EnableInterruptSource (This, Source);
-  }
-}
-
-/**
-  Enable interrupt source Source.
-
-  @param This     Instance pointer for this protocol
-  @param Source   Hardware source of the interrupt
-
-  @retval EFI_SUCCESS       Source interrupt enabled.
-  @retval EFI_DEVICE_ERROR  Hardware could not be programmed.
-
-**/
-EFI_STATUS
-EFIAPI
-EnableInterruptSource (
-  IN EFI_HARDWARE_INTERRUPT_PROTOCOL    *This,
-  IN HARDWARE_INTERRUPT_SOURCE          Source
-  )
-{
-  UINT32    RegOffset;
-  UINTN     RegShift;
-  
-  if (Source > mGicNumInterrupts) {
-    ASSERT(FALSE);
-    return EFI_UNSUPPORTED;
-  }
-  
-  // Calculate enable register offset and bit position
-  RegOffset = Source / 32;
-  RegShift = Source % 32;
-
-  // Write set-enable register
-  MmioWrite32 (PcdGet32(PcdGicDistributorBase) + ARM_GIC_ICDISER + (4*RegOffset), 1 << RegShift);
-  
-  return EFI_SUCCESS;
-}
-
-/**
-  Disable interrupt source Source.
-
-  @param This     Instance pointer for this protocol
-  @param Source   Hardware source of the interrupt
-
-  @retval EFI_SUCCESS       Source interrupt disabled.
-  @retval EFI_DEVICE_ERROR  Hardware could not be programmed.
-
-**/
-EFI_STATUS
-EFIAPI
-DisableInterruptSource (
-  IN EFI_HARDWARE_INTERRUPT_PROTOCOL    *This,
-  IN HARDWARE_INTERRUPT_SOURCE          Source
-  )
-{
-  UINT32    RegOffset;
-  UINTN     RegShift;
-  
-  if (Source > mGicNumInterrupts) {
-    ASSERT(FALSE);
-    return EFI_UNSUPPORTED;
-  }
-  
-  // Calculate enable register offset and bit position
-  RegOffset = Source / 32;
-  RegShift = Source % 32;
-
-  // Write set-enable register
-  MmioWrite32 (PcdGet32(PcdGicDistributorBase) + ARM_GIC_ICDICER + (4*RegOffset), 1 << RegShift);
-  
-  return EFI_SUCCESS;
-}
-
-/**
-  Return current state of interrupt source Source.
-
-  @param This     Instance pointer for this protocol
-  @param Source   Hardware source of the interrupt
-  @param InterruptState  TRUE: source enabled, FALSE: source disabled.
-
-  @retval EFI_SUCCESS       InterruptState is valid
-  @retval EFI_DEVICE_ERROR  InterruptState is not valid
-
-**/
-EFI_STATUS
-EFIAPI
-GetInterruptSourceState (
-  IN EFI_HARDWARE_INTERRUPT_PROTOCOL    *This,
-  IN HARDWARE_INTERRUPT_SOURCE          Source,
-  IN BOOLEAN                            *InterruptState
-  )
-{
-  UINT32    RegOffset;
-  UINTN     RegShift;
-  
-  if (Source > mGicNumInterrupts) {
-    ASSERT(FALSE);
-    return EFI_UNSUPPORTED;
-  }
-  
-  // calculate enable register offset and bit position
-  RegOffset = Source / 32;
-  RegShift = Source % 32;
-    
-  if ((MmioRead32 (PcdGet32(PcdGicDistributorBase) + ARM_GIC_ICDISER + (4*RegOffset)) & (1<<RegShift)) == 0) {
-    *InterruptState = FALSE;
-  } else {
-    *InterruptState = TRUE;
-  }
-  
-  return EFI_SUCCESS;
-}
-
-/**
-  Signal to the hardware that the End Of Intrrupt state 
-  has been reached.
-
-  @param This     Instance pointer for this protocol
-  @param Source   Hardware source of the interrupt
-
-  @retval EFI_SUCCESS       Source interrupt EOI'ed.
-  @retval EFI_DEVICE_ERROR  Hardware could not be programmed.
-
-**/
-EFI_STATUS
-EFIAPI
-EndOfInterrupt (
-  IN EFI_HARDWARE_INTERRUPT_PROTOCOL    *This,
-  IN HARDWARE_INTERRUPT_SOURCE          Source
-  )
-{
-  if (Source > mGicNumInterrupts) {
-    ASSERT(FALSE);
-    return EFI_UNSUPPORTED;
-  }
-
-  MmioWrite32 (PcdGet32(PcdGicInterruptInterfaceBase) + ARM_GIC_ICCEIOR, Source);
-  return EFI_SUCCESS;
-}
-
-/**
-  EFI_CPU_INTERRUPT_HANDLER that is called when a processor interrupt occurs.
-
-  @param  InterruptType    Defines the type of interrupt or exception that
-                           occurred on the processor.This parameter is processor architecture specific.
-  @param  SystemContext    A pointer to the processor context when
-                           the interrupt occurred on the processor.
-
-  @return None
-
-**/
-VOID
-EFIAPI
-IrqInterruptHandler (
-  IN EFI_EXCEPTION_TYPE           InterruptType,
-  IN EFI_SYSTEM_CONTEXT           SystemContext
-  )
-{
-  UINT32                      GicInterrupt;
-  HARDWARE_INTERRUPT_HANDLER  InterruptHandler;
-
-  GicInterrupt = MmioRead32 (PcdGet32(PcdGicInterruptInterfaceBase) + ARM_GIC_ICCIAR);
-
-  // Special Interrupts (ID1020-ID1023) have an Interrupt ID greater than the number of interrupt (ie: Spurious interrupt).
-  if (GicInterrupt >= mGicNumInterrupts) {
-    // The special interrupt do not need to be acknowledge
-    return;
-  }
-  
-  InterruptHandler = gRegisteredInterruptHandlers[GicInterrupt];
-  if (InterruptHandler != NULL) {
-    // Call the registered interrupt handler.
-    InterruptHandler (GicInterrupt, SystemContext);
-  } else {
-    DEBUG ((EFI_D_ERROR, "Spurious GIC interrupt: 0x%x\n", GicInterrupt));
-  }
-
-  EndOfInterrupt (&gHardwareInterruptProtocol, GicInterrupt);
-}
-
-//
-// Making this global saves a few bytes in image size
-//
-EFI_HANDLE  gHardwareInterruptHandle = NULL;
-
-//
-// The protocol instance produced by this driver
-//
-EFI_HARDWARE_INTERRUPT_PROTOCOL gHardwareInterruptProtocol = {
-  RegisterInterruptSource,
-  EnableInterruptSource,
-  DisableInterruptSource,
-  GetInterruptSourceState,
-  EndOfInterrupt
-};
-
-/**
-  Shutdown our hardware
-  
-  DXE Core will disable interrupts and turn off the timer and disable interrupts
-  after all the event handlers have run.
-
-  @param[in]  Event   The Event that is being processed
-  @param[in]  Context Event Context
-**/
-VOID
-EFIAPI
-ExitBootServicesEvent (
-  IN EFI_EVENT  Event,
-  IN VOID       *Context
-  )
-{
-  UINTN    Index;
-  
-  // Acknowledge all pending interrupts
-  for (Index = 0; Index < mGicNumInterrupts; Index++) {
-    DisableInterruptSource (&gHardwareInterruptProtocol, Index);
-  }
-
-  for (Index = 0; Index < mGicNumInterrupts; Index++) {
-    EndOfInterrupt (&gHardwareInterruptProtocol, Index);
-  }
-
-  // Disable Gic Interface
-  MmioWrite32 (PcdGet32(PcdGicInterruptInterfaceBase) + ARM_GIC_ICCICR, 0x0);
-  MmioWrite32 (PcdGet32(PcdGicInterruptInterfaceBase) + ARM_GIC_ICCPMR, 0x0);
-
-  // Disable Gic Distributor
-  MmioWrite32 (PcdGet32(PcdGicDistributorBase) + ARM_GIC_ICDDCR, 0x0);
-}
-
-/**
-  Initialize the state information for the CPU Architectural Protocol
-
-  @param  ImageHandle   of the loaded driver
-  @param  SystemTable   Pointer to the System Table
-
-  @retval EFI_SUCCESS           Protocol registered
-  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure
-  @retval EFI_DEVICE_ERROR      Hardware problems
-
-**/
-EFI_STATUS
-InterruptDxeInitialize (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
-  )
-{
-  EFI_STATUS              Status;
-  UINTN                   Index;
-  UINT32                  RegOffset;
-  UINTN                   RegShift;
-  EFI_CPU_ARCH_PROTOCOL   *Cpu;
-  UINT32                  CpuTarget;
-  
-  // Check PcdGicPrimaryCoreId has been set in case the Primary Core is not the core 0 of Cluster 0
-  DEBUG_CODE_BEGIN();
-  if ((PcdGet32(PcdArmPrimaryCore) != 0) && (PcdGet32 (PcdGicPrimaryCoreId) == 0)) {
-    DEBUG((EFI_D_WARN,"Warning: the PCD PcdGicPrimaryCoreId does not seem to be set up for the configuration.\n"));
-  }
-  DEBUG_CODE_END();
-
-  // Make sure the Interrupt Controller Protocol is not already installed in the system.
-  ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gHardwareInterruptProtocolGuid);
-
-  mGicNumInterrupts = ArmGicGetMaxNumInterrupts (PcdGet32(PcdGicDistributorBase));
-
-  for (Index = 0; Index < mGicNumInterrupts; Index++) {
-    DisableInterruptSource (&gHardwareInterruptProtocol, Index);
-    
-    // Set Priority 
-    RegOffset = Index / 4;
-    RegShift = (Index % 4) * 8;
-    MmioAndThenOr32 (
-      PcdGet32(PcdGicDistributorBase) + ARM_GIC_ICDIPR + (4*RegOffset),
-      ~(0xff << RegShift), 
-      ARM_GIC_DEFAULT_PRIORITY << RegShift
-      );
-  }
-
-  // Configure interrupts for Primary Cpu
-  CpuTarget = (1 << PcdGet32 (PcdGicPrimaryCoreId));
-  CpuTarget |= (CpuTarget << 24) | (CpuTarget << 16) | (CpuTarget << 8);
-  for (Index = 0; Index < (mGicNumInterrupts / 4); Index++) {
-    MmioWrite32 (PcdGet32(PcdGicDistributorBase) + ARM_GIC_ICDIPTR + (Index*4), CpuTarget);
-  }
-
-  // Set binary point reg to 0x7 (no preemption)
-  MmioWrite32 (PcdGet32(PcdGicInterruptInterfaceBase) + ARM_GIC_ICCBPR, 0x7);
-
-  // Set priority mask reg to 0xff to allow all priorities through
-  MmioWrite32 (PcdGet32(PcdGicInterruptInterfaceBase) + ARM_GIC_ICCPMR, 0xff);
-  
-  // Enable gic cpu interface
-  MmioWrite32 (PcdGet32(PcdGicInterruptInterfaceBase) + ARM_GIC_ICCICR, 0x1);
-
-  // Enable gic distributor
-  MmioWrite32 (PcdGet32(PcdGicDistributorBase) + ARM_GIC_ICDDCR, 0x1);
-  
-  // Initialize the array for the Interrupt Handlers
-  gRegisteredInterruptHandlers = (HARDWARE_INTERRUPT_HANDLER*)AllocateZeroPool (sizeof(HARDWARE_INTERRUPT_HANDLER) * mGicNumInterrupts);
-  
-  Status = gBS->InstallMultipleProtocolInterfaces (
-                  &gHardwareInterruptHandle,
-                  &gHardwareInterruptProtocolGuid,   &gHardwareInterruptProtocol,
-                  NULL
-                  );
-  ASSERT_EFI_ERROR (Status);
-  
-  //
-  // Get the CPU protocol that this driver requires.
-  //
-  Status = gBS->LocateProtocol(&gEfiCpuArchProtocolGuid, NULL, (VOID **)&Cpu);
-  ASSERT_EFI_ERROR(Status);
-
-  //
-  // Unregister the default exception handler.
-  //
-  Status = Cpu->RegisterInterruptHandler(Cpu, EXCEPT_ARM_IRQ, NULL);
-  ASSERT_EFI_ERROR(Status);
-
-  //
-  // Register to receive interrupts
-  //
-  Status = Cpu->RegisterInterruptHandler(Cpu, EXCEPT_ARM_IRQ, IrqInterruptHandler);
-  ASSERT_EFI_ERROR(Status);
-
-  // Register for an ExitBootServicesEvent
-  Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent);
-  ASSERT_EFI_ERROR (Status);
-
-  return Status;
-}
+/*++\r
+\r
+Copyright (c) 2009, Hewlett-Packard Company. All rights reserved.<BR>\r
+Portions copyright (c) 2010, Apple Inc. All rights reserved.<BR>\r
+Portions copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR> \r
+\r
+This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.   \r
+\r
+Module Name:\r
+\r
+  Gic.c\r
+\r
+Abstract:\r
+\r
+  Driver implementing the GIC interrupt controller protocol\r
+\r
+--*/\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/ArmGicLib.h>\r
+\r
+#include <Protocol/Cpu.h>\r
+#include <Protocol/HardwareInterrupt.h>\r
+\r
+#define ARM_GIC_DEFAULT_PRIORITY  0x80\r
+\r
+extern EFI_HARDWARE_INTERRUPT_PROTOCOL gHardwareInterruptProtocol;\r
+\r
+//\r
+// Notifications\r
+//\r
+EFI_EVENT EfiExitBootServicesEvent      = (EFI_EVENT)NULL;\r
+\r
+// Maximum Number of Interrupts\r
+UINTN mGicNumInterrupts                 = 0;\r
+\r
+HARDWARE_INTERRUPT_HANDLER  *gRegisteredInterruptHandlers = NULL;\r
+\r
+/**\r
+  Register Handler for the specified interrupt source.\r
+\r
+  @param This     Instance pointer for this protocol\r
+  @param Source   Hardware source of the interrupt\r
+  @param Handler  Callback for interrupt. NULL to unregister\r
+\r
+  @retval EFI_SUCCESS Source was updated to support Handler.\r
+  @retval EFI_DEVICE_ERROR  Hardware could not be programmed.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RegisterInterruptSource (\r
+  IN EFI_HARDWARE_INTERRUPT_PROTOCOL    *This,\r
+  IN HARDWARE_INTERRUPT_SOURCE          Source,\r
+  IN HARDWARE_INTERRUPT_HANDLER         Handler\r
+  )\r
+{\r
+  if (Source > mGicNumInterrupts) {\r
+    ASSERT(FALSE);\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  \r
+  if ((Handler == NULL) && (gRegisteredInterruptHandlers[Source] == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if ((Handler != NULL) && (gRegisteredInterruptHandlers[Source] != NULL)) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  gRegisteredInterruptHandlers[Source] = Handler;\r
+\r
+  // If the interrupt handler is unregistered then disable the interrupt\r
+  if (NULL == Handler){\r
+       return This->DisableInterruptSource (This, Source);\r
+  } else {\r
+       return This->EnableInterruptSource (This, Source);\r
+  }\r
+}\r
+\r
+/**\r
+  Enable interrupt source Source.\r
+\r
+  @param This     Instance pointer for this protocol\r
+  @param Source   Hardware source of the interrupt\r
+\r
+  @retval EFI_SUCCESS       Source interrupt enabled.\r
+  @retval EFI_DEVICE_ERROR  Hardware could not be programmed.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EnableInterruptSource (\r
+  IN EFI_HARDWARE_INTERRUPT_PROTOCOL    *This,\r
+  IN HARDWARE_INTERRUPT_SOURCE          Source\r
+  )\r
+{\r
+  UINT32    RegOffset;\r
+  UINTN     RegShift;\r
+  \r
+  if (Source > mGicNumInterrupts) {\r
+    ASSERT(FALSE);\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  \r
+  // Calculate enable register offset and bit position\r
+  RegOffset = Source / 32;\r
+  RegShift = Source % 32;\r
+\r
+  // Write set-enable register\r
+  MmioWrite32 (PcdGet32(PcdGicDistributorBase) + ARM_GIC_ICDISER + (4*RegOffset), 1 << RegShift);\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Disable interrupt source Source.\r
+\r
+  @param This     Instance pointer for this protocol\r
+  @param Source   Hardware source of the interrupt\r
+\r
+  @retval EFI_SUCCESS       Source interrupt disabled.\r
+  @retval EFI_DEVICE_ERROR  Hardware could not be programmed.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DisableInterruptSource (\r
+  IN EFI_HARDWARE_INTERRUPT_PROTOCOL    *This,\r
+  IN HARDWARE_INTERRUPT_SOURCE          Source\r
+  )\r
+{\r
+  UINT32    RegOffset;\r
+  UINTN     RegShift;\r
+  \r
+  if (Source > mGicNumInterrupts) {\r
+    ASSERT(FALSE);\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  \r
+  // Calculate enable register offset and bit position\r
+  RegOffset = Source / 32;\r
+  RegShift = Source % 32;\r
+\r
+  // Write set-enable register\r
+  MmioWrite32 (PcdGet32(PcdGicDistributorBase) + ARM_GIC_ICDICER + (4*RegOffset), 1 << RegShift);\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Return current state of interrupt source Source.\r
+\r
+  @param This     Instance pointer for this protocol\r
+  @param Source   Hardware source of the interrupt\r
+  @param InterruptState  TRUE: source enabled, FALSE: source disabled.\r
+\r
+  @retval EFI_SUCCESS       InterruptState is valid\r
+  @retval EFI_DEVICE_ERROR  InterruptState is not valid\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetInterruptSourceState (\r
+  IN EFI_HARDWARE_INTERRUPT_PROTOCOL    *This,\r
+  IN HARDWARE_INTERRUPT_SOURCE          Source,\r
+  IN BOOLEAN                            *InterruptState\r
+  )\r
+{\r
+  UINT32    RegOffset;\r
+  UINTN     RegShift;\r
+  \r
+  if (Source > mGicNumInterrupts) {\r
+    ASSERT(FALSE);\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  \r
+  // calculate enable register offset and bit position\r
+  RegOffset = Source / 32;\r
+  RegShift = Source % 32;\r
+    \r
+  if ((MmioRead32 (PcdGet32(PcdGicDistributorBase) + ARM_GIC_ICDISER + (4*RegOffset)) & (1<<RegShift)) == 0) {\r
+    *InterruptState = FALSE;\r
+  } else {\r
+    *InterruptState = TRUE;\r
+  }\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Signal to the hardware that the End Of Intrrupt state \r
+  has been reached.\r
+\r
+  @param This     Instance pointer for this protocol\r
+  @param Source   Hardware source of the interrupt\r
+\r
+  @retval EFI_SUCCESS       Source interrupt EOI'ed.\r
+  @retval EFI_DEVICE_ERROR  Hardware could not be programmed.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EndOfInterrupt (\r
+  IN EFI_HARDWARE_INTERRUPT_PROTOCOL    *This,\r
+  IN HARDWARE_INTERRUPT_SOURCE          Source\r
+  )\r
+{\r
+  if (Source > mGicNumInterrupts) {\r
+    ASSERT(FALSE);\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  MmioWrite32 (PcdGet32(PcdGicInterruptInterfaceBase) + ARM_GIC_ICCEIOR, Source);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  EFI_CPU_INTERRUPT_HANDLER that is called when a processor interrupt occurs.\r
+\r
+  @param  InterruptType    Defines the type of interrupt or exception that\r
+                           occurred on the processor.This parameter is processor architecture specific.\r
+  @param  SystemContext    A pointer to the processor context when\r
+                           the interrupt occurred on the processor.\r
+\r
+  @return None\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+IrqInterruptHandler (\r
+  IN EFI_EXCEPTION_TYPE           InterruptType,\r
+  IN EFI_SYSTEM_CONTEXT           SystemContext\r
+  )\r
+{\r
+  UINT32                      GicInterrupt;\r
+  HARDWARE_INTERRUPT_HANDLER  InterruptHandler;\r
+\r
+  GicInterrupt = MmioRead32 (PcdGet32(PcdGicInterruptInterfaceBase) + ARM_GIC_ICCIAR);\r
+\r
+  // Special Interrupts (ID1020-ID1023) have an Interrupt ID greater than the number of interrupt (ie: Spurious interrupt).\r
+  if (GicInterrupt >= mGicNumInterrupts) {\r
+    // The special interrupt do not need to be acknowledge\r
+    return;\r
+  }\r
+  \r
+  InterruptHandler = gRegisteredInterruptHandlers[GicInterrupt];\r
+  if (InterruptHandler != NULL) {\r
+    // Call the registered interrupt handler.\r
+    InterruptHandler (GicInterrupt, SystemContext);\r
+  } else {\r
+    DEBUG ((EFI_D_ERROR, "Spurious GIC interrupt: 0x%x\n", GicInterrupt));\r
+  }\r
+\r
+  EndOfInterrupt (&gHardwareInterruptProtocol, GicInterrupt);\r
+}\r
+\r
+//\r
+// Making this global saves a few bytes in image size\r
+//\r
+EFI_HANDLE  gHardwareInterruptHandle = NULL;\r
+\r
+//\r
+// The protocol instance produced by this driver\r
+//\r
+EFI_HARDWARE_INTERRUPT_PROTOCOL gHardwareInterruptProtocol = {\r
+  RegisterInterruptSource,\r
+  EnableInterruptSource,\r
+  DisableInterruptSource,\r
+  GetInterruptSourceState,\r
+  EndOfInterrupt\r
+};\r
+\r
+/**\r
+  Shutdown our hardware\r
+  \r
+  DXE Core will disable interrupts and turn off the timer and disable interrupts\r
+  after all the event handlers have run.\r
+\r
+  @param[in]  Event   The Event that is being processed\r
+  @param[in]  Context Event Context\r
+**/\r
+VOID\r
+EFIAPI\r
+ExitBootServicesEvent (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+  UINTN    Index;\r
+  \r
+  // Acknowledge all pending interrupts\r
+  for (Index = 0; Index < mGicNumInterrupts; Index++) {\r
+    DisableInterruptSource (&gHardwareInterruptProtocol, Index);\r
+  }\r
+\r
+  for (Index = 0; Index < mGicNumInterrupts; Index++) {\r
+    EndOfInterrupt (&gHardwareInterruptProtocol, Index);\r
+  }\r
+\r
+  // Disable Gic Interface\r
+  MmioWrite32 (PcdGet32(PcdGicInterruptInterfaceBase) + ARM_GIC_ICCICR, 0x0);\r
+  MmioWrite32 (PcdGet32(PcdGicInterruptInterfaceBase) + ARM_GIC_ICCPMR, 0x0);\r
+\r
+  // Disable Gic Distributor\r
+  MmioWrite32 (PcdGet32(PcdGicDistributorBase) + ARM_GIC_ICDDCR, 0x0);\r
+}\r
+\r
+/**\r
+  Initialize the state information for the CPU Architectural Protocol\r
+\r
+  @param  ImageHandle   of the loaded driver\r
+  @param  SystemTable   Pointer to the System Table\r
+\r
+  @retval EFI_SUCCESS           Protocol registered\r
+  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure\r
+  @retval EFI_DEVICE_ERROR      Hardware problems\r
+\r
+**/\r
+EFI_STATUS\r
+InterruptDxeInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  UINTN                   Index;\r
+  UINT32                  RegOffset;\r
+  UINTN                   RegShift;\r
+  EFI_CPU_ARCH_PROTOCOL   *Cpu;\r
+  UINT32                  CpuTarget;\r
+  \r
+  // Check PcdGicPrimaryCoreId has been set in case the Primary Core is not the core 0 of Cluster 0\r
+  DEBUG_CODE_BEGIN();\r
+  if ((PcdGet32(PcdArmPrimaryCore) != 0) && (PcdGet32 (PcdGicPrimaryCoreId) == 0)) {\r
+    DEBUG((EFI_D_WARN,"Warning: the PCD PcdGicPrimaryCoreId does not seem to be set up for the configuration.\n"));\r
+  }\r
+  DEBUG_CODE_END();\r
+\r
+  // Make sure the Interrupt Controller Protocol is not already installed in the system.\r
+  ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gHardwareInterruptProtocolGuid);\r
+\r
+  mGicNumInterrupts = ArmGicGetMaxNumInterrupts (PcdGet32(PcdGicDistributorBase));\r
+\r
+  for (Index = 0; Index < mGicNumInterrupts; Index++) {\r
+    DisableInterruptSource (&gHardwareInterruptProtocol, Index);\r
+    \r
+    // Set Priority \r
+    RegOffset = Index / 4;\r
+    RegShift = (Index % 4) * 8;\r
+    MmioAndThenOr32 (\r
+      PcdGet32(PcdGicDistributorBase) + ARM_GIC_ICDIPR + (4*RegOffset),\r
+      ~(0xff << RegShift), \r
+      ARM_GIC_DEFAULT_PRIORITY << RegShift\r
+      );\r
+  }\r
+\r
+  // Configure interrupts for Primary Cpu\r
+  CpuTarget = (1 << PcdGet32 (PcdGicPrimaryCoreId));\r
+  CpuTarget |= (CpuTarget << 24) | (CpuTarget << 16) | (CpuTarget << 8);\r
+  for (Index = 0; Index < (mGicNumInterrupts / 4); Index++) {\r
+    MmioWrite32 (PcdGet32(PcdGicDistributorBase) + ARM_GIC_ICDIPTR + (Index*4), CpuTarget);\r
+  }\r
+\r
+  // Set binary point reg to 0x7 (no preemption)\r
+  MmioWrite32 (PcdGet32(PcdGicInterruptInterfaceBase) + ARM_GIC_ICCBPR, 0x7);\r
+\r
+  // Set priority mask reg to 0xff to allow all priorities through\r
+  MmioWrite32 (PcdGet32(PcdGicInterruptInterfaceBase) + ARM_GIC_ICCPMR, 0xff);\r
+  \r
+  // Enable gic cpu interface\r
+  MmioWrite32 (PcdGet32(PcdGicInterruptInterfaceBase) + ARM_GIC_ICCICR, 0x1);\r
+\r
+  // Enable gic distributor\r
+  MmioWrite32 (PcdGet32(PcdGicDistributorBase) + ARM_GIC_ICDDCR, 0x1);\r
+  \r
+  // Initialize the array for the Interrupt Handlers\r
+  gRegisteredInterruptHandlers = (HARDWARE_INTERRUPT_HANDLER*)AllocateZeroPool (sizeof(HARDWARE_INTERRUPT_HANDLER) * mGicNumInterrupts);\r
+  \r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &gHardwareInterruptHandle,\r
+                  &gHardwareInterruptProtocolGuid,   &gHardwareInterruptProtocol,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  //\r
+  // Get the CPU protocol that this driver requires.\r
+  //\r
+  Status = gBS->LocateProtocol(&gEfiCpuArchProtocolGuid, NULL, (VOID **)&Cpu);\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  //\r
+  // Unregister the default exception handler.\r
+  //\r
+  Status = Cpu->RegisterInterruptHandler(Cpu, EXCEPT_ARM_IRQ, NULL);\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  //\r
+  // Register to receive interrupts\r
+  //\r
+  Status = Cpu->RegisterInterruptHandler(Cpu, EXCEPT_ARM_IRQ, IrqInterruptHandler);\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  // Register for an ExitBootServicesEvent\r
+  Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
index b63216ee9890af9f27afa69e0e5f70c3af0ed777..422fd414b722475c015486c0525a672734bebfcb 100644 (file)
@@ -1,57 +1,57 @@
-#/** @file
-#  
-#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-#  Copyright (c) 2012, ARM Ltd. All rights reserved.<BR>
-#
-#  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                      = PL390GicDxe
-  FILE_GUID                      = DE371F7C-DEC4-4D21-ADF1-593ABCC15882 
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-
-  ENTRY_POINT                    = InterruptDxeInitialize
-
-
-[Sources.common]
-  PL390Gic.c
-  PL390GicDxe.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  ArmPkg/ArmPkg.dec
-
-[LibraryClasses]
-  BaseLib
-  UefiLib
-  UefiBootServicesTableLib
-  DebugLib
-  PrintLib
-  MemoryAllocationLib
-  UefiDriverEntryPoint
-  IoLib
-
-[Protocols]
-  gHardwareInterruptProtocolGuid
-  gEfiCpuArchProtocolGuid
-  
-[FixedPcd.common]
-  gArmTokenSpaceGuid.PcdGicDistributorBase
-  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase
-  
-  gArmTokenSpaceGuid.PcdArmPrimaryCore
-  gArmTokenSpaceGuid.PcdGicPrimaryCoreId
-
-[Depex]
-  gEfiCpuArchProtocolGuid
+#/** @file\r
+#  \r
+#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+#  Copyright (c) 2012, ARM Ltd. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PL390GicDxe\r
+  FILE_GUID                      = DE371F7C-DEC4-4D21-ADF1-593ABCC15882 \r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = InterruptDxeInitialize\r
+\r
+\r
+[Sources.common]\r
+  PL390Gic.c\r
+  PL390GicDxe.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  UefiLib\r
+  UefiBootServicesTableLib\r
+  DebugLib\r
+  PrintLib\r
+  MemoryAllocationLib\r
+  UefiDriverEntryPoint\r
+  IoLib\r
+\r
+[Protocols]\r
+  gHardwareInterruptProtocolGuid\r
+  gEfiCpuArchProtocolGuid\r
+  \r
+[FixedPcd.common]\r
+  gArmTokenSpaceGuid.PcdGicDistributorBase\r
+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase\r
+  \r
+  gArmTokenSpaceGuid.PcdArmPrimaryCore\r
+  gArmTokenSpaceGuid.PcdGicPrimaryCoreId\r
+\r
+[Depex]\r
+  gEfiCpuArchProtocolGuid\r
index 50de7668eaa08b11dd6ab50ce843135a60b52c55..cbc34e8e412123515087f7e3e0080fbb93d84b44 100644 (file)
-/** @file
-  Timer Architecture Protocol driver of the ARM flavor
-
-  Copyright (c) 2011 ARM Ltd. All rights reserved.<BR>
-  
-  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 <PiDxe.h>
-
-#include <Library/ArmLib.h>
-#include <Library/BaseLib.h>
-#include <Library/DebugLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiLib.h>
-#include <Library/PcdLib.h>
-#include <Library/IoLib.h>
-#include <Library/ArmV7ArchTimerLib.h>
-
-#include <Protocol/Timer.h>
-#include <Protocol/HardwareInterrupt.h>
-
-// The notification function to call on every timer interrupt.
-EFI_TIMER_NOTIFY      mTimerNotifyFunction     = (EFI_TIMER_NOTIFY)NULL;
-EFI_EVENT             EfiExitBootServicesEvent = (EFI_EVENT)NULL;
-
-// The current period of the timer interrupt
-UINT64 mTimerPeriod = 0;
-
-// Cached copy of the Hardware Interrupt protocol instance
-EFI_HARDWARE_INTERRUPT_PROTOCOL *gInterrupt = NULL;
-
-/**
-  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.
-
-  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.
-  @param  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.
-  @retval EFI_SUCCESS           The timer handler was registered.
-  @retval EFI_UNSUPPORTED       The platform does not support timer interrupts.
-  @retval EFI_ALREADY_STARTED   NotifyFunction is not NULL, and a handler is already
-                                registered.
-  @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not
-                                previously registered.
-  @retval EFI_DEVICE_ERROR      The timer handler could not be registered.
-
-**/
-EFI_STATUS
-EFIAPI
-TimerDriverRegisterHandler (
-  IN EFI_TIMER_ARCH_PROTOCOL  *This,
-  IN EFI_TIMER_NOTIFY         NotifyFunction
-  )
-{
-  if ((NotifyFunction == NULL) && (mTimerNotifyFunction == NULL)) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  if ((NotifyFunction != NULL) && (mTimerNotifyFunction != NULL)) {
-    return EFI_ALREADY_STARTED;
-  }
-
-  mTimerNotifyFunction = NotifyFunction;
-
-  return EFI_SUCCESS;
-}
-
-/**
-    Disable the timer
-**/
-VOID
-EFIAPI
-ExitBootServicesEvent (
-  IN EFI_EVENT  Event,
-  IN VOID       *Context
-  )
-{
-  ArmArchTimerDisableTimer ();
-}
-
-/**
-
-  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. 
-
-  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.
-  @param  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.
-
-
-  @retval EFI_SUCCESS           The timer period was changed.
-  @retval EFI_UNSUPPORTED       The platform cannot change the period of the timer interrupt.
-  @retval EFI_DEVICE_ERROR      The timer period could not be changed due to a device error.
-
-**/
-EFI_STATUS
-EFIAPI
-TimerDriverSetTimerPeriod (
-  IN EFI_TIMER_ARCH_PROTOCOL  *This,
-  IN UINT64                   TimerPeriod
-  )
-{
-  UINT64      TimerTicks;
-  
-  // Always disable the timer
-  ArmArchTimerDisableTimer ();
-
-  if (TimerPeriod != 0) {
-    // Convert TimerPeriod to micro sec units
-    TimerTicks = DivU64x32 (TimerPeriod, 10);
-
-    TimerTicks = MultU64x32 (TimerTicks, (PcdGet32(PcdArmArchTimerFreqInHz)/1000000));
-
-    ArmArchTimerSetTimerVal((UINTN)TimerTicks);
-
-    // Enable the timer
-    ArmArchTimerEnableTimer ();
-  }
-
-  // Save the new timer period
-  mTimerPeriod = TimerPeriod;
-  return EFI_SUCCESS;
-}
-
-/**
-  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.
-
-  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.
-  @param  TimerPeriod      A pointer to the timer period to retrieve in 100 ns units. If
-                           0 is returned, then the timer is currently disabled.
-
-
-  @retval EFI_SUCCESS           The timer period was returned in TimerPeriod.
-  @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
-
-**/
-EFI_STATUS
-EFIAPI
-TimerDriverGetTimerPeriod (
-  IN EFI_TIMER_ARCH_PROTOCOL   *This,
-  OUT UINT64                   *TimerPeriod
-  )
-{
-  if (TimerPeriod == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  *TimerPeriod = mTimerPeriod;
-  return EFI_SUCCESS;
-}
-
-/**
-  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.
-
-  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.
-
-  @retval EFI_SUCCESS           The soft timer interrupt was generated.
-  @retval EFI_UNSUPPORTED       The platform does not support the generation of soft timer interrupts.
-
-**/
-EFI_STATUS
-EFIAPI
-TimerDriverGenerateSoftInterrupt (
-  IN EFI_TIMER_ARCH_PROTOCOL  *This
-  )
-{
-  return EFI_UNSUPPORTED;
-}
-
-/**
-  Interface structure for the Timer Architectural Protocol.
-
-  @par Protocol Description:
-  This protocol provides the services to initialize a periodic timer
-  interrupt, and to register a handler that is called each time the timer
-  interrupt fires.  It may also provide a service to adjust the rate of the
-  periodic timer interrupt.  When a timer interrupt occurs, the handler is
-  passed the amount of time that has passed since the previous timer
-  interrupt.
-
-  @param RegisterHandler
-  Registers a handler that will be called each time the
-  timer interrupt fires.  TimerPeriod defines the minimum
-  time between timer interrupts, so TimerPeriod will also
-  be the minimum time between calls to the registered
-  handler.
-
-  @param SetTimerPeriod
-  Sets the period of the timer interrupt in 100 nS units.
-  This function is optional, and may return EFI_UNSUPPORTED.
-  If this function is supported, then the timer period will
-  be rounded up to the nearest supported timer period.
-
-
-  @param GetTimerPeriod
-  Retrieves the period of the timer interrupt in 100 nS units.
-
-  @param GenerateSoftInterrupt
-  Generates a soft timer interrupt that simulates the firing of
-  the timer interrupt. This service can be used to invoke the   registered handler if the timer interrupt has been masked for
-  a period of time.
-
-**/
-EFI_TIMER_ARCH_PROTOCOL   gTimer = {
-  TimerDriverRegisterHandler,
-  TimerDriverSetTimerPeriod,
-  TimerDriverGetTimerPeriod,
-  TimerDriverGenerateSoftInterrupt
-};
-
-/**
-
-  C Interrupt Handler called in the interrupt context when Source interrupt is active.
-
-
-  @param Source         Source of the interrupt. Hardware routing off a specific platform defines
-                        what source means.
-
-  @param SystemContext  Pointer to system register context. Mostly used by debuggers and will
-                        update the system context after the return from the interrupt if
-                        modified. Don't change these values unless you know what you are doing
-
-**/
-VOID
-EFIAPI
-TimerInterruptHandler (
-  IN  HARDWARE_INTERRUPT_SOURCE   Source,
-  IN  EFI_SYSTEM_CONTEXT          SystemContext
-  )
-{
-  EFI_TPL      OriginalTPL;
-
-  //
-  // DXE core uses this callback for the EFI timer tick. The DXE core uses locks
-  // that raise to TPL_HIGH and then restore back to current level. Thus we need
-  // to make sure TPL level is set to TPL_HIGH while we are handling the timer tick.
-  //
-  OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);
-
-  // Check if the timer interrupt is active
-  if ((ArmArchTimerGetTimerCtrlReg () ) & ARM_ARCH_TIMER_ISTATUS) {
-
-    // Signal end of interrupt early to help avoid losing subsequent ticks from long duration handlers
-    gInterrupt->EndOfInterrupt (gInterrupt, Source);
-
-    if (mTimerNotifyFunction) {
-      mTimerNotifyFunction (mTimerPeriod);
-    }
-
-    // Reload the Timer
-    TimerDriverSetTimerPeriod (&gTimer, FixedPcdGet32(PcdTimerPeriod));
-  }
-
-  // Enable timer interrupts
-  gInterrupt->EnableInterruptSource (gInterrupt, Source);
-
-  gBS->RestoreTPL (OriginalTPL);
-}
-
-
-/**
-  Initialize the state information for the Timer Architectural Protocol and
-  the Timer Debug support protocol that allows the debugger to break into a
-  running program.
-
-  @param  ImageHandle   of the loaded driver
-  @param  SystemTable   Pointer to the System Table
-
-  @retval EFI_SUCCESS           Protocol registered
-  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure
-  @retval EFI_DEVICE_ERROR      Hardware problems
-
-**/
-EFI_STATUS
-EFIAPI
-TimerInitialize (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
-  )
-{
-  EFI_HANDLE  Handle = NULL;
-  EFI_STATUS  Status;
-  UINTN TimerCtrlReg;
-
-  if (ArmIsArchTimerImplemented () == 0) {
-    DEBUG ((EFI_D_ERROR, "ARM Architectural Timer is not available in the CPU, hence cann't use this Driver \n"));
-    ASSERT (0);
-  }
-
-  // Find the interrupt controller protocol.  ASSERT if not found.
-  Status = gBS->LocateProtocol (&gHardwareInterruptProtocolGuid, NULL, (VOID **)&gInterrupt);
-  ASSERT_EFI_ERROR (Status);
-
-  // Disable the timer
-  Status = TimerDriverSetTimerPeriod (&gTimer, 0);
-  ASSERT_EFI_ERROR (Status);
-
-  // Install secure and Non-secure interrupt handlers
-  // Note: Because it is not possible to determine the security state of the
-  // CPU dynamically, we just install interrupt handler for both sec and non-sec
-  // timer PPI
-  Status = gInterrupt->RegisterInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerSecIntrNum), TimerInterruptHandler);
-  ASSERT_EFI_ERROR (Status);
-
-  Status = gInterrupt->RegisterInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerIntrNum), TimerInterruptHandler);
-  ASSERT_EFI_ERROR (Status);
-
-  // Unmask timer interrupts
-  TimerCtrlReg = ArmArchTimerGetTimerCtrlReg ();
-  TimerCtrlReg &= ~ARM_ARCH_TIMER_IMASK;
-  ArmArchTimerSetTimerCtrlReg (TimerCtrlReg);
-
-  // Set up default timer
-  Status = TimerDriverSetTimerPeriod (&gTimer, FixedPcdGet32(PcdTimerPeriod)); // TIMER_DEFAULT_PERIOD
-  ASSERT_EFI_ERROR (Status);
-
-  // Install the Timer Architectural Protocol onto a new handle
-  Status = gBS->InstallMultipleProtocolInterfaces(
-                  &Handle,
-                  &gEfiTimerArchProtocolGuid,      &gTimer,
-                  NULL
-                  );
-  ASSERT_EFI_ERROR(Status);
-
-  // enable Secure timer interrupts
-  Status = gInterrupt->EnableInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerSecIntrNum));
-
-  // enable NonSecure timer interrupts
-  Status = gInterrupt->EnableInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerIntrNum));
-
-  // Register for an ExitBootServicesEvent
-  Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent);
-  ASSERT_EFI_ERROR (Status);
-
-  return Status;
-}
+/** @file\r
+  Timer Architecture Protocol driver of the ARM flavor\r
+\r
+  Copyright (c) 2011 ARM Ltd. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials                          \r
+  are licensed and made available under the terms and conditions of the BSD License         \r
+  which accompanies this distribution.  The full text of the license may be found at        \r
+  http://opensource.org/licenses/bsd-license.php                                            \r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+**/\r
+\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Library/ArmLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/ArmV7ArchTimerLib.h>\r
+\r
+#include <Protocol/Timer.h>\r
+#include <Protocol/HardwareInterrupt.h>\r
+\r
+// The notification function to call on every timer interrupt.\r
+EFI_TIMER_NOTIFY      mTimerNotifyFunction     = (EFI_TIMER_NOTIFY)NULL;\r
+EFI_EVENT             EfiExitBootServicesEvent = (EFI_EVENT)NULL;\r
+\r
+// The current period of the timer interrupt\r
+UINT64 mTimerPeriod = 0;\r
+\r
+// Cached copy of the Hardware Interrupt protocol instance\r
+EFI_HARDWARE_INTERRUPT_PROTOCOL *gInterrupt = NULL;\r
+\r
+/**\r
+  This function registers the handler NotifyFunction so it is called every time \r
+  the timer interrupt fires.  It also passes the amount of time since the last \r
+  handler call to the NotifyFunction.  If NotifyFunction is NULL, then the \r
+  handler is unregistered.  If the handler is registered, then EFI_SUCCESS is \r
+  returned.  If the CPU does not support registering a timer interrupt handler, \r
+  then EFI_UNSUPPORTED is returned.  If an attempt is made to register a handler \r
+  when a handler is already registered, then EFI_ALREADY_STARTED is returned.  \r
+  If an attempt is made to unregister a handler when a handler is not registered, \r
+  then EFI_INVALID_PARAMETER is returned.  If an error occurs attempting to \r
+  register the NotifyFunction with the timer interrupt, then EFI_DEVICE_ERROR \r
+  is returned.\r
+\r
+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param  NotifyFunction   The function to call when a timer interrupt fires. This\r
+                           function executes at TPL_HIGH_LEVEL. The DXE Core will\r
+                           register a handler for the timer interrupt, so it can know\r
+                           how much time has passed. This information is used to\r
+                           signal timer based events. NULL will unregister the handler.\r
+  @retval EFI_SUCCESS           The timer handler was registered.\r
+  @retval EFI_UNSUPPORTED       The platform does not support timer interrupts.\r
+  @retval EFI_ALREADY_STARTED   NotifyFunction is not NULL, and a handler is already\r
+                                registered.\r
+  @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not\r
+                                previously registered.\r
+  @retval EFI_DEVICE_ERROR      The timer handler could not be registered.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverRegisterHandler (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  IN EFI_TIMER_NOTIFY         NotifyFunction\r
+  )\r
+{\r
+  if ((NotifyFunction == NULL) && (mTimerNotifyFunction == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if ((NotifyFunction != NULL) && (mTimerNotifyFunction != NULL)) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  mTimerNotifyFunction = NotifyFunction;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+    Disable the timer\r
+**/\r
+VOID\r
+EFIAPI\r
+ExitBootServicesEvent (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+  ArmArchTimerDisableTimer ();\r
+}\r
+\r
+/**\r
+\r
+  This function adjusts the period of timer interrupts to the value specified \r
+  by TimerPeriod.  If the timer period is updated, then the selected timer \r
+  period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned.  If \r
+  the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.  \r
+  If an error occurs while attempting to update the timer period, then the \r
+  timer hardware will be put back in its state prior to this call, and \r
+  EFI_DEVICE_ERROR is returned.  If TimerPeriod is 0, then the timer interrupt \r
+  is disabled.  This is not the same as disabling the CPU's interrupts.  \r
+  Instead, it must either turn off the timer hardware, or it must adjust the \r
+  interrupt controller so that a CPU interrupt is not generated when the timer \r
+  interrupt fires. \r
+\r
+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param  TimerPeriod      The rate to program the timer interrupt in 100 nS units. If\r
+                           the timer hardware is not programmable, then EFI_UNSUPPORTED is\r
+                           returned. If the timer is programmable, then the timer period\r
+                           will be rounded up to the nearest timer period that is supported\r
+                           by the timer hardware. If TimerPeriod is set to 0, then the\r
+                           timer interrupts will be disabled.\r
+\r
+\r
+  @retval EFI_SUCCESS           The timer period was changed.\r
+  @retval EFI_UNSUPPORTED       The platform cannot change the period of the timer interrupt.\r
+  @retval EFI_DEVICE_ERROR      The timer period could not be changed due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverSetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  IN UINT64                   TimerPeriod\r
+  )\r
+{\r
+  UINT64      TimerTicks;\r
+  \r
+  // Always disable the timer\r
+  ArmArchTimerDisableTimer ();\r
+\r
+  if (TimerPeriod != 0) {\r
+    // Convert TimerPeriod to micro sec units\r
+    TimerTicks = DivU64x32 (TimerPeriod, 10);\r
+\r
+    TimerTicks = MultU64x32 (TimerTicks, (PcdGet32(PcdArmArchTimerFreqInHz)/1000000));\r
+\r
+    ArmArchTimerSetTimerVal((UINTN)TimerTicks);\r
+\r
+    // Enable the timer\r
+    ArmArchTimerEnableTimer ();\r
+  }\r
+\r
+  // Save the new timer period\r
+  mTimerPeriod = TimerPeriod;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This function retrieves the period of timer interrupts in 100 ns units, \r
+  returns that value in TimerPeriod, and returns EFI_SUCCESS.  If TimerPeriod \r
+  is NULL, then EFI_INVALID_PARAMETER is returned.  If a TimerPeriod of 0 is \r
+  returned, then the timer is currently disabled.\r
+\r
+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param  TimerPeriod      A pointer to the timer period to retrieve in 100 ns units. If\r
+                           0 is returned, then the timer is currently disabled.\r
+\r
+\r
+  @retval EFI_SUCCESS           The timer period was returned in TimerPeriod.\r
+  @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverGetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL   *This,\r
+  OUT UINT64                   *TimerPeriod\r
+  )\r
+{\r
+  if (TimerPeriod == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *TimerPeriod = mTimerPeriod;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This function generates a soft timer interrupt. If the platform does not support soft \r
+  timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCESS is returned. \r
+  If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.RegisterHandler() \r
+  service, then a soft timer interrupt will be generated. If the timer interrupt is \r
+  enabled when this service is called, then the registered handler will be invoked. The \r
+  registered handler should not be able to distinguish a hardware-generated timer \r
+  interrupt from a software-generated timer interrupt.\r
+\r
+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.\r
+\r
+  @retval EFI_SUCCESS           The soft timer interrupt was generated.\r
+  @retval EFI_UNSUPPORTED       The platform does not support the generation of soft timer interrupts.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverGenerateSoftInterrupt (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Interface structure for the Timer Architectural Protocol.\r
+\r
+  @par Protocol Description:\r
+  This protocol provides the services to initialize a periodic timer\r
+  interrupt, and to register a handler that is called each time the timer\r
+  interrupt fires.  It may also provide a service to adjust the rate of the\r
+  periodic timer interrupt.  When a timer interrupt occurs, the handler is\r
+  passed the amount of time that has passed since the previous timer\r
+  interrupt.\r
+\r
+  @param RegisterHandler\r
+  Registers a handler that will be called each time the\r
+  timer interrupt fires.  TimerPeriod defines the minimum\r
+  time between timer interrupts, so TimerPeriod will also\r
+  be the minimum time between calls to the registered\r
+  handler.\r
+\r
+  @param SetTimerPeriod\r
+  Sets the period of the timer interrupt in 100 nS units.\r
+  This function is optional, and may return EFI_UNSUPPORTED.\r
+  If this function is supported, then the timer period will\r
+  be rounded up to the nearest supported timer period.\r
+\r
+\r
+  @param GetTimerPeriod\r
+  Retrieves the period of the timer interrupt in 100 nS units.\r
+\r
+  @param GenerateSoftInterrupt\r
+  Generates a soft timer interrupt that simulates the firing of\r
+  the timer interrupt. This service can be used to invoke the   registered handler if the timer interrupt has been masked for\r
+  a period of time.\r
+\r
+**/\r
+EFI_TIMER_ARCH_PROTOCOL   gTimer = {\r
+  TimerDriverRegisterHandler,\r
+  TimerDriverSetTimerPeriod,\r
+  TimerDriverGetTimerPeriod,\r
+  TimerDriverGenerateSoftInterrupt\r
+};\r
+\r
+/**\r
+\r
+  C Interrupt Handler called in the interrupt context when Source interrupt is active.\r
+\r
+\r
+  @param Source         Source of the interrupt. Hardware routing off a specific platform defines\r
+                        what source means.\r
+\r
+  @param SystemContext  Pointer to system register context. Mostly used by debuggers and will\r
+                        update the system context after the return from the interrupt if\r
+                        modified. Don't change these values unless you know what you are doing\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+TimerInterruptHandler (\r
+  IN  HARDWARE_INTERRUPT_SOURCE   Source,\r
+  IN  EFI_SYSTEM_CONTEXT          SystemContext\r
+  )\r
+{\r
+  EFI_TPL      OriginalTPL;\r
+\r
+  //\r
+  // DXE core uses this callback for the EFI timer tick. The DXE core uses locks\r
+  // that raise to TPL_HIGH and then restore back to current level. Thus we need\r
+  // to make sure TPL level is set to TPL_HIGH while we are handling the timer tick.\r
+  //\r
+  OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+\r
+  // Check if the timer interrupt is active\r
+  if ((ArmArchTimerGetTimerCtrlReg () ) & ARM_ARCH_TIMER_ISTATUS) {\r
+\r
+    // Signal end of interrupt early to help avoid losing subsequent ticks from long duration handlers\r
+    gInterrupt->EndOfInterrupt (gInterrupt, Source);\r
+\r
+    if (mTimerNotifyFunction) {\r
+      mTimerNotifyFunction (mTimerPeriod);\r
+    }\r
+\r
+    // Reload the Timer\r
+    TimerDriverSetTimerPeriod (&gTimer, FixedPcdGet32(PcdTimerPeriod));\r
+  }\r
+\r
+  // Enable timer interrupts\r
+  gInterrupt->EnableInterruptSource (gInterrupt, Source);\r
+\r
+  gBS->RestoreTPL (OriginalTPL);\r
+}\r
+\r
+\r
+/**\r
+  Initialize the state information for the Timer Architectural Protocol and\r
+  the Timer Debug support protocol that allows the debugger to break into a\r
+  running program.\r
+\r
+  @param  ImageHandle   of the loaded driver\r
+  @param  SystemTable   Pointer to the System Table\r
+\r
+  @retval EFI_SUCCESS           Protocol registered\r
+  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure\r
+  @retval EFI_DEVICE_ERROR      Hardware problems\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_HANDLE  Handle = NULL;\r
+  EFI_STATUS  Status;\r
+  UINTN TimerCtrlReg;\r
+\r
+  if (ArmIsArchTimerImplemented () == 0) {\r
+    DEBUG ((EFI_D_ERROR, "ARM Architectural Timer is not available in the CPU, hence cann't use this Driver \n"));\r
+    ASSERT (0);\r
+  }\r
+\r
+  // Find the interrupt controller protocol.  ASSERT if not found.\r
+  Status = gBS->LocateProtocol (&gHardwareInterruptProtocolGuid, NULL, (VOID **)&gInterrupt);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  // Disable the timer\r
+  Status = TimerDriverSetTimerPeriod (&gTimer, 0);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  // Install secure and Non-secure interrupt handlers\r
+  // Note: Because it is not possible to determine the security state of the\r
+  // CPU dynamically, we just install interrupt handler for both sec and non-sec\r
+  // timer PPI\r
+  Status = gInterrupt->RegisterInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerSecIntrNum), TimerInterruptHandler);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = gInterrupt->RegisterInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerIntrNum), TimerInterruptHandler);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  // Unmask timer interrupts\r
+  TimerCtrlReg = ArmArchTimerGetTimerCtrlReg ();\r
+  TimerCtrlReg &= ~ARM_ARCH_TIMER_IMASK;\r
+  ArmArchTimerSetTimerCtrlReg (TimerCtrlReg);\r
+\r
+  // Set up default timer\r
+  Status = TimerDriverSetTimerPeriod (&gTimer, FixedPcdGet32(PcdTimerPeriod)); // TIMER_DEFAULT_PERIOD\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  // Install the Timer Architectural Protocol onto a new handle\r
+  Status = gBS->InstallMultipleProtocolInterfaces(\r
+                  &Handle,\r
+                  &gEfiTimerArchProtocolGuid,      &gTimer,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  // enable Secure timer interrupts\r
+  Status = gInterrupt->EnableInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerSecIntrNum));\r
+\r
+  // enable NonSecure timer interrupts\r
+  Status = gInterrupt->EnableInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerIntrNum));\r
+\r
+  // Register for an ExitBootServicesEvent\r
+  Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
index 4fe2e2f0bf61761b29a66ac7b4d019bdda7a3ca7..061fcbc688d9455027a9945d5ceacdf97e8b9e58 100644 (file)
@@ -1,59 +1,59 @@
-#/** @file
-#  
-#    Component description file for Timer DXE module
-#  
-#  Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>
-#  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                      = ArmTimerDxe
-  FILE_GUID                      = 49ea041e-6752-42ca-b0b1-7344fe2546b7 
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-
-  ENTRY_POINT                    = TimerInitialize
-
-[Sources.common]
-  TimerDxe.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  ArmPkg/ArmPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  ArmLib
-  BaseLib
-  UefiRuntimeServicesTableLib
-  UefiLib
-  UefiBootServicesTableLib
-  BaseMemoryLib
-  DebugLib
-  UefiDriverEntryPoint
-  IoLib  
-
-[Guids]
-
-[Protocols]
-  gEfiTimerArchProtocolGuid  
-  gHardwareInterruptProtocolGuid
-
-[Pcd.common]
-  gEmbeddedTokenSpaceGuid.PcdTimerPeriod
-  gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum  
-  gArmTokenSpaceGuid.PcdArmArchTimerIntrNum
-  gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz  
-
-[Depex]
-  gHardwareInterruptProtocolGuid
-  
\ No newline at end of file
+#/** @file\r
+#  \r
+#    Component description file for Timer DXE module\r
+#  \r
+#  Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = ArmTimerDxe\r
+  FILE_GUID                      = 49ea041e-6752-42ca-b0b1-7344fe2546b7 \r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = TimerInitialize\r
+\r
+[Sources.common]\r
+  TimerDxe.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  ArmLib\r
+  BaseLib\r
+  UefiRuntimeServicesTableLib\r
+  UefiLib\r
+  UefiBootServicesTableLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  UefiDriverEntryPoint\r
+  IoLib  \r
+\r
+[Guids]\r
+\r
+[Protocols]\r
+  gEfiTimerArchProtocolGuid  \r
+  gHardwareInterruptProtocolGuid\r
+\r
+[Pcd.common]\r
+  gEmbeddedTokenSpaceGuid.PcdTimerPeriod\r
+  gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum  \r
+  gArmTokenSpaceGuid.PcdArmArchTimerIntrNum\r
+  gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz  \r
+\r
+[Depex]\r
+  gHardwareInterruptProtocolGuid\r
+  \r
\ No newline at end of file
index 25b7289483df2ae6df4bcc470aa0191fe93bc371..30ce6665f0df5871122c3aae949e99d0861a4fe7 100644 (file)
@@ -1,46 +1,46 @@
-#/** @file
-#  Support a Semi Host file system over a debuggers JTAG
-#
-#  Copyright (c) 2009, Apple Inc. All rights reserved.<BR>
-#  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                      = SemihostFs
-  FILE_GUID                      = C5B9C74A-6D72-4719-99AB-C59F199091EB
-  MODULE_TYPE                    = UEFI_DRIVER
-  VERSION_STRING                 = 1.0
-
-  ENTRY_POINT                    = SemihostFsEntryPoint
-
-[Sources.ARM]
-  Arm/SemihostFs.c
-  
-[Packages]
-  MdePkg/MdePkg.dec
-  ArmPkg/ArmPkg.dec
-
-[LibraryClasses]
-  BaseLib
-  MemoryAllocationLib
-  SemihostLib
-  UefiDriverEntryPoint
-  UefiLib
-
-[Guids]
-  gEfiFileSystemInfoGuid
-  gEfiFileInfoGuid
-  gEfiFileSystemVolumeLabelInfoIdGuid
-
-[Protocols]
-  gEfiSimpleFileSystemProtocolGuid
-  gEfiDevicePathProtocolGuid
-  
+#/** @file\r
+#  Support a Semi Host file system over a debuggers JTAG\r
+#\r
+#  Copyright (c) 2009, Apple Inc. All rights reserved.<BR>\r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = SemihostFs\r
+  FILE_GUID                      = C5B9C74A-6D72-4719-99AB-C59F199091EB\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = SemihostFsEntryPoint\r
+\r
+[Sources.ARM]\r
+  Arm/SemihostFs.c\r
+  \r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  MemoryAllocationLib\r
+  SemihostLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+\r
+[Guids]\r
+  gEfiFileSystemInfoGuid\r
+  gEfiFileInfoGuid\r
+  gEfiFileSystemVolumeLabelInfoIdGuid\r
+\r
+[Protocols]\r
+  gEfiSimpleFileSystemProtocolGuid\r
+  gEfiDevicePathProtocolGuid\r
+  \r
index 6f92b111d60c4aff2dea0cdb4f7d8371eb992016..0c415992dfe6c85f13e4798088db5d1ce551fa01 100644 (file)
@@ -1,28 +1,28 @@
-/** @file
-
-  Copyright (c) 2011-2012, ARM Limited. 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.
-
-**/
-
-#ifndef __ARMCPU_LIB__
-#define __ARMCPU_LIB__
-
-VOID
-ArmCpuSetup (
-  IN  UINTN         MpId
-  );
-
-VOID
-ArmCpuSetupSmpNonSecure (
-  IN  UINTN         MpId
-  );
-
-#endif // __ARMCPU_LIB__
+/** @file\r
+\r
+  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __ARMCPU_LIB__\r
+#define __ARMCPU_LIB__\r
+\r
+VOID\r
+ArmCpuSetup (\r
+  IN  UINTN         MpId\r
+  );\r
+\r
+VOID\r
+ArmCpuSetupSmpNonSecure (\r
+  IN  UINTN         MpId\r
+  );\r
+\r
+#endif // __ARMCPU_LIB__\r
index 038f2ddfa2f7edbf988f3f23c3d5f65e7bd2bc40..757c95ec7904657e855e5bfc7dcbb9fc6703bb58 100644 (file)
@@ -1,43 +1,43 @@
-/** @file
-
-  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __ARM_DISASSEBLER_LIB_H__
-#define __ARM_DISASSEBLER_LIB_H__
-
-/**
-  Place a dissasembly of of **OpCodePtr into buffer, and update OpCodePtr to 
-  point to next instructin. 
-  
-  We cheat and only decode instructions that access 
-  memory. If the instruction is not found we dump the instruction in hex.
-   
-  @param  OpCodePtrPtr  Pointer to pointer of ARM Thumb instruction to disassemble.  
-  @param  Thumb         TRUE for Thumb(2), FALSE for ARM instruction stream
-  @param  Extended      TRUE dump hex for instruction too.
+/** @file\r
+\r
+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __ARM_DISASSEBLER_LIB_H__\r
+#define __ARM_DISASSEBLER_LIB_H__\r
+\r
+/**\r
+  Place a dissasembly of of **OpCodePtr into buffer, and update OpCodePtr to \r
+  point to next instructin. \r
+  \r
+  We cheat and only decode instructions that access \r
+  memory. If the instruction is not found we dump the instruction in hex.\r
+   \r
+  @param  OpCodePtrPtr  Pointer to pointer of ARM Thumb instruction to disassemble.  \r
+  @param  Thumb         TRUE for Thumb(2), FALSE for ARM instruction stream\r
+  @param  Extended      TRUE dump hex for instruction too.\r
   @param  ItBlock       Size of IT Block\r
   @param  ItBlock       Size of IT Block\r
-  @param  Buf           Buffer to sprintf disassembly into.
-  @param  Size          Size of Buf in bytes. 
-  
-**/
-VOID
-DisassembleInstruction (
-  IN  UINT8     **OpCodePtr,
-  IN  BOOLEAN   Thumb,
-  IN  BOOLEAN   Extended,
+  @param  Buf           Buffer to sprintf disassembly into.\r
+  @param  Size          Size of Buf in bytes. \r
+  \r
+**/\r
+VOID\r
+DisassembleInstruction (\r
+  IN  UINT8     **OpCodePtr,\r
+  IN  BOOLEAN   Thumb,\r
+  IN  BOOLEAN   Extended,\r
   IN OUT UINT32 *ItBlock,\r
   IN OUT UINT32 *ItBlock,\r
-  OUT CHAR8     *Buf,
-  OUT UINTN     Size
-  );
-  
-#endif 
+  OUT CHAR8     *Buf,\r
+  OUT UINTN     Size\r
+  );\r
+  \r
+#endif \r
index 23beb242749cfe41d5fb03098a684f324130ab7a..1e55284317d13b031e0c9c2802c38f47e3d6fe30 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __ARM_LIB__
-#define __ARM_LIB__
-
-#include <Uefi/UefiBaseType.h>
-
-#ifdef ARM_CPU_ARMv6
-#include <Chipset/ARM1176JZ-S.h>
-#else
-#include <Chipset/ArmV7.h>
-#endif
-
-typedef enum {
-  ARM_CACHE_TYPE_WRITE_BACK,
-  ARM_CACHE_TYPE_UNKNOWN
-} ARM_CACHE_TYPE;
-
-typedef enum {
-  ARM_CACHE_ARCHITECTURE_UNIFIED,
-  ARM_CACHE_ARCHITECTURE_SEPARATE,
-  ARM_CACHE_ARCHITECTURE_UNKNOWN
-} ARM_CACHE_ARCHITECTURE;
-
-typedef struct {
-  ARM_CACHE_TYPE          Type;
-  ARM_CACHE_ARCHITECTURE  Architecture;
-  BOOLEAN                 DataCachePresent;
-  UINTN                   DataCacheSize;
-  UINTN                   DataCacheAssociativity;
-  UINTN                   DataCacheLineLength;
-  BOOLEAN                 InstructionCachePresent;
-  UINTN                   InstructionCacheSize;
-  UINTN                   InstructionCacheAssociativity;
-  UINTN                   InstructionCacheLineLength;
-} ARM_CACHE_INFO;
-
-/**
- * The UEFI firmware must not use the ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_* attributes.
- *
- * The Non Secure memory attribute (ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_*) should only
- * be used in Secure World to distinguished Secure to Non-Secure memory.
- */
-typedef enum {
-  ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED = 0,
-  ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_UNCACHED_UNBUFFERED,
-  ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK,
-  ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK,
-  ARM_MEMORY_REGION_ATTRIBUTE_WRITE_THROUGH,
-  ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_THROUGH,
-  ARM_MEMORY_REGION_ATTRIBUTE_DEVICE,
-  ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_DEVICE
-} ARM_MEMORY_REGION_ATTRIBUTES;
-
-#define IS_ARM_MEMORY_REGION_ATTRIBUTES_SECURE(attr) ((UINT32)(attr) & 1)
-
-typedef struct {
-  EFI_PHYSICAL_ADDRESS          PhysicalBase;
-  EFI_VIRTUAL_ADDRESS           VirtualBase;
-  UINTN                         Length;
-  ARM_MEMORY_REGION_ATTRIBUTES  Attributes;
-} ARM_MEMORY_REGION_DESCRIPTOR;
-
-typedef VOID (*CACHE_OPERATION)(VOID);
-typedef VOID (*LINE_OPERATION)(UINTN);
-
-//
-// ARM Processor Mode
-//
-typedef enum {
-  ARM_PROCESSOR_MODE_USER       = 0x10,
-  ARM_PROCESSOR_MODE_FIQ        = 0x11,
-  ARM_PROCESSOR_MODE_IRQ        = 0x12,
-  ARM_PROCESSOR_MODE_SUPERVISOR = 0x13,
-  ARM_PROCESSOR_MODE_ABORT      = 0x17,
-  ARM_PROCESSOR_MODE_HYP        = 0x1A,
-  ARM_PROCESSOR_MODE_UNDEFINED  = 0x1B,
-  ARM_PROCESSOR_MODE_SYSTEM     = 0x1F,
-  ARM_PROCESSOR_MODE_MASK       = 0x1F
-} ARM_PROCESSOR_MODE;
-
-//
-// ARM Cpu IDs
-//
-#define ARM_CPU_IMPLEMENTER_MASK          (0xFFU << 24)
-#define ARM_CPU_IMPLEMENTER_ARMLTD        (0x41U << 24)
-#define ARM_CPU_IMPLEMENTER_DEC           (0x44U << 24)
-#define ARM_CPU_IMPLEMENTER_MOT           (0x4DU << 24)
-#define ARM_CPU_IMPLEMENTER_QUALCOMM      (0x51U << 24)
-#define ARM_CPU_IMPLEMENTER_MARVELL       (0x56U << 24)
-
-#define ARM_CPU_PRIMARY_PART_MASK         (0xFFF << 4)
-#define ARM_CPU_PRIMARY_PART_CORTEXA5     (0xC05 << 4)
-#define ARM_CPU_PRIMARY_PART_CORTEXA7     (0xC07 << 4)
-#define ARM_CPU_PRIMARY_PART_CORTEXA8     (0xC08 << 4)
-#define ARM_CPU_PRIMARY_PART_CORTEXA9     (0xC09 << 4)
-#define ARM_CPU_PRIMARY_PART_CORTEXA15    (0xC0F << 4)
-
-//
-// ARM MP Core IDs
-//
-#define IS_PRIMARY_CORE(MpId) (((MpId) & PcdGet32(PcdArmPrimaryCoreMask)) == PcdGet32(PcdArmPrimaryCore))
-#define ARM_CORE_MASK         0xFF
-#define ARM_CLUSTER_MASK      (0xFF << 8)
-#define GET_CORE_ID(MpId)     ((MpId) & ARM_CORE_MASK)
-#define GET_CLUSTER_ID(MpId)  (((MpId) & ARM_CLUSTER_MASK) >> 8)
-// Get the position of the core for the Stack Offset (4 Core per Cluster)
-//   Position = (ClusterId * 4) + CoreId
-#define GET_CORE_POS(MpId)    ((((MpId) & ARM_CLUSTER_MASK) >> 6) + ((MpId) & ARM_CORE_MASK))
-#define PRIMARY_CORE_ID       (PcdGet32(PcdArmPrimaryCore) & ARM_CORE_MASK)
-
-ARM_CACHE_TYPE
-EFIAPI
-ArmCacheType (
-  VOID
-  );
-
-ARM_CACHE_ARCHITECTURE
-EFIAPI
-ArmCacheArchitecture (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmCacheInformation (
-  OUT ARM_CACHE_INFO  *CacheInfo
-  );
-
-BOOLEAN
-EFIAPI
-ArmDataCachePresent (
-  VOID
-  );
-  
-UINTN
-EFIAPI
-ArmDataCacheSize (
-  VOID
-  );
-  
-UINTN
-EFIAPI
-ArmDataCacheAssociativity (
-  VOID
-  );
-  
-UINTN
-EFIAPI
-ArmDataCacheLineLength (
-  VOID
-  );
-  
-BOOLEAN
-EFIAPI
-ArmInstructionCachePresent (
-  VOID
-  );
-  
-UINTN
-EFIAPI
-ArmInstructionCacheSize (
-  VOID
-  );
-  
-UINTN
-EFIAPI
-ArmInstructionCacheAssociativity (
-  VOID
-  );
-  
-UINTN
-EFIAPI
-ArmInstructionCacheLineLength (
-  VOID
-  );
-  
-UINT32
-EFIAPI
-Cp15IdCode (
-  VOID
-  );
-  
-UINT32
-EFIAPI
-Cp15CacheInfo (
-  VOID
-  );
-
-BOOLEAN
-EFIAPI
-ArmIsMpCore (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmInvalidateDataCache (
-  VOID
-  );
-
-
-VOID
-EFIAPI
-ArmCleanInvalidateDataCache (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmCleanDataCache (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmCleanDataCacheToPoU (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmInvalidateInstructionCache (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmInvalidateDataCacheEntryByMVA (
-  IN  UINTN   Address
-  );
-
-VOID
-EFIAPI
-ArmCleanDataCacheEntryByMVA (
-  IN  UINTN   Address
-  );
-
-VOID
-EFIAPI
-ArmCleanInvalidateDataCacheEntryByMVA (
-  IN  UINTN   Address
-  );
-
-VOID
-EFIAPI
-ArmEnableDataCache (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmDisableDataCache (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmEnableInstructionCache (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmDisableInstructionCache (
-  VOID
-  );
-  
-VOID
-EFIAPI
-ArmEnableMmu (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmDisableMmu (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmDisableCachesAndMmu (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmInvalidateInstructionAndDataTlb (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmEnableInterrupts (
-  VOID
-  );
-
-UINTN
-EFIAPI
-ArmDisableInterrupts (
-  VOID
-  );
-  
-BOOLEAN
-EFIAPI
-ArmGetInterruptState (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmEnableFiq (
-  VOID
-  );
-
-UINTN
-EFIAPI
-ArmDisableFiq (
-  VOID
-  );
-  
-BOOLEAN
-EFIAPI
-ArmGetFiqState (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmInvalidateTlb (
-  VOID
-  );
-  
-VOID
-EFIAPI
-ArmUpdateTranslationTableEntry (
-  IN  VOID     *TranslationTableEntry,
-  IN  VOID     *Mva
-  );
-  
-VOID
-EFIAPI
-ArmSetDomainAccessControl (
-  IN  UINT32  Domain
-  );
-
-VOID
-EFIAPI
-ArmSetTTBR0 (
-  IN  VOID  *TranslationTableBase
-  );
-
-VOID *
-EFIAPI
-ArmGetTTBR0BaseAddress (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmConfigureMmu (
-  IN  ARM_MEMORY_REGION_DESCRIPTOR  *MemoryTable,
-  OUT VOID                          **TranslationTableBase OPTIONAL,
-  OUT UINTN                         *TranslationTableSize  OPTIONAL
-  );
-  
-BOOLEAN
-EFIAPI
-ArmMmuEnabled (
-  VOID
-  );
-  
-VOID
-EFIAPI
-ArmSwitchProcessorMode (
-  IN ARM_PROCESSOR_MODE Mode
-  );
-
-ARM_PROCESSOR_MODE
-EFIAPI
-ArmProcessorMode (
-  VOID
-  );
-  
-VOID
-EFIAPI
-ArmEnableBranchPrediction (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmDisableBranchPrediction (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmSetLowVectors (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmSetHighVectors (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmDataMemoryBarrier (
-  VOID
-  );
-  
-VOID
-EFIAPI
-ArmDataSyncronizationBarrier (
-  VOID
-  );
-  
-VOID
-EFIAPI
-ArmInstructionSynchronizationBarrier (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmWriteVBar (
-  IN  UINT32   VectorBase
-  );
-
-UINT32
-EFIAPI
-ArmReadVBar (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmWriteAuxCr (
-  IN  UINT32    Bit
-  );
-
-UINT32
-EFIAPI
-ArmReadAuxCr (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmSetAuxCrBit (
-  IN  UINT32    Bits
-  );
-
-VOID
-EFIAPI
-ArmUnsetAuxCrBit (
-  IN  UINT32    Bits
-  );
-
-VOID
-EFIAPI
-ArmCallSEV (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmCallWFE (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmCallWFI (
-  VOID
-  );
-
-UINTN
-EFIAPI
-ArmReadMpidr (
-  VOID
-  );
-
-UINT32
-EFIAPI
-ArmReadCpacr (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmWriteCpacr (
-  IN  UINT32   Access
-  );
-
-VOID
-EFIAPI
-ArmEnableVFP (
-  VOID
-  );
-
-UINT32
-EFIAPI
-ArmReadNsacr (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmWriteNsacr (
-  IN  UINT32   SetWayFormat
-  );
-
-UINT32
-EFIAPI
-ArmReadScr (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmWriteScr (
-  IN  UINT32   SetWayFormat
-  );
-
-UINT32
-EFIAPI
-ArmReadMVBar (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmWriteMVBar (
-  IN  UINT32   VectorMonitorBase
-  );
-
-UINT32
-EFIAPI
-ArmReadSctlr (
-  VOID
-  );
-
-#endif // __ARM_LIB__
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __ARM_LIB__\r
+#define __ARM_LIB__\r
+\r
+#include <Uefi/UefiBaseType.h>\r
+\r
+#ifdef ARM_CPU_ARMv6\r
+#include <Chipset/ARM1176JZ-S.h>\r
+#else\r
+#include <Chipset/ArmV7.h>\r
+#endif\r
+\r
+typedef enum {\r
+  ARM_CACHE_TYPE_WRITE_BACK,\r
+  ARM_CACHE_TYPE_UNKNOWN\r
+} ARM_CACHE_TYPE;\r
+\r
+typedef enum {\r
+  ARM_CACHE_ARCHITECTURE_UNIFIED,\r
+  ARM_CACHE_ARCHITECTURE_SEPARATE,\r
+  ARM_CACHE_ARCHITECTURE_UNKNOWN\r
+} ARM_CACHE_ARCHITECTURE;\r
+\r
+typedef struct {\r
+  ARM_CACHE_TYPE          Type;\r
+  ARM_CACHE_ARCHITECTURE  Architecture;\r
+  BOOLEAN                 DataCachePresent;\r
+  UINTN                   DataCacheSize;\r
+  UINTN                   DataCacheAssociativity;\r
+  UINTN                   DataCacheLineLength;\r
+  BOOLEAN                 InstructionCachePresent;\r
+  UINTN                   InstructionCacheSize;\r
+  UINTN                   InstructionCacheAssociativity;\r
+  UINTN                   InstructionCacheLineLength;\r
+} ARM_CACHE_INFO;\r
+\r
+/**\r
+ * The UEFI firmware must not use the ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_* attributes.\r
+ *\r
+ * The Non Secure memory attribute (ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_*) should only\r
+ * be used in Secure World to distinguished Secure to Non-Secure memory.\r
+ */\r
+typedef enum {\r
+  ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED = 0,\r
+  ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_UNCACHED_UNBUFFERED,\r
+  ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK,\r
+  ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK,\r
+  ARM_MEMORY_REGION_ATTRIBUTE_WRITE_THROUGH,\r
+  ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_THROUGH,\r
+  ARM_MEMORY_REGION_ATTRIBUTE_DEVICE,\r
+  ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_DEVICE\r
+} ARM_MEMORY_REGION_ATTRIBUTES;\r
+\r
+#define IS_ARM_MEMORY_REGION_ATTRIBUTES_SECURE(attr) ((UINT32)(attr) & 1)\r
+\r
+typedef struct {\r
+  EFI_PHYSICAL_ADDRESS          PhysicalBase;\r
+  EFI_VIRTUAL_ADDRESS           VirtualBase;\r
+  UINTN                         Length;\r
+  ARM_MEMORY_REGION_ATTRIBUTES  Attributes;\r
+} ARM_MEMORY_REGION_DESCRIPTOR;\r
+\r
+typedef VOID (*CACHE_OPERATION)(VOID);\r
+typedef VOID (*LINE_OPERATION)(UINTN);\r
+\r
+//\r
+// ARM Processor Mode\r
+//\r
+typedef enum {\r
+  ARM_PROCESSOR_MODE_USER       = 0x10,\r
+  ARM_PROCESSOR_MODE_FIQ        = 0x11,\r
+  ARM_PROCESSOR_MODE_IRQ        = 0x12,\r
+  ARM_PROCESSOR_MODE_SUPERVISOR = 0x13,\r
+  ARM_PROCESSOR_MODE_ABORT      = 0x17,\r
+  ARM_PROCESSOR_MODE_HYP        = 0x1A,\r
+  ARM_PROCESSOR_MODE_UNDEFINED  = 0x1B,\r
+  ARM_PROCESSOR_MODE_SYSTEM     = 0x1F,\r
+  ARM_PROCESSOR_MODE_MASK       = 0x1F\r
+} ARM_PROCESSOR_MODE;\r
+\r
+//\r
+// ARM Cpu IDs\r
+//\r
+#define ARM_CPU_IMPLEMENTER_MASK          (0xFFU << 24)\r
+#define ARM_CPU_IMPLEMENTER_ARMLTD        (0x41U << 24)\r
+#define ARM_CPU_IMPLEMENTER_DEC           (0x44U << 24)\r
+#define ARM_CPU_IMPLEMENTER_MOT           (0x4DU << 24)\r
+#define ARM_CPU_IMPLEMENTER_QUALCOMM      (0x51U << 24)\r
+#define ARM_CPU_IMPLEMENTER_MARVELL       (0x56U << 24)\r
+\r
+#define ARM_CPU_PRIMARY_PART_MASK         (0xFFF << 4)\r
+#define ARM_CPU_PRIMARY_PART_CORTEXA5     (0xC05 << 4)\r
+#define ARM_CPU_PRIMARY_PART_CORTEXA7     (0xC07 << 4)\r
+#define ARM_CPU_PRIMARY_PART_CORTEXA8     (0xC08 << 4)\r
+#define ARM_CPU_PRIMARY_PART_CORTEXA9     (0xC09 << 4)\r
+#define ARM_CPU_PRIMARY_PART_CORTEXA15    (0xC0F << 4)\r
+\r
+//\r
+// ARM MP Core IDs\r
+//\r
+#define IS_PRIMARY_CORE(MpId) (((MpId) & PcdGet32(PcdArmPrimaryCoreMask)) == PcdGet32(PcdArmPrimaryCore))\r
+#define ARM_CORE_MASK         0xFF\r
+#define ARM_CLUSTER_MASK      (0xFF << 8)\r
+#define GET_CORE_ID(MpId)     ((MpId) & ARM_CORE_MASK)\r
+#define GET_CLUSTER_ID(MpId)  (((MpId) & ARM_CLUSTER_MASK) >> 8)\r
+// Get the position of the core for the Stack Offset (4 Core per Cluster)\r
+//   Position = (ClusterId * 4) + CoreId\r
+#define GET_CORE_POS(MpId)    ((((MpId) & ARM_CLUSTER_MASK) >> 6) + ((MpId) & ARM_CORE_MASK))\r
+#define PRIMARY_CORE_ID       (PcdGet32(PcdArmPrimaryCore) & ARM_CORE_MASK)\r
+\r
+ARM_CACHE_TYPE\r
+EFIAPI\r
+ArmCacheType (\r
+  VOID\r
+  );\r
+\r
+ARM_CACHE_ARCHITECTURE\r
+EFIAPI\r
+ArmCacheArchitecture (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmCacheInformation (\r
+  OUT ARM_CACHE_INFO  *CacheInfo\r
+  );\r
+\r
+BOOLEAN\r
+EFIAPI\r
+ArmDataCachePresent (\r
+  VOID\r
+  );\r
+  \r
+UINTN\r
+EFIAPI\r
+ArmDataCacheSize (\r
+  VOID\r
+  );\r
+  \r
+UINTN\r
+EFIAPI\r
+ArmDataCacheAssociativity (\r
+  VOID\r
+  );\r
+  \r
+UINTN\r
+EFIAPI\r
+ArmDataCacheLineLength (\r
+  VOID\r
+  );\r
+  \r
+BOOLEAN\r
+EFIAPI\r
+ArmInstructionCachePresent (\r
+  VOID\r
+  );\r
+  \r
+UINTN\r
+EFIAPI\r
+ArmInstructionCacheSize (\r
+  VOID\r
+  );\r
+  \r
+UINTN\r
+EFIAPI\r
+ArmInstructionCacheAssociativity (\r
+  VOID\r
+  );\r
+  \r
+UINTN\r
+EFIAPI\r
+ArmInstructionCacheLineLength (\r
+  VOID\r
+  );\r
+  \r
+UINT32\r
+EFIAPI\r
+Cp15IdCode (\r
+  VOID\r
+  );\r
+  \r
+UINT32\r
+EFIAPI\r
+Cp15CacheInfo (\r
+  VOID\r
+  );\r
+\r
+BOOLEAN\r
+EFIAPI\r
+ArmIsMpCore (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmInvalidateDataCache (\r
+  VOID\r
+  );\r
+\r
+\r
+VOID\r
+EFIAPI\r
+ArmCleanInvalidateDataCache (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmCleanDataCache (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmCleanDataCacheToPoU (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmInvalidateInstructionCache (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmInvalidateDataCacheEntryByMVA (\r
+  IN  UINTN   Address\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmCleanDataCacheEntryByMVA (\r
+  IN  UINTN   Address\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmCleanInvalidateDataCacheEntryByMVA (\r
+  IN  UINTN   Address\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmEnableDataCache (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmDisableDataCache (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmEnableInstructionCache (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmDisableInstructionCache (\r
+  VOID\r
+  );\r
+  \r
+VOID\r
+EFIAPI\r
+ArmEnableMmu (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmDisableMmu (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmDisableCachesAndMmu (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmInvalidateInstructionAndDataTlb (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmEnableInterrupts (\r
+  VOID\r
+  );\r
+\r
+UINTN\r
+EFIAPI\r
+ArmDisableInterrupts (\r
+  VOID\r
+  );\r
+  \r
+BOOLEAN\r
+EFIAPI\r
+ArmGetInterruptState (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmEnableFiq (\r
+  VOID\r
+  );\r
+\r
+UINTN\r
+EFIAPI\r
+ArmDisableFiq (\r
+  VOID\r
+  );\r
+  \r
+BOOLEAN\r
+EFIAPI\r
+ArmGetFiqState (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmInvalidateTlb (\r
+  VOID\r
+  );\r
+  \r
+VOID\r
+EFIAPI\r
+ArmUpdateTranslationTableEntry (\r
+  IN  VOID     *TranslationTableEntry,\r
+  IN  VOID     *Mva\r
+  );\r
+  \r
+VOID\r
+EFIAPI\r
+ArmSetDomainAccessControl (\r
+  IN  UINT32  Domain\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmSetTTBR0 (\r
+  IN  VOID  *TranslationTableBase\r
+  );\r
+\r
+VOID *\r
+EFIAPI\r
+ArmGetTTBR0BaseAddress (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmConfigureMmu (\r
+  IN  ARM_MEMORY_REGION_DESCRIPTOR  *MemoryTable,\r
+  OUT VOID                          **TranslationTableBase OPTIONAL,\r
+  OUT UINTN                         *TranslationTableSize  OPTIONAL\r
+  );\r
+  \r
+BOOLEAN\r
+EFIAPI\r
+ArmMmuEnabled (\r
+  VOID\r
+  );\r
+  \r
+VOID\r
+EFIAPI\r
+ArmSwitchProcessorMode (\r
+  IN ARM_PROCESSOR_MODE Mode\r
+  );\r
+\r
+ARM_PROCESSOR_MODE\r
+EFIAPI\r
+ArmProcessorMode (\r
+  VOID\r
+  );\r
+  \r
+VOID\r
+EFIAPI\r
+ArmEnableBranchPrediction (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmDisableBranchPrediction (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmSetLowVectors (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmSetHighVectors (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmDataMemoryBarrier (\r
+  VOID\r
+  );\r
+  \r
+VOID\r
+EFIAPI\r
+ArmDataSyncronizationBarrier (\r
+  VOID\r
+  );\r
+  \r
+VOID\r
+EFIAPI\r
+ArmInstructionSynchronizationBarrier (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmWriteVBar (\r
+  IN  UINT32   VectorBase\r
+  );\r
+\r
+UINT32\r
+EFIAPI\r
+ArmReadVBar (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmWriteAuxCr (\r
+  IN  UINT32    Bit\r
+  );\r
+\r
+UINT32\r
+EFIAPI\r
+ArmReadAuxCr (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmSetAuxCrBit (\r
+  IN  UINT32    Bits\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmUnsetAuxCrBit (\r
+  IN  UINT32    Bits\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmCallSEV (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmCallWFE (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmCallWFI (\r
+  VOID\r
+  );\r
+\r
+UINTN\r
+EFIAPI\r
+ArmReadMpidr (\r
+  VOID\r
+  );\r
+\r
+UINT32\r
+EFIAPI\r
+ArmReadCpacr (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmWriteCpacr (\r
+  IN  UINT32   Access\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmEnableVFP (\r
+  VOID\r
+  );\r
+\r
+UINT32\r
+EFIAPI\r
+ArmReadNsacr (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmWriteNsacr (\r
+  IN  UINT32   SetWayFormat\r
+  );\r
+\r
+UINT32\r
+EFIAPI\r
+ArmReadScr (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmWriteScr (\r
+  IN  UINT32   SetWayFormat\r
+  );\r
+\r
+UINT32\r
+EFIAPI\r
+ArmReadMVBar (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmWriteMVBar (\r
+  IN  UINT32   VectorMonitorBase\r
+  );\r
+\r
+UINT32\r
+EFIAPI\r
+ArmReadSctlr (\r
+  VOID\r
+  );\r
+\r
+#endif // __ARM_LIB__\r
index d2f4a46c66709972cbccdc69d4b5aaf6e855e0e1..983184810fb96d01b138d31c379f01f9b13cd61a 100644 (file)
-/** @file
-
-  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __ARM_V7_ARCH_TIMER_LIB_H__
-#define __ARM_V7_ARCH_TIMER_LIB_H__
-
-#define ARM_ARCH_TIMER_ENABLE           (1 << 0)
-#define ARM_ARCH_TIMER_IMASK            (1 << 1)
-#define ARM_ARCH_TIMER_ISTATUS          (1 << 2)
-
-typedef enum {
-  CntFrq = 0,
-  CntPct,
-  CntkCtl,
-  CntpTval,
-  CntpCtl,
-  CntvTval,
-  CntvCtl,
-  CntvCt,
-  CntpCval,
-  CntvCval,
-  CntvOff,
-  CnthCtl,
-  CnthpTval,
-  CnthpCtl,
-  CnthpCval,
-  RegMaximum
-}ARM_ARCH_TIMER_REGS;
-
-VOID
-EFIAPI
-ArmArchTimerReadReg (
-  IN   ARM_ARCH_TIMER_REGS   Reg,
-  OUT  VOID                  *DstBuf
-  );
-
-VOID
-EFIAPI
-ArmArchTimerWriteReg (
-  IN   ARM_ARCH_TIMER_REGS   Reg,
-  IN   VOID                  *SrcBuf
-  );
-
-VOID
-EFIAPI
-ArmArchTimerEnableTimer (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmArchTimerDisableTimer (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmArchTimerSetTimerFreq (
-  IN   UINTN  FreqInHz
-  );
-
-UINTN
-EFIAPI
-ArmArchTimerGetTimerFreq (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmArchTimerSetTimerVal (
-  IN   UINTN   Val
-  );
-
-UINTN
-EFIAPI
-ArmArchTimerGetTimerVal (
-  VOID
-  );
-
-UINT64
-EFIAPI
-ArmArchTimerGetSystemCount (
-  VOID
-  );
-
-UINTN
-EFIAPI
-ArmArchTimerGetTimerCtrlReg (
-  VOID
-  );
-
-VOID
-EFIAPI
-ArmArchTimerSetTimerCtrlReg (
-  UINTN Val
-  );
-
-VOID
-EFIAPI
-ArmArchTimerSetCompareVal (
-  IN   UINT64   Val
-  );
-
-#endif // __ARM_V7_ARCH_TIMER_LIB_H__
+/** @file\r
+\r
+  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __ARM_V7_ARCH_TIMER_LIB_H__\r
+#define __ARM_V7_ARCH_TIMER_LIB_H__\r
+\r
+#define ARM_ARCH_TIMER_ENABLE           (1 << 0)\r
+#define ARM_ARCH_TIMER_IMASK            (1 << 1)\r
+#define ARM_ARCH_TIMER_ISTATUS          (1 << 2)\r
+\r
+typedef enum {\r
+  CntFrq = 0,\r
+  CntPct,\r
+  CntkCtl,\r
+  CntpTval,\r
+  CntpCtl,\r
+  CntvTval,\r
+  CntvCtl,\r
+  CntvCt,\r
+  CntpCval,\r
+  CntvCval,\r
+  CntvOff,\r
+  CnthCtl,\r
+  CnthpTval,\r
+  CnthpCtl,\r
+  CnthpCval,\r
+  RegMaximum\r
+}ARM_ARCH_TIMER_REGS;\r
+\r
+VOID\r
+EFIAPI\r
+ArmArchTimerReadReg (\r
+  IN   ARM_ARCH_TIMER_REGS   Reg,\r
+  OUT  VOID                  *DstBuf\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmArchTimerWriteReg (\r
+  IN   ARM_ARCH_TIMER_REGS   Reg,\r
+  IN   VOID                  *SrcBuf\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmArchTimerEnableTimer (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmArchTimerDisableTimer (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmArchTimerSetTimerFreq (\r
+  IN   UINTN  FreqInHz\r
+  );\r
+\r
+UINTN\r
+EFIAPI\r
+ArmArchTimerGetTimerFreq (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmArchTimerSetTimerVal (\r
+  IN   UINTN   Val\r
+  );\r
+\r
+UINTN\r
+EFIAPI\r
+ArmArchTimerGetTimerVal (\r
+  VOID\r
+  );\r
+\r
+UINT64\r
+EFIAPI\r
+ArmArchTimerGetSystemCount (\r
+  VOID\r
+  );\r
+\r
+UINTN\r
+EFIAPI\r
+ArmArchTimerGetTimerCtrlReg (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmArchTimerSetTimerCtrlReg (\r
+  UINTN Val\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+ArmArchTimerSetCompareVal (\r
+  IN   UINT64   Val\r
+  );\r
+\r
+#endif // __ARM_V7_ARCH_TIMER_LIB_H__\r
index cf3fe0cca07af324a645dda970d7aceff6d38550..7166dbb36e989f2a7b568e680b9805d35f08beb6 100644 (file)
@@ -1,31 +1,31 @@
-/** @file
-
-  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __DEFAULT_EXCEPTION_HANDLER_LIB_H__
-#define __DEFAULT_EXCEPTION_HANDLER_LIB_H__
-
-/**
-  This is the default action to take on an unexpected exception
-
-  @param  ExceptionType    Type of the exception
-  @param  SystemContext    Register state at the time of the Exception
-
-**/
-VOID
-DefaultExceptionHandler (
-  IN     EFI_EXCEPTION_TYPE           ExceptionType,
-  IN OUT EFI_SYSTEM_CONTEXT           SystemContext
-  );
-  
-#endif 
+/** @file\r
+\r
+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __DEFAULT_EXCEPTION_HANDLER_LIB_H__\r
+#define __DEFAULT_EXCEPTION_HANDLER_LIB_H__\r
+\r
+/**\r
+  This is the default action to take on an unexpected exception\r
+\r
+  @param  ExceptionType    Type of the exception\r
+  @param  SystemContext    Register state at the time of the Exception\r
+\r
+**/\r
+VOID\r
+DefaultExceptionHandler (\r
+  IN     EFI_EXCEPTION_TYPE           ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT           SystemContext\r
+  );\r
+  \r
+#endif \r
index 68f4b772eb638184538ee50ae7722fc044bd54ea..2ced7f107cc5bab61b9b44852ec3bc4161d50c78 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __SEMIHOSTING_H__
-#define __SEMIHOSTING_H__
-
-/*
- *
- *  Please refer to ARM RVDS 3.0 Compiler and Libraries Guide for more information
- *  about the semihosting interface.
- *
- */
-#define SEMIHOST_FILE_MODE_READ     (0 << 2)
-#define SEMIHOST_FILE_MODE_WRITE    (1 << 2)
-#define SEMIHOST_FILE_MODE_APPEND   (2 << 2)
-#define SEMIHOST_FILE_MODE_CREATE   (1 << 1)
-#define SEMIHOST_FILE_MODE_BINARY   (1 << 0)
-#define SEMIHOST_FILE_MODE_ASCII    (0 << 0)
-
-BOOLEAN
-SemihostConnectionSupported (
-  VOID
-  );
-
-RETURN_STATUS
-SemihostFileOpen (
-  IN  CHAR8  *FileName,
-  IN  UINT32 Mode,
-  OUT UINT32 *FileHandle
-  );
-
-RETURN_STATUS
-SemihostFileSeek (
-  IN UINT32 FileHandle,
-  IN UINT32 Offset
-  );
-
-RETURN_STATUS
-SemihostFileRead (
-  IN     UINT32 FileHandle,
-  IN OUT UINT32 *Length,
-  OUT    VOID   *Buffer
-  );
-
-RETURN_STATUS
-SemihostFileWrite (
-  IN     UINT32 FileHandle,
-  IN OUT UINT32 *Length,
-  IN     VOID   *Buffer
-  );
-
-RETURN_STATUS
-SemihostFileClose (
-  IN UINT32 FileHandle
-  );
-
-RETURN_STATUS
-SemihostFileLength (
-  IN  UINT32 FileHandle,
-  OUT UINT32 *Length
-  );
-
-RETURN_STATUS
-SemihostFileRemove (
-  IN CHAR8 *FileName
-  );
-
-CHAR8
-SemihostReadCharacter (
-  VOID
-  );
-
-VOID
-SemihostWriteCharacter (
-  IN CHAR8 Character
-  );
-
-VOID
-SemihostWriteString (
-  IN CHAR8 *String
-  );
-  
-UINT32
-SemihostSystem (
-  IN CHAR8 *CommandLine
-  );
-  
-#endif // __SEMIHOSTING_H__
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __SEMIHOSTING_H__\r
+#define __SEMIHOSTING_H__\r
+\r
+/*\r
+ *\r
+ *  Please refer to ARM RVDS 3.0 Compiler and Libraries Guide for more information\r
+ *  about the semihosting interface.\r
+ *\r
+ */\r
\r
+#define SEMIHOST_FILE_MODE_READ     (0 << 2)\r
+#define SEMIHOST_FILE_MODE_WRITE    (1 << 2)\r
+#define SEMIHOST_FILE_MODE_APPEND   (2 << 2)\r
+#define SEMIHOST_FILE_MODE_CREATE   (1 << 1)\r
+#define SEMIHOST_FILE_MODE_BINARY   (1 << 0)\r
+#define SEMIHOST_FILE_MODE_ASCII    (0 << 0)\r
+\r
+BOOLEAN\r
+SemihostConnectionSupported (\r
+  VOID\r
+  );\r
+\r
+RETURN_STATUS\r
+SemihostFileOpen (\r
+  IN  CHAR8  *FileName,\r
+  IN  UINT32 Mode,\r
+  OUT UINT32 *FileHandle\r
+  );\r
+\r
+RETURN_STATUS\r
+SemihostFileSeek (\r
+  IN UINT32 FileHandle,\r
+  IN UINT32 Offset\r
+  );\r
+\r
+RETURN_STATUS\r
+SemihostFileRead (\r
+  IN     UINT32 FileHandle,\r
+  IN OUT UINT32 *Length,\r
+  OUT    VOID   *Buffer\r
+  );\r
+\r
+RETURN_STATUS\r
+SemihostFileWrite (\r
+  IN     UINT32 FileHandle,\r
+  IN OUT UINT32 *Length,\r
+  IN     VOID   *Buffer\r
+  );\r
+\r
+RETURN_STATUS\r
+SemihostFileClose (\r
+  IN UINT32 FileHandle\r
+  );\r
+\r
+RETURN_STATUS\r
+SemihostFileLength (\r
+  IN  UINT32 FileHandle,\r
+  OUT UINT32 *Length\r
+  );\r
+\r
+RETURN_STATUS\r
+SemihostFileRemove (\r
+  IN CHAR8 *FileName\r
+  );\r
+\r
+CHAR8\r
+SemihostReadCharacter (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+SemihostWriteCharacter (\r
+  IN CHAR8 Character\r
+  );\r
+\r
+VOID\r
+SemihostWriteString (\r
+  IN CHAR8 *String\r
+  );\r
+  \r
+UINT32\r
+SemihostSystem (\r
+  IN CHAR8 *CommandLine\r
+  );\r
+  \r
+#endif // __SEMIHOSTING_H__\r
index ac77fbc6997f71f59a675aaed4b1b62bfa058c33..4161fc7c6245457ca51503173eed53acc6212cde 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __UNCACHED_MEMORY_ALLOCATION_LIB_H__
-#define __UNCACHED_MEMORY_ALLOCATION_LIB_H__
-
-/**
-  Converts a cached or uncached address to a physical address suitable for use in SoC registers.
-
-  @param  VirtualAddress                 The pointer to convert.
-
-  @return The physical address of the supplied virtual pointer.
-
-**/
-EFI_PHYSICAL_ADDRESS
-ConvertToPhysicalAddress (
-  IN VOID *VirtualAddress
-  );
-
-/**
-  Converts a cached or uncached address to a cached address.
-
-  @param  Address                 The pointer to convert.
-
-  @return The address of the cached memory location corresponding to the input address.
-
-**/
-VOID *
-ConvertToCachedAddress (
-  IN VOID *Address
-  );
-
-/**
-  Converts a cached or uncached address to an uncached address.
-
-  @param  Address                 The pointer to convert.
-
-  @return The address of the uncached memory location corresponding to the input address.
-
-**/
-VOID *
-ConvertToUncachedAddress (
-  IN VOID *Address
-  );
-
-/**
-  Allocates one or more 4KB pages of type EfiBootServicesData.
-
-  Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the
-  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL
-  is returned.  If there is not enough memory remaining to satisfy the request, then NULL is
-  returned.
-
-  @param  Pages                 The number of 4 KB pages to allocate.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocatePages (
-  IN UINTN  Pages
-  );
-
-/**
-  Allocates one or more 4KB pages of type EfiRuntimeServicesData.
-
-  Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
-  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL
-  is returned.  If there is not enough memory remaining to satisfy the request, then NULL is
-  returned.
-
-  @param  Pages                 The number of 4 KB pages to allocate.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateRuntimePages (
-  IN UINTN  Pages
-  );
-
-/**
-  Allocates one or more 4KB pages of type EfiReservedMemoryType.
-
-  Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the
-  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL
-  is returned.  If there is not enough memory remaining to satisfy the request, then NULL is
-  returned.
-
-  @param  Pages                 The number of 4 KB pages to allocate.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateReservedPages (
-  IN UINTN  Pages
-  );
-
-/**
-  Frees one or more 4KB pages that were previously allocated with one of the page allocation
-  functions in the Memory Allocation Library.
-
-  Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer
-  must have been allocated on a previous call to the page allocation services of the Memory
-  Allocation Library.
-  If Buffer was not allocated with a page allocation function in the Memory Allocation Library,
-  then ASSERT().
-  If Pages is zero, then ASSERT().
-  @param  Buffer                Pointer to the buffer of pages to free.
-  @param  Pages                 The number of 4 KB pages to free.
-
-**/
-VOID
-EFIAPI
-UncachedFreePages (
-  IN VOID   *Buffer,
-  IN UINTN  Pages
-  );
-
-/**
-  Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
-
-  Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
-  alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is
-  returned.  If there is not enough memory at the specified alignment remaining to satisfy the
-  request, then NULL is returned.
-  If Alignment is not a power of two and Alignment is not zero, then ASSERT().
-
-  @param  Pages                 The number of 4 KB pages to allocate.
-  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.
-                                If Alignment is zero, then byte alignment is used.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateAlignedPages (
-  IN UINTN  Pages,
-  IN UINTN  Alignment
-  );
-
-/**
-  Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.
-
-  Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an
-  alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is
-  returned.  If there is not enough memory at the specified alignment remaining to satisfy the
-  request, then NULL is returned.
-  If Alignment is not a power of two and Alignment is not zero, then ASSERT().
-
-  @param  Pages                 The number of 4 KB pages to allocate.
-  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.
-                                If Alignment is zero, then byte alignment is used.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateAlignedRuntimePages (
-  IN UINTN  Pages,
-  IN UINTN  Alignment
-  );
-
-/**
-  Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.
-
-  Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an
-  alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is
-  returned.  If there is not enough memory at the specified alignment remaining to satisfy the
-  request, then NULL is returned.
-  If Alignment is not a power of two and Alignment is not zero, then ASSERT().
-
-  @param  Pages                 The number of 4 KB pages to allocate.
-  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.
-                                If Alignment is zero, then byte alignment is used.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateAlignedReservedPages (
-  IN UINTN  Pages,
-  IN UINTN  Alignment
-  );
-
-/**
-  Frees one or more 4KB pages that were previously allocated with one of the aligned page
-  allocation functions in the Memory Allocation Library.
-
-  Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer
-  must have been allocated on a previous call to the aligned page allocation services of the Memory
-  Allocation Library.
-  If Buffer was not allocated with an aligned page allocation function in the Memory Allocation
-  Library, then ASSERT().
-  If Pages is zero, then ASSERT().
-  
-  @param  Buffer                Pointer to the buffer of pages to free.
-  @param  Pages                 The number of 4 KB pages to free.
-
-**/
-VOID
-EFIAPI
-UncachedFreeAlignedPages (
-  IN VOID   *Buffer,
-  IN UINTN  Pages
-  );
-
-/**
-  Allocates a buffer of type EfiBootServicesData.
-
-  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
-  pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is
-  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.
-
-  @param  AllocationSize        The number of bytes to allocate.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocatePool (
-  IN UINTN  AllocationSize
-  );
-
-/**
-  Allocates a buffer of type EfiRuntimeServicesData.
-
-  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns
-  a pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is
-  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.
-
-  @param  AllocationSize        The number of bytes to allocate.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateRuntimePool (
-  IN UINTN  AllocationSize
-  );
-
-/**
-  Allocates a buffer of type EfieservedMemoryType.
-
-  Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType and returns
-  a pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is
-  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.
-
-  @param  AllocationSize        The number of bytes to allocate.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateReservedPool (
-  IN UINTN  AllocationSize
-  );
-
-/**
-  Allocates and zeros a buffer of type EfiBootServicesData.
-
-  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
-  buffer with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a
-  valid buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the
-  request, then NULL is returned.
-
-  @param  AllocationSize        The number of bytes to allocate and zero.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateZeroPool (
-  IN UINTN  AllocationSize
-  );
-
-/**
-  Allocates and zeros a buffer of type EfiRuntimeServicesData.
-
-  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the
-  buffer with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a
-  valid buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the
-  request, then NULL is returned.
-
-  @param  AllocationSize        The number of bytes to allocate and zero.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateRuntimeZeroPool (
-  IN UINTN  AllocationSize
-  );
-
-/**
-  Allocates and zeros a buffer of type EfiReservedMemoryType.
-
-  Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the
-  buffer with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a
-  valid buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the
-  request, then NULL is returned.
-
-  @param  AllocationSize        The number of bytes to allocate and zero.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateReservedZeroPool (
-  IN UINTN  AllocationSize
-  );
-
-/**
-  Copies a buffer to an allocated buffer of type EfiBootServicesData.
-
-  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies
-  AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
-  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there
-  is not enough memory remaining to satisfy the request, then NULL is returned.
-  If Buffer is NULL, then ASSERT().
-  If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). 
-
-  @param  AllocationSize        The number of bytes to allocate and zero.
-  @param  Buffer                The buffer to copy to the allocated buffer.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateCopyPool (
-  IN UINTN       AllocationSize,
-  IN CONST VOID  *Buffer
-  );
-
-/**
-  Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.
-
-  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies
-  AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
-  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there
-  is not enough memory remaining to satisfy the request, then NULL is returned.
-  If Buffer is NULL, then ASSERT().
-  If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). 
-
-  @param  AllocationSize        The number of bytes to allocate and zero.
-  @param  Buffer                The buffer to copy to the allocated buffer.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateRuntimeCopyPool (
-  IN UINTN       AllocationSize,
-  IN CONST VOID  *Buffer
-  );
-
-/**
-  Copies a buffer to an allocated buffer of type EfiReservedMemoryType.
-
-  Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies
-  AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
-  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there
-  is not enough memory remaining to satisfy the request, then NULL is returned.
-  If Buffer is NULL, then ASSERT().
-  If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). 
-
-  @param  AllocationSize        The number of bytes to allocate and zero.
-  @param  Buffer                The buffer to copy to the allocated buffer.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateReservedCopyPool (
-  IN UINTN       AllocationSize,
-  IN CONST VOID  *Buffer
-  );
-
-/**
-  Frees a buffer that was previously allocated with one of the pool allocation functions in the
-  Memory Allocation Library.
-
-  Frees the buffer specified by Buffer.  Buffer must have been allocated on a previous call to the
-  pool allocation services of the Memory Allocation Library.
-  If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
-  then ASSERT().
-
-  @param  Buffer                Pointer to the buffer to free.
-
-**/
-VOID
-EFIAPI
-UncachedFreePool (
-  IN VOID   *Buffer
-  );
-
-/**
-  Allocates a buffer of type EfiBootServicesData at a specified alignment.
-
-  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an
-  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,
-  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified
-  alignment remaining to satisfy the request, then NULL is returned.
-  If Alignment is not a power of two and Alignment is not zero, then ASSERT().
-
-  @param  AllocationSize        The number of bytes to allocate.
-  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.
-                                If Alignment is zero, then byte alignment is used.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateAlignedPool (
-  IN UINTN  AllocationSize,
-  IN UINTN  Alignment
-  );
-
-/**
-  Allocates a buffer of type EfiRuntimeServicesData at a specified alignment.
-
-  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an
-  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,
-  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified
-  alignment remaining to satisfy the request, then NULL is returned.
-  If Alignment is not a power of two and Alignment is not zero, then ASSERT().
-
-  @param  AllocationSize        The number of bytes to allocate.
-  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.
-                                If Alignment is zero, then byte alignment is used.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateAlignedRuntimePool (
-  IN UINTN  AllocationSize,
-  IN UINTN  Alignment
-  );
-
-/**
-  Allocates a buffer of type EfieservedMemoryType at a specified alignment.
-
-  Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an
-  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,
-  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified
-  alignment remaining to satisfy the request, then NULL is returned.
-  If Alignment is not a power of two and Alignment is not zero, then ASSERT().
-
-  @param  AllocationSize        The number of bytes to allocate.
-  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.
-                                If Alignment is zero, then byte alignment is used.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateAlignedReservedPool (
-  IN UINTN  AllocationSize,
-  IN UINTN  Alignment
-  );
-
-/**
-  Allocates and zeros a buffer of type EfiBootServicesData at a specified alignment.
-
-  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an
-  alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
-  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there
-  is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
-  returned.
-  If Alignment is not a power of two and Alignment is not zero, then ASSERT().
-
-  @param  AllocationSize        The number of bytes to allocate.
-  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.
-                                If Alignment is zero, then byte alignment is used.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateAlignedZeroPool (
-  IN UINTN  AllocationSize,
-  IN UINTN  Alignment
-  );
-
-/**
-  Allocates and zeros a buffer of type EfiRuntimeServicesData at a specified alignment.
-
-  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an
-  alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
-  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there
-  is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
-  returned.
-  If Alignment is not a power of two and Alignment is not zero, then ASSERT().
-
-  @param  AllocationSize        The number of bytes to allocate.
-  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.
-                                If Alignment is zero, then byte alignment is used.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateAlignedRuntimeZeroPool (
-  IN UINTN  AllocationSize,
-  IN UINTN  Alignment
-  );
-
-/**
-  Allocates and zeros a buffer of type EfieservedMemoryType at a specified alignment.
-
-  Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an
-  alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
-  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there
-  is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
-  returned.
-  If Alignment is not a power of two and Alignment is not zero, then ASSERT().
-
-  @param  AllocationSize        The number of bytes to allocate.
-  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.
-                                If Alignment is zero, then byte alignment is used.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateAlignedReservedZeroPool (
-  IN UINTN  AllocationSize,
-  IN UINTN  Alignment
-  );
-
-/**
-  Copies a buffer to an allocated buffer of type EfiBootServicesData at a specified alignment.
-
-  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData type with an
-  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,
-  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified
-  alignment remaining to satisfy the request, then NULL is returned.
-  If Alignment is not a power of two and Alignment is not zero, then ASSERT().
-
-  @param  AllocationSize        The number of bytes to allocate.
-  @param  Buffer                The buffer to copy to the allocated buffer.
-  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.
-                                If Alignment is zero, then byte alignment is used.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateAlignedCopyPool (
-  IN UINTN       AllocationSize,
-  IN CONST VOID  *Buffer,
-  IN UINTN       Alignment
-  );
-
-/**
-  Copies a buffer to an allocated buffer of type EfiRuntimeServicesData at a specified alignment.
-
-  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData type with an
-  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,
-  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified
-  alignment remaining to satisfy the request, then NULL is returned.
-  If Alignment is not a power of two and Alignment is not zero, then ASSERT().
-
-  @param  AllocationSize        The number of bytes to allocate.
-  @param  Buffer                The buffer to copy to the allocated buffer.
-  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.
-                                If Alignment is zero, then byte alignment is used.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateAlignedRuntimeCopyPool (
-  IN UINTN       AllocationSize,
-  IN CONST VOID  *Buffer,
-  IN UINTN       Alignment
-  );
-
-/**
-  Copies a buffer to an allocated buffer of type EfiReservedMemoryType at a specified alignment.
-
-  Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType type with an
-  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,
-  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified
-  alignment remaining to satisfy the request, then NULL is returned.
-  If Alignment is not a power of two and Alignment is not zero, then ASSERT().
-
-  @param  AllocationSize        The number of bytes to allocate.
-  @param  Buffer                The buffer to copy to the allocated buffer.
-  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.
-                                If Alignment is zero, then byte alignment is used.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-UncachedAllocateAlignedReservedCopyPool (
-  IN UINTN       AllocationSize,
-  IN CONST VOID  *Buffer,
-  IN UINTN       Alignment
-  );
-
-/**
-  Frees a buffer that was previously allocated with one of the aligned pool allocation functions 
-  in the Memory Allocation Library.
-
-  Frees the buffer specified by Buffer.  Buffer must have been allocated on a previous call to the
-  aligned pool allocation services of the Memory Allocation Library.
-  If Buffer was not allocated with an aligned pool allocation function in the Memory Allocation
-  Library, then ASSERT().
-
-  @param  Buffer                Pointer to the buffer to free.
-
-**/
-VOID
-EFIAPI
-UncachedFreeAlignedPool (
-  IN VOID   *Buffer
-  );
-
-VOID
-EFIAPI
-UncachedSafeFreePool (
-  IN VOID   *Buffer
-  );
-
-#endif // __UNCACHED_MEMORY_ALLOCATION_LIB_H__
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __UNCACHED_MEMORY_ALLOCATION_LIB_H__\r
+#define __UNCACHED_MEMORY_ALLOCATION_LIB_H__\r
+\r
+/**\r
+  Converts a cached or uncached address to a physical address suitable for use in SoC registers.\r
+\r
+  @param  VirtualAddress                 The pointer to convert.\r
+\r
+  @return The physical address of the supplied virtual pointer.\r
+\r
+**/\r
+EFI_PHYSICAL_ADDRESS\r
+ConvertToPhysicalAddress (\r
+  IN VOID *VirtualAddress\r
+  );\r
+\r
+/**\r
+  Converts a cached or uncached address to a cached address.\r
+\r
+  @param  Address                 The pointer to convert.\r
+\r
+  @return The address of the cached memory location corresponding to the input address.\r
+\r
+**/\r
+VOID *\r
+ConvertToCachedAddress (\r
+  IN VOID *Address\r
+  );\r
+\r
+/**\r
+  Converts a cached or uncached address to an uncached address.\r
+\r
+  @param  Address                 The pointer to convert.\r
+\r
+  @return The address of the uncached memory location corresponding to the input address.\r
+\r
+**/\r
+VOID *\r
+ConvertToUncachedAddress (\r
+  IN VOID *Address\r
+  );\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiBootServicesData.\r
+\r
+  Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the\r
+  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL\r
+  is returned.  If there is not enough memory remaining to satisfy the request, then NULL is\r
+  returned.\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocatePages (\r
+  IN UINTN  Pages\r
+  );\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiRuntimeServicesData.\r
+\r
+  Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the\r
+  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL\r
+  is returned.  If there is not enough memory remaining to satisfy the request, then NULL is\r
+  returned.\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateRuntimePages (\r
+  IN UINTN  Pages\r
+  );\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiReservedMemoryType.\r
+\r
+  Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the\r
+  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL\r
+  is returned.  If there is not enough memory remaining to satisfy the request, then NULL is\r
+  returned.\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateReservedPages (\r
+  IN UINTN  Pages\r
+  );\r
+\r
+/**\r
+  Frees one or more 4KB pages that were previously allocated with one of the page allocation\r
+  functions in the Memory Allocation Library.\r
+\r
+  Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer\r
+  must have been allocated on a previous call to the page allocation services of the Memory\r
+  Allocation Library.\r
+  If Buffer was not allocated with a page allocation function in the Memory Allocation Library,\r
+  then ASSERT().\r
+  If Pages is zero, then ASSERT().\r
\r
+  @param  Buffer                Pointer to the buffer of pages to free.\r
+  @param  Pages                 The number of 4 KB pages to free.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+UncachedFreePages (\r
+  IN VOID   *Buffer,\r
+  IN UINTN  Pages\r
+  );\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.\r
+\r
+  Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is\r
+  returned.  If there is not enough memory at the specified alignment remaining to satisfy the\r
+  request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateAlignedPages (\r
+  IN UINTN  Pages,\r
+  IN UINTN  Alignment\r
+  );\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.\r
+\r
+  Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is\r
+  returned.  If there is not enough memory at the specified alignment remaining to satisfy the\r
+  request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateAlignedRuntimePages (\r
+  IN UINTN  Pages,\r
+  IN UINTN  Alignment\r
+  );\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.\r
+\r
+  Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is\r
+  returned.  If there is not enough memory at the specified alignment remaining to satisfy the\r
+  request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateAlignedReservedPages (\r
+  IN UINTN  Pages,\r
+  IN UINTN  Alignment\r
+  );\r
+\r
+/**\r
+  Frees one or more 4KB pages that were previously allocated with one of the aligned page\r
+  allocation functions in the Memory Allocation Library.\r
+\r
+  Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer\r
+  must have been allocated on a previous call to the aligned page allocation services of the Memory\r
+  Allocation Library.\r
+  If Buffer was not allocated with an aligned page allocation function in the Memory Allocation\r
+  Library, then ASSERT().\r
+  If Pages is zero, then ASSERT().\r
+  \r
+  @param  Buffer                Pointer to the buffer of pages to free.\r
+  @param  Pages                 The number of 4 KB pages to free.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+UncachedFreeAlignedPages (\r
+  IN VOID   *Buffer,\r
+  IN UINTN  Pages\r
+  );\r
+\r
+/**\r
+  Allocates a buffer of type EfiBootServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a\r
+  pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is\r
+  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocatePool (\r
+  IN UINTN  AllocationSize\r
+  );\r
+\r
+/**\r
+  Allocates a buffer of type EfiRuntimeServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns\r
+  a pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is\r
+  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateRuntimePool (\r
+  IN UINTN  AllocationSize\r
+  );\r
+\r
+/**\r
+  Allocates a buffer of type EfieservedMemoryType.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType and returns\r
+  a pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is\r
+  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateReservedPool (\r
+  IN UINTN  AllocationSize\r
+  );\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfiBootServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the\r
+  buffer with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a\r
+  valid buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the\r
+  request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateZeroPool (\r
+  IN UINTN  AllocationSize\r
+  );\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfiRuntimeServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the\r
+  buffer with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a\r
+  valid buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the\r
+  request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateRuntimeZeroPool (\r
+  IN UINTN  AllocationSize\r
+  );\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfiReservedMemoryType.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the\r
+  buffer with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a\r
+  valid buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the\r
+  request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateReservedZeroPool (\r
+  IN UINTN  AllocationSize\r
+  );\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiBootServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies\r
+  AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory remaining to satisfy the request, then NULL is returned.\r
+  If Buffer is NULL, then ASSERT().\r
+  If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer\r
+  );\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies\r
+  AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory remaining to satisfy the request, then NULL is returned.\r
+  If Buffer is NULL, then ASSERT().\r
+  If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateRuntimeCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer\r
+  );\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiReservedMemoryType.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies\r
+  AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory remaining to satisfy the request, then NULL is returned.\r
+  If Buffer is NULL, then ASSERT().\r
+  If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
+\r
+  @param  AllocationSize        The number of bytes to allocate and zero.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateReservedCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer\r
+  );\r
+\r
+/**\r
+  Frees a buffer that was previously allocated with one of the pool allocation functions in the\r
+  Memory Allocation Library.\r
+\r
+  Frees the buffer specified by Buffer.  Buffer must have been allocated on a previous call to the\r
+  pool allocation services of the Memory Allocation Library.\r
+  If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,\r
+  then ASSERT().\r
+\r
+  @param  Buffer                Pointer to the buffer to free.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+UncachedFreePool (\r
+  IN VOID   *Buffer\r
+  );\r
+\r
+/**\r
+  Allocates a buffer of type EfiBootServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateAlignedPool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  );\r
+\r
+/**\r
+  Allocates a buffer of type EfiRuntimeServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateAlignedRuntimePool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  );\r
+\r
+/**\r
+  Allocates a buffer of type EfieservedMemoryType at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateAlignedReservedPool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  );\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfiBootServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an\r
+  alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory at the specified alignment remaining to satisfy the request, then NULL is\r
+  returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateAlignedZeroPool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  );\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfiRuntimeServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an\r
+  alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory at the specified alignment remaining to satisfy the request, then NULL is\r
+  returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateAlignedRuntimeZeroPool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  );\r
+\r
+/**\r
+  Allocates and zeros a buffer of type EfieservedMemoryType at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an\r
+  alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the\r
+  allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
+  is not enough memory at the specified alignment remaining to satisfy the request, then NULL is\r
+  returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateAlignedReservedZeroPool (\r
+  IN UINTN  AllocationSize,\r
+  IN UINTN  Alignment\r
+  );\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiBootServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData type with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateAlignedCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Alignment\r
+  );\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiRuntimeServicesData at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData type with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateAlignedRuntimeCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Alignment\r
+  );\r
+\r
+/**\r
+  Copies a buffer to an allocated buffer of type EfiReservedMemoryType at a specified alignment.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType type with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If AllocationSize is 0,\r
+  then a valid buffer of 0 size is returned.  If there is not enough memory at the specified\r
+  alignment remaining to satisfy the request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+  @param  Buffer                The buffer to copy to the allocated buffer.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+UncachedAllocateAlignedReservedCopyPool (\r
+  IN UINTN       AllocationSize,\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Alignment\r
+  );\r
+\r
+/**\r
+  Frees a buffer that was previously allocated with one of the aligned pool allocation functions \r
+  in the Memory Allocation Library.\r
+\r
+  Frees the buffer specified by Buffer.  Buffer must have been allocated on a previous call to the\r
+  aligned pool allocation services of the Memory Allocation Library.\r
+  If Buffer was not allocated with an aligned pool allocation function in the Memory Allocation\r
+  Library, then ASSERT().\r
+\r
+  @param  Buffer                Pointer to the buffer to free.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+UncachedFreeAlignedPool (\r
+  IN VOID   *Buffer\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+UncachedSafeFreePool (\r
+  IN VOID   *Buffer\r
+  );\r
+\r
+#endif // __UNCACHED_MEMORY_ALLOCATION_LIB_H__\r
index 0dd453003c577409052d2cfd8da3da724dd305c5..2557a2cf096abe4d7d13fd4c3ce9ec80c7882092 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <Base.h>
-#include <Library/ArmLib.h>
-#include <Library/PcdLib.h>
-
-VOID
-CacheRangeOperation (
-  IN  VOID            *Start,
-  IN  UINTN           Length,
-  IN  CACHE_OPERATION CacheOperation,
-  IN  LINE_OPERATION  LineOperation
-  )
-{
-  UINTN ArmCacheLineLength         = ArmDataCacheLineLength();
-  UINTN ArmCacheLineAlignmentMask  = ArmCacheLineLength - 1;
-  UINTN ArmCacheOperationThreshold = PcdGet32(PcdArmCacheOperationThreshold);
-  
-  if ((CacheOperation != NULL) && (Length >= ArmCacheOperationThreshold)) {
-    CacheOperation ();
-  } else {
-    // Align address (rounding down)
-    UINTN AlignedAddress = (UINTN)Start - ((UINTN)Start & ArmCacheLineAlignmentMask);
-    UINTN EndAddress     = (UINTN)Start + Length;
-
-    // Perform the line operation on an address in each cache line
-    while (AlignedAddress < EndAddress) {
-      LineOperation(AlignedAddress);
-      AlignedAddress += ArmCacheLineLength;
-    }
-  }
-}
-
-VOID
-EFIAPI
-InvalidateInstructionCache (
-  VOID
-  )
-{
-  ArmCleanDataCache();
-  ArmInvalidateInstructionCache();
-}
-
-VOID
-EFIAPI
-InvalidateDataCache (
-  VOID
-  )
-{
-  ArmInvalidateDataCache();
-}
-
-VOID *
-EFIAPI
-InvalidateInstructionCacheRange (
-  IN      VOID                      *Address,
-  IN      UINTN                     Length
-  )
-{
-  CacheRangeOperation (Address, Length, ArmCleanDataCacheToPoU, ArmCleanDataCacheEntryByMVA);
-  ArmInvalidateInstructionCache ();
-  return Address;
-}
-
-VOID
-EFIAPI
-WriteBackInvalidateDataCache (
-  VOID
-  )
-{
-  ArmCleanInvalidateDataCache();
-}
-
-VOID *
-EFIAPI
-WriteBackInvalidateDataCacheRange (
-  IN      VOID                      *Address,
-  IN      UINTN                     Length
-  )
-{
-  CacheRangeOperation(Address, Length, ArmCleanInvalidateDataCache, ArmCleanInvalidateDataCacheEntryByMVA);
-  return Address;
-}
-
-VOID
-EFIAPI
-WriteBackDataCache (
-  VOID
-  )
-{
-  ArmCleanDataCache();
-}
-
-VOID *
-EFIAPI
-WriteBackDataCacheRange (
-  IN      VOID                      *Address,
-  IN      UINTN                     Length
-  )
-{
-  CacheRangeOperation(Address, Length, ArmCleanDataCache, ArmCleanDataCacheEntryByMVA);
-  return Address;
-}
-
-VOID *
-EFIAPI
-InvalidateDataCacheRange (
-  IN      VOID                      *Address,
-  IN      UINTN                     Length
-  )
-{
-  CacheRangeOperation(Address, Length, NULL, ArmInvalidateDataCacheEntryByMVA);
-  return Address;
-}
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include <Base.h>\r
+#include <Library/ArmLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+VOID\r
+CacheRangeOperation (\r
+  IN  VOID            *Start,\r
+  IN  UINTN           Length,\r
+  IN  CACHE_OPERATION CacheOperation,\r
+  IN  LINE_OPERATION  LineOperation\r
+  )\r
+{\r
+  UINTN ArmCacheLineLength         = ArmDataCacheLineLength();\r
+  UINTN ArmCacheLineAlignmentMask  = ArmCacheLineLength - 1;\r
+  UINTN ArmCacheOperationThreshold = PcdGet32(PcdArmCacheOperationThreshold);\r
+  \r
+  if ((CacheOperation != NULL) && (Length >= ArmCacheOperationThreshold)) {\r
+    CacheOperation ();\r
+  } else {\r
+    // Align address (rounding down)\r
+    UINTN AlignedAddress = (UINTN)Start - ((UINTN)Start & ArmCacheLineAlignmentMask);\r
+    UINTN EndAddress     = (UINTN)Start + Length;\r
+\r
+    // Perform the line operation on an address in each cache line\r
+    while (AlignedAddress < EndAddress) {\r
+      LineOperation(AlignedAddress);\r
+      AlignedAddress += ArmCacheLineLength;\r
+    }\r
+  }\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+InvalidateInstructionCache (\r
+  VOID\r
+  )\r
+{\r
+  ArmCleanDataCache();\r
+  ArmInvalidateInstructionCache();\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+InvalidateDataCache (\r
+  VOID\r
+  )\r
+{\r
+  ArmInvalidateDataCache();\r
+}\r
+\r
+VOID *\r
+EFIAPI\r
+InvalidateInstructionCacheRange (\r
+  IN      VOID                      *Address,\r
+  IN      UINTN                     Length\r
+  )\r
+{\r
+  CacheRangeOperation (Address, Length, ArmCleanDataCacheToPoU, ArmCleanDataCacheEntryByMVA);\r
+  ArmInvalidateInstructionCache ();\r
+  return Address;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+WriteBackInvalidateDataCache (\r
+  VOID\r
+  )\r
+{\r
+  ArmCleanInvalidateDataCache();\r
+}\r
+\r
+VOID *\r
+EFIAPI\r
+WriteBackInvalidateDataCacheRange (\r
+  IN      VOID                      *Address,\r
+  IN      UINTN                     Length\r
+  )\r
+{\r
+  CacheRangeOperation(Address, Length, ArmCleanInvalidateDataCache, ArmCleanInvalidateDataCacheEntryByMVA);\r
+  return Address;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+WriteBackDataCache (\r
+  VOID\r
+  )\r
+{\r
+  ArmCleanDataCache();\r
+}\r
+\r
+VOID *\r
+EFIAPI\r
+WriteBackDataCacheRange (\r
+  IN      VOID                      *Address,\r
+  IN      UINTN                     Length\r
+  )\r
+{\r
+  CacheRangeOperation(Address, Length, ArmCleanDataCache, ArmCleanDataCacheEntryByMVA);\r
+  return Address;\r
+}\r
+\r
+VOID *\r
+EFIAPI\r
+InvalidateDataCacheRange (\r
+  IN      VOID                      *Address,\r
+  IN      UINTN                     Length\r
+  )\r
+{\r
+  CacheRangeOperation(Address, Length, NULL, ArmInvalidateDataCacheEntryByMVA);\r
+  return Address;\r
+}\r
index 12470480d3eae023facd474c3d0a2d26be5105cb..7a43bfe9bca816fa228a68181fe0325ee6e9d673 100644 (file)
@@ -1,37 +1,37 @@
-#/** @file
-# Semihosting  serail port lib
-#
-# Copyright (c) 2008, Apple Inc. All rights reserved.<BR>
-#
-#  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                      = ArmCacheMaintenanceLib
-  FILE_GUID                      = 1A20BE1F-33AD-450C-B49A-7123FCA8B7F9
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = CacheMaintenanceLib 
-
-[Sources.common]
-  ArmCacheMaintenanceLib.c
-
-[Packages]
-  ArmPkg/ArmPkg.dec
-  MdePkg/MdePkg.dec
-
-[LibraryClasses]
-  ArmLib
-  BaseLib
-
-[FixedPcd]
-  gArmTokenSpaceGuid.PcdArmCacheOperationThreshold
-  
+#/** @file\r
+# Semihosting  serail port lib\r
+#\r
+# Copyright (c) 2008, Apple Inc. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = ArmCacheMaintenanceLib\r
+  FILE_GUID                      = 1A20BE1F-33AD-450C-B49A-7123FCA8B7F9\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = CacheMaintenanceLib \r
+\r
+[Sources.common]\r
+  ArmCacheMaintenanceLib.c\r
+\r
+[Packages]\r
+  ArmPkg/ArmPkg.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+  ArmLib\r
+  BaseLib\r
+\r
+[FixedPcd]\r
+  gArmTokenSpaceGuid.PcdArmCacheOperationThreshold\r
+  \r
index 5c809ba3a3dae5630cd5e16f2e2ae81839267118..5465695115ff923084bb1e1dd29594565a706efe 100755 (executable)
@@ -47,4 +47,4 @@
 [Pcd]\r
 \r
 [Depex]\r
 [Pcd]\r
 \r
 [Depex]\r
-  gEfiCpuArchProtocolGuid
\ No newline at end of file
+  gEfiCpuArchProtocolGuid\r
\ No newline at end of file
index 86427035ed8e1ba5b36d0bdcda89703ae1aa69c3..c683861cbb10f5b6aeb39c0f168edd66cefab1b5 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <Chipset/ARM1176JZ-S.h>
-#include <Library/ArmLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/MemoryAllocationLib.h>
-
-VOID
-FillTranslationTable (
-  IN  UINT32                        *TranslationTable,
-  IN  ARM_MEMORY_REGION_DESCRIPTOR  *MemoryRegion
-  )
-{
-  UINT32  *Entry;
-  UINTN   Sections;
-  UINTN   Index;
-  UINT32  Attributes;
-  UINT32  PhysicalBase = MemoryRegion->PhysicalBase;
-  
-  switch (MemoryRegion->Attributes) {
-    case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK:
-      Attributes = TT_DESCRIPTOR_SECTION_WRITE_BACK(0);
-      break;
-    case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_THROUGH:
-      Attributes = TT_DESCRIPTOR_SECTION_WRITE_THROUGH(0);
-      break;
-    case ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED:
-      Attributes = TT_DESCRIPTOR_SECTION_UNCACHED(0);
-      break;
-    case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK:
-      Attributes = TT_DESCRIPTOR_SECTION_WRITE_BACK(1);
-      break;
-    case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_THROUGH:
-      Attributes = TT_DESCRIPTOR_SECTION_WRITE_THROUGH(1);
-      break;
-    case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_UNCACHED_UNBUFFERED:
-      Attributes = TT_DESCRIPTOR_SECTION_UNCACHED(1);
-      break;
-    default:
-      Attributes = TT_DESCRIPTOR_SECTION_UNCACHED(0);
-      break;
-  }
-  
-  Entry    = TRANSLATION_TABLE_ENTRY_FOR_VIRTUAL_ADDRESS(TranslationTable, MemoryRegion->VirtualBase);
-  Sections = ((( MemoryRegion->Length - 1 ) / TT_DESCRIPTOR_SECTION_SIZE ) + 1 );
-  
-  for (Index = 0; Index < Sections; Index++)
-  {
-    *Entry++     =  TT_DESCRIPTOR_SECTION_BASE_ADDRESS(PhysicalBase) | Attributes;
-    PhysicalBase += TT_DESCRIPTOR_SECTION_SIZE;
-  }
-}
-
-VOID
-EFIAPI
-ArmConfigureMmu (
-  IN  ARM_MEMORY_REGION_DESCRIPTOR  *MemoryTable,
-  OUT VOID                          **TranslationTableBase OPTIONAL,
-  OUT UINTN                         *TranslationTableSize  OPTIONAL
-  )
-{
-  VOID  *TranslationTable;
-
-  // Allocate pages for translation table.
-  TranslationTable = AllocatePages(EFI_SIZE_TO_PAGES(TRANSLATION_TABLE_SIZE + TRANSLATION_TABLE_ALIGNMENT));
-  TranslationTable = (VOID *)(((UINTN)TranslationTable + TRANSLATION_TABLE_ALIGNMENT_MASK) & ~TRANSLATION_TABLE_ALIGNMENT_MASK);
-
-  if (TranslationTableBase != NULL) {
-    *TranslationTableBase = TranslationTable;
-  }
-  
-  if (TranslationTableBase != NULL) {
-    *TranslationTableSize = TRANSLATION_TABLE_SIZE;
-  }
-
-  ZeroMem(TranslationTable, TRANSLATION_TABLE_SIZE);
-
-  ArmCleanInvalidateDataCache();
-  ArmInvalidateInstructionCache();
-  ArmInvalidateTlb();
-
-  ArmDisableDataCache();
-  ArmDisableInstructionCache();
-  ArmDisableMmu();
-
-  // Make sure nothing sneaked into the cache
-  ArmCleanInvalidateDataCache();
-  ArmInvalidateInstructionCache();
-
-  while (MemoryTable->Length != 0) {
-    FillTranslationTable(TranslationTable, MemoryTable);
-    MemoryTable++;
-  }
-
-  ArmSetTTBR0(TranslationTable);
-    
-  ArmSetDomainAccessControl(DOMAIN_ACCESS_CONTROL_NONE(15) |
-                            DOMAIN_ACCESS_CONTROL_NONE(14) |
-                            DOMAIN_ACCESS_CONTROL_NONE(13) |
-                            DOMAIN_ACCESS_CONTROL_NONE(12) |
-                            DOMAIN_ACCESS_CONTROL_NONE(11) |
-                            DOMAIN_ACCESS_CONTROL_NONE(10) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 9) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 8) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 7) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 6) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 5) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 4) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 3) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 2) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 1) |
-                            DOMAIN_ACCESS_CONTROL_MANAGER(0));
-    
-  ArmEnableInstructionCache();
-  ArmEnableDataCache();
-  ArmEnableMmu();  
-}
-
-
-
-
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Chipset/ARM1176JZ-S.h>\r
+#include <Library/ArmLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+VOID\r
+FillTranslationTable (\r
+  IN  UINT32                        *TranslationTable,\r
+  IN  ARM_MEMORY_REGION_DESCRIPTOR  *MemoryRegion\r
+  )\r
+{\r
+  UINT32  *Entry;\r
+  UINTN   Sections;\r
+  UINTN   Index;\r
+  UINT32  Attributes;\r
+  UINT32  PhysicalBase = MemoryRegion->PhysicalBase;\r
+  \r
+  switch (MemoryRegion->Attributes) {\r
+    case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK:\r
+      Attributes = TT_DESCRIPTOR_SECTION_WRITE_BACK(0);\r
+      break;\r
+    case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_THROUGH:\r
+      Attributes = TT_DESCRIPTOR_SECTION_WRITE_THROUGH(0);\r
+      break;\r
+    case ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED:\r
+      Attributes = TT_DESCRIPTOR_SECTION_UNCACHED(0);\r
+      break;\r
+    case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK:\r
+      Attributes = TT_DESCRIPTOR_SECTION_WRITE_BACK(1);\r
+      break;\r
+    case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_THROUGH:\r
+      Attributes = TT_DESCRIPTOR_SECTION_WRITE_THROUGH(1);\r
+      break;\r
+    case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_UNCACHED_UNBUFFERED:\r
+      Attributes = TT_DESCRIPTOR_SECTION_UNCACHED(1);\r
+      break;\r
+    default:\r
+      Attributes = TT_DESCRIPTOR_SECTION_UNCACHED(0);\r
+      break;\r
+  }\r
+  \r
+  Entry    = TRANSLATION_TABLE_ENTRY_FOR_VIRTUAL_ADDRESS(TranslationTable, MemoryRegion->VirtualBase);\r
+  Sections = ((( MemoryRegion->Length - 1 ) / TT_DESCRIPTOR_SECTION_SIZE ) + 1 );\r
+  \r
+  for (Index = 0; Index < Sections; Index++)\r
+  {\r
+    *Entry++     =  TT_DESCRIPTOR_SECTION_BASE_ADDRESS(PhysicalBase) | Attributes;\r
+    PhysicalBase += TT_DESCRIPTOR_SECTION_SIZE;\r
+  }\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmConfigureMmu (\r
+  IN  ARM_MEMORY_REGION_DESCRIPTOR  *MemoryTable,\r
+  OUT VOID                          **TranslationTableBase OPTIONAL,\r
+  OUT UINTN                         *TranslationTableSize  OPTIONAL\r
+  )\r
+{\r
+  VOID  *TranslationTable;\r
+\r
+  // Allocate pages for translation table.\r
+  TranslationTable = AllocatePages(EFI_SIZE_TO_PAGES(TRANSLATION_TABLE_SIZE + TRANSLATION_TABLE_ALIGNMENT));\r
+  TranslationTable = (VOID *)(((UINTN)TranslationTable + TRANSLATION_TABLE_ALIGNMENT_MASK) & ~TRANSLATION_TABLE_ALIGNMENT_MASK);\r
+\r
+  if (TranslationTableBase != NULL) {\r
+    *TranslationTableBase = TranslationTable;\r
+  }\r
+  \r
+  if (TranslationTableBase != NULL) {\r
+    *TranslationTableSize = TRANSLATION_TABLE_SIZE;\r
+  }\r
+\r
+  ZeroMem(TranslationTable, TRANSLATION_TABLE_SIZE);\r
+\r
+  ArmCleanInvalidateDataCache();\r
+  ArmInvalidateInstructionCache();\r
+  ArmInvalidateTlb();\r
+\r
+  ArmDisableDataCache();\r
+  ArmDisableInstructionCache();\r
+  ArmDisableMmu();\r
+\r
+  // Make sure nothing sneaked into the cache\r
+  ArmCleanInvalidateDataCache();\r
+  ArmInvalidateInstructionCache();\r
+\r
+  while (MemoryTable->Length != 0) {\r
+    FillTranslationTable(TranslationTable, MemoryTable);\r
+    MemoryTable++;\r
+  }\r
+\r
+  ArmSetTTBR0(TranslationTable);\r
+    \r
+  ArmSetDomainAccessControl(DOMAIN_ACCESS_CONTROL_NONE(15) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE(14) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE(13) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE(12) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE(11) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE(10) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 9) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 8) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 7) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 6) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 5) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 4) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 3) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 2) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 1) |\r
+                            DOMAIN_ACCESS_CONTROL_MANAGER(0));\r
+    \r
+  ArmEnableInstructionCache();\r
+  ArmEnableDataCache();\r
+  ArmEnableMmu();  \r
+}\r
+\r
+\r
+\r
+\r
index 7ff377c023c3137212a7c5e8cdb67d928f623aa8..2f4be7e93f54495c31ee37a2ec9130f1e49d1f3b 100644 (file)
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-# Copyright (c) 2011, ARM Limited. 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 <AsmMacroIoLib.h>
-
-.text
-.align 2
-GCC_ASM_EXPORT(ArmDisableCachesAndMmu)
-GCC_ASM_EXPORT(ArmInvalidateInstructionAndDataTlb)
-GCC_ASM_EXPORT(ArmCleanInvalidateDataCache)
-GCC_ASM_EXPORT(ArmCleanDataCache)
-GCC_ASM_EXPORT(ArmInvalidateDataCache)
-GCC_ASM_EXPORT(ArmInvalidateInstructionCache)
-GCC_ASM_EXPORT(ArmInvalidateDataCacheEntryByMVA)
-GCC_ASM_EXPORT(ArmCleanDataCacheEntryByMVA)
-GCC_ASM_EXPORT(ArmCleanInvalidateDataCacheEntryByMVA)
-GCC_ASM_EXPORT(ArmEnableMmu)
-GCC_ASM_EXPORT(ArmDisableMmu)
-GCC_ASM_EXPORT(ArmMmuEnabled)
-GCC_ASM_EXPORT(ArmEnableDataCache)
-GCC_ASM_EXPORT(ArmDisableDataCache)
-GCC_ASM_EXPORT(ArmEnableInstructionCache)
-GCC_ASM_EXPORT(ArmDisableInstructionCache)
-GCC_ASM_EXPORT(ArmEnableBranchPrediction)
-GCC_ASM_EXPORT(ArmDisableBranchPrediction)
-GCC_ASM_EXPORT(ArmDataMemoryBarrier)
-GCC_ASM_EXPORT(ArmDataSyncronizationBarrier)
-GCC_ASM_EXPORT(ArmInstructionSynchronizationBarrier)
-GCC_ASM_EXPORT(ArmSetLowVectors)
-GCC_ASM_EXPORT(ArmSetHighVectors)
-GCC_ASM_EXPORT(ArmIsMpCore)
-GCC_ASM_EXPORT(ArmCallWFI)
-GCC_ASM_EXPORT(ArmReadMpidr)
-GCC_ASM_EXPORT(ArmUpdateTranslationTableEntry)
-GCC_ASM_EXPORT(ArmEnableFiq)
-GCC_ASM_EXPORT(ArmDisableFiq)
-GCC_ASM_EXPORT(ArmEnableInterrupts)
-GCC_ASM_EXPORT(ArmDisableInterrupts)
-GCC_ASM_EXPORT (ArmEnableVFP)
-
-Arm11PartNumberMask:  .word       0xFFF0
-Arm11PartNumber:      .word          0xB020
-
-.set DC_ON, (0x1<<2)
-.set IC_ON, (0x1<<12)
-.set XP_ON, (0x1<<23)
-.set CTRL_M_BIT,  (1 << 0)
-.set CTRL_C_BIT,  (1 << 2)
-.set CTRL_I_BIT,  (1 << 12)
-
-ASM_PFX(ArmDisableCachesAndMmu):
-  mrc   p15, 0, r0, c1, c0, 0           @ Get control register
-  bic   r0, r0, #CTRL_M_BIT             @ Disable MMU
-  bic   r0, r0, #CTRL_C_BIT             @ Disable D Cache
-  bic   r0, r0, #CTRL_I_BIT             @ Disable I Cache
-  mcr   p15, 0, r0, c1, c0, 0           @ Write control register
-  bx      LR
-
-ASM_PFX(ArmInvalidateInstructionAndDataTlb):
-  mcr     p15, 0, r0, c8, c7, 0      @ Invalidate Inst TLB and Data TLB
-  bx lr
-
-ASM_PFX(ArmInvalidateDataCacheEntryByMVA):
-  mcr     p15, 0, r0, c7, c6, 1   @invalidate single data cache line                                           
-  bx      lr
-
-
-ASM_PFX(ArmCleanDataCacheEntryByMVA):
-  mcr     p15, 0, r0, c7, c10, 1  @clean single data cache line     
-  bx      lr
-
-
-ASM_PFX(ArmCleanInvalidateDataCacheEntryByMVA):
-  mcr     p15, 0, r0, c7, c14, 1  @clean and invalidate single data cache line
-  bx      lr
-
-
-ASM_PFX(ArmCleanDataCache):
-  mcr     p15, 0, r0, c7, c10, 0  @ clean entire data cache
-  bx      lr
-
-
-ASM_PFX(ArmCleanInvalidateDataCache):
-  mcr     p15, 0, r0, c7, c14, 0  @ clean and invalidate entire data cache
-  bx      lr
-
-
-ASM_PFX(ArmInvalidateDataCache):
-  mcr     p15, 0, r0, c7, c6, 0  @ invalidate entire data cache
-  bx      lr
-
-
-ASM_PFX(ArmInvalidateInstructionCache):
-  mcr     p15, 0, r0, c7, c5, 0  @invalidate entire instruction cache
-  mov     R0,#0
-  mcr     p15,0,R0,c7,c5,4       @Flush Prefetch buffer
-  bx      lr
-
-ASM_PFX(ArmEnableMmu):
-  mrc     p15,0,R0,c1,c0,0
-  orr     R0,R0,#1
-  mcr     p15,0,R0,c1,c0,0
-  bx      LR
-
-ASM_PFX(ArmMmuEnabled):
-  mrc     p15,0,R0,c1,c0,0
-  and     R0,R0,#1
-  bx      LR
-
-ASM_PFX(ArmDisableMmu):
-  mrc     p15,0,R0,c1,c0,0
-  bic     R0,R0,#1
-  mcr     p15,0,R0,c1,c0,0
-  mov     R0,#0
-  mcr     p15,0,R0,c7,c10,4     @Data synchronization barrier
-  mov     R0,#0
-  mcr     p15,0,R0,c7,c5,4      @Flush Prefetch buffer
-  bx      LR
-
-ASM_PFX(ArmEnableDataCache):
-  LoadConstantToReg(DC_ON, R1)  @ldr     R1,=DC_ON
-  mrc     p15,0,R0,c1,c0,0      @Read control register configuration data
-  orr     R0,R0,R1              @Set C bit
-  mcr     p15,0,r0,c1,c0,0      @Write control register configuration data
-  bx      LR
-    
-ASM_PFX(ArmDisableDataCache):
-  LoadConstantToReg(DC_ON, R1)  @ldr     R1,=DC_ON
-  mrc     p15,0,R0,c1,c0,0      @Read control register configuration data
-  bic     R0,R0,R1              @Clear C bit
-  mcr     p15,0,r0,c1,c0,0      @Write control register configuration data
-  bx      LR
-
-ASM_PFX(ArmEnableInstructionCache):
-  ldr     R1,=IC_ON
-  mrc     p15,0,R0,c1,c0,0     @Read control register configuration data
-  orr     R0,R0,R1             @Set I bit
-  mcr     p15,0,r0,c1,c0,0     @Write control register configuration data
-  bx      LR
-  
-ASM_PFX(ArmDisableInstructionCache):
-  ldr     R1,=IC_ON
-  mrc     p15,0,R0,c1,c0,0     @Read control register configuration data
-  bic     R0,R0,R1             @Clear I bit.
-  mcr     p15,0,r0,c1,c0,0     @Write control register configuration data
-  bx      LR
-
-ASM_PFX(ArmEnableBranchPrediction):
-  mrc     p15, 0, r0, c1, c0, 0
-  orr     r0, r0, #0x00000800
-  mcr     p15, 0, r0, c1, c0, 0
-  bx      LR
-
-ASM_PFX(ArmDisableBranchPrediction):
-  mrc     p15, 0, r0, c1, c0, 0
-  bic     r0, r0, #0x00000800
-  mcr     p15, 0, r0, c1, c0, 0
-  bx      LR
-
-ASM_PFX(ArmDataMemoryBarrier):
-  mov R0, #0
-  mcr P15, #0, R0, C7, C10, #5 
-  bx      LR
-  
-ASM_PFX(ArmDataSyncronizationBarrier):
-  mov R0, #0
-  mcr P15, #0, R0, C7, C10, #4 
-  bx      LR
-  
-ASM_PFX(ArmInstructionSynchronizationBarrier):
-  mov R0, #0
-  mcr P15, #0, R0, C7, C5, #4 
-  bx      LR
-
-ASM_PFX(ArmSetLowVectors):
-  mrc     p15, 0, r0, c1, c0, 0 @ Read SCTLR into R0 (Read control register configuration data)
-  bic     r0, r0, #0x00002000   @ clear V bit
-  mcr     p15, 0, r0, c1, c0, 0 @ Write R0 into SCTLR (Write control register configuration data)
-  bx      LR
-
-ASM_PFX(ArmSetHighVectors):
-  mrc     p15, 0, r0, c1, c0, 0 @ Read SCTLR into R0 (Read control register configuration data)
-  orr     r0, r0, #0x00002000   @ clear V bit
-  mcr     p15, 0, r0, c1, c0, 0 @ Write R0 into SCTLR (Write control register configuration data)
-  bx      LR
-
-ASM_PFX(ArmIsMpCore):
-  push    { r1 }
-  mrc     p15, 0, r0, c0, c0, 0
-  # Extract Part Number to check it is an ARM11MP core (0xB02)
-  LoadConstantToReg (Arm11PartNumberMask, r1)
-  and     r0, r0, r1
-  LoadConstantToReg (Arm11PartNumber, r1)
-  cmp     r0, r1
-  movne   r0, #0
-  pop     { r1 }
-  bx      lr     
-
-ASM_PFX(ArmCallWFI):
-  wfi
-  bx      lr
-
-ASM_PFX(ArmReadMpidr):
-  mrc     p15, 0, r0, c0, c0, 5       @ read MPIDR
-  bx      lr
-
-ASM_PFX(ArmEnableFiq):
-  mrs     R0,CPSR
-  bic     R0,R0,#0x40    @Enable FIQ interrupts
-  msr     CPSR_c,R0
-  bx      LR
-
-ASM_PFX(ArmDisableFiq):
-  mrs     R0,CPSR
-  orr     R1,R0,#0x40    @Disable FIQ interrupts
-  msr     CPSR_c,R1
-  tst     R0,#0x80
-  moveq   R0,#1
-  movne   R0,#0
-  bx      LR
-
-ASM_PFX(ArmEnableInterrupts):
-  mrs     R0,CPSR
-  bic     R0,R0,#0x80    @Enable IRQ interrupts
-  msr     CPSR_c,R0
-  bx      LR
-
-ASM_PFX(ArmDisableInterrupts):
-  mrs     R0,CPSR
-  orr     R1,R0,#0x80    @Disable IRQ interrupts
-  msr     CPSR_c,R1
-  tst     R0,#0x80
-  moveq   R0,#1
-  movne   R0,#0
-  bx      LR
-
-ASM_PFX(ArmEnableVFP):
-  # Read CPACR (Coprocessor Access Control Register)
-  mrc     p15, 0, r0, c1, c0, 2
-  # Enable VPF access (Full Access to CP10, CP11) (V* instructions)
-  orr     r0, r0, #0x00f00000
-  # Write back CPACR (Coprocessor Access Control Register)
-  mcr     p15, 0, r0, c1, c0, 2
-  # Set EN bit in FPEXC. The Advanced SIMD and VFP extensions are enabled and operate normally.
-  mov     r0, #0x40000000
-  #TODO: Fixme - need compilation flag
-  #fmxr    FPEXC, r0
-  bx      lr
-
-ASM_FUNCTION_REMOVE_IF_UNREFERENCED
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+# Copyright (c) 2011, ARM Limited. All rights reserved.\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+#include <AsmMacroIoLib.h>\r
+\r
+.text\r
+.align 2\r
+GCC_ASM_EXPORT(ArmDisableCachesAndMmu)\r
+GCC_ASM_EXPORT(ArmInvalidateInstructionAndDataTlb)\r
+GCC_ASM_EXPORT(ArmCleanInvalidateDataCache)\r
+GCC_ASM_EXPORT(ArmCleanDataCache)\r
+GCC_ASM_EXPORT(ArmInvalidateDataCache)\r
+GCC_ASM_EXPORT(ArmInvalidateInstructionCache)\r
+GCC_ASM_EXPORT(ArmInvalidateDataCacheEntryByMVA)\r
+GCC_ASM_EXPORT(ArmCleanDataCacheEntryByMVA)\r
+GCC_ASM_EXPORT(ArmCleanInvalidateDataCacheEntryByMVA)\r
+GCC_ASM_EXPORT(ArmEnableMmu)\r
+GCC_ASM_EXPORT(ArmDisableMmu)\r
+GCC_ASM_EXPORT(ArmMmuEnabled)\r
+GCC_ASM_EXPORT(ArmEnableDataCache)\r
+GCC_ASM_EXPORT(ArmDisableDataCache)\r
+GCC_ASM_EXPORT(ArmEnableInstructionCache)\r
+GCC_ASM_EXPORT(ArmDisableInstructionCache)\r
+GCC_ASM_EXPORT(ArmEnableBranchPrediction)\r
+GCC_ASM_EXPORT(ArmDisableBranchPrediction)\r
+GCC_ASM_EXPORT(ArmDataMemoryBarrier)\r
+GCC_ASM_EXPORT(ArmDataSyncronizationBarrier)\r
+GCC_ASM_EXPORT(ArmInstructionSynchronizationBarrier)\r
+GCC_ASM_EXPORT(ArmSetLowVectors)\r
+GCC_ASM_EXPORT(ArmSetHighVectors)\r
+GCC_ASM_EXPORT(ArmIsMpCore)\r
+GCC_ASM_EXPORT(ArmCallWFI)\r
+GCC_ASM_EXPORT(ArmReadMpidr)\r
+GCC_ASM_EXPORT(ArmUpdateTranslationTableEntry)\r
+GCC_ASM_EXPORT(ArmEnableFiq)\r
+GCC_ASM_EXPORT(ArmDisableFiq)\r
+GCC_ASM_EXPORT(ArmEnableInterrupts)\r
+GCC_ASM_EXPORT(ArmDisableInterrupts)\r
+GCC_ASM_EXPORT (ArmEnableVFP)\r
+\r
+Arm11PartNumberMask:  .word       0xFFF0\r
+Arm11PartNumber:      .word          0xB020\r
+\r
+.set DC_ON, (0x1<<2)\r
+.set IC_ON, (0x1<<12)\r
+.set XP_ON, (0x1<<23)\r
+.set CTRL_M_BIT,  (1 << 0)\r
+.set CTRL_C_BIT,  (1 << 2)\r
+.set CTRL_I_BIT,  (1 << 12)\r
+\r
+ASM_PFX(ArmDisableCachesAndMmu):\r
+  mrc   p15, 0, r0, c1, c0, 0           @ Get control register\r
+  bic   r0, r0, #CTRL_M_BIT             @ Disable MMU\r
+  bic   r0, r0, #CTRL_C_BIT             @ Disable D Cache\r
+  bic   r0, r0, #CTRL_I_BIT             @ Disable I Cache\r
+  mcr   p15, 0, r0, c1, c0, 0           @ Write control register\r
+  bx      LR\r
+\r
+ASM_PFX(ArmInvalidateInstructionAndDataTlb):\r
+  mcr     p15, 0, r0, c8, c7, 0      @ Invalidate Inst TLB and Data TLB\r
+  bx lr\r
+\r
+ASM_PFX(ArmInvalidateDataCacheEntryByMVA):\r
+  mcr     p15, 0, r0, c7, c6, 1   @invalidate single data cache line                                           \r
+  bx      lr\r
+\r
+\r
+ASM_PFX(ArmCleanDataCacheEntryByMVA):\r
+  mcr     p15, 0, r0, c7, c10, 1  @clean single data cache line     \r
+  bx      lr\r
+\r
+\r
+ASM_PFX(ArmCleanInvalidateDataCacheEntryByMVA):\r
+  mcr     p15, 0, r0, c7, c14, 1  @clean and invalidate single data cache line\r
+  bx      lr\r
+\r
+\r
+ASM_PFX(ArmCleanDataCache):\r
+  mcr     p15, 0, r0, c7, c10, 0  @ clean entire data cache\r
+  bx      lr\r
+\r
+\r
+ASM_PFX(ArmCleanInvalidateDataCache):\r
+  mcr     p15, 0, r0, c7, c14, 0  @ clean and invalidate entire data cache\r
+  bx      lr\r
+\r
+\r
+ASM_PFX(ArmInvalidateDataCache):\r
+  mcr     p15, 0, r0, c7, c6, 0  @ invalidate entire data cache\r
+  bx      lr\r
+\r
+\r
+ASM_PFX(ArmInvalidateInstructionCache):\r
+  mcr     p15, 0, r0, c7, c5, 0  @invalidate entire instruction cache\r
+  mov     R0,#0\r
+  mcr     p15,0,R0,c7,c5,4       @Flush Prefetch buffer\r
+  bx      lr\r
+\r
+ASM_PFX(ArmEnableMmu):\r
+  mrc     p15,0,R0,c1,c0,0\r
+  orr     R0,R0,#1\r
+  mcr     p15,0,R0,c1,c0,0\r
+  bx      LR\r
+\r
+ASM_PFX(ArmMmuEnabled):\r
+  mrc     p15,0,R0,c1,c0,0\r
+  and     R0,R0,#1\r
+  bx      LR\r
+\r
+ASM_PFX(ArmDisableMmu):\r
+  mrc     p15,0,R0,c1,c0,0\r
+  bic     R0,R0,#1\r
+  mcr     p15,0,R0,c1,c0,0\r
+  mov     R0,#0\r
+  mcr     p15,0,R0,c7,c10,4     @Data synchronization barrier\r
+  mov     R0,#0\r
+  mcr     p15,0,R0,c7,c5,4      @Flush Prefetch buffer\r
+  bx      LR\r
+\r
+ASM_PFX(ArmEnableDataCache):\r
+  LoadConstantToReg(DC_ON, R1)  @ldr     R1,=DC_ON\r
+  mrc     p15,0,R0,c1,c0,0      @Read control register configuration data\r
+  orr     R0,R0,R1              @Set C bit\r
+  mcr     p15,0,r0,c1,c0,0      @Write control register configuration data\r
+  bx      LR\r
+    \r
+ASM_PFX(ArmDisableDataCache):\r
+  LoadConstantToReg(DC_ON, R1)  @ldr     R1,=DC_ON\r
+  mrc     p15,0,R0,c1,c0,0      @Read control register configuration data\r
+  bic     R0,R0,R1              @Clear C bit\r
+  mcr     p15,0,r0,c1,c0,0      @Write control register configuration data\r
+  bx      LR\r
+\r
+ASM_PFX(ArmEnableInstructionCache):\r
+  ldr     R1,=IC_ON\r
+  mrc     p15,0,R0,c1,c0,0     @Read control register configuration data\r
+  orr     R0,R0,R1             @Set I bit\r
+  mcr     p15,0,r0,c1,c0,0     @Write control register configuration data\r
+  bx      LR\r
+  \r
+ASM_PFX(ArmDisableInstructionCache):\r
+  ldr     R1,=IC_ON\r
+  mrc     p15,0,R0,c1,c0,0     @Read control register configuration data\r
+  bic     R0,R0,R1             @Clear I bit.\r
+  mcr     p15,0,r0,c1,c0,0     @Write control register configuration data\r
+  bx      LR\r
+\r
+ASM_PFX(ArmEnableBranchPrediction):\r
+  mrc     p15, 0, r0, c1, c0, 0\r
+  orr     r0, r0, #0x00000800\r
+  mcr     p15, 0, r0, c1, c0, 0\r
+  bx      LR\r
+\r
+ASM_PFX(ArmDisableBranchPrediction):\r
+  mrc     p15, 0, r0, c1, c0, 0\r
+  bic     r0, r0, #0x00000800\r
+  mcr     p15, 0, r0, c1, c0, 0\r
+  bx      LR\r
+\r
+ASM_PFX(ArmDataMemoryBarrier):\r
+  mov R0, #0\r
+  mcr P15, #0, R0, C7, C10, #5 \r
+  bx      LR\r
+  \r
+ASM_PFX(ArmDataSyncronizationBarrier):\r
+  mov R0, #0\r
+  mcr P15, #0, R0, C7, C10, #4 \r
+  bx      LR\r
+  \r
+ASM_PFX(ArmInstructionSynchronizationBarrier):\r
+  mov R0, #0\r
+  mcr P15, #0, R0, C7, C5, #4 \r
+  bx      LR\r
+\r
+ASM_PFX(ArmSetLowVectors):\r
+  mrc     p15, 0, r0, c1, c0, 0 @ Read SCTLR into R0 (Read control register configuration data)\r
+  bic     r0, r0, #0x00002000   @ clear V bit\r
+  mcr     p15, 0, r0, c1, c0, 0 @ Write R0 into SCTLR (Write control register configuration data)\r
+  bx      LR\r
+\r
+ASM_PFX(ArmSetHighVectors):\r
+  mrc     p15, 0, r0, c1, c0, 0 @ Read SCTLR into R0 (Read control register configuration data)\r
+  orr     r0, r0, #0x00002000   @ clear V bit\r
+  mcr     p15, 0, r0, c1, c0, 0 @ Write R0 into SCTLR (Write control register configuration data)\r
+  bx      LR\r
+\r
+ASM_PFX(ArmIsMpCore):\r
+  push    { r1 }\r
+  mrc     p15, 0, r0, c0, c0, 0\r
+  # Extract Part Number to check it is an ARM11MP core (0xB02)\r
+  LoadConstantToReg (Arm11PartNumberMask, r1)\r
+  and     r0, r0, r1\r
+  LoadConstantToReg (Arm11PartNumber, r1)\r
+  cmp     r0, r1\r
+  movne   r0, #0\r
+  pop     { r1 }\r
+  bx      lr     \r
+\r
+ASM_PFX(ArmCallWFI):\r
+  wfi\r
+  bx      lr\r
+\r
+ASM_PFX(ArmReadMpidr):\r
+  mrc     p15, 0, r0, c0, c0, 5       @ read MPIDR\r
+  bx      lr\r
+\r
+ASM_PFX(ArmEnableFiq):\r
+  mrs     R0,CPSR\r
+  bic     R0,R0,#0x40    @Enable FIQ interrupts\r
+  msr     CPSR_c,R0\r
+  bx      LR\r
+\r
+ASM_PFX(ArmDisableFiq):\r
+  mrs     R0,CPSR\r
+  orr     R1,R0,#0x40    @Disable FIQ interrupts\r
+  msr     CPSR_c,R1\r
+  tst     R0,#0x80\r
+  moveq   R0,#1\r
+  movne   R0,#0\r
+  bx      LR\r
+\r
+ASM_PFX(ArmEnableInterrupts):\r
+  mrs     R0,CPSR\r
+  bic     R0,R0,#0x80    @Enable IRQ interrupts\r
+  msr     CPSR_c,R0\r
+  bx      LR\r
+\r
+ASM_PFX(ArmDisableInterrupts):\r
+  mrs     R0,CPSR\r
+  orr     R1,R0,#0x80    @Disable IRQ interrupts\r
+  msr     CPSR_c,R1\r
+  tst     R0,#0x80\r
+  moveq   R0,#1\r
+  movne   R0,#0\r
+  bx      LR\r
+\r
+ASM_PFX(ArmEnableVFP):\r
+  # Read CPACR (Coprocessor Access Control Register)\r
+  mrc     p15, 0, r0, c1, c0, 2\r
+  # Enable VPF access (Full Access to CP10, CP11) (V* instructions)\r
+  orr     r0, r0, #0x00f00000\r
+  # Write back CPACR (Coprocessor Access Control Register)\r
+  mcr     p15, 0, r0, c1, c0, 2\r
+  # Set EN bit in FPEXC. The Advanced SIMD and VFP extensions are enabled and operate normally.\r
+  mov     r0, #0x40000000\r
+  #TODO: Fixme - need compilation flag\r
+  #fmxr    FPEXC, r0\r
+  bx      lr\r
+\r
+ASM_FUNCTION_REMOVE_IF_UNREFERENCED\r
index fb3e91b7ed8c68a966c9a853fc54c7f2f0b94eb6..8c27093045b9e6e534203977e64f5403369e57e5 100644 (file)
-//------------------------------------------------------------------------------ 
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-    EXPORT  ArmCleanInvalidateDataCache
-    EXPORT  ArmCleanDataCache
-    EXPORT  ArmInvalidateDataCache
-    EXPORT  ArmInvalidateInstructionCache
-    EXPORT  ArmInvalidateDataCacheEntryByMVA
-    EXPORT  ArmCleanDataCacheEntryByMVA
-    EXPORT  ArmCleanInvalidateDataCacheEntryByMVA
-    EXPORT  ArmEnableMmu
-    EXPORT  ArmDisableMmu
-    EXPORT  ArmMmuEnabled
-    EXPORT  ArmEnableDataCache
-    EXPORT  ArmDisableDataCache
-    EXPORT  ArmEnableInstructionCache
-    EXPORT  ArmDisableInstructionCache
-    EXPORT  ArmEnableBranchPrediction
-    EXPORT  ArmDisableBranchPrediction
-    EXPORT  ArmDataMemoryBarrier
-    EXPORT  ArmDataSyncronizationBarrier
-    EXPORT  ArmInstructionSynchronizationBarrier
-
-
-DC_ON       EQU     ( 0x1:SHL:2 )
-IC_ON       EQU     ( 0x1:SHL:12 )
-XP_ON       EQU     ( 0x1:SHL:23 )
-
-
-    AREA    ArmCacheLib, CODE, READONLY
-    PRESERVE8
-
-
-ArmInvalidateDataCacheEntryByMVA
-  mcr     p15, 0, r0, c7, c6, 1   ; invalidate single data cache line                                           
-  bx      lr
-
-
-ArmCleanDataCacheEntryByMVA
-  mcr     p15, 0, r0, c7, c10, 1  ; clean single data cache line     
-  bx      lr
-
-
-ArmCleanInvalidateDataCacheEntryByMVA
-  mcr     p15, 0, r0, c7, c14, 1  ; clean and invalidate single data cache line
-  bx      lr
-
-
-ArmCleanDataCache
-  mcr     p15, 0, r0, c7, c10, 0  ; clean entire data cache
-  bx      lr
-
-
-ArmCleanInvalidateDataCache
-  mcr     p15, 0, r0, c7, c14, 0  ; clean and invalidate entire data cache
-  bx      lr
-
-
-ArmInvalidateDataCache
-  mcr     p15, 0, r0, c7, c6, 0  ; invalidate entire data cache
-  bx      lr
-
-
-ArmInvalidateInstructionCache
-  mcr     p15, 0, r0, c7, c5, 0  ;invalidate entire instruction cache
-  mov     R0,#0
-  mcr     p15,0,R0,c7,c5,4       ;Flush Prefetch buffer
-  bx      lr
-
-ArmEnableMmu
-  mrc     p15,0,R0,c1,c0,0
-  orr     R0,R0,#1
-  mcr     p15,0,R0,c1,c0,0
-  bx      LR
-
-ArmMmuEnabled
-  mrc     p15,0,R0,c1,c0,0
-  and     R0,R0,#1
-  bx      LR
-
-ArmDisableMmu
-  mrc     p15,0,R0,c1,c0,0
-  bic     R0,R0,#1
-  mcr     p15,0,R0,c1,c0,0
-  mov     R0,#0
-  mcr     p15,0,R0,c7,c10,4     ;Data synchronization barrier
-  mov     R0,#0
-  mcr     p15,0,R0,c7,c5,4      ;Flush Prefetch buffer
-  bx      LR
-
-ArmEnableDataCache
-  LDR     R1,=DC_ON
-  MRC     p15,0,R0,c1,c0,0      ;Read control register configuration data
-  ORR     R0,R0,R1              ;Set C bit
-  MCR     p15,0,r0,c1,c0,0      ;Write control register configuration data
-  BX      LR
-    
-ArmDisableDataCache
-  LDR     R1,=DC_ON
-  MRC     p15,0,R0,c1,c0,0      ;Read control register configuration data
-  BIC     R0,R0,R1              ;Clear C bit
-  MCR     p15,0,r0,c1,c0,0      ;Write control register configuration data
-  BX      LR
-
-ArmEnableInstructionCache
-  LDR     R1,=IC_ON
-  MRC     p15,0,R0,c1,c0,0     ;Read control register configuration data
-  ORR     R0,R0,R1             ;Set I bit
-  MCR     p15,0,r0,c1,c0,0     ;Write control register configuration data
-  BX      LR
-  
-ArmDisableInstructionCache
-  LDR     R1,=IC_ON
-  MRC     p15,0,R0,c1,c0,0     ;Read control register configuration data
-  BIC     R0,R0,R1             ;Clear I bit.
-  MCR     p15,0,r0,c1,c0,0     ;Write control register configuration data
-  BX      LR
-
-ArmEnableBranchPrediction
-  mrc     p15, 0, r0, c1, c0, 0
-  orr     r0, r0, #0x00000800
-  mcr     p15, 0, r0, c1, c0, 0
-  bx      LR
-
-ArmDisableBranchPrediction
-  mrc     p15, 0, r0, c1, c0, 0
-  bic     r0, r0, #0x00000800
-  mcr     p15, 0, r0, c1, c0, 0
-  bx      LR
-
-ASM_PFX(ArmDataMemoryBarrier):
-  mov R0, #0
-  mcr P15, #0, R0, C7, C10, #5 
-  bx      LR
-  
-ASM_PFX(ArmDataSyncronizationBarrier):
-  mov R0, #0
-  mcr P15, #0, R0, C7, C10, #4 
-  bx      LR
-  
-ASM_PFX(ArmInstructionSynchronizationBarrier):
-  MOV R0, #0
-  MCR P15, #0, R0, C7, C5, #4 
-  bx      LR
-
-    END
+//------------------------------------------------------------------------------ \r
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+    EXPORT  ArmCleanInvalidateDataCache\r
+    EXPORT  ArmCleanDataCache\r
+    EXPORT  ArmInvalidateDataCache\r
+    EXPORT  ArmInvalidateInstructionCache\r
+    EXPORT  ArmInvalidateDataCacheEntryByMVA\r
+    EXPORT  ArmCleanDataCacheEntryByMVA\r
+    EXPORT  ArmCleanInvalidateDataCacheEntryByMVA\r
+    EXPORT  ArmEnableMmu\r
+    EXPORT  ArmDisableMmu\r
+    EXPORT  ArmMmuEnabled\r
+    EXPORT  ArmEnableDataCache\r
+    EXPORT  ArmDisableDataCache\r
+    EXPORT  ArmEnableInstructionCache\r
+    EXPORT  ArmDisableInstructionCache\r
+    EXPORT  ArmEnableBranchPrediction\r
+    EXPORT  ArmDisableBranchPrediction\r
+    EXPORT  ArmDataMemoryBarrier\r
+    EXPORT  ArmDataSyncronizationBarrier\r
+    EXPORT  ArmInstructionSynchronizationBarrier\r
+\r
+\r
+DC_ON       EQU     ( 0x1:SHL:2 )\r
+IC_ON       EQU     ( 0x1:SHL:12 )\r
+XP_ON       EQU     ( 0x1:SHL:23 )\r
+\r
+\r
+    AREA    ArmCacheLib, CODE, READONLY\r
+    PRESERVE8\r
+\r
+\r
+ArmInvalidateDataCacheEntryByMVA\r
+  mcr     p15, 0, r0, c7, c6, 1   ; invalidate single data cache line                                           \r
+  bx      lr\r
+\r
+\r
+ArmCleanDataCacheEntryByMVA\r
+  mcr     p15, 0, r0, c7, c10, 1  ; clean single data cache line     \r
+  bx      lr\r
+\r
+\r
+ArmCleanInvalidateDataCacheEntryByMVA\r
+  mcr     p15, 0, r0, c7, c14, 1  ; clean and invalidate single data cache line\r
+  bx      lr\r
+\r
+\r
+ArmCleanDataCache\r
+  mcr     p15, 0, r0, c7, c10, 0  ; clean entire data cache\r
+  bx      lr\r
+\r
+\r
+ArmCleanInvalidateDataCache\r
+  mcr     p15, 0, r0, c7, c14, 0  ; clean and invalidate entire data cache\r
+  bx      lr\r
+\r
+\r
+ArmInvalidateDataCache\r
+  mcr     p15, 0, r0, c7, c6, 0  ; invalidate entire data cache\r
+  bx      lr\r
+\r
+\r
+ArmInvalidateInstructionCache\r
+  mcr     p15, 0, r0, c7, c5, 0  ;invalidate entire instruction cache\r
+  mov     R0,#0\r
+  mcr     p15,0,R0,c7,c5,4       ;Flush Prefetch buffer\r
+  bx      lr\r
+\r
+ArmEnableMmu\r
+  mrc     p15,0,R0,c1,c0,0\r
+  orr     R0,R0,#1\r
+  mcr     p15,0,R0,c1,c0,0\r
+  bx      LR\r
+\r
+ArmMmuEnabled\r
+  mrc     p15,0,R0,c1,c0,0\r
+  and     R0,R0,#1\r
+  bx      LR\r
+\r
+ArmDisableMmu\r
+  mrc     p15,0,R0,c1,c0,0\r
+  bic     R0,R0,#1\r
+  mcr     p15,0,R0,c1,c0,0\r
+  mov     R0,#0\r
+  mcr     p15,0,R0,c7,c10,4     ;Data synchronization barrier\r
+  mov     R0,#0\r
+  mcr     p15,0,R0,c7,c5,4      ;Flush Prefetch buffer\r
+  bx      LR\r
+\r
+ArmEnableDataCache\r
+  LDR     R1,=DC_ON\r
+  MRC     p15,0,R0,c1,c0,0      ;Read control register configuration data\r
+  ORR     R0,R0,R1              ;Set C bit\r
+  MCR     p15,0,r0,c1,c0,0      ;Write control register configuration data\r
+  BX      LR\r
+    \r
+ArmDisableDataCache\r
+  LDR     R1,=DC_ON\r
+  MRC     p15,0,R0,c1,c0,0      ;Read control register configuration data\r
+  BIC     R0,R0,R1              ;Clear C bit\r
+  MCR     p15,0,r0,c1,c0,0      ;Write control register configuration data\r
+  BX      LR\r
+\r
+ArmEnableInstructionCache\r
+  LDR     R1,=IC_ON\r
+  MRC     p15,0,R0,c1,c0,0     ;Read control register configuration data\r
+  ORR     R0,R0,R1             ;Set I bit\r
+  MCR     p15,0,r0,c1,c0,0     ;Write control register configuration data\r
+  BX      LR\r
+  \r
+ArmDisableInstructionCache\r
+  LDR     R1,=IC_ON\r
+  MRC     p15,0,R0,c1,c0,0     ;Read control register configuration data\r
+  BIC     R0,R0,R1             ;Clear I bit.\r
+  MCR     p15,0,r0,c1,c0,0     ;Write control register configuration data\r
+  BX      LR\r
+\r
+ArmEnableBranchPrediction\r
+  mrc     p15, 0, r0, c1, c0, 0\r
+  orr     r0, r0, #0x00000800\r
+  mcr     p15, 0, r0, c1, c0, 0\r
+  bx      LR\r
+\r
+ArmDisableBranchPrediction\r
+  mrc     p15, 0, r0, c1, c0, 0\r
+  bic     r0, r0, #0x00000800\r
+  mcr     p15, 0, r0, c1, c0, 0\r
+  bx      LR\r
+\r
+ASM_PFX(ArmDataMemoryBarrier):\r
+  mov R0, #0\r
+  mcr P15, #0, R0, C7, C10, #5 \r
+  bx      LR\r
+  \r
+ASM_PFX(ArmDataSyncronizationBarrier):\r
+  mov R0, #0\r
+  mcr P15, #0, R0, C7, C10, #4 \r
+  bx      LR\r
+  \r
+ASM_PFX(ArmInstructionSynchronizationBarrier):\r
+  MOV R0, #0\r
+  MCR P15, #0, R0, C7, C5, #4 \r
+  bx      LR\r
+\r
+    END\r
index 7c3a384a976c6c204c9b4c094bee7a9ee9351c86..c92f9159c66d42cd3a3f89c3b755fa87ce6a4ae3 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <Chipset/ARM926EJ-S.h>
-#include <Library/ArmLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/DebugLib.h>
-
-VOID
-FillTranslationTable (
-  IN  UINT32                        *TranslationTable,
-  IN  ARM_MEMORY_REGION_DESCRIPTOR  *MemoryRegion
-  )
-{
-  UINT32  *Entry;
-  UINTN   Sections;
-  UINTN   Index;
-  UINT32  Attributes;
-  UINT32  PhysicalBase = MemoryRegion->PhysicalBase;
-  
-  switch (MemoryRegion->Attributes) {
-    case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK:
-      Attributes = TT_DESCRIPTOR_SECTION_WRITE_BACK;
-      break;
-    case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_THROUGH:
-      Attributes = TT_DESCRIPTOR_SECTION_WRITE_THROUGH;
-      break;
-    case ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED:
-      Attributes = TT_DESCRIPTOR_SECTION_UNCACHED_UNBUFFERED;
-      break;
-    case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK:
-    case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_THROUGH:
-    case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_UNCACHED_UNBUFFERED:
-      ASSERT(0); // Trustzone is not supported on ARMv5
-    default:
-      Attributes = TT_DESCRIPTOR_SECTION_UNCACHED_UNBUFFERED;
-      break;
-  }
-  
-  Entry    = TRANSLATION_TABLE_ENTRY_FOR_VIRTUAL_ADDRESS(TranslationTable, MemoryRegion->VirtualBase);
-  Sections = MemoryRegion->Length / TT_DESCRIPTOR_SECTION_SIZE;
-  
-  // The current code does not support memory region size that is not aligned on TT_DESCRIPTOR_SECTION_SIZE boundary
-  ASSERT (MemoryRegion->Length % TT_DESCRIPTOR_SECTION_SIZE == 0);
-  
-  for (Index = 0; Index < Sections; Index++)
-  {
-    *Entry++     =  TT_DESCRIPTOR_SECTION_BASE_ADDRESS(PhysicalBase) | Attributes;
-    PhysicalBase += TT_DESCRIPTOR_SECTION_SIZE;
-  }
-}
-
-VOID
-EFIAPI
-ArmConfigureMmu (
-  IN  ARM_MEMORY_REGION_DESCRIPTOR  *MemoryTable,
-  OUT VOID                          **TranslationTableBase OPTIONAL,
-  OUT UINTN                         *TranslationTableSize  OPTIONAL
-  )
-{
-  VOID  *TranslationTable;
-
-  // Allocate pages for translation table.
-  TranslationTable = AllocatePages(EFI_SIZE_TO_PAGES(TRANSLATION_TABLE_SIZE + TRANSLATION_TABLE_ALIGNMENT));
-  TranslationTable = (VOID *)(((UINTN)TranslationTable + TRANSLATION_TABLE_ALIGNMENT_MASK) & ~TRANSLATION_TABLE_ALIGNMENT_MASK);
-
-  if (TranslationTableBase != NULL) {
-    *TranslationTableBase = TranslationTable;
-  }
-  
-  if (TranslationTableBase != NULL) {
-    *TranslationTableSize = TRANSLATION_TABLE_SIZE;
-  }
-
-  ZeroMem(TranslationTable, TRANSLATION_TABLE_SIZE);
-
-  ArmCleanInvalidateDataCache();
-  ArmInvalidateInstructionCache();
-  ArmInvalidateTlb();
-
-  ArmDisableDataCache();
-  ArmDisableInstructionCache();
-  ArmDisableMmu();
-
-  // Make sure nothing sneaked into the cache
-  ArmCleanInvalidateDataCache();
-  ArmInvalidateInstructionCache();
-
-  while (MemoryTable->Length != 0) {
-    FillTranslationTable(TranslationTable, MemoryTable);
-    MemoryTable++;
-  }
-
-  ArmSetTTBR0(TranslationTable);
-    
-  ArmSetDomainAccessControl(DOMAIN_ACCESS_CONTROL_NONE(15) |
-                            DOMAIN_ACCESS_CONTROL_NONE(14) |
-                            DOMAIN_ACCESS_CONTROL_NONE(13) |
-                            DOMAIN_ACCESS_CONTROL_NONE(12) |
-                            DOMAIN_ACCESS_CONTROL_NONE(11) |
-                            DOMAIN_ACCESS_CONTROL_NONE(10) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 9) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 8) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 7) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 6) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 5) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 4) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 3) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 2) |
-                            DOMAIN_ACCESS_CONTROL_NONE( 1) |
-                            DOMAIN_ACCESS_CONTROL_MANAGER(0));
-    
-  ArmEnableInstructionCache();
-  ArmEnableDataCache();
-  ArmEnableMmu();
-}
-
-
-
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Chipset/ARM926EJ-S.h>\r
+#include <Library/ArmLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+VOID\r
+FillTranslationTable (\r
+  IN  UINT32                        *TranslationTable,\r
+  IN  ARM_MEMORY_REGION_DESCRIPTOR  *MemoryRegion\r
+  )\r
+{\r
+  UINT32  *Entry;\r
+  UINTN   Sections;\r
+  UINTN   Index;\r
+  UINT32  Attributes;\r
+  UINT32  PhysicalBase = MemoryRegion->PhysicalBase;\r
+  \r
+  switch (MemoryRegion->Attributes) {\r
+    case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK:\r
+      Attributes = TT_DESCRIPTOR_SECTION_WRITE_BACK;\r
+      break;\r
+    case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_THROUGH:\r
+      Attributes = TT_DESCRIPTOR_SECTION_WRITE_THROUGH;\r
+      break;\r
+    case ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED:\r
+      Attributes = TT_DESCRIPTOR_SECTION_UNCACHED_UNBUFFERED;\r
+      break;\r
+    case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK:\r
+    case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_THROUGH:\r
+    case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_UNCACHED_UNBUFFERED:\r
+      ASSERT(0); // Trustzone is not supported on ARMv5\r
+    default:\r
+      Attributes = TT_DESCRIPTOR_SECTION_UNCACHED_UNBUFFERED;\r
+      break;\r
+  }\r
+  \r
+  Entry    = TRANSLATION_TABLE_ENTRY_FOR_VIRTUAL_ADDRESS(TranslationTable, MemoryRegion->VirtualBase);\r
+  Sections = MemoryRegion->Length / TT_DESCRIPTOR_SECTION_SIZE;\r
+  \r
+  // The current code does not support memory region size that is not aligned on TT_DESCRIPTOR_SECTION_SIZE boundary\r
+  ASSERT (MemoryRegion->Length % TT_DESCRIPTOR_SECTION_SIZE == 0);\r
+  \r
+  for (Index = 0; Index < Sections; Index++)\r
+  {\r
+    *Entry++     =  TT_DESCRIPTOR_SECTION_BASE_ADDRESS(PhysicalBase) | Attributes;\r
+    PhysicalBase += TT_DESCRIPTOR_SECTION_SIZE;\r
+  }\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmConfigureMmu (\r
+  IN  ARM_MEMORY_REGION_DESCRIPTOR  *MemoryTable,\r
+  OUT VOID                          **TranslationTableBase OPTIONAL,\r
+  OUT UINTN                         *TranslationTableSize  OPTIONAL\r
+  )\r
+{\r
+  VOID  *TranslationTable;\r
+\r
+  // Allocate pages for translation table.\r
+  TranslationTable = AllocatePages(EFI_SIZE_TO_PAGES(TRANSLATION_TABLE_SIZE + TRANSLATION_TABLE_ALIGNMENT));\r
+  TranslationTable = (VOID *)(((UINTN)TranslationTable + TRANSLATION_TABLE_ALIGNMENT_MASK) & ~TRANSLATION_TABLE_ALIGNMENT_MASK);\r
+\r
+  if (TranslationTableBase != NULL) {\r
+    *TranslationTableBase = TranslationTable;\r
+  }\r
+  \r
+  if (TranslationTableBase != NULL) {\r
+    *TranslationTableSize = TRANSLATION_TABLE_SIZE;\r
+  }\r
+\r
+  ZeroMem(TranslationTable, TRANSLATION_TABLE_SIZE);\r
+\r
+  ArmCleanInvalidateDataCache();\r
+  ArmInvalidateInstructionCache();\r
+  ArmInvalidateTlb();\r
+\r
+  ArmDisableDataCache();\r
+  ArmDisableInstructionCache();\r
+  ArmDisableMmu();\r
+\r
+  // Make sure nothing sneaked into the cache\r
+  ArmCleanInvalidateDataCache();\r
+  ArmInvalidateInstructionCache();\r
+\r
+  while (MemoryTable->Length != 0) {\r
+    FillTranslationTable(TranslationTable, MemoryTable);\r
+    MemoryTable++;\r
+  }\r
+\r
+  ArmSetTTBR0(TranslationTable);\r
+    \r
+  ArmSetDomainAccessControl(DOMAIN_ACCESS_CONTROL_NONE(15) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE(14) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE(13) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE(12) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE(11) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE(10) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 9) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 8) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 7) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 6) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 5) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 4) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 3) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 2) |\r
+                            DOMAIN_ACCESS_CONTROL_NONE( 1) |\r
+                            DOMAIN_ACCESS_CONTROL_MANAGER(0));\r
+    \r
+  ArmEnableInstructionCache();\r
+  ArmEnableDataCache();\r
+  ArmEnableMmu();\r
+}\r
+\r
+\r
+\r
index 49e266dd38bdc012590f9e0c9945fae253dbba3c..28cc5b6e6c33e03ca6011f30921985c642a8c050 100644 (file)
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-.text
-.align 2
-GCC_ASM_EXPORT(ArmCleanInvalidateDataCache)
-GCC_ASM_EXPORT(ArmCleanDataCache)
-GCC_ASM_EXPORT(ArmInvalidateDataCache)
-GCC_ASM_EXPORT(ArmInvalidateInstructionCache)
-GCC_ASM_EXPORT(ArmInvalidateDataCacheEntryByMVA)
-GCC_ASM_EXPORT(ArmCleanDataCacheEntryByMVA)
-GCC_ASM_EXPORT(ArmCleanInvalidateDataCacheEntryByMVA)
-GCC_ASM_EXPORT(ArmEnableMmu)
-GCC_ASM_EXPORT(ArmDisableMmu)
-GCC_ASM_EXPORT(ArmMmuEnabled)
-GCC_ASM_EXPORT(ArmEnableDataCache)
-GCC_ASM_EXPORT(ArmDisableDataCache)
-GCC_ASM_EXPORT(ArmEnableInstructionCache)
-GCC_ASM_EXPORT(ArmDisableInstructionCache)
-GCC_ASM_EXPORT(ArmEnableBranchPrediction)
-GCC_ASM_EXPORT(ArmDisableBranchPrediction)
-GCC_ASM_EXPORT(ArmDataMemoryBarrier)
-GCC_ASM_EXPORT(ArmDataSyncronizationBarrier)
-GCC_ASM_EXPORT(ArmInstructionSynchronizationBarrier)
-
-
-.set DC_ON, (1<<2)
-.set IC_ON, (1<<12)
-
-#------------------------------------------------------------------------------
-
-ASM_PFX(ArmInvalidateDataCacheEntryByMVA):
-  mcr     p15, 0, r0, c7, c6, 1   @ invalidate single data cache line                                           
-  bx      lr
-
-ASM_PFX(ArmCleanDataCacheEntryByMVA):
-  mcr     p15, 0, r0, c7, c10, 1  @ clean single data cache line     
-  bx      lr
-
-ASM_PFX(ArmCleanInvalidateDataCacheEntryByMVA):
-  mcr     p15, 0, r0, c7, c14, 1  @ clean and invalidate single data cache line
-  bx      lr
-
-ASM_PFX(ArmEnableInstructionCache):
-  ldr    r1,=IC_ON
-  mrc    p15,0,r0,c1,c0,0     @Read control register configuration data
-  orr    r0,r0,r1             @Set I bit
-  mcr    p15,0,r0,c1,c0,0     @Write control register configuration data
-  bx     LR
-  
-ASM_PFX(ArmDisableInstructionCache):
-  ldr    r1,=IC_ON
-  mrc    p15,0,r0,c1,c0,0     @Read control register configuration data
-  bic    r0,r0,r1             @Clear I bit.
-  mcr    p15,0,r0,c1,c0,0     @Write control register configuration data
-  bx     LR
-  
-ASM_PFX(ArmInvalidateInstructionCache):
-  mov     r0,#0
-  mcr     p15,0,r0,c7,c5,0     @Invalidate entire Instruction cache. 
-                         @Also flushes the branch target cache.
-  mov     r0,#0
-  mcr     p15,0,r0,c7,c10,4    @Data write buffer
-  bx      LR
-
-ASM_PFX(ArmEnableMmu):
-  mrc     p15,0,R0,c1,c0,0
-  orr     R0,R0,#1
-  mcr     p15,0,R0,c1,c0,0
-  bx      LR
-
-ASM_PFX(ArmMmuEnabled):
-  mrc     p15,0,R0,c1,c0,0
-  and     R0,R0,#1
-  bx      LR
-
-ASM_PFX(ArmDisableMmu):
-  mrc     p15,0,R0,c1,c0,0
-  bic     R0,R0,#1
-  mcr     p15,0,R0,c1,c0,0
-  mov     R0,#0
-  mcr     p15,0,R0,c7,c10,4     @Drain write buffer
-  bx      LR
-
-ASM_PFX(ArmEnableDataCache):
-  ldr     R1,=DC_ON
-  mrc     p15,0,R0,c1,c0,0      @Read control register configuration data
-  orr     R0,R0,R1              @Set C bit
-  mcr     p15,0,r0,c1,c0,0      @Write control register configuration data
-  bx      LR
-  
-ASM_PFX(ArmDisableDataCache):
-  ldr     R1,=DC_ON
-  mrc     p15,0,R0,c1,c0,0      @Read control register configuration data
-  bic     R0,R0,R1              @Clear C bit
-  mcr     p15,0,r0,c1,c0,0      @Write control register configuration data
-  bx      LR
-
-ASM_PFX(ArmCleanDataCache):
-  mrc     p15,0,r15,c7,c10,3
-  bne     ASM_PFX(ArmCleanDataCache)
-  mov     R0,#0
-  mcr     p15,0,R0,c7,c10,4  @Drain write buffer
-  bx      LR
-    
-ASM_PFX(ArmInvalidateDataCache):
-  mov     R0,#0
-  mcr     p15,0,R0,c7,c6,0        @Invalidate entire data cache
-  mov     R0,#0
-  mcr     p15,0,R0,c7,c10,4       @Drain write buffer
-  bx      LR
-
-ASM_PFX(ArmCleanInvalidateDataCache):
-  mrc     p15,0,r15,c7,c14,3
-  bne     ASM_PFX(ArmCleanInvalidateDataCache)
-  mov     R0,#0
-  mcr     p15,0,R0,c7,c10,4        @Drain write buffer
-  bx      LR
-
-ASM_PFX(ArmEnableBranchPrediction):
-  bx      LR                      @Branch prediction is not supported.
-
-ASM_PFX(ArmDisableBranchPrediction):
-  bx      LR                      @Branch prediction is not supported.
-
-ASM_PFX(ArmDataMemoryBarrier):
-  mov R0, #0
-  mcr P15, #0, R0, C7, C10, #5    @ check if this is OK?
-  bx      LR
-  
-ASM_PFX(ArmDataSyncronizationBarrier):
-  mov R0, #0
-  mcr P15, #0, R0, C7, C10, #4   @ check if this is OK?
-  bx      LR
-  
-ASM_PFX(ArmInstructionSynchronizationBarrier):
-  mov R0, #0
-  mcr P15, #0, R0, C7, C5, #4     @ check if this is OK?
-  bx      LR
-
-ASM_FUNCTION_REMOVE_IF_UNREFERENCED
-
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+.text\r
+.align 2\r
+GCC_ASM_EXPORT(ArmCleanInvalidateDataCache)\r
+GCC_ASM_EXPORT(ArmCleanDataCache)\r
+GCC_ASM_EXPORT(ArmInvalidateDataCache)\r
+GCC_ASM_EXPORT(ArmInvalidateInstructionCache)\r
+GCC_ASM_EXPORT(ArmInvalidateDataCacheEntryByMVA)\r
+GCC_ASM_EXPORT(ArmCleanDataCacheEntryByMVA)\r
+GCC_ASM_EXPORT(ArmCleanInvalidateDataCacheEntryByMVA)\r
+GCC_ASM_EXPORT(ArmEnableMmu)\r
+GCC_ASM_EXPORT(ArmDisableMmu)\r
+GCC_ASM_EXPORT(ArmMmuEnabled)\r
+GCC_ASM_EXPORT(ArmEnableDataCache)\r
+GCC_ASM_EXPORT(ArmDisableDataCache)\r
+GCC_ASM_EXPORT(ArmEnableInstructionCache)\r
+GCC_ASM_EXPORT(ArmDisableInstructionCache)\r
+GCC_ASM_EXPORT(ArmEnableBranchPrediction)\r
+GCC_ASM_EXPORT(ArmDisableBranchPrediction)\r
+GCC_ASM_EXPORT(ArmDataMemoryBarrier)\r
+GCC_ASM_EXPORT(ArmDataSyncronizationBarrier)\r
+GCC_ASM_EXPORT(ArmInstructionSynchronizationBarrier)\r
+\r
+\r
+.set DC_ON, (1<<2)\r
+.set IC_ON, (1<<12)\r
+\r
+#------------------------------------------------------------------------------\r
+\r
+ASM_PFX(ArmInvalidateDataCacheEntryByMVA):\r
+  mcr     p15, 0, r0, c7, c6, 1   @ invalidate single data cache line                                           \r
+  bx      lr\r
+\r
+ASM_PFX(ArmCleanDataCacheEntryByMVA):\r
+  mcr     p15, 0, r0, c7, c10, 1  @ clean single data cache line     \r
+  bx      lr\r
+\r
+ASM_PFX(ArmCleanInvalidateDataCacheEntryByMVA):\r
+  mcr     p15, 0, r0, c7, c14, 1  @ clean and invalidate single data cache line\r
+  bx      lr\r
+\r
+ASM_PFX(ArmEnableInstructionCache):\r
+  ldr    r1,=IC_ON\r
+  mrc    p15,0,r0,c1,c0,0     @Read control register configuration data\r
+  orr    r0,r0,r1             @Set I bit\r
+  mcr    p15,0,r0,c1,c0,0     @Write control register configuration data\r
+  bx     LR\r
+  \r
+ASM_PFX(ArmDisableInstructionCache):\r
+  ldr    r1,=IC_ON\r
+  mrc    p15,0,r0,c1,c0,0     @Read control register configuration data\r
+  bic    r0,r0,r1             @Clear I bit.\r
+  mcr    p15,0,r0,c1,c0,0     @Write control register configuration data\r
+  bx     LR\r
+  \r
+ASM_PFX(ArmInvalidateInstructionCache):\r
+  mov     r0,#0\r
+  mcr     p15,0,r0,c7,c5,0     @Invalidate entire Instruction cache. \r
+                         @Also flushes the branch target cache.\r
+  mov     r0,#0\r
+  mcr     p15,0,r0,c7,c10,4    @Data write buffer\r
+  bx      LR\r
+\r
+ASM_PFX(ArmEnableMmu):\r
+  mrc     p15,0,R0,c1,c0,0\r
+  orr     R0,R0,#1\r
+  mcr     p15,0,R0,c1,c0,0\r
+  bx      LR\r
+\r
+ASM_PFX(ArmMmuEnabled):\r
+  mrc     p15,0,R0,c1,c0,0\r
+  and     R0,R0,#1\r
+  bx      LR\r
+\r
+ASM_PFX(ArmDisableMmu):\r
+  mrc     p15,0,R0,c1,c0,0\r
+  bic     R0,R0,#1\r
+  mcr     p15,0,R0,c1,c0,0\r
+  mov     R0,#0\r
+  mcr     p15,0,R0,c7,c10,4     @Drain write buffer\r
+  bx      LR\r
+\r
+ASM_PFX(ArmEnableDataCache):\r
+  ldr     R1,=DC_ON\r
+  mrc     p15,0,R0,c1,c0,0      @Read control register configuration data\r
+  orr     R0,R0,R1              @Set C bit\r
+  mcr     p15,0,r0,c1,c0,0      @Write control register configuration data\r
+  bx      LR\r
+  \r
+ASM_PFX(ArmDisableDataCache):\r
+  ldr     R1,=DC_ON\r
+  mrc     p15,0,R0,c1,c0,0      @Read control register configuration data\r
+  bic     R0,R0,R1              @Clear C bit\r
+  mcr     p15,0,r0,c1,c0,0      @Write control register configuration data\r
+  bx      LR\r
+\r
+ASM_PFX(ArmCleanDataCache):\r
+  mrc     p15,0,r15,c7,c10,3\r
+  bne     ASM_PFX(ArmCleanDataCache)\r
+  mov     R0,#0\r
+  mcr     p15,0,R0,c7,c10,4  @Drain write buffer\r
+  bx      LR\r
+    \r
+ASM_PFX(ArmInvalidateDataCache):\r
+  mov     R0,#0\r
+  mcr     p15,0,R0,c7,c6,0        @Invalidate entire data cache\r
+  mov     R0,#0\r
+  mcr     p15,0,R0,c7,c10,4       @Drain write buffer\r
+  bx      LR\r
+\r
+ASM_PFX(ArmCleanInvalidateDataCache):\r
+  mrc     p15,0,r15,c7,c14,3\r
+  bne     ASM_PFX(ArmCleanInvalidateDataCache)\r
+  mov     R0,#0\r
+  mcr     p15,0,R0,c7,c10,4        @Drain write buffer\r
+  bx      LR\r
+\r
+ASM_PFX(ArmEnableBranchPrediction):\r
+  bx      LR                      @Branch prediction is not supported.\r
+\r
+ASM_PFX(ArmDisableBranchPrediction):\r
+  bx      LR                      @Branch prediction is not supported.\r
+\r
+ASM_PFX(ArmDataMemoryBarrier):\r
+  mov R0, #0\r
+  mcr P15, #0, R0, C7, C10, #5    @ check if this is OK?\r
+  bx      LR\r
+  \r
+ASM_PFX(ArmDataSyncronizationBarrier):\r
+  mov R0, #0\r
+  mcr P15, #0, R0, C7, C10, #4   @ check if this is OK?\r
+  bx      LR\r
+  \r
+ASM_PFX(ArmInstructionSynchronizationBarrier):\r
+  mov R0, #0\r
+  mcr P15, #0, R0, C7, C5, #4     @ check if this is OK?\r
+  bx      LR\r
+\r
+ASM_FUNCTION_REMOVE_IF_UNREFERENCED\r
+\r
index dfee136b2baf04f3b87d355d04656e8ea9746202..fc87828e202789ba0dff12676394903f25bc7ce7 100644 (file)
-//------------------------------------------------------------------------------ 
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-    EXPORT  ArmCleanInvalidateDataCache
-    EXPORT  ArmCleanDataCache
-    EXPORT  ArmInvalidateDataCache
-    EXPORT  ArmInvalidateInstructionCache
-    EXPORT  ArmInvalidateDataCacheEntryByMVA
-    EXPORT  ArmCleanDataCacheEntryByMVA
-    EXPORT  ArmCleanInvalidateDataCacheEntryByMVA
-    EXPORT  ArmEnableMmu
-    EXPORT  ArmDisableMmu
-    EXPORT  ArmMmuEnabled
-    EXPORT  ArmEnableDataCache
-    EXPORT  ArmDisableDataCache
-    EXPORT  ArmEnableInstructionCache
-    EXPORT  ArmDisableInstructionCache
-    EXPORT  ArmEnableBranchPrediction
-    EXPORT  ArmDisableBranchPrediction
-    EXPORT  ArmDataMemoryBarrier
-    EXPORT  ArmDataSyncronizationBarrier
-    EXPORT  ArmInstructionSynchronizationBarrier
-
-
-DC_ON       EQU     ( 0x1:SHL:2 )
-IC_ON       EQU     ( 0x1:SHL:12 )
-
-    AREA    ArmCacheLib, CODE, READONLY
-    PRESERVE8
-
-
-ArmInvalidateDataCacheEntryByMVA
-  MCR     p15, 0, r0, c7, c6, 1   ; invalidate single data cache line                                           
-  BX      lr
-
-
-ArmCleanDataCacheEntryByMVA
-  MCR     p15, 0, r0, c7, c10, 1  ; clean single data cache line     
-  BX      lr
-
-
-ArmCleanInvalidateDataCacheEntryByMVA
-  MCR     p15, 0, r0, c7, c14, 1  ; clean and invalidate single data cache line
-  BX      lr
-
-ArmEnableInstructionCache
-  LDR     R1,=IC_ON
-  MRC     p15,0,R0,c1,c0,0     ;Read control register configuration data
-  ORR     R0,R0,R1             ;Set I bit
-  MCR     p15,0,r0,c1,c0,0     ;Write control register configuration data
-  BX      LR
-  
-ArmDisableInstructionCache
-  LDR     R1,=IC_ON
-  MRC     p15,0,R0,c1,c0,0     ;Read control register configuration data
-  BIC     R0,R0,R1             ;Clear I bit.
-  MCR     p15,0,r0,c1,c0,0     ;Write control register configuration data
-  BX      LR
-
-ArmInvalidateInstructionCache
-  MOV     R0,#0
-  MCR     p15,0,R0,c7,c5,0      ;Invalidate entire instruction cache
-  MOV     R0,#0
-  MCR     p15,0,R0,c7,c10,4     ;Drain write buffer
-  BX      LR
-
-ArmEnableMmu
-  mrc     p15,0,R0,c1,c0,0
-  orr     R0,R0,#1
-  mcr     p15,0,R0,c1,c0,0
-  bx      LR
-
-ArmMmuEnabled
-  mrc     p15,0,R0,c1,c0,0
-  and     R0,R0,#1
-  bx      LR
-
-ArmDisableMmu
-  mrc     p15,0,R0,c1,c0,0
-  bic     R0,R0,#1
-  mcr     p15,0,R0,c1,c0,0
-  mov     R0,#0
-  mcr     p15,0,R0,c7,c10,4     ;Drain write buffer
-  bx      LR
-
-ArmEnableDataCache
-  LDR     R1,=DC_ON
-  MRC     p15,0,R0,c1,c0,0      ;Read control register configuration data
-  ORR     R0,R0,R1              ;Set C bit
-  MCR     p15,0,r0,c1,c0,0      ;Write control register configuration data
-  BX      LR
-    
-ArmDisableDataCache
-  LDR     R1,=DC_ON
-  MRC     p15,0,R0,c1,c0,0      ;Read control register configuration data
-  BIC     R0,R0,R1              ;Clear C bit
-  MCR     p15,0,r0,c1,c0,0      ;Write control register configuration data
-  BX      LR
-
-ArmCleanDataCache
-  MRC     p15,0,r15,c7,c10,3
-  BNE     ArmCleanDataCache
-  MOV     R0,#0
-  MCR     p15,0,R0,c7,c10,4      ;Drain write buffer
-  BX      LR
-
-ArmInvalidateDataCache
-  MOV     R0,#0
-  MCR     p15,0,R0,c7,c6,0      ;Invalidate entire data cache
-  MOV     R0,#0
-  MCR     p15,0,R0,c7,c10,4     ;Drain write buffer
-  BX      LR
-  
-ArmCleanInvalidateDataCache
-  MRC     p15,0,r15,c7,c14,3
-  BNE     ArmCleanInvalidateDataCache
-  MOV     R0,#0
-  MCR     p15,0,R0,c7,c10,4      ;Drain write buffer
-  BX      LR
-
-ArmEnableBranchPrediction
-  bx      LR                    ;Branch prediction is not supported.
-
-ArmDisableBranchPrediction
-  bx      LR                    ;Branch prediction is not supported.
-
-ASM_PFX(ArmDataMemoryBarrier):
-  mov R0, #0
-  mcr P15, #0, R0, C7, C10, #5  ; Check to see if this is correct
-  bx      LR
-  
-ASM_PFX(ArmDataSyncronizationBarrier):
-  mov R0, #0
-  mcr P15, #0, R0, C7, C10, #4 ; Check to see if this is correct
-  bx      LR
-  
-ASM_PFX(ArmInstructionSynchronizationBarrier):
-  MOV R0, #0
-  MCR P15, #0, R0, C7, C5, #4 ; Check to see if this is correct
-  bx      LR
-
-    END
+//------------------------------------------------------------------------------ \r
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+    EXPORT  ArmCleanInvalidateDataCache\r
+    EXPORT  ArmCleanDataCache\r
+    EXPORT  ArmInvalidateDataCache\r
+    EXPORT  ArmInvalidateInstructionCache\r
+    EXPORT  ArmInvalidateDataCacheEntryByMVA\r
+    EXPORT  ArmCleanDataCacheEntryByMVA\r
+    EXPORT  ArmCleanInvalidateDataCacheEntryByMVA\r
+    EXPORT  ArmEnableMmu\r
+    EXPORT  ArmDisableMmu\r
+    EXPORT  ArmMmuEnabled\r
+    EXPORT  ArmEnableDataCache\r
+    EXPORT  ArmDisableDataCache\r
+    EXPORT  ArmEnableInstructionCache\r
+    EXPORT  ArmDisableInstructionCache\r
+    EXPORT  ArmEnableBranchPrediction\r
+    EXPORT  ArmDisableBranchPrediction\r
+    EXPORT  ArmDataMemoryBarrier\r
+    EXPORT  ArmDataSyncronizationBarrier\r
+    EXPORT  ArmInstructionSynchronizationBarrier\r
+\r
+\r
+DC_ON       EQU     ( 0x1:SHL:2 )\r
+IC_ON       EQU     ( 0x1:SHL:12 )\r
+\r
+    AREA    ArmCacheLib, CODE, READONLY\r
+    PRESERVE8\r
+\r
+\r
+ArmInvalidateDataCacheEntryByMVA\r
+  MCR     p15, 0, r0, c7, c6, 1   ; invalidate single data cache line                                           \r
+  BX      lr\r
+\r
+\r
+ArmCleanDataCacheEntryByMVA\r
+  MCR     p15, 0, r0, c7, c10, 1  ; clean single data cache line     \r
+  BX      lr\r
+\r
+\r
+ArmCleanInvalidateDataCacheEntryByMVA\r
+  MCR     p15, 0, r0, c7, c14, 1  ; clean and invalidate single data cache line\r
+  BX      lr\r
+\r
+ArmEnableInstructionCache\r
+  LDR     R1,=IC_ON\r
+  MRC     p15,0,R0,c1,c0,0     ;Read control register configuration data\r
+  ORR     R0,R0,R1             ;Set I bit\r
+  MCR     p15,0,r0,c1,c0,0     ;Write control register configuration data\r
+  BX      LR\r
+  \r
+ArmDisableInstructionCache\r
+  LDR     R1,=IC_ON\r
+  MRC     p15,0,R0,c1,c0,0     ;Read control register configuration data\r
+  BIC     R0,R0,R1             ;Clear I bit.\r
+  MCR     p15,0,r0,c1,c0,0     ;Write control register configuration data\r
+  BX      LR\r
+\r
+ArmInvalidateInstructionCache\r
+  MOV     R0,#0\r
+  MCR     p15,0,R0,c7,c5,0      ;Invalidate entire instruction cache\r
+  MOV     R0,#0\r
+  MCR     p15,0,R0,c7,c10,4     ;Drain write buffer\r
+  BX      LR\r
+\r
+ArmEnableMmu\r
+  mrc     p15,0,R0,c1,c0,0\r
+  orr     R0,R0,#1\r
+  mcr     p15,0,R0,c1,c0,0\r
+  bx      LR\r
+\r
+ArmMmuEnabled\r
+  mrc     p15,0,R0,c1,c0,0\r
+  and     R0,R0,#1\r
+  bx      LR\r
+\r
+ArmDisableMmu\r
+  mrc     p15,0,R0,c1,c0,0\r
+  bic     R0,R0,#1\r
+  mcr     p15,0,R0,c1,c0,0\r
+  mov     R0,#0\r
+  mcr     p15,0,R0,c7,c10,4     ;Drain write buffer\r
+  bx      LR\r
+\r
+ArmEnableDataCache\r
+  LDR     R1,=DC_ON\r
+  MRC     p15,0,R0,c1,c0,0      ;Read control register configuration data\r
+  ORR     R0,R0,R1              ;Set C bit\r
+  MCR     p15,0,r0,c1,c0,0      ;Write control register configuration data\r
+  BX      LR\r
+    \r
+ArmDisableDataCache\r
+  LDR     R1,=DC_ON\r
+  MRC     p15,0,R0,c1,c0,0      ;Read control register configuration data\r
+  BIC     R0,R0,R1              ;Clear C bit\r
+  MCR     p15,0,r0,c1,c0,0      ;Write control register configuration data\r
+  BX      LR\r
+\r
+ArmCleanDataCache\r
+  MRC     p15,0,r15,c7,c10,3\r
+  BNE     ArmCleanDataCache\r
+  MOV     R0,#0\r
+  MCR     p15,0,R0,c7,c10,4      ;Drain write buffer\r
+  BX      LR\r
+\r
+ArmInvalidateDataCache\r
+  MOV     R0,#0\r
+  MCR     p15,0,R0,c7,c6,0      ;Invalidate entire data cache\r
+  MOV     R0,#0\r
+  MCR     p15,0,R0,c7,c10,4     ;Drain write buffer\r
+  BX      LR\r
+  \r
+ArmCleanInvalidateDataCache\r
+  MRC     p15,0,r15,c7,c14,3\r
+  BNE     ArmCleanInvalidateDataCache\r
+  MOV     R0,#0\r
+  MCR     p15,0,R0,c7,c10,4      ;Drain write buffer\r
+  BX      LR\r
+\r
+ArmEnableBranchPrediction\r
+  bx      LR                    ;Branch prediction is not supported.\r
+\r
+ArmDisableBranchPrediction\r
+  bx      LR                    ;Branch prediction is not supported.\r
+\r
+ASM_PFX(ArmDataMemoryBarrier):\r
+  mov R0, #0\r
+  mcr P15, #0, R0, C7, C10, #5  ; Check to see if this is correct\r
+  bx      LR\r
+  \r
+ASM_PFX(ArmDataSyncronizationBarrier):\r
+  mov R0, #0\r
+  mcr P15, #0, R0, C7, C10, #4 ; Check to see if this is correct\r
+  bx      LR\r
+  \r
+ASM_PFX(ArmInstructionSynchronizationBarrier):\r
+  MOV R0, #0\r
+  MCR P15, #0, R0, C7, C5, #4 ; Check to see if this is correct\r
+  bx      LR\r
+\r
+    END\r
index 7835b414c027a9f60f0f64613cdd647fcbfab29e..478a5da6952c2f5b6a7ef231d82d7be64eaae987 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011, ARM Limited. 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 <Uefi.h> 
-#include <Chipset/ArmV7.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/ArmLib.h>
-#include <Library/BaseLib.h>
-#include <Library/DebugLib.h>
-#include "ArmV7Lib.h"
-#include "ArmLibPrivate.h"
-#include <Library/ArmV7ArchTimerLib.h>
-
-VOID
-EFIAPI
-ArmArchTimerReadReg (
-    IN   ARM_ARCH_TIMER_REGS   Reg,
-    OUT  VOID                  *DstBuf
-    )
-{
-  // Check if the Generic/Architecture timer is implemented
-  if (ArmIsArchTimerImplemented ()) {
-
-    switch (Reg) {
-
-    case CntFrq:
-      *((UINTN *)DstBuf) = ArmReadCntFrq ();
-      break;
-
-    case CntPct:
-      *((UINT64 *)DstBuf) = ArmReadCntPct ();
-      break;
-
-    case CntkCtl:
-      *((UINTN *)DstBuf) = ArmReadCntkCtl();
-      break;
-
-    case CntpTval:
-      *((UINTN *)DstBuf) = ArmReadCntpTval ();
-      break;
-
-    case CntpCtl:
-      *((UINTN *)DstBuf) = ArmReadCntpCtl ();
-      break;
-
-    case CntvTval:
-      *((UINTN *)DstBuf) = ArmReadCntvTval ();
-      break;
-
-    case CntvCtl:
-      *((UINTN *)DstBuf) = ArmReadCntvCtl ();
-      break;
-
-    case CntvCt:
-      *((UINT64 *)DstBuf) = ArmReadCntvCt ();
-      break;
-
-    case CntpCval:
-      *((UINT64 *)DstBuf) = ArmReadCntpCval ();
-      break;
-
-    case CntvCval:
-      *((UINT64 *)DstBuf) = ArmReadCntvCval ();
-      break;
-
-    case CntvOff:
-      *((UINT64 *)DstBuf) = ArmReadCntvOff ();
-      break;
-
-    case CnthCtl:
-    case CnthpTval:
-    case CnthpCtl:
-    case CnthpCval:
-    DEBUG ((EFI_D_ERROR, "The register is related to Hypervisor Mode. Can't perform requested operation\n "));
-      break;
-
-    default:
-      DEBUG ((EFI_D_ERROR, "Unknown ARM Generic Timer register %x. \n ", Reg));
-    }
-  } else {
-    DEBUG ((EFI_D_ERROR, "Attempt to read ARM Generic Timer registers. But ARM Generic Timer extension is not implemented \n "));
-    ASSERT (0);
-  }
-}
-
-VOID
-EFIAPI
-ArmArchTimerWriteReg (
-    IN   ARM_ARCH_TIMER_REGS   Reg,
-    IN   VOID                  *SrcBuf
-    )
-{
-  // Check if the Generic/Architecture timer is implemented
-  if (ArmIsArchTimerImplemented ()) {
-
-    switch (Reg) {
-
-    case CntFrq:
-      ArmWriteCntFrq (*((UINTN *)SrcBuf));
-      break;
-
-    case CntPct:
-      DEBUG ((EFI_D_ERROR, "Can't write to Read Only Register: CNTPCT \n"));
-      break;
-
-    case CntkCtl:
-      ArmWriteCntkCtl (*((UINTN *)SrcBuf));
-      break;
-
-    case CntpTval:
-      ArmWriteCntpTval (*((UINTN *)SrcBuf));
-      break;
-
-    case CntpCtl:
-      ArmWriteCntpCtl (*((UINTN *)SrcBuf));
-      break;
-
-    case CntvTval:
-      ArmWriteCntvTval (*((UINTN *)SrcBuf));
-      break;
-
-    case CntvCtl:
-      ArmWriteCntvCtl (*((UINTN *)SrcBuf));
-      break;
-
-    case CntvCt:
-      DEBUG ((EFI_D_ERROR, "Can't write to Read Only Register: CNTVCT \n"));
-      break;
-
-    case CntpCval:
-      ArmWriteCntpCval (*((UINT64 *)SrcBuf) );
-      break;
-
-    case CntvCval:
-      ArmWriteCntvCval (*((UINT64 *)SrcBuf) );
-      break;
-
-    case CntvOff:
-      ArmWriteCntvOff (*((UINT64 *)SrcBuf));
-      break;
-
-    case CnthCtl:
-    case CnthpTval:
-    case CnthpCtl:
-    case CnthpCval:
-      DEBUG ((EFI_D_ERROR, "The register is related to Hypervisor Mode. Can't perform requested operation\n "));
-      break;
-
-    default:
-      DEBUG ((EFI_D_ERROR, "Unknown ARM Generic Timer register %x. \n ", Reg));
-    }
-  } else {
-    DEBUG ((EFI_D_ERROR, "Attempt to write to ARM Generic Timer registers. But ARM Generic Timer extension is not implemented \n "));
-    ASSERT (0);
-  }
-}
-
-VOID
-EFIAPI
-ArmArchTimerEnableTimer (
-    VOID
-    )
-{
-  UINTN TimerCtrlReg;
-
-  ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg);
-  TimerCtrlReg |= ARM_ARCH_TIMER_ENABLE;
-  ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg);
-}
-
-VOID
-EFIAPI
-ArmArchTimerDisableTimer (
-    VOID
-    )
-{
-  UINTN TimerCtrlReg;
-
-  ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg);
-  TimerCtrlReg &= ~ARM_ARCH_TIMER_ENABLE;
-  ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg);
-}
-
-VOID
-EFIAPI
-ArmArchTimerSetTimerFreq (
-    IN   UINTN  FreqInHz
-    )
-{
-  ArmArchTimerWriteReg (CntFrq, (VOID *)&FreqInHz);
-}
-
-UINTN
-EFIAPI
-ArmArchTimerGetTimerFreq (
-    VOID
-    )
-{
-  UINTN ArchTimerFreq = 0;
-  ArmArchTimerReadReg (CntFrq, (VOID *)&ArchTimerFreq);
-  return ArchTimerFreq;
-}
-
-UINTN
-EFIAPI
-ArmArchTimerGetTimerVal (
-    VOID
-    )
-{
-  UINTN ArchTimerVal;
-  ArmArchTimerReadReg (CntpTval, (VOID *)&ArchTimerVal);
-  return ArchTimerVal;
-}
-
-
-VOID
-EFIAPI
-ArmArchTimerSetTimerVal (
-    IN   UINTN   Val
-    )
-{
-  ArmArchTimerWriteReg (CntpTval, (VOID *)&Val);
-}
-
-UINT64
-EFIAPI
-ArmArchTimerGetSystemCount (
-    VOID
-    )
-{
-  UINT64 SystemCount;
-  ArmArchTimerReadReg (CntPct, (VOID *)&SystemCount);
-  return SystemCount;
-}
-
-UINTN
-EFIAPI
-ArmArchTimerGetTimerCtrlReg (
-    VOID
-    )
-{
-  UINTN  Val;
-  ArmArchTimerReadReg (CntpCtl, (VOID *)&Val);
-  return Val;
-}
-
-VOID
-EFIAPI
-ArmArchTimerSetTimerCtrlReg (
-    UINTN Val
-    )
-{
-  ArmArchTimerWriteReg (CntpCtl, (VOID *)&Val);
-}
-
-VOID
-EFIAPI
-ArmArchTimerSetCompareVal (
-    IN   UINT64   Val
-    )
-{
-  ArmArchTimerWriteReg (CntpCval, (VOID *)&Val);
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include <Uefi.h> \r
+#include <Chipset/ArmV7.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/ArmLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include "ArmV7Lib.h"\r
+#include "ArmLibPrivate.h"\r
+#include <Library/ArmV7ArchTimerLib.h>\r
+\r
+VOID\r
+EFIAPI\r
+ArmArchTimerReadReg (\r
+    IN   ARM_ARCH_TIMER_REGS   Reg,\r
+    OUT  VOID                  *DstBuf\r
+    )\r
+{\r
+  // Check if the Generic/Architecture timer is implemented\r
+  if (ArmIsArchTimerImplemented ()) {\r
+\r
+    switch (Reg) {\r
+\r
+    case CntFrq:\r
+      *((UINTN *)DstBuf) = ArmReadCntFrq ();\r
+      break;\r
+\r
+    case CntPct:\r
+      *((UINT64 *)DstBuf) = ArmReadCntPct ();\r
+      break;\r
+\r
+    case CntkCtl:\r
+      *((UINTN *)DstBuf) = ArmReadCntkCtl();\r
+      break;\r
+\r
+    case CntpTval:\r
+      *((UINTN *)DstBuf) = ArmReadCntpTval ();\r
+      break;\r
+\r
+    case CntpCtl:\r
+      *((UINTN *)DstBuf) = ArmReadCntpCtl ();\r
+      break;\r
+\r
+    case CntvTval:\r
+      *((UINTN *)DstBuf) = ArmReadCntvTval ();\r
+      break;\r
+\r
+    case CntvCtl:\r
+      *((UINTN *)DstBuf) = ArmReadCntvCtl ();\r
+      break;\r
+\r
+    case CntvCt:\r
+      *((UINT64 *)DstBuf) = ArmReadCntvCt ();\r
+      break;\r
+\r
+    case CntpCval:\r
+      *((UINT64 *)DstBuf) = ArmReadCntpCval ();\r
+      break;\r
+\r
+    case CntvCval:\r
+      *((UINT64 *)DstBuf) = ArmReadCntvCval ();\r
+      break;\r
+\r
+    case CntvOff:\r
+      *((UINT64 *)DstBuf) = ArmReadCntvOff ();\r
+      break;\r
+\r
+    case CnthCtl:\r
+    case CnthpTval:\r
+    case CnthpCtl:\r
+    case CnthpCval:\r
+    DEBUG ((EFI_D_ERROR, "The register is related to Hypervisor Mode. Can't perform requested operation\n "));\r
+      break;\r
+\r
+    default:\r
+      DEBUG ((EFI_D_ERROR, "Unknown ARM Generic Timer register %x. \n ", Reg));\r
+    }\r
+  } else {\r
+    DEBUG ((EFI_D_ERROR, "Attempt to read ARM Generic Timer registers. But ARM Generic Timer extension is not implemented \n "));\r
+    ASSERT (0);\r
+  }\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmArchTimerWriteReg (\r
+    IN   ARM_ARCH_TIMER_REGS   Reg,\r
+    IN   VOID                  *SrcBuf\r
+    )\r
+{\r
+  // Check if the Generic/Architecture timer is implemented\r
+  if (ArmIsArchTimerImplemented ()) {\r
+\r
+    switch (Reg) {\r
+\r
+    case CntFrq:\r
+      ArmWriteCntFrq (*((UINTN *)SrcBuf));\r
+      break;\r
+\r
+    case CntPct:\r
+      DEBUG ((EFI_D_ERROR, "Can't write to Read Only Register: CNTPCT \n"));\r
+      break;\r
+\r
+    case CntkCtl:\r
+      ArmWriteCntkCtl (*((UINTN *)SrcBuf));\r
+      break;\r
+\r
+    case CntpTval:\r
+      ArmWriteCntpTval (*((UINTN *)SrcBuf));\r
+      break;\r
+\r
+    case CntpCtl:\r
+      ArmWriteCntpCtl (*((UINTN *)SrcBuf));\r
+      break;\r
+\r
+    case CntvTval:\r
+      ArmWriteCntvTval (*((UINTN *)SrcBuf));\r
+      break;\r
+\r
+    case CntvCtl:\r
+      ArmWriteCntvCtl (*((UINTN *)SrcBuf));\r
+      break;\r
+\r
+    case CntvCt:\r
+      DEBUG ((EFI_D_ERROR, "Can't write to Read Only Register: CNTVCT \n"));\r
+      break;\r
+\r
+    case CntpCval:\r
+      ArmWriteCntpCval (*((UINT64 *)SrcBuf) );\r
+      break;\r
+\r
+    case CntvCval:\r
+      ArmWriteCntvCval (*((UINT64 *)SrcBuf) );\r
+      break;\r
+\r
+    case CntvOff:\r
+      ArmWriteCntvOff (*((UINT64 *)SrcBuf));\r
+      break;\r
+\r
+    case CnthCtl:\r
+    case CnthpTval:\r
+    case CnthpCtl:\r
+    case CnthpCval:\r
+      DEBUG ((EFI_D_ERROR, "The register is related to Hypervisor Mode. Can't perform requested operation\n "));\r
+      break;\r
+\r
+    default:\r
+      DEBUG ((EFI_D_ERROR, "Unknown ARM Generic Timer register %x. \n ", Reg));\r
+    }\r
+  } else {\r
+    DEBUG ((EFI_D_ERROR, "Attempt to write to ARM Generic Timer registers. But ARM Generic Timer extension is not implemented \n "));\r
+    ASSERT (0);\r
+  }\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmArchTimerEnableTimer (\r
+    VOID\r
+    )\r
+{\r
+  UINTN TimerCtrlReg;\r
+\r
+  ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg);\r
+  TimerCtrlReg |= ARM_ARCH_TIMER_ENABLE;\r
+  ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg);\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmArchTimerDisableTimer (\r
+    VOID\r
+    )\r
+{\r
+  UINTN TimerCtrlReg;\r
+\r
+  ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg);\r
+  TimerCtrlReg &= ~ARM_ARCH_TIMER_ENABLE;\r
+  ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg);\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmArchTimerSetTimerFreq (\r
+    IN   UINTN  FreqInHz\r
+    )\r
+{\r
+  ArmArchTimerWriteReg (CntFrq, (VOID *)&FreqInHz);\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+ArmArchTimerGetTimerFreq (\r
+    VOID\r
+    )\r
+{\r
+  UINTN ArchTimerFreq = 0;\r
+  ArmArchTimerReadReg (CntFrq, (VOID *)&ArchTimerFreq);\r
+  return ArchTimerFreq;\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+ArmArchTimerGetTimerVal (\r
+    VOID\r
+    )\r
+{\r
+  UINTN ArchTimerVal;\r
+  ArmArchTimerReadReg (CntpTval, (VOID *)&ArchTimerVal);\r
+  return ArchTimerVal;\r
+}\r
+\r
+\r
+VOID\r
+EFIAPI\r
+ArmArchTimerSetTimerVal (\r
+    IN   UINTN   Val\r
+    )\r
+{\r
+  ArmArchTimerWriteReg (CntpTval, (VOID *)&Val);\r
+}\r
+\r
+UINT64\r
+EFIAPI\r
+ArmArchTimerGetSystemCount (\r
+    VOID\r
+    )\r
+{\r
+  UINT64 SystemCount;\r
+  ArmArchTimerReadReg (CntPct, (VOID *)&SystemCount);\r
+  return SystemCount;\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+ArmArchTimerGetTimerCtrlReg (\r
+    VOID\r
+    )\r
+{\r
+  UINTN  Val;\r
+  ArmArchTimerReadReg (CntpCtl, (VOID *)&Val);\r
+  return Val;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmArchTimerSetTimerCtrlReg (\r
+    UINTN Val\r
+    )\r
+{\r
+  ArmArchTimerWriteReg (CntpCtl, (VOID *)&Val);\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmArchTimerSetCompareVal (\r
+    IN   UINT64   Val\r
+    )\r
+{\r
+  ArmArchTimerWriteReg (CntpCval, (VOID *)&Val);\r
+}\r
index d9cf8826ceb1cee651f719c7d89889a5c9bc54ec..cc5074bfc27325bd66298849e06e47e99c3dac4d 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <Uefi.h>
-#include <Chipset/ArmV7.h>
-#include <Library/ArmLib.h>
-#include <Library/BaseLib.h>
-#include <Library/IoLib.h>
-#include "ArmV7Lib.h"
-#include "ArmLibPrivate.h"
-
-ARM_CACHE_TYPE
-EFIAPI
-ArmCacheType (
-  VOID
-  )
-{
-  return ARM_CACHE_TYPE_WRITE_BACK;
-}
-
-ARM_CACHE_ARCHITECTURE
-EFIAPI
-ArmCacheArchitecture (
-  VOID
-  )
-{
-  UINT32 CLIDR = ReadCLIDR ();
-
-  return (ARM_CACHE_ARCHITECTURE)CLIDR; // BugBug Fix Me
-}
-
-BOOLEAN
-EFIAPI
-ArmDataCachePresent (
-  VOID
-  )
-{
-  UINT32 CLIDR = ReadCLIDR ();
-  
-  if ((CLIDR & 0x2) == 0x2) {
-    // Instruction cache exists
-    return TRUE;
-  }
-  if ((CLIDR & 0x7) == 0x4) {
-    // Unified cache
-    return TRUE;
-  }
-  
-  return FALSE;
-}
-  
-UINTN
-EFIAPI
-ArmDataCacheSize (
-  VOID
-  )
-{
-  UINT32 NumSets;
-  UINT32 Associativity;
-  UINT32 LineSize;
-  UINT32 CCSIDR = ReadCCSIDR (0);
-  
-  LineSize      = (1 << ((CCSIDR & 0x7) + 2));
-  Associativity = ((CCSIDR >> 3) & 0x3ff) + 1;
-  NumSets       = ((CCSIDR >> 13) & 0x7fff) + 1;
-
-  // LineSize is in words (4 byte chunks)
-  return  NumSets * Associativity * LineSize * 4;      
-}
-  
-UINTN
-EFIAPI
-ArmDataCacheAssociativity (
-  VOID
-  )
-{
-  UINT32 CCSIDR = ReadCCSIDR (0);
-
-  return ((CCSIDR >> 3) & 0x3ff) + 1;
-}
-  
-UINTN
-ArmDataCacheSets (
-  VOID
-  )
-{
-  UINT32 CCSIDR = ReadCCSIDR (0);
-  
-  return ((CCSIDR >> 13) & 0x7fff) + 1;
-}
-
-UINTN
-EFIAPI
-ArmDataCacheLineLength (
-  VOID
-  )
-{
-  UINT32 CCSIDR = ReadCCSIDR (0) & 7;
-
-  // * 4 converts to bytes
-  return (1 << (CCSIDR + 2)) * 4;
-}
-  
-BOOLEAN
-EFIAPI
-ArmInstructionCachePresent (
-  VOID
-  )
-{
-  UINT32 CLIDR = ReadCLIDR ();
-  
-  if ((CLIDR & 1) == 1) {
-    // Instruction cache exists
-    return TRUE;
-  }
-  if ((CLIDR & 0x7) == 0x4) {
-    // Unified cache
-    return TRUE;
-  }
-  
-  return FALSE;
-}
-  
-UINTN
-EFIAPI
-ArmInstructionCacheSize (
-  VOID
-  )
-{
-  UINT32 NumSets;
-  UINT32 Associativity;
-  UINT32 LineSize;
-  UINT32 CCSIDR = ReadCCSIDR (1);
-  
-  LineSize      = (1 << ((CCSIDR & 0x7) + 2));
-  Associativity = ((CCSIDR >> 3) & 0x3ff) + 1;
-  NumSets       = ((CCSIDR >> 13) & 0x7fff) + 1;
-
-  // LineSize is in words (4 byte chunks)
-  return  NumSets * Associativity * LineSize * 4;      
-}
-  
-UINTN
-EFIAPI
-ArmInstructionCacheAssociativity (
-  VOID
-  )
-{
-  UINT32 CCSIDR = ReadCCSIDR (1);
-
-  return ((CCSIDR >> 3) & 0x3ff) + 1;
-//  return 4;
-}
-  
-UINTN
-EFIAPI
-ArmInstructionCacheSets (
-  VOID
-  )
-{
-  UINT32 CCSIDR = ReadCCSIDR (1);
-  
-  return ((CCSIDR >> 13) & 0x7fff) + 1;
-}
-
-UINTN
-EFIAPI
-ArmInstructionCacheLineLength (
-  VOID
-  )
-{
-  UINT32 CCSIDR = ReadCCSIDR (1) & 7;
-
-  // * 4 converts to bytes
-  return (1 << (CCSIDR + 2)) * 4;
-
-//  return 64;
-}
-
-
-VOID
-ArmV7DataCacheOperation (
-  IN  ARM_V7_CACHE_OPERATION  DataCacheOperation
-  )
-{
-  UINTN     SavedInterruptState;
-
-  SavedInterruptState = ArmGetInterruptState ();
-  ArmDisableInterrupts ();
-  
-  ArmV7AllDataCachesOperation (DataCacheOperation);
-  
-  ArmDrainWriteBuffer ();
-  
-  if (SavedInterruptState) {
-    ArmEnableInterrupts ();
-  }
-}
-
-
-VOID
-ArmV7PoUDataCacheOperation (
-  IN  ARM_V7_CACHE_OPERATION  DataCacheOperation
-  )
-{
-  UINTN     SavedInterruptState;
-
-  SavedInterruptState = ArmGetInterruptState ();
-  ArmDisableInterrupts ();
-  
-  ArmV7PerformPoUDataCacheOperation (DataCacheOperation);
-  
-  ArmDrainWriteBuffer ();
-  
-  if (SavedInterruptState) {
-    ArmEnableInterrupts ();
-  }
-}
-
-VOID
-EFIAPI
-ArmInvalidateDataCache (
-  VOID
-  )
-{
-  ArmV7DataCacheOperation (ArmInvalidateDataCacheEntryBySetWay);
-}
-
-VOID
-EFIAPI
-ArmCleanInvalidateDataCache (
-  VOID
-  )
-{
-  ArmV7DataCacheOperation (ArmCleanInvalidateDataCacheEntryBySetWay);
-}
-
-VOID
-EFIAPI
-ArmCleanDataCache (
-  VOID
-  )
-{
-  ArmV7DataCacheOperation (ArmCleanDataCacheEntryBySetWay);
-}
-
-VOID
-EFIAPI
-ArmCleanDataCacheToPoU (
-  VOID
-  )
-{
-  ArmV7PoUDataCacheOperation (ArmCleanDataCacheEntryBySetWay);
-}
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include <Uefi.h>\r
+#include <Chipset/ArmV7.h>\r
+#include <Library/ArmLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/IoLib.h>\r
+#include "ArmV7Lib.h"\r
+#include "ArmLibPrivate.h"\r
+\r
+ARM_CACHE_TYPE\r
+EFIAPI\r
+ArmCacheType (\r
+  VOID\r
+  )\r
+{\r
+  return ARM_CACHE_TYPE_WRITE_BACK;\r
+}\r
+\r
+ARM_CACHE_ARCHITECTURE\r
+EFIAPI\r
+ArmCacheArchitecture (\r
+  VOID\r
+  )\r
+{\r
+  UINT32 CLIDR = ReadCLIDR ();\r
+\r
+  return (ARM_CACHE_ARCHITECTURE)CLIDR; // BugBug Fix Me\r
+}\r
+\r
+BOOLEAN\r
+EFIAPI\r
+ArmDataCachePresent (\r
+  VOID\r
+  )\r
+{\r
+  UINT32 CLIDR = ReadCLIDR ();\r
+  \r
+  if ((CLIDR & 0x2) == 0x2) {\r
+    // Instruction cache exists\r
+    return TRUE;\r
+  }\r
+  if ((CLIDR & 0x7) == 0x4) {\r
+    // Unified cache\r
+    return TRUE;\r
+  }\r
+  \r
+  return FALSE;\r
+}\r
+  \r
+UINTN\r
+EFIAPI\r
+ArmDataCacheSize (\r
+  VOID\r
+  )\r
+{\r
+  UINT32 NumSets;\r
+  UINT32 Associativity;\r
+  UINT32 LineSize;\r
+  UINT32 CCSIDR = ReadCCSIDR (0);\r
+  \r
+  LineSize      = (1 << ((CCSIDR & 0x7) + 2));\r
+  Associativity = ((CCSIDR >> 3) & 0x3ff) + 1;\r
+  NumSets       = ((CCSIDR >> 13) & 0x7fff) + 1;\r
+\r
+  // LineSize is in words (4 byte chunks)\r
+  return  NumSets * Associativity * LineSize * 4;      \r
+}\r
+  \r
+UINTN\r
+EFIAPI\r
+ArmDataCacheAssociativity (\r
+  VOID\r
+  )\r
+{\r
+  UINT32 CCSIDR = ReadCCSIDR (0);\r
+\r
+  return ((CCSIDR >> 3) & 0x3ff) + 1;\r
+}\r
+  \r
+UINTN\r
+ArmDataCacheSets (\r
+  VOID\r
+  )\r
+{\r
+  UINT32 CCSIDR = ReadCCSIDR (0);\r
+  \r
+  return ((CCSIDR >> 13) & 0x7fff) + 1;\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+ArmDataCacheLineLength (\r
+  VOID\r
+  )\r
+{\r
+  UINT32 CCSIDR = ReadCCSIDR (0) & 7;\r
+\r
+  // * 4 converts to bytes\r
+  return (1 << (CCSIDR + 2)) * 4;\r
+}\r
+  \r
+BOOLEAN\r
+EFIAPI\r
+ArmInstructionCachePresent (\r
+  VOID\r
+  )\r
+{\r
+  UINT32 CLIDR = ReadCLIDR ();\r
+  \r
+  if ((CLIDR & 1) == 1) {\r
+    // Instruction cache exists\r
+    return TRUE;\r
+  }\r
+  if ((CLIDR & 0x7) == 0x4) {\r
+    // Unified cache\r
+    return TRUE;\r
+  }\r
+  \r
+  return FALSE;\r
+}\r
+  \r
+UINTN\r
+EFIAPI\r
+ArmInstructionCacheSize (\r
+  VOID\r
+  )\r
+{\r
+  UINT32 NumSets;\r
+  UINT32 Associativity;\r
+  UINT32 LineSize;\r
+  UINT32 CCSIDR = ReadCCSIDR (1);\r
+  \r
+  LineSize      = (1 << ((CCSIDR & 0x7) + 2));\r
+  Associativity = ((CCSIDR >> 3) & 0x3ff) + 1;\r
+  NumSets       = ((CCSIDR >> 13) & 0x7fff) + 1;\r
+\r
+  // LineSize is in words (4 byte chunks)\r
+  return  NumSets * Associativity * LineSize * 4;      \r
+}\r
+  \r
+UINTN\r
+EFIAPI\r
+ArmInstructionCacheAssociativity (\r
+  VOID\r
+  )\r
+{\r
+  UINT32 CCSIDR = ReadCCSIDR (1);\r
+\r
+  return ((CCSIDR >> 3) & 0x3ff) + 1;\r
+//  return 4;\r
+}\r
+  \r
+UINTN\r
+EFIAPI\r
+ArmInstructionCacheSets (\r
+  VOID\r
+  )\r
+{\r
+  UINT32 CCSIDR = ReadCCSIDR (1);\r
+  \r
+  return ((CCSIDR >> 13) & 0x7fff) + 1;\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+ArmInstructionCacheLineLength (\r
+  VOID\r
+  )\r
+{\r
+  UINT32 CCSIDR = ReadCCSIDR (1) & 7;\r
+\r
+  // * 4 converts to bytes\r
+  return (1 << (CCSIDR + 2)) * 4;\r
+\r
+//  return 64;\r
+}\r
+\r
+\r
+VOID\r
+ArmV7DataCacheOperation (\r
+  IN  ARM_V7_CACHE_OPERATION  DataCacheOperation\r
+  )\r
+{\r
+  UINTN     SavedInterruptState;\r
+\r
+  SavedInterruptState = ArmGetInterruptState ();\r
+  ArmDisableInterrupts ();\r
+  \r
+  ArmV7AllDataCachesOperation (DataCacheOperation);\r
+  \r
+  ArmDrainWriteBuffer ();\r
+  \r
+  if (SavedInterruptState) {\r
+    ArmEnableInterrupts ();\r
+  }\r
+}\r
+\r
+\r
+VOID\r
+ArmV7PoUDataCacheOperation (\r
+  IN  ARM_V7_CACHE_OPERATION  DataCacheOperation\r
+  )\r
+{\r
+  UINTN     SavedInterruptState;\r
+\r
+  SavedInterruptState = ArmGetInterruptState ();\r
+  ArmDisableInterrupts ();\r
+  \r
+  ArmV7PerformPoUDataCacheOperation (DataCacheOperation);\r
+  \r
+  ArmDrainWriteBuffer ();\r
+  \r
+  if (SavedInterruptState) {\r
+    ArmEnableInterrupts ();\r
+  }\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmInvalidateDataCache (\r
+  VOID\r
+  )\r
+{\r
+  ArmV7DataCacheOperation (ArmInvalidateDataCacheEntryBySetWay);\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmCleanInvalidateDataCache (\r
+  VOID\r
+  )\r
+{\r
+  ArmV7DataCacheOperation (ArmCleanInvalidateDataCacheEntryBySetWay);\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmCleanDataCache (\r
+  VOID\r
+  )\r
+{\r
+  ArmV7DataCacheOperation (ArmCleanDataCacheEntryBySetWay);\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmCleanDataCacheToPoU (\r
+  VOID\r
+  )\r
+{\r
+  ArmV7PoUDataCacheOperation (ArmCleanDataCacheEntryBySetWay);\r
+}\r
index ca8d06a5502109cb0693ecfbeb741d14b4d532b6..d0faa00d1e9c2490718d7b6374d9bd4d991e3d23 100755 (executable)
@@ -38,16 +38,16 @@ InternalMemCopyMem (
   )\r
 **/\r
   EXPORT InternalMemCopyMem\r
   )\r
 **/\r
   EXPORT InternalMemCopyMem\r
-
-  AREA AsmMemStuff, CODE, READONLY
+\r
+  AREA AsmMemStuff, CODE, READONLY\r
 \r
 InternalMemCopyMem\r
 \r
 InternalMemCopyMem\r
-  stmfd  sp!, {r4-r11, lr}
-  // Save the input parameters in extra registers (r11 = destination, r14 = source, r12 = length)
-  mov  r11, r0
-  mov  r10, r0
-  mov  r12, r2
-  mov  r14, r1
+  stmfd  sp!, {r4-r11, lr}\r
+  // Save the input parameters in extra registers (r11 = destination, r14 = source, r12 = length)\r
+  mov  r11, r0\r
+  mov  r10, r0\r
+  mov  r12, r2\r
+  mov  r14, r1\r
   \r
 memcopy_check_overlapped\r
   cmp  r11, r1\r
   \r
 memcopy_check_overlapped\r
   cmp  r11, r1\r
@@ -70,42 +70,42 @@ memcopy_check_overlapped
 memcopy_check_optim_default\r
   // Check if we can use an optimized path ((length >= 32) && destination word-aligned && source word-aligned) for the memcopy (optimized path if r0 == 1)\r
   tst  r0, #0xF\r
 memcopy_check_optim_default\r
   // Check if we can use an optimized path ((length >= 32) && destination word-aligned && source word-aligned) for the memcopy (optimized path if r0 == 1)\r
   tst  r0, #0xF\r
-  movne  r0, #0
-  bne   memcopy_default
-  tst  r1, #0xF
-  movne  r3, #0
-  moveq  r3, #1
-  cmp  r2, #31
-  movls  r0, #0
-  andhi  r0, r3, #1
-  b     memcopy_default
-    
-memcopy_check_optim_overlap
-  // r10 = dest_end, r14 = source_end
-  add  r10, r11, r12
-  add  r14, r12, r1
-
-  // Are we in the optimized case ((length >= 32) && dest_end word-aligned && source_end word-aligned)
-  cmp  r2, #31
-  movls  r0, #0
-  movhi  r0, #1
-  tst  r10, #0xF
-  movne  r0, #0
-  tst  r14, #0xF
-  movne  r0, #0
+  movne  r0, #0\r
+  bne   memcopy_default\r
+  tst  r1, #0xF\r
+  movne  r3, #0\r
+  moveq  r3, #1\r
+  cmp  r2, #31\r
+  movls  r0, #0\r
+  andhi  r0, r3, #1\r
+  b     memcopy_default\r
+    \r
+memcopy_check_optim_overlap\r
+  // r10 = dest_end, r14 = source_end\r
+  add  r10, r11, r12\r
+  add  r14, r12, r1\r
+\r
+  // Are we in the optimized case ((length >= 32) && dest_end word-aligned && source_end word-aligned)\r
+  cmp  r2, #31\r
+  movls  r0, #0\r
+  movhi  r0, #1\r
+  tst  r10, #0xF\r
+  movne  r0, #0\r
+  tst  r14, #0xF\r
+  movne  r0, #0\r
   b  memcopy_overlapped\r
   b  memcopy_overlapped\r
-  
+  \r
 memcopy_overlapped_non_optim\r
   // We read 1 byte from the end of the source buffer\r
 memcopy_overlapped_non_optim\r
   // We read 1 byte from the end of the source buffer\r
-  sub  r3, r14, #1
-  sub  r12, r12, #1
-  ldrb  r3, [r3, #0]  
-  sub  r2, r10, #1
-  cmp  r12, #0
+  sub  r3, r14, #1\r
+  sub  r12, r12, #1\r
+  ldrb  r3, [r3, #0]  \r
+  sub  r2, r10, #1\r
+  cmp  r12, #0\r
   // We write 1 byte at the end of the dest buffer\r
   // We write 1 byte at the end of the dest buffer\r
-  sub  r10, r10, #1
-  sub  r14, r14, #1
-  strb  r3, [r2, #0]
+  sub  r10, r10, #1\r
+  sub  r14, r14, #1\r
+  strb  r3, [r2, #0]\r
   bne  memcopy_overlapped_non_optim\r
   b   memcopy_end\r
 \r
   bne  memcopy_overlapped_non_optim\r
   b   memcopy_end\r
 \r
@@ -114,16 +114,16 @@ memcopy_overlapped
   // Are we in the optimized case ?\r
   cmp  r0, #0\r
   beq  memcopy_overlapped_non_optim\r
   // Are we in the optimized case ?\r
   cmp  r0, #0\r
   beq  memcopy_overlapped_non_optim\r
-  
+  \r
   // Optimized Overlapped - Read 32 bytes\r
   sub  r14, r14, #32\r
   sub  r12, r12, #32\r
   cmp  r12, #31\r
   ldmia  r14, {r2-r9}\r
   // Optimized Overlapped - Read 32 bytes\r
   sub  r14, r14, #32\r
   sub  r12, r12, #32\r
   cmp  r12, #31\r
   ldmia  r14, {r2-r9}\r
-  
+  \r
   // If length is less than 32 then disable optim\r
   movls  r0, #0\r
   // If length is less than 32 then disable optim\r
   movls  r0, #0\r
-  
+  \r
   cmp  r12, #0\r
   \r
   // Optimized Overlapped - Write 32 bytes  \r
   cmp  r12, #0\r
   \r
   // Optimized Overlapped - Write 32 bytes  \r
@@ -136,37 +136,37 @@ memcopy_overlapped
   \r
 memcopy_default_non_optim\r
   // Byte copy\r
   \r
 memcopy_default_non_optim\r
   // Byte copy\r
-  ldrb  r3, [r14], #1  
-  sub  r12, r12, #1
-  strb  r3, [r10], #1
-  
+  ldrb  r3, [r14], #1  \r
+  sub  r12, r12, #1\r
+  strb  r3, [r10], #1\r
+  \r
 memcopy_default\r
 memcopy_default\r
-  cmp  r12, #0
-  beq  memcopy_end
-  
+  cmp  r12, #0\r
+  beq  memcopy_end\r
+  \r
 // r10 = dest, r14 = source\r
 memcopy_default_loop\r
 // r10 = dest, r14 = source\r
 memcopy_default_loop\r
-  cmp  r0, #0
+  cmp  r0, #0\r
   beq  memcopy_default_non_optim\r
   beq  memcopy_default_non_optim\r
-  
+  \r
   // Optimized memcopy - Read 32 Bytes\r
   // Optimized memcopy - Read 32 Bytes\r
-  sub  r12, r12, #32
-  cmp  r12, #31
-  ldmia  r14!, {r2-r9}
+  sub  r12, r12, #32\r
+  cmp  r12, #31\r
+  ldmia  r14!, {r2-r9}\r
   \r
   // If length is less than 32 then disable optim\r
   \r
   // If length is less than 32 then disable optim\r
-  movls  r0, #0
+  movls  r0, #0\r
   \r
   \r
-  cmp  r12, #0
+  cmp  r12, #0\r
   \r
   // Optimized memcopy - Write 32 Bytes\r
   \r
   // Optimized memcopy - Write 32 Bytes\r
-  stmia  r10!, {r2-r9}
-
+  stmia  r10!, {r2-r9}\r
+\r
   // while (length != 0)\r
   bne  memcopy_default_loop\r
   // while (length != 0)\r
   bne  memcopy_default_loop\r
-  
+  \r
 memcopy_end\r
 memcopy_end\r
-  mov  r0, r11
+  mov  r0, r11\r
   ldmfd  sp!, {r4-r11, pc}\r
   \r
   END\r
   ldmfd  sp!, {r4-r11, pc}\r
   \r
   END\r
index e7cbdf1ed0ba82cba85e54daec3828365883d7e0..5df7c6b794f4d31546ddb372d2fd24ab2dfbfad2 100755 (executable)
@@ -38,78 +38,78 @@ InternalMemCopyMem (
   )\r
 **/\r
   EXPORT InternalMemCopyMem\r
   )\r
 **/\r
   EXPORT InternalMemCopyMem\r
-
-  AREA AsmMemStuff, CODE, READONLY
+\r
+  AREA AsmMemStuff, CODE, READONLY\r
 \r
 InternalMemCopyMem\r
 \r
 InternalMemCopyMem\r
-  stmfd  sp!, {r4, r9, lr}
-  tst  r0, #3
-  mov  r4, r0
-  mov  r9, r0
-  mov  ip, r2
-  mov  lr, r1
-  movne  r0, #0
-  bne  L4
-  tst  r1, #3
-  movne  r3, #0
-  moveq  r3, #1
-  cmp  r2, #127
-  movls  r0, #0
-  andhi  r0, r3, #1
-L4
-  cmp  r4, r1
-  bcc  L26
-  bls  L7
-  rsb  r3, r1, r4
-  cmp  ip, r3
-  bcc  L26
-  cmp  ip, #0
-  beq  L7
-  add  r9, r4, ip
-  add  lr, ip, r1
-  b  L16
-L29
-  sub  ip, ip, #8
-  cmp  ip, #7
-  ldrd  r2, [lr, #-8]!
-  movls  r0, #0
-  cmp  ip, #0
-  strd  r2, [r9, #-8]!
-  beq  L7
-L16
-  cmp  r0, #0
-  bne  L29
-  sub  r3, lr, #1
-  sub  ip, ip, #1
-  ldrb  r3, [r3, #0]  
-  sub  r2, r9, #1
-  cmp  ip, #0
-  sub  r9, r9, #1
-  sub  lr, lr, #1
-  strb  r3, [r2, #0]
-  bne  L16
-  b   L7
-L11
-  ldrb  r3, [lr], #1  
-  sub  ip, ip, #1
-  strb  r3, [r9], #1
-L26
-  cmp  ip, #0
-  beq  L7
-L30
-  cmp  r0, #0
-  beq  L11
-  sub  ip, ip, #128          // 32
-  cmp  ip, #127              // 31
-  vldm     lr!, {d0-d15}
-  movls  r0, #0
-  cmp  ip, #0
-  vstm  r9!, {d0-d15}
-  bne  L30
-L7
-  dsb
-  mov  r0, r4
-  ldmfd  sp!, {r4, r9, pc}
+  stmfd  sp!, {r4, r9, lr}\r
+  tst  r0, #3\r
+  mov  r4, r0\r
+  mov  r9, r0\r
+  mov  ip, r2\r
+  mov  lr, r1\r
+  movne  r0, #0\r
+  bne  L4\r
+  tst  r1, #3\r
+  movne  r3, #0\r
+  moveq  r3, #1\r
+  cmp  r2, #127\r
+  movls  r0, #0\r
+  andhi  r0, r3, #1\r
+L4\r
+  cmp  r4, r1\r
+  bcc  L26\r
+  bls  L7\r
+  rsb  r3, r1, r4\r
+  cmp  ip, r3\r
+  bcc  L26\r
+  cmp  ip, #0\r
+  beq  L7\r
+  add  r9, r4, ip\r
+  add  lr, ip, r1\r
+  b  L16\r
+L29\r
+  sub  ip, ip, #8\r
+  cmp  ip, #7\r
+  ldrd  r2, [lr, #-8]!\r
+  movls  r0, #0\r
+  cmp  ip, #0\r
+  strd  r2, [r9, #-8]!\r
+  beq  L7\r
+L16\r
+  cmp  r0, #0\r
+  bne  L29\r
+  sub  r3, lr, #1\r
+  sub  ip, ip, #1\r
+  ldrb  r3, [r3, #0]  \r
+  sub  r2, r9, #1\r
+  cmp  ip, #0\r
+  sub  r9, r9, #1\r
+  sub  lr, lr, #1\r
+  strb  r3, [r2, #0]\r
+  bne  L16\r
+  b   L7\r
+L11\r
+  ldrb  r3, [lr], #1  \r
+  sub  ip, ip, #1\r
+  strb  r3, [r9], #1\r
+L26\r
+  cmp  ip, #0\r
+  beq  L7\r
+L30\r
+  cmp  r0, #0\r
+  beq  L11\r
+  sub  ip, ip, #128          // 32\r
+  cmp  ip, #127              // 31\r
+  vldm     lr!, {d0-d15}\r
+  movls  r0, #0\r
+  cmp  ip, #0\r
+  vstm  r9!, {d0-d15}\r
+  bne  L30\r
+L7\r
+  dsb\r
+  mov  r0, r4\r
+  ldmfd  sp!, {r4, r9, pc}\r
 \r
   END\r
   \r
 \r
   END\r
   \r
index d5c50cbef4b0610c3a7545f604945728cf10a8d1..0415ed70912236218e53bfadc714cc89fc36c700 100755 (executable)
@@ -77,4 +77,4 @@ L43:
   cmp      r1, #0\r
   bne      L34\r
   ldmfd    sp!, {pc}\r
   cmp      r1, #0\r
   bne      L34\r
   ldmfd    sp!, {pc}\r
-  
\ No newline at end of file
+  \r
\ No newline at end of file
index bbab580cf135d9d37b0657b80e174e89bda1e51c..de438d6c56b82d66798c0bfe81e8b88563ab4a3e 100755 (executable)
@@ -36,7 +36,7 @@ InternalMemSetMem (
   \r
   EXPORT InternalMemSetMem\r
   \r
   \r
   EXPORT InternalMemSetMem\r
   \r
-  AREA AsmMemStuff, CODE, READONLY
+  AREA AsmMemStuff, CODE, READONLY\r
 \r
 InternalMemSetMem\r
   stmfd  sp!, {lr}\r
 \r
 InternalMemSetMem\r
   stmfd  sp!, {lr}\r
@@ -77,4 +77,4 @@ L43
   ldmfd    sp!, {pc}\r
   \r
   END\r
   ldmfd    sp!, {pc}\r
   \r
   END\r
-  
\ No newline at end of file
+  \r
\ No newline at end of file
index 2d7f96e28b413cada131f12bb3fbecc92b226b3a..2b88bf1e051b13c0ddf5b165739eca27ebd78815 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 "BdsInternal.h"
-
-//#include <Library/DxeServicesLib.h>
-
-STATIC
-EFI_STATUS
-BdsLoadFileFromFirmwareVolume (
-  IN  EFI_HANDLE      FvHandle,
-  IN  CHAR16    *FilePath,
-  IN  EFI_FV_FILETYPE FileTypeFilter,
-  OUT EFI_DEVICE_PATH     **EfiAppDevicePath
-  )
-{
-  EFI_FIRMWARE_VOLUME2_PROTOCOL *FvProtocol;
-  VOID                          *Key;
-  EFI_STATUS                    Status, FileStatus;
-  EFI_GUID                      NameGuid;
-  EFI_FV_FILETYPE               FileType;
-  EFI_FV_FILE_ATTRIBUTES        Attributes;
-  UINTN                         Size;
-  UINTN                         UiStringLen;
-  CHAR16                        *UiSection;
-  UINT32                        Authentication;
-  EFI_DEVICE_PATH               *FvDevicePath;
-  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH    FileDevicePath;
-
-  Status = gBS->HandleProtocol (FvHandle,&gEfiFirmwareVolume2ProtocolGuid, (VOID **)&FvProtocol);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  // Length of FilePath
-  UiStringLen = StrLen (FilePath);
-
-  // Allocate Key
-  Key = AllocatePool (FvProtocol->KeySize);
-  ASSERT (Key != NULL);
-  ZeroMem (Key, FvProtocol->KeySize);
-
-  do {
-    // Search in all files
-    FileType = FileTypeFilter;
-
-    Status = FvProtocol->GetNextFile (FvProtocol, Key, &FileType, &NameGuid, &Attributes, &Size);
-    if (!EFI_ERROR (Status)) {
-      UiSection = NULL;
-      FileStatus = FvProtocol->ReadSection (
-                    FvProtocol,
-                    &NameGuid,
-                    EFI_SECTION_USER_INTERFACE,
-                    0,
-                    (VOID **)&UiSection,
-                    &Size,
-                    &Authentication
-                    );
-      if (!EFI_ERROR (FileStatus)) {
-        if (StrnCmp (FilePath, UiSection, UiStringLen) == 0) {
-          //
-          // We found a UiString match.
-          //
-          Status = gBS->HandleProtocol (FvHandle, &gEfiDevicePathProtocolGuid, (VOID **)&FvDevicePath);
-
-          // Generate the Device Path for the file
-          //DevicePath = DuplicateDevicePath(FvDevicePath);
-          EfiInitializeFwVolDevicepathNode (&FileDevicePath, &NameGuid);
-          *EfiAppDevicePath = AppendDevicePathNode (FvDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&FileDevicePath);
-
-          FreePool (Key);
-          FreePool (UiSection);
-          return FileStatus;
-        }
-        FreePool (UiSection);
-      }
-    }
-  } while (!EFI_ERROR (Status));
-
-  FreePool(Key);
-  return Status;
-}
-
-/**
-  Start an EFI Application from any Firmware Volume
-
-  @param  EfiApp                EFI Application Name
-
-  @retval EFI_SUCCESS           All drivers have been connected
-  @retval EFI_NOT_FOUND         The Linux kernel Device Path has not been found
-  @retval EFI_OUT_OF_RESOURCES  There is not enough resource memory to store the matching results.
-
-**/
-EFI_STATUS
-BdsLoadApplication (
-  IN EFI_HANDLE                  ParentImageHandle,
-  IN CHAR16*                     EfiApp,
-  IN UINTN                       LoadOptionsSize,
-  IN VOID*                       LoadOptions
-  )
-{
-  EFI_STATUS                      Status;
-  UINTN                           NoHandles, HandleIndex;
-  EFI_HANDLE                      *Handles;
-  EFI_DEVICE_PATH                 *EfiAppDevicePath;
-
-  // Need to connect every drivers to ensure no dependencies are missing for the application
-  Status = BdsConnectAllDrivers();
-  if (EFI_ERROR(Status)) {
-    DEBUG ((EFI_D_ERROR, "FAIL to connect all drivers\n"));
-    return Status;
-  }
-
-  // Search the application in any Firmware Volume
-  Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &NoHandles, &Handles);
-  if (EFI_ERROR (Status) || (NoHandles == 0)) {
-    DEBUG ((EFI_D_ERROR, "FAIL to find Firmware Volume\n"));
-    return Status;
-  }
-
-  // Search in all Firmware Volume for the EFI Application
-  for (HandleIndex = 0; HandleIndex < NoHandles; HandleIndex++) {
-    EfiAppDevicePath = NULL;
-    Status = BdsLoadFileFromFirmwareVolume (Handles[HandleIndex], EfiApp, EFI_FV_FILETYPE_APPLICATION, &EfiAppDevicePath);
-    if (!EFI_ERROR (Status)) {
-      // Start the application
-      Status = BdsStartEfiApplication (ParentImageHandle, EfiAppDevicePath, LoadOptionsSize, LoadOptions);
-      return Status;
-    }
-  }
-
-  return Status;
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*\r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*\r
+**/\r
+\r
+#include "BdsInternal.h"\r
+\r
+//#include <Library/DxeServicesLib.h>\r
+\r
+STATIC\r
+EFI_STATUS\r
+BdsLoadFileFromFirmwareVolume (\r
+  IN  EFI_HANDLE      FvHandle,\r
+  IN  CHAR16    *FilePath,\r
+  IN  EFI_FV_FILETYPE FileTypeFilter,\r
+  OUT EFI_DEVICE_PATH     **EfiAppDevicePath\r
+  )\r
+{\r
+  EFI_FIRMWARE_VOLUME2_PROTOCOL *FvProtocol;\r
+  VOID                          *Key;\r
+  EFI_STATUS                    Status, FileStatus;\r
+  EFI_GUID                      NameGuid;\r
+  EFI_FV_FILETYPE               FileType;\r
+  EFI_FV_FILE_ATTRIBUTES        Attributes;\r
+  UINTN                         Size;\r
+  UINTN                         UiStringLen;\r
+  CHAR16                        *UiSection;\r
+  UINT32                        Authentication;\r
+  EFI_DEVICE_PATH               *FvDevicePath;\r
+  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH    FileDevicePath;\r
+\r
+  Status = gBS->HandleProtocol (FvHandle,&gEfiFirmwareVolume2ProtocolGuid, (VOID **)&FvProtocol);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  // Length of FilePath\r
+  UiStringLen = StrLen (FilePath);\r
+\r
+  // Allocate Key\r
+  Key = AllocatePool (FvProtocol->KeySize);\r
+  ASSERT (Key != NULL);\r
+  ZeroMem (Key, FvProtocol->KeySize);\r
+\r
+  do {\r
+    // Search in all files\r
+    FileType = FileTypeFilter;\r
+\r
+    Status = FvProtocol->GetNextFile (FvProtocol, Key, &FileType, &NameGuid, &Attributes, &Size);\r
+    if (!EFI_ERROR (Status)) {\r
+      UiSection = NULL;\r
+      FileStatus = FvProtocol->ReadSection (\r
+                    FvProtocol,\r
+                    &NameGuid,\r
+                    EFI_SECTION_USER_INTERFACE,\r
+                    0,\r
+                    (VOID **)&UiSection,\r
+                    &Size,\r
+                    &Authentication\r
+                    );\r
+      if (!EFI_ERROR (FileStatus)) {\r
+        if (StrnCmp (FilePath, UiSection, UiStringLen) == 0) {\r
+          //\r
+          // We found a UiString match.\r
+          //\r
+          Status = gBS->HandleProtocol (FvHandle, &gEfiDevicePathProtocolGuid, (VOID **)&FvDevicePath);\r
+\r
+          // Generate the Device Path for the file\r
+          //DevicePath = DuplicateDevicePath(FvDevicePath);\r
+          EfiInitializeFwVolDevicepathNode (&FileDevicePath, &NameGuid);\r
+          *EfiAppDevicePath = AppendDevicePathNode (FvDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&FileDevicePath);\r
+\r
+          FreePool (Key);\r
+          FreePool (UiSection);\r
+          return FileStatus;\r
+        }\r
+        FreePool (UiSection);\r
+      }\r
+    }\r
+  } while (!EFI_ERROR (Status));\r
+\r
+  FreePool(Key);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Start an EFI Application from any Firmware Volume\r
+\r
+  @param  EfiApp                EFI Application Name\r
+\r
+  @retval EFI_SUCCESS           All drivers have been connected\r
+  @retval EFI_NOT_FOUND         The Linux kernel Device Path has not been found\r
+  @retval EFI_OUT_OF_RESOURCES  There is not enough resource memory to store the matching results.\r
+\r
+**/\r
+EFI_STATUS\r
+BdsLoadApplication (\r
+  IN EFI_HANDLE                  ParentImageHandle,\r
+  IN CHAR16*                     EfiApp,\r
+  IN UINTN                       LoadOptionsSize,\r
+  IN VOID*                       LoadOptions\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  UINTN                           NoHandles, HandleIndex;\r
+  EFI_HANDLE                      *Handles;\r
+  EFI_DEVICE_PATH                 *EfiAppDevicePath;\r
+\r
+  // Need to connect every drivers to ensure no dependencies are missing for the application\r
+  Status = BdsConnectAllDrivers();\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG ((EFI_D_ERROR, "FAIL to connect all drivers\n"));\r
+    return Status;\r
+  }\r
+\r
+  // Search the application in any Firmware Volume\r
+  Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &NoHandles, &Handles);\r
+  if (EFI_ERROR (Status) || (NoHandles == 0)) {\r
+    DEBUG ((EFI_D_ERROR, "FAIL to find Firmware Volume\n"));\r
+    return Status;\r
+  }\r
+\r
+  // Search in all Firmware Volume for the EFI Application\r
+  for (HandleIndex = 0; HandleIndex < NoHandles; HandleIndex++) {\r
+    EfiAppDevicePath = NULL;\r
+    Status = BdsLoadFileFromFirmwareVolume (Handles[HandleIndex], EfiApp, EFI_FV_FILETYPE_APPLICATION, &EfiAppDevicePath);\r
+    if (!EFI_ERROR (Status)) {\r
+      // Start the application\r
+      Status = BdsStartEfiApplication (ParentImageHandle, EfiAppDevicePath, LoadOptionsSize, LoadOptions);\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
index a8b77a3d22712f26f14943faed2e593c7e813f55..2c93243795ca1f446f89a8cab5d591b74d8738f7 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 "BdsInternal.h"
-
-#include <Protocol/UsbIo.h>
-#include <Protocol/DiskIo.h>
-#include <Protocol/LoadedImage.h>
-
-#define IS_DEVICE_PATH_NODE(node,type,subtype) (((node)->Type == (type)) && ((node)->SubType == (subtype)))
-
-// Extract the FilePath from the Device Path
-CHAR16*
-BdsExtractFilePathFromDevicePath (
-  IN  CONST CHAR16    *StrDevicePath,
-  IN  UINTN           NumberDevicePathNode
-  )
-{
-  UINTN       Node;
-  CHAR16      *Str;
-
-  Str = (CHAR16*)StrDevicePath;
-  Node = 0;
-  while ((Str != NULL) && (*Str != L'\0') && (Node < NumberDevicePathNode)) {
-    if ((*Str == L'/') || (*Str == L'\\')) {
-        Node++;
-    }
-    Str++;
-  }
-
-  if (*Str == L'\0') {
-    return NULL;
-  } else {
-    return Str;
-  }
-}
-
-BOOLEAN
-BdsIsRemovableUsb (
-  IN  EFI_DEVICE_PATH*  DevicePath
-  )
-{
-  return ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
-          ((DevicePathSubType (DevicePath) == MSG_USB_CLASS_DP) ||
-           (DevicePathSubType (DevicePath) == MSG_USB_WWID_DP)));
-}
-
-EFI_STATUS
-BdsGetDeviceUsb (
-  IN  EFI_DEVICE_PATH*  RemovableDevicePath,
-  OUT EFI_HANDLE*       DeviceHandle,
-  OUT EFI_DEVICE_PATH** NewDevicePath
-  )
-{
-  EFI_STATUS                    Status;
-  UINTN                         Index;
-  UINTN                         UsbIoHandleCount;
-  EFI_HANDLE                    *UsbIoBuffer;
-  EFI_DEVICE_PATH*              UsbIoDevicePath;
-  EFI_DEVICE_PATH*              TmpDevicePath;
-  USB_WWID_DEVICE_PATH*         WwidDevicePath1;
-  USB_WWID_DEVICE_PATH*         WwidDevicePath2;
-  USB_CLASS_DEVICE_PATH*        UsbClassDevicePath1;
-  USB_CLASS_DEVICE_PATH*        UsbClassDevicePath2;
-
-  // Get all the UsbIo handles
-  UsbIoHandleCount = 0;
-  Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiUsbIoProtocolGuid, NULL, &UsbIoHandleCount, &UsbIoBuffer);
-  if (EFI_ERROR(Status) || (UsbIoHandleCount == 0)) {
-    return Status;
-  }
-
-  // Check if one of the handles matches the USB description
-  for (Index = 0; Index < UsbIoHandleCount; Index++) {
-    Status = gBS->HandleProtocol (UsbIoBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID **) &UsbIoDevicePath);
-    if (!EFI_ERROR(Status)) {
-      TmpDevicePath = UsbIoDevicePath;
-      while (!IsDevicePathEnd (TmpDevicePath)) {
-        // Check if the Device Path node is a USB Removable device Path node
-        if (BdsIsRemovableUsb (TmpDevicePath)) {
-          if (TmpDevicePath->SubType == MSG_USB_WWID_DP) {
-            WwidDevicePath1 = (USB_WWID_DEVICE_PATH*)RemovableDevicePath;
-            WwidDevicePath2 = (USB_WWID_DEVICE_PATH*)TmpDevicePath;
-            if ((WwidDevicePath1->VendorId == WwidDevicePath2->VendorId) &&
-                (WwidDevicePath1->ProductId == WwidDevicePath2->ProductId) &&
-                (CompareMem (WwidDevicePath1+1, WwidDevicePath2+1, DevicePathNodeLength(WwidDevicePath1)-sizeof(USB_WWID_DEVICE_PATH)) == 0))
-            {
-              *DeviceHandle = UsbIoBuffer[Index];
-              // Add the additional original Device Path Nodes (eg: FilePath Device Path Node) to the new Device Path
-              *NewDevicePath = AppendDevicePath (UsbIoDevicePath, NextDevicePathNode(RemovableDevicePath));
-              return EFI_SUCCESS;
-            }
-          } else {
-            UsbClassDevicePath1 = (USB_CLASS_DEVICE_PATH*)RemovableDevicePath;
-            UsbClassDevicePath2 = (USB_CLASS_DEVICE_PATH*)TmpDevicePath;
-            if ((UsbClassDevicePath1->VendorId != 0xFFFF) && (UsbClassDevicePath1->VendorId == UsbClassDevicePath2->VendorId) &&
-                (UsbClassDevicePath1->ProductId != 0xFFFF) && (UsbClassDevicePath1->ProductId == UsbClassDevicePath2->ProductId) &&
-                (UsbClassDevicePath1->DeviceClass != 0xFF) && (UsbClassDevicePath1->DeviceClass == UsbClassDevicePath2->DeviceClass) &&
-                (UsbClassDevicePath1->DeviceSubClass != 0xFF) && (UsbClassDevicePath1->DeviceSubClass == UsbClassDevicePath2->DeviceSubClass) &&
-                (UsbClassDevicePath1->DeviceProtocol != 0xFF) && (UsbClassDevicePath1->DeviceProtocol == UsbClassDevicePath2->DeviceProtocol))
-            {
-              *DeviceHandle = UsbIoBuffer[Index];
-              // Add the additional original Device Path Nodes (eg: FilePath Device Path Node) to the new Device Path
-              *NewDevicePath = AppendDevicePath (UsbIoDevicePath, NextDevicePathNode(RemovableDevicePath));
-              return EFI_SUCCESS;
-            }
-          }
-        }
-        TmpDevicePath = NextDevicePathNode (TmpDevicePath);
-      }
-
-    }
-  }
-
-  return EFI_NOT_FOUND;
-}
-
-BOOLEAN
-BdsIsRemovableHd (
-  IN  EFI_DEVICE_PATH*  DevicePath
-  )
-{
-  return IS_DEVICE_PATH_NODE(DevicePath, MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP);
-}
-
-EFI_STATUS
-BdsGetDeviceHd (
-  IN  EFI_DEVICE_PATH*  RemovableDevicePath,
-  OUT EFI_HANDLE*       DeviceHandle,
-  OUT EFI_DEVICE_PATH** NewDevicePath
-  )
-{
-  EFI_STATUS                    Status;
-  UINTN                         Index;
-  UINTN                         PartitionHandleCount;
-  EFI_HANDLE                    *PartitionBuffer;
-  EFI_DEVICE_PATH*              PartitionDevicePath;
-  EFI_DEVICE_PATH*              TmpDevicePath;
-  HARDDRIVE_DEVICE_PATH*        HardDriveDevicePath1;
-  HARDDRIVE_DEVICE_PATH*        HardDriveDevicePath2;
-
-  // Get all the DiskIo handles
-  PartitionHandleCount = 0;
-  Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiDiskIoProtocolGuid, NULL, &PartitionHandleCount, &PartitionBuffer);
-  if (EFI_ERROR(Status) || (PartitionHandleCount == 0)) {
-    return Status;
-  }
-
-  // Check if one of the handles matches the Hard Disk Description
-  for (Index = 0; Index < PartitionHandleCount; Index++) {
-    Status = gBS->HandleProtocol (PartitionBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID **) &PartitionDevicePath);
-    if (!EFI_ERROR(Status)) {
-      TmpDevicePath = PartitionDevicePath;
-      while (!IsDevicePathEnd (TmpDevicePath)) {
-        // Check if the Device Path node is a HD Removable device Path node
-        if (BdsIsRemovableHd (TmpDevicePath)) {
-          HardDriveDevicePath1 = (HARDDRIVE_DEVICE_PATH*)RemovableDevicePath;
-          HardDriveDevicePath2 = (HARDDRIVE_DEVICE_PATH*)TmpDevicePath;
-          if ((HardDriveDevicePath1->SignatureType == HardDriveDevicePath2->SignatureType) &&
-              (CompareGuid ((EFI_GUID *)HardDriveDevicePath1->Signature,(EFI_GUID *)HardDriveDevicePath2->Signature) == TRUE) &&
-              (HardDriveDevicePath1->PartitionNumber == HardDriveDevicePath2->PartitionNumber))
-          {
-            *DeviceHandle = PartitionBuffer[Index];
-            // Add the additional original Device Path Nodes (eg: FilePath Device Path Node) to the new Device Path
-            *NewDevicePath = AppendDevicePath (PartitionDevicePath, NextDevicePathNode(RemovableDevicePath));
-            return EFI_SUCCESS;
-          }
-        }
-        TmpDevicePath = NextDevicePathNode (TmpDevicePath);
-      }
-
-    }
-  }
-
-  return EFI_NOT_FOUND;
-}
-
-/*BOOLEAN
-BdsIsRemovableCdrom (
-  IN  EFI_DEVICE_PATH*  DevicePath
-  )
-{
-  return IS_DEVICE_PATH_NODE(DevicePath, MEDIA_DEVICE_PATH, MEDIA_CDROM_DP);
-}
-
-EFI_STATUS
-BdsGetDeviceCdrom (
-  IN  EFI_DEVICE_PATH*  RemovableDevicePath,
-  OUT EFI_HANDLE*       DeviceHandle,
-  OUT EFI_DEVICE_PATH** DevicePath
-  )
-{
-  ASSERT(0);
-  return EFI_UNSUPPORTED;
-}*/
-
-typedef BOOLEAN
-(*BDS_IS_REMOVABLE) (
-  IN  EFI_DEVICE_PATH*  DevicePath
-  );
-
-typedef EFI_STATUS
-(*BDS_GET_DEVICE) (
-  IN  EFI_DEVICE_PATH*  RemovableDevicePath,
-  OUT EFI_HANDLE*       DeviceHandle,
-  OUT EFI_DEVICE_PATH** DevicePath
-  );
-
-typedef struct {
-  BDS_IS_REMOVABLE    IsRemovable;
-  BDS_GET_DEVICE      GetDevice;
-} BDS_REMOVABLE_DEVICE_SUPPORT;
-
-BDS_REMOVABLE_DEVICE_SUPPORT  RemovableDeviceSupport[] = {
-  { BdsIsRemovableUsb, BdsGetDeviceUsb },
-  { BdsIsRemovableHd, BdsGetDeviceHd },
-  //{ BdsIsRemovableCdrom, BdsGetDeviceCdrom }
-};
-
-STATIC
-BOOLEAN
-IsRemovableDevice (
-  IN  EFI_DEVICE_PATH*  DevicePath
-  )
-{
-  UINTN             Index;
-  EFI_DEVICE_PATH*  TmpDevicePath;
-
-  TmpDevicePath = DevicePath;
-  while (!IsDevicePathEnd (TmpDevicePath)) {
-    for (Index = 0; Index < sizeof(RemovableDeviceSupport) / sizeof(BDS_REMOVABLE_DEVICE_SUPPORT); Index++) {
-      if (RemovableDeviceSupport[Index].IsRemovable(TmpDevicePath)) {
-        return TRUE;
-      }
-    }
-    TmpDevicePath = NextDevicePathNode (TmpDevicePath);
-  }
-
-  return FALSE;
-}
-
-STATIC
-EFI_STATUS
-TryRemovableDevice (
-  IN  EFI_DEVICE_PATH*  DevicePath,
-  OUT EFI_HANDLE*       DeviceHandle,
-  OUT EFI_DEVICE_PATH** NewDevicePath
-  )
-{
-  EFI_STATUS        Status;
-  UINTN             Index;
-  EFI_DEVICE_PATH*  TmpDevicePath;
-  BDS_REMOVABLE_DEVICE_SUPPORT* RemovableDevice;
-  EFI_DEVICE_PATH* RemovableDevicePath;
-  BOOLEAN         RemovableFound;
-
-  RemovableDevice     = NULL;
-  RemovableDevicePath = NULL;
-  RemovableFound      = FALSE;
-  TmpDevicePath       = DevicePath;
-
-  while (!IsDevicePathEnd (TmpDevicePath) && !RemovableFound) {
-    for (Index = 0; Index < sizeof(RemovableDeviceSupport) / sizeof(BDS_REMOVABLE_DEVICE_SUPPORT); Index++) {
-      RemovableDevice = &RemovableDeviceSupport[Index];
-      if (RemovableDevice->IsRemovable(TmpDevicePath)) {
-        RemovableDevicePath = TmpDevicePath;
-        RemovableFound = TRUE;
-        break;
-      }
-    }
-    TmpDevicePath = NextDevicePathNode (TmpDevicePath);
-  }
-
-  if (!RemovableFound) {
-    return EFI_NOT_FOUND;
-  }
-
-  // Search into the current started drivers
-  Status = RemovableDevice->GetDevice (RemovableDevicePath, DeviceHandle, NewDevicePath);
-  if (Status == EFI_NOT_FOUND) {
-    // Connect all the drivers
-    BdsConnectAllDrivers ();
-
-    // Search again into all the drivers
-    Status = RemovableDevice->GetDevice (RemovableDevicePath, DeviceHandle, NewDevicePath);
-  }
-
-  return Status;
-}
-
-/**
-  Connect a Device Path and return the handle of the driver that support this DevicePath
-
-  @param  DevicePath            Device Path of the File to connect
-  @param  Handle                Handle of the driver that support this DevicePath
-  @param  RemainingDevicePath   Remaining DevicePath nodes that do not match the driver DevicePath
-
-  @retval EFI_SUCCESS           A driver that matches the Device Path has been found
-  @retval EFI_NOT_FOUND         No handles match the search.
-  @retval EFI_INVALID_PARAMETER DevicePath or Handle is NULL
-
-**/
-EFI_STATUS
-BdsConnectDevicePath (
-  IN  EFI_DEVICE_PATH_PROTOCOL* DevicePath,
-  OUT EFI_HANDLE                *Handle,
-  OUT EFI_DEVICE_PATH_PROTOCOL  **RemainingDevicePath
-  )
-{
-  EFI_DEVICE_PATH*            Remaining;
-  EFI_DEVICE_PATH*            NewDevicePath;
-  EFI_STATUS                  Status;
-
-  if ((DevicePath == NULL) || (Handle == NULL)) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  do {
-    Remaining = DevicePath;
-    // The LocateDevicePath() function locates all devices on DevicePath that support Protocol and returns
-    // the handle to the device that is closest to DevicePath. On output, the device path pointer is modified
-    // to point to the remaining part of the device path
-    Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &Remaining, Handle);
-    if (!EFI_ERROR (Status)) {
-      // Recursive = FALSE: We do not want to start all the device tree
-      Status = gBS->ConnectController (*Handle, NULL, Remaining, FALSE);
-    }
-
-    /*// We need to check if RemainingDevicePath does not point on the last node. Otherwise, calling
-    // NextDevicePathNode() will return an undetermined Device Path Node
-    if (!IsDevicePathEnd (RemainingDevicePath)) {
-      RemainingDevicePath = NextDevicePathNode (RemainingDevicePath);
-    }*/
-  } while (!EFI_ERROR (Status) && !IsDevicePathEnd (Remaining));
-
-  if (!EFI_ERROR (Status)) {
-    // Now, we have got the whole Device Path connected, call again ConnectController to ensure all the supported Driver
-    // Binding Protocol are connected (such as DiskIo and SimpleFileSystem)
-    Remaining = DevicePath;
-    Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid,&Remaining,Handle);
-    if (!EFI_ERROR (Status)) {
-      Status = gBS->ConnectController (*Handle, NULL, Remaining, FALSE);
-      if (EFI_ERROR (Status)) {
-        // If the last node is a Memory Map Device Path just return EFI_SUCCESS.
-        if ((Remaining->Type == HARDWARE_DEVICE_PATH) && (Remaining->SubType == HW_MEMMAP_DP)) {
-            Status = EFI_SUCCESS;
-        }
-      }
-    }
-  } else if (!IsDevicePathEnd (Remaining) && !IsRemovableDevice (Remaining)) {
-
-    /*// If the remaining Device Path is a FilePath or MemoryMap then we consider the Device Path has been loaded correctly
-    if ((Remaining->Type == MEDIA_DEVICE_PATH) && (Remaining->SubType == MEDIA_FILEPATH_DP)) {
-      Status = EFI_SUCCESS;
-    } else if ((Remaining->Type == HARDWARE_DEVICE_PATH) && (Remaining->SubType == HW_MEMMAP_DP)) {
-      Status = EFI_SUCCESS;
-    }*/
-
-    //TODO: Should we just return success and leave the caller decide if it is the expected RemainingPath
-    Status = EFI_SUCCESS;
-  } else {
-    Status = TryRemovableDevice (DevicePath, Handle, &NewDevicePath);
-    if (!EFI_ERROR (Status)) {
-      return BdsConnectDevicePath (NewDevicePath, Handle, RemainingDevicePath);
-    }
-  }
-
-  if (RemainingDevicePath) {
-    *RemainingDevicePath = Remaining;
-  }
-
-  return Status;
-}
-
-BOOLEAN
-BdsFileSystemSupport (
-  IN EFI_DEVICE_PATH *DevicePath,
-  IN EFI_HANDLE Handle,
-  IN EFI_DEVICE_PATH *RemainingDevicePath
-  )
-{
-  EFI_STATUS  Status;
-  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL     *FsProtocol;
-
-  Status = gBS->HandleProtocol (Handle,&gEfiSimpleFileSystemProtocolGuid, (VOID **)&FsProtocol);
-
-  return (!EFI_ERROR(Status) && IS_DEVICE_PATH_NODE(RemainingDevicePath,MEDIA_DEVICE_PATH,MEDIA_FILEPATH_DP));
-}
-
-EFI_STATUS
-BdsFileSystemLoadImage (
-  IN     EFI_DEVICE_PATH *DevicePath,
-  IN     EFI_HANDLE Handle,
-  IN     EFI_DEVICE_PATH *RemainingDevicePath,
-  IN     EFI_ALLOCATE_TYPE     Type,
-  IN OUT EFI_PHYSICAL_ADDRESS* Image,
-  OUT    UINTN                 *ImageSize
-  )
-{
-  FILEPATH_DEVICE_PATH*             FilePathDevicePath;
-  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL     *FsProtocol;
-  EFI_FILE_PROTOCOL                   *Fs;
-  EFI_STATUS Status;
-  EFI_FILE_INFO       *FileInfo;
-  EFI_FILE_PROTOCOL   *File;
-  UINTN               Size;
-
-  ASSERT (IS_DEVICE_PATH_NODE(RemainingDevicePath,MEDIA_DEVICE_PATH,MEDIA_FILEPATH_DP));
-
-  FilePathDevicePath = (FILEPATH_DEVICE_PATH*)RemainingDevicePath;
-
-  Status = gBS->HandleProtocol(Handle,&gEfiSimpleFileSystemProtocolGuid, (VOID **)&FsProtocol);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  // Try to Open the volume and get root directory
-  Status = FsProtocol->OpenVolume (FsProtocol, &Fs);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  File = NULL;
-  Status = Fs->Open(Fs, &File, FilePathDevicePath->PathName, EFI_FILE_MODE_READ, 0);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  Size = 0;
-  File->GetInfo(File, &gEfiFileInfoGuid, &Size, NULL);
-  FileInfo = AllocatePool (Size);
-  Status = File->GetInfo(File, &gEfiFileInfoGuid, &Size, FileInfo);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  // Get the file size
-  Size = FileInfo->FileSize;
-  if (ImageSize) {
-    *ImageSize = Size;
-  }
-  FreePool(FileInfo);
-
-  Status = gBS->AllocatePages (Type, EfiBootServicesCode, EFI_SIZE_TO_PAGES(Size), Image);
-  // Try to allocate in any pages if failed to allocate memory at the defined location
-  if ((Status == EFI_OUT_OF_RESOURCES) && (Type != AllocateAnyPages)) {
-    Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesCode, EFI_SIZE_TO_PAGES(Size), Image);
-  }
-  if (!EFI_ERROR(Status)) {
-    Status = File->Read (File, &Size, (VOID*)(UINTN)(*Image));
-  }
-
-  return Status;
-}
-
-BOOLEAN
-BdsMemoryMapSupport (
-  IN EFI_DEVICE_PATH *DevicePath,
-  IN EFI_HANDLE Handle,
-  IN EFI_DEVICE_PATH *RemainingDevicePath
-  )
-{
-  return IS_DEVICE_PATH_NODE(DevicePath,HARDWARE_DEVICE_PATH,HW_MEMMAP_DP) ||
-         IS_DEVICE_PATH_NODE(RemainingDevicePath,HARDWARE_DEVICE_PATH,HW_MEMMAP_DP);
-}
-
-EFI_STATUS
-BdsMemoryMapLoadImage (
-  IN     EFI_DEVICE_PATH *DevicePath,
-  IN     EFI_HANDLE Handle,
-  IN     EFI_DEVICE_PATH *RemainingDevicePath,
-  IN     EFI_ALLOCATE_TYPE     Type,
-  IN OUT EFI_PHYSICAL_ADDRESS* Image,
-  OUT    UINTN                 *ImageSize
-  )
-{
-  EFI_STATUS            Status;
-  MEMMAP_DEVICE_PATH*   MemMapPathDevicePath;
-  UINTN                 Size;
-
-  if (IS_DEVICE_PATH_NODE(RemainingDevicePath,HARDWARE_DEVICE_PATH,HW_MEMMAP_DP)) {
-    MemMapPathDevicePath = (MEMMAP_DEVICE_PATH*)RemainingDevicePath;
-  } else {
-    ASSERT (IS_DEVICE_PATH_NODE(DevicePath,HARDWARE_DEVICE_PATH,HW_MEMMAP_DP));
-    MemMapPathDevicePath = (MEMMAP_DEVICE_PATH*)DevicePath;
-  }
-
-  Size = MemMapPathDevicePath->EndingAddress - MemMapPathDevicePath->StartingAddress;
-  if (Size == 0) {
-      return EFI_INVALID_PARAMETER;
-  }
-
-  Status = gBS->AllocatePages (Type, EfiBootServicesCode, EFI_SIZE_TO_PAGES(Size), Image);
-  // Try to allocate in any pages if failed to allocate memory at the defined location
-  if ((Status == EFI_OUT_OF_RESOURCES) && (Type != AllocateAnyPages)) {
-    Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesCode, EFI_SIZE_TO_PAGES(Size), Image);
-  }
-  if (!EFI_ERROR(Status)) {
-    CopyMem ((VOID*)(UINTN)(*Image), (CONST VOID*)(UINTN)MemMapPathDevicePath->StartingAddress, Size);
-
-    if (ImageSize != NULL) {
-        *ImageSize = Size;
-    }
-  }
-
-  return Status;
-}
-
-BOOLEAN
-BdsFirmwareVolumeSupport (
-  IN EFI_DEVICE_PATH *DevicePath,
-  IN EFI_HANDLE Handle,
-  IN EFI_DEVICE_PATH *RemainingDevicePath
-  )
-{
-  return IS_DEVICE_PATH_NODE(RemainingDevicePath, MEDIA_DEVICE_PATH, MEDIA_PIWG_FW_FILE_DP);
-}
-
-EFI_STATUS
-BdsFirmwareVolumeLoadImage (
-  IN     EFI_DEVICE_PATH *DevicePath,
-  IN     EFI_HANDLE Handle,
-  IN     EFI_DEVICE_PATH *RemainingDevicePath,
-  IN     EFI_ALLOCATE_TYPE     Type,
-  IN OUT EFI_PHYSICAL_ADDRESS* Image,
-  OUT    UINTN                 *ImageSize
-  )
-{
-  EFI_STATUS            Status;
-  EFI_FIRMWARE_VOLUME2_PROTOCOL     *FwVol;
-  EFI_GUID                          *FvNameGuid;
-  EFI_SECTION_TYPE                  SectionType;
-  EFI_FV_FILETYPE                   FvType;
-  EFI_FV_FILE_ATTRIBUTES            Attrib;
-  UINT32                            AuthenticationStatus;
-  VOID* ImageBuffer;
-
-  ASSERT (IS_DEVICE_PATH_NODE(RemainingDevicePath, MEDIA_DEVICE_PATH, MEDIA_PIWG_FW_FILE_DP));
-
-  Status = gBS->HandleProtocol(Handle,&gEfiFirmwareVolume2ProtocolGuid, (VOID **)&FwVol);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  FvNameGuid = EfiGetNameGuidFromFwVolDevicePathNode ((CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)RemainingDevicePath);
-  if (FvNameGuid == NULL) {
-    Status = EFI_INVALID_PARAMETER;
-  }
-
-  SectionType = EFI_SECTION_PE32;
-  AuthenticationStatus = 0;
-  //Note: ReadSection at the opposite of ReadFile does not allow to pass ImageBuffer == NULL to get the size of the file.
-  ImageBuffer = NULL;
-  Status = FwVol->ReadSection (
-                    FwVol,
-                    FvNameGuid,
-                    SectionType,
-                    0,
-                    &ImageBuffer,
-                    ImageSize,
-                    &AuthenticationStatus
-                    );
-  if (!EFI_ERROR (Status)) {
-#if 0
-    // In case the buffer has some address requirements, we must copy the buffer to a buffer following the requirements
-    if (Type != AllocateAnyPages) {
-      Status = gBS->AllocatePages (Type, EfiBootServicesCode, EFI_SIZE_TO_PAGES(*ImageSize),Image);
-      if (!EFI_ERROR(Status)) {
-        CopyMem ((VOID*)(UINTN)(*Image), ImageBuffer, *ImageSize);
-        FreePool (ImageBuffer);
-      }
-    }
-#else
-    // We must copy the buffer into a page allocations. Otherwise, the caller could call gBS->FreePages() on the pool allocation
-    Status = gBS->AllocatePages (Type, EfiBootServicesCode, EFI_SIZE_TO_PAGES(*ImageSize), Image);
-    // Try to allocate in any pages if failed to allocate memory at the defined location
-    if ((Status == EFI_OUT_OF_RESOURCES) && (Type != AllocateAnyPages)) {
-      Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesCode, EFI_SIZE_TO_PAGES(*ImageSize), Image);
-    }
-    if (!EFI_ERROR(Status)) {
-      CopyMem ((VOID*)(UINTN)(*Image), ImageBuffer, *ImageSize);
-      FreePool (ImageBuffer);
-    }
-#endif
-  } else {
-    // Try a raw file, since a PE32 SECTION does not exist
-    Status = FwVol->ReadFile (
-                        FwVol,
-                        FvNameGuid,
-                        NULL,
-                        ImageSize,
-                        &FvType,
-                        &Attrib,
-                        &AuthenticationStatus
-                        );
-    if (!EFI_ERROR(Status)) {
-      Status = gBS->AllocatePages (Type, EfiBootServicesCode, EFI_SIZE_TO_PAGES(*ImageSize), Image);
-      // Try to allocate in any pages if failed to allocate memory at the defined location
-      if ((Status == EFI_OUT_OF_RESOURCES) && (Type != AllocateAnyPages)) {
-        Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesCode, EFI_SIZE_TO_PAGES(*ImageSize), Image);
-      }
-      if (!EFI_ERROR(Status)) {
-        Status = FwVol->ReadFile (
-                                FwVol,
-                                FvNameGuid,
-                                (VOID*)(UINTN)(*Image),
-                                ImageSize,
-                                &FvType,
-                                &Attrib,
-                                &AuthenticationStatus
-                                );
-      }
-    }
-  }
-  return Status;
-}
-
-BOOLEAN
-BdsPxeSupport (
-  IN EFI_DEVICE_PATH*           DevicePath,
-  IN EFI_HANDLE                 Handle,
-  IN EFI_DEVICE_PATH*           RemainingDevicePath
-  )
-{
-  EFI_STATUS                  Status;
-  EFI_PXE_BASE_CODE_PROTOCOL* PxeBcProtocol;
-
-  if (!IsDevicePathEnd(RemainingDevicePath)) {
-    return FALSE;
-  }
-
-  Status = gBS->HandleProtocol (Handle, &gEfiPxeBaseCodeProtocolGuid, (VOID **)&PxeBcProtocol);
-  if (EFI_ERROR (Status)) {
-    return FALSE;
-  } else {
-    return TRUE;
-  }
-}
-
-EFI_STATUS
-BdsPxeLoadImage (
-  IN     EFI_DEVICE_PATH*       DevicePath,
-  IN     EFI_HANDLE             Handle,
-  IN     EFI_DEVICE_PATH*       RemainingDevicePath,
-  IN     EFI_ALLOCATE_TYPE      Type,
-  IN OUT EFI_PHYSICAL_ADDRESS   *Image,
-  OUT    UINTN                  *ImageSize
-  )
-{
-  EFI_STATUS              Status;
-  EFI_LOAD_FILE_PROTOCOL  *LoadFileProtocol;
-  UINTN                   BufferSize;
-
-  // Get Load File Protocol attached to the PXE protocol
-  Status = gBS->HandleProtocol (Handle, &gEfiLoadFileProtocolGuid, (VOID **)&LoadFileProtocol);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  Status = LoadFileProtocol->LoadFile (LoadFileProtocol, DevicePath, TRUE, &BufferSize, NULL);
-  if (Status == EFI_BUFFER_TOO_SMALL) {
-    Status = gBS->AllocatePages (Type, EfiBootServicesCode, EFI_SIZE_TO_PAGES(BufferSize), Image);
-    if (EFI_ERROR(Status)) {
-      return Status;
-    }
-
-    Status = LoadFileProtocol->LoadFile (LoadFileProtocol, DevicePath, TRUE, &BufferSize, (VOID*)(UINTN)(*Image));
-    if (!EFI_ERROR(Status) && (ImageSize != NULL)) {
-      *ImageSize = BufferSize;
-    }
-  }
-
-  return Status;
-}
-
-BOOLEAN
-BdsTftpSupport (
-  IN EFI_DEVICE_PATH*           DevicePath,
-  IN EFI_HANDLE                 Handle,
-  IN EFI_DEVICE_PATH*           RemainingDevicePath
-  )
-{
-  EFI_STATUS  Status;
-  EFI_DEVICE_PATH  *NextDevicePath;
-  EFI_PXE_BASE_CODE_PROTOCOL  *PxeBcProtocol;
-
-  // Validate the Remaining Device Path
-  if (IsDevicePathEnd(RemainingDevicePath)) {
-    return FALSE;
-  }
-  if (!IS_DEVICE_PATH_NODE(RemainingDevicePath,MESSAGING_DEVICE_PATH,MSG_IPv4_DP) &&
-      !IS_DEVICE_PATH_NODE(RemainingDevicePath,MESSAGING_DEVICE_PATH,MSG_IPv6_DP)) {
-    return FALSE;
-  }
-  NextDevicePath = NextDevicePathNode (RemainingDevicePath);
-  if (IsDevicePathEnd(NextDevicePath)) {
-    return FALSE;
-  }
-  if (!IS_DEVICE_PATH_NODE(NextDevicePath,MEDIA_DEVICE_PATH,MEDIA_FILEPATH_DP)) {
-    return FALSE;
-  }
-
-  Status = gBS->HandleProtocol (Handle, &gEfiPxeBaseCodeProtocolGuid, (VOID **)&PxeBcProtocol);
-  if (EFI_ERROR (Status)) {
-    return FALSE;
-  } else {
-    return TRUE;
-  }
-}
-
-EFI_STATUS
-BdsTftpLoadImage (
-  IN     EFI_DEVICE_PATH*       DevicePath,
-  IN     EFI_HANDLE             Handle,
-  IN     EFI_DEVICE_PATH*       RemainingDevicePath,
-  IN     EFI_ALLOCATE_TYPE      Type,
-  IN OUT EFI_PHYSICAL_ADDRESS   *Image,
-  OUT    UINTN                  *ImageSize
-  )
-{
-  EFI_STATUS                  Status;
-  EFI_PXE_BASE_CODE_PROTOCOL  *Pxe;
-  UINT64                      TftpBufferSize;
-  VOID*                       TftpBuffer;
-  EFI_IP_ADDRESS              ServerIp;
-  IPv4_DEVICE_PATH*           IPv4DevicePathNode;
-  FILEPATH_DEVICE_PATH*       FilePathDevicePath;
-  EFI_IP_ADDRESS              LocalIp;
-
-  ASSERT(IS_DEVICE_PATH_NODE(RemainingDevicePath,MESSAGING_DEVICE_PATH,MSG_IPv4_DP));
-
-  IPv4DevicePathNode = (IPv4_DEVICE_PATH*)RemainingDevicePath;
-  FilePathDevicePath = (FILEPATH_DEVICE_PATH*)(IPv4DevicePathNode + 1);
-
-  Status = gBS->LocateProtocol (&gEfiPxeBaseCodeProtocolGuid, NULL, (VOID **)&Pxe);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  Status = Pxe->Start (Pxe, FALSE);
-  if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) {
-    return Status;
-  }
-
-  if (!IPv4DevicePathNode->StaticIpAddress) {
-    Status = Pxe->Dhcp(Pxe, TRUE);
-  } else {
-    CopyMem (&LocalIp.v4, &IPv4DevicePathNode->LocalIpAddress, sizeof (EFI_IPv4_ADDRESS));
-    Status = Pxe->SetStationIp (Pxe, &LocalIp, NULL);
-  }
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  CopyMem (&ServerIp.v4, &IPv4DevicePathNode->RemoteIpAddress, sizeof (EFI_IPv4_ADDRESS));
-
-  Status = Pxe->Mtftp (
-                  Pxe,
-                  EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE,
-                  NULL,
-                  FALSE,
-                  &TftpBufferSize,
-                  NULL,
-                  &ServerIp,
-                  (UINT8 *)FilePathDevicePath->PathName,
-                  NULL,
-                  TRUE
-                  );
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  // Allocate a buffer to hold the whole file.
-  TftpBuffer = AllocatePool(TftpBufferSize);
-  if (TftpBuffer == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  Status = Pxe->Mtftp (
-                  Pxe,
-                  EFI_PXE_BASE_CODE_TFTP_READ_FILE,
-                  TftpBuffer,
-                  FALSE,
-                  &TftpBufferSize,
-                  NULL,
-                  &ServerIp,
-                  (UINT8 *)FilePathDevicePath->PathName,
-                  NULL,
-                  FALSE
-                  );
-  if (EFI_ERROR(Status)) {
-    FreePool(TftpBuffer);
-  } else if (ImageSize != NULL) {
-    *ImageSize = (UINTN)TftpBufferSize;
-  }
-
-  return Status;
-}
-
-BDS_FILE_LOADER FileLoaders[] = {
-    { BdsFileSystemSupport, BdsFileSystemLoadImage },
-    { BdsFirmwareVolumeSupport, BdsFirmwareVolumeLoadImage },
-    //{ BdsLoadFileSupport, BdsLoadFileLoadImage },
-    { BdsMemoryMapSupport, BdsMemoryMapLoadImage },
-    { BdsPxeSupport, BdsPxeLoadImage },
-    { BdsTftpSupport, BdsTftpLoadImage },
-    { NULL, NULL }
-};
-
-EFI_STATUS
-BdsLoadImage (
-  IN     EFI_DEVICE_PATH       *DevicePath,
-  IN     EFI_ALLOCATE_TYPE     Type,
-  IN OUT EFI_PHYSICAL_ADDRESS* Image,
-  OUT    UINTN                 *FileSize
-  )
-{
-  EFI_STATUS      Status;
-  EFI_HANDLE      Handle;
-  EFI_DEVICE_PATH *RemainingDevicePath;
-  BDS_FILE_LOADER*  FileLoader;
-
-  Status = BdsConnectDevicePath (DevicePath, &Handle, &RemainingDevicePath);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  FileLoader = FileLoaders;
-  while (FileLoader->Support != NULL) {
-    if (FileLoader->Support (DevicePath, Handle, RemainingDevicePath)) {
-      return FileLoader->LoadImage (DevicePath, Handle, RemainingDevicePath, Type, Image, FileSize);
-    }
-    FileLoader++;
-  }
-
-  return EFI_UNSUPPORTED;
-}
-
-/**
-  Start an EFI Application from a Device Path
-
-  @param  ParentImageHandle     Handle of the calling image
-  @param  DevicePath            Location of the EFI Application
-
-  @retval EFI_SUCCESS           All drivers have been connected
-  @retval EFI_NOT_FOUND         The Linux kernel Device Path has not been found
-  @retval EFI_OUT_OF_RESOURCES  There is not enough resource memory to store the matching results.
-
-**/
-EFI_STATUS
-BdsStartEfiApplication (
-  IN EFI_HANDLE                  ParentImageHandle,
-  IN EFI_DEVICE_PATH_PROTOCOL    *DevicePath,
-  IN UINTN                       LoadOptionsSize,
-  IN VOID*                       LoadOptions
-  )
-{
-  EFI_STATUS                   Status;
-  EFI_HANDLE                   ImageHandle;
-  EFI_PHYSICAL_ADDRESS         BinaryBuffer;
-  UINTN                        BinarySize;
-  EFI_LOADED_IMAGE_PROTOCOL*   LoadedImage;
-
-  // Find the nearest supported file loader
-  Status = BdsLoadImage (DevicePath, AllocateAnyPages, &BinaryBuffer, &BinarySize);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  // Load the image from the Buffer with Boot Services function
-  Status = gBS->LoadImage (TRUE, ParentImageHandle, DevicePath, (VOID*)(UINTN)BinaryBuffer, BinarySize, &ImageHandle);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  // Passed LoadOptions to the EFI Application
-  if (LoadOptionsSize != 0) {
-    Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);
-    if (EFI_ERROR(Status)) {
-      return Status;
-    }
-
-    LoadedImage->LoadOptionsSize  = LoadOptionsSize;
-    LoadedImage->LoadOptions      = LoadOptions;
-  }
-
-  // Before calling the image, enable the Watchdog Timer for  the 5 Minute period
-  gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);
-  // Start the image
-  Status = gBS->StartImage (ImageHandle, NULL, NULL);
-  // Clear the Watchdog Timer after the image returns
-  gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);
-
-  return Status;
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include "BdsInternal.h"\r
+\r
+#include <Protocol/UsbIo.h>\r
+#include <Protocol/DiskIo.h>\r
+#include <Protocol/LoadedImage.h>\r
+\r
+#define IS_DEVICE_PATH_NODE(node,type,subtype) (((node)->Type == (type)) && ((node)->SubType == (subtype)))\r
+\r
+// Extract the FilePath from the Device Path\r
+CHAR16*\r
+BdsExtractFilePathFromDevicePath (\r
+  IN  CONST CHAR16    *StrDevicePath,\r
+  IN  UINTN           NumberDevicePathNode\r
+  )\r
+{\r
+  UINTN       Node;\r
+  CHAR16      *Str;\r
+\r
+  Str = (CHAR16*)StrDevicePath;\r
+  Node = 0;\r
+  while ((Str != NULL) && (*Str != L'\0') && (Node < NumberDevicePathNode)) {\r
+    if ((*Str == L'/') || (*Str == L'\\')) {\r
+        Node++;\r
+    }\r
+    Str++;\r
+  }\r
+\r
+  if (*Str == L'\0') {\r
+    return NULL;\r
+  } else {\r
+    return Str;\r
+  }\r
+}\r
+\r
+BOOLEAN\r
+BdsIsRemovableUsb (\r
+  IN  EFI_DEVICE_PATH*  DevicePath\r
+  )\r
+{\r
+  return ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&\r
+          ((DevicePathSubType (DevicePath) == MSG_USB_CLASS_DP) ||\r
+           (DevicePathSubType (DevicePath) == MSG_USB_WWID_DP)));\r
+}\r
+\r
+EFI_STATUS\r
+BdsGetDeviceUsb (\r
+  IN  EFI_DEVICE_PATH*  RemovableDevicePath,\r
+  OUT EFI_HANDLE*       DeviceHandle,\r
+  OUT EFI_DEVICE_PATH** NewDevicePath\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  UINTN                         Index;\r
+  UINTN                         UsbIoHandleCount;\r
+  EFI_HANDLE                    *UsbIoBuffer;\r
+  EFI_DEVICE_PATH*              UsbIoDevicePath;\r
+  EFI_DEVICE_PATH*              TmpDevicePath;\r
+  USB_WWID_DEVICE_PATH*         WwidDevicePath1;\r
+  USB_WWID_DEVICE_PATH*         WwidDevicePath2;\r
+  USB_CLASS_DEVICE_PATH*        UsbClassDevicePath1;\r
+  USB_CLASS_DEVICE_PATH*        UsbClassDevicePath2;\r
+\r
+  // Get all the UsbIo handles\r
+  UsbIoHandleCount = 0;\r
+  Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiUsbIoProtocolGuid, NULL, &UsbIoHandleCount, &UsbIoBuffer);\r
+  if (EFI_ERROR(Status) || (UsbIoHandleCount == 0)) {\r
+    return Status;\r
+  }\r
+\r
+  // Check if one of the handles matches the USB description\r
+  for (Index = 0; Index < UsbIoHandleCount; Index++) {\r
+    Status = gBS->HandleProtocol (UsbIoBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID **) &UsbIoDevicePath);\r
+    if (!EFI_ERROR(Status)) {\r
+      TmpDevicePath = UsbIoDevicePath;\r
+      while (!IsDevicePathEnd (TmpDevicePath)) {\r
+        // Check if the Device Path node is a USB Removable device Path node\r
+        if (BdsIsRemovableUsb (TmpDevicePath)) {\r
+          if (TmpDevicePath->SubType == MSG_USB_WWID_DP) {\r
+            WwidDevicePath1 = (USB_WWID_DEVICE_PATH*)RemovableDevicePath;\r
+            WwidDevicePath2 = (USB_WWID_DEVICE_PATH*)TmpDevicePath;\r
+            if ((WwidDevicePath1->VendorId == WwidDevicePath2->VendorId) &&\r
+                (WwidDevicePath1->ProductId == WwidDevicePath2->ProductId) &&\r
+                (CompareMem (WwidDevicePath1+1, WwidDevicePath2+1, DevicePathNodeLength(WwidDevicePath1)-sizeof(USB_WWID_DEVICE_PATH)) == 0))\r
+            {\r
+              *DeviceHandle = UsbIoBuffer[Index];\r
+              // Add the additional original Device Path Nodes (eg: FilePath Device Path Node) to the new Device Path\r
+              *NewDevicePath = AppendDevicePath (UsbIoDevicePath, NextDevicePathNode(RemovableDevicePath));\r
+              return EFI_SUCCESS;\r
+            }\r
+          } else {\r
+            UsbClassDevicePath1 = (USB_CLASS_DEVICE_PATH*)RemovableDevicePath;\r
+            UsbClassDevicePath2 = (USB_CLASS_DEVICE_PATH*)TmpDevicePath;\r
+            if ((UsbClassDevicePath1->VendorId != 0xFFFF) && (UsbClassDevicePath1->VendorId == UsbClassDevicePath2->VendorId) &&\r
+                (UsbClassDevicePath1->ProductId != 0xFFFF) && (UsbClassDevicePath1->ProductId == UsbClassDevicePath2->ProductId) &&\r
+                (UsbClassDevicePath1->DeviceClass != 0xFF) && (UsbClassDevicePath1->DeviceClass == UsbClassDevicePath2->DeviceClass) &&\r
+                (UsbClassDevicePath1->DeviceSubClass != 0xFF) && (UsbClassDevicePath1->DeviceSubClass == UsbClassDevicePath2->DeviceSubClass) &&\r
+                (UsbClassDevicePath1->DeviceProtocol != 0xFF) && (UsbClassDevicePath1->DeviceProtocol == UsbClassDevicePath2->DeviceProtocol))\r
+            {\r
+              *DeviceHandle = UsbIoBuffer[Index];\r
+              // Add the additional original Device Path Nodes (eg: FilePath Device Path Node) to the new Device Path\r
+              *NewDevicePath = AppendDevicePath (UsbIoDevicePath, NextDevicePathNode(RemovableDevicePath));\r
+              return EFI_SUCCESS;\r
+            }\r
+          }\r
+        }\r
+        TmpDevicePath = NextDevicePathNode (TmpDevicePath);\r
+      }\r
+\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+BOOLEAN\r
+BdsIsRemovableHd (\r
+  IN  EFI_DEVICE_PATH*  DevicePath\r
+  )\r
+{\r
+  return IS_DEVICE_PATH_NODE(DevicePath, MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP);\r
+}\r
+\r
+EFI_STATUS\r
+BdsGetDeviceHd (\r
+  IN  EFI_DEVICE_PATH*  RemovableDevicePath,\r
+  OUT EFI_HANDLE*       DeviceHandle,\r
+  OUT EFI_DEVICE_PATH** NewDevicePath\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  UINTN                         Index;\r
+  UINTN                         PartitionHandleCount;\r
+  EFI_HANDLE                    *PartitionBuffer;\r
+  EFI_DEVICE_PATH*              PartitionDevicePath;\r
+  EFI_DEVICE_PATH*              TmpDevicePath;\r
+  HARDDRIVE_DEVICE_PATH*        HardDriveDevicePath1;\r
+  HARDDRIVE_DEVICE_PATH*        HardDriveDevicePath2;\r
+\r
+  // Get all the DiskIo handles\r
+  PartitionHandleCount = 0;\r
+  Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiDiskIoProtocolGuid, NULL, &PartitionHandleCount, &PartitionBuffer);\r
+  if (EFI_ERROR(Status) || (PartitionHandleCount == 0)) {\r
+    return Status;\r
+  }\r
+\r
+  // Check if one of the handles matches the Hard Disk Description\r
+  for (Index = 0; Index < PartitionHandleCount; Index++) {\r
+    Status = gBS->HandleProtocol (PartitionBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID **) &PartitionDevicePath);\r
+    if (!EFI_ERROR(Status)) {\r
+      TmpDevicePath = PartitionDevicePath;\r
+      while (!IsDevicePathEnd (TmpDevicePath)) {\r
+        // Check if the Device Path node is a HD Removable device Path node\r
+        if (BdsIsRemovableHd (TmpDevicePath)) {\r
+          HardDriveDevicePath1 = (HARDDRIVE_DEVICE_PATH*)RemovableDevicePath;\r
+          HardDriveDevicePath2 = (HARDDRIVE_DEVICE_PATH*)TmpDevicePath;\r
+          if ((HardDriveDevicePath1->SignatureType == HardDriveDevicePath2->SignatureType) &&\r
+              (CompareGuid ((EFI_GUID *)HardDriveDevicePath1->Signature,(EFI_GUID *)HardDriveDevicePath2->Signature) == TRUE) &&\r
+              (HardDriveDevicePath1->PartitionNumber == HardDriveDevicePath2->PartitionNumber))\r
+          {\r
+            *DeviceHandle = PartitionBuffer[Index];\r
+            // Add the additional original Device Path Nodes (eg: FilePath Device Path Node) to the new Device Path\r
+            *NewDevicePath = AppendDevicePath (PartitionDevicePath, NextDevicePathNode(RemovableDevicePath));\r
+            return EFI_SUCCESS;\r
+          }\r
+        }\r
+        TmpDevicePath = NextDevicePathNode (TmpDevicePath);\r
+      }\r
+\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+/*BOOLEAN\r
+BdsIsRemovableCdrom (\r
+  IN  EFI_DEVICE_PATH*  DevicePath\r
+  )\r
+{\r
+  return IS_DEVICE_PATH_NODE(DevicePath, MEDIA_DEVICE_PATH, MEDIA_CDROM_DP);\r
+}\r
+\r
+EFI_STATUS\r
+BdsGetDeviceCdrom (\r
+  IN  EFI_DEVICE_PATH*  RemovableDevicePath,\r
+  OUT EFI_HANDLE*       DeviceHandle,\r
+  OUT EFI_DEVICE_PATH** DevicePath\r
+  )\r
+{\r
+  ASSERT(0);\r
+  return EFI_UNSUPPORTED;\r
+}*/\r
+\r
+typedef BOOLEAN\r
+(*BDS_IS_REMOVABLE) (\r
+  IN  EFI_DEVICE_PATH*  DevicePath\r
+  );\r
+\r
+typedef EFI_STATUS\r
+(*BDS_GET_DEVICE) (\r
+  IN  EFI_DEVICE_PATH*  RemovableDevicePath,\r
+  OUT EFI_HANDLE*       DeviceHandle,\r
+  OUT EFI_DEVICE_PATH** DevicePath\r
+  );\r
+\r
+typedef struct {\r
+  BDS_IS_REMOVABLE    IsRemovable;\r
+  BDS_GET_DEVICE      GetDevice;\r
+} BDS_REMOVABLE_DEVICE_SUPPORT;\r
+\r
+BDS_REMOVABLE_DEVICE_SUPPORT  RemovableDeviceSupport[] = {\r
+  { BdsIsRemovableUsb, BdsGetDeviceUsb },\r
+  { BdsIsRemovableHd, BdsGetDeviceHd },\r
+  //{ BdsIsRemovableCdrom, BdsGetDeviceCdrom }\r
+};\r
+\r
+STATIC\r
+BOOLEAN\r
+IsRemovableDevice (\r
+  IN  EFI_DEVICE_PATH*  DevicePath\r
+  )\r
+{\r
+  UINTN             Index;\r
+  EFI_DEVICE_PATH*  TmpDevicePath;\r
+\r
+  TmpDevicePath = DevicePath;\r
+  while (!IsDevicePathEnd (TmpDevicePath)) {\r
+    for (Index = 0; Index < sizeof(RemovableDeviceSupport) / sizeof(BDS_REMOVABLE_DEVICE_SUPPORT); Index++) {\r
+      if (RemovableDeviceSupport[Index].IsRemovable(TmpDevicePath)) {\r
+        return TRUE;\r
+      }\r
+    }\r
+    TmpDevicePath = NextDevicePathNode (TmpDevicePath);\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+TryRemovableDevice (\r
+  IN  EFI_DEVICE_PATH*  DevicePath,\r
+  OUT EFI_HANDLE*       DeviceHandle,\r
+  OUT EFI_DEVICE_PATH** NewDevicePath\r
+  )\r
+{\r
+  EFI_STATUS        Status;\r
+  UINTN             Index;\r
+  EFI_DEVICE_PATH*  TmpDevicePath;\r
+  BDS_REMOVABLE_DEVICE_SUPPORT* RemovableDevice;\r
+  EFI_DEVICE_PATH* RemovableDevicePath;\r
+  BOOLEAN         RemovableFound;\r
+\r
+  RemovableDevice     = NULL;\r
+  RemovableDevicePath = NULL;\r
+  RemovableFound      = FALSE;\r
+  TmpDevicePath       = DevicePath;\r
+\r
+  while (!IsDevicePathEnd (TmpDevicePath) && !RemovableFound) {\r
+    for (Index = 0; Index < sizeof(RemovableDeviceSupport) / sizeof(BDS_REMOVABLE_DEVICE_SUPPORT); Index++) {\r
+      RemovableDevice = &RemovableDeviceSupport[Index];\r
+      if (RemovableDevice->IsRemovable(TmpDevicePath)) {\r
+        RemovableDevicePath = TmpDevicePath;\r
+        RemovableFound = TRUE;\r
+        break;\r
+      }\r
+    }\r
+    TmpDevicePath = NextDevicePathNode (TmpDevicePath);\r
+  }\r
+\r
+  if (!RemovableFound) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  // Search into the current started drivers\r
+  Status = RemovableDevice->GetDevice (RemovableDevicePath, DeviceHandle, NewDevicePath);\r
+  if (Status == EFI_NOT_FOUND) {\r
+    // Connect all the drivers\r
+    BdsConnectAllDrivers ();\r
+\r
+    // Search again into all the drivers\r
+    Status = RemovableDevice->GetDevice (RemovableDevicePath, DeviceHandle, NewDevicePath);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Connect a Device Path and return the handle of the driver that support this DevicePath\r
+\r
+  @param  DevicePath            Device Path of the File to connect\r
+  @param  Handle                Handle of the driver that support this DevicePath\r
+  @param  RemainingDevicePath   Remaining DevicePath nodes that do not match the driver DevicePath\r
+\r
+  @retval EFI_SUCCESS           A driver that matches the Device Path has been found\r
+  @retval EFI_NOT_FOUND         No handles match the search.\r
+  @retval EFI_INVALID_PARAMETER DevicePath or Handle is NULL\r
+\r
+**/\r
+EFI_STATUS\r
+BdsConnectDevicePath (\r
+  IN  EFI_DEVICE_PATH_PROTOCOL* DevicePath,\r
+  OUT EFI_HANDLE                *Handle,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **RemainingDevicePath\r
+  )\r
+{\r
+  EFI_DEVICE_PATH*            Remaining;\r
+  EFI_DEVICE_PATH*            NewDevicePath;\r
+  EFI_STATUS                  Status;\r
+\r
+  if ((DevicePath == NULL) || (Handle == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  do {\r
+    Remaining = DevicePath;\r
+    // The LocateDevicePath() function locates all devices on DevicePath that support Protocol and returns\r
+    // the handle to the device that is closest to DevicePath. On output, the device path pointer is modified\r
+    // to point to the remaining part of the device path\r
+    Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &Remaining, Handle);\r
+    if (!EFI_ERROR (Status)) {\r
+      // Recursive = FALSE: We do not want to start all the device tree\r
+      Status = gBS->ConnectController (*Handle, NULL, Remaining, FALSE);\r
+    }\r
+\r
+    /*// We need to check if RemainingDevicePath does not point on the last node. Otherwise, calling\r
+    // NextDevicePathNode() will return an undetermined Device Path Node\r
+    if (!IsDevicePathEnd (RemainingDevicePath)) {\r
+      RemainingDevicePath = NextDevicePathNode (RemainingDevicePath);\r
+    }*/\r
+  } while (!EFI_ERROR (Status) && !IsDevicePathEnd (Remaining));\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    // Now, we have got the whole Device Path connected, call again ConnectController to ensure all the supported Driver\r
+    // Binding Protocol are connected (such as DiskIo and SimpleFileSystem)\r
+    Remaining = DevicePath;\r
+    Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid,&Remaining,Handle);\r
+    if (!EFI_ERROR (Status)) {\r
+      Status = gBS->ConnectController (*Handle, NULL, Remaining, FALSE);\r
+      if (EFI_ERROR (Status)) {\r
+        // If the last node is a Memory Map Device Path just return EFI_SUCCESS.\r
+        if ((Remaining->Type == HARDWARE_DEVICE_PATH) && (Remaining->SubType == HW_MEMMAP_DP)) {\r
+            Status = EFI_SUCCESS;\r
+        }\r
+      }\r
+    }\r
+  } else if (!IsDevicePathEnd (Remaining) && !IsRemovableDevice (Remaining)) {\r
+\r
+    /*// If the remaining Device Path is a FilePath or MemoryMap then we consider the Device Path has been loaded correctly\r
+    if ((Remaining->Type == MEDIA_DEVICE_PATH) && (Remaining->SubType == MEDIA_FILEPATH_DP)) {\r
+      Status = EFI_SUCCESS;\r
+    } else if ((Remaining->Type == HARDWARE_DEVICE_PATH) && (Remaining->SubType == HW_MEMMAP_DP)) {\r
+      Status = EFI_SUCCESS;\r
+    }*/\r
+\r
+    //TODO: Should we just return success and leave the caller decide if it is the expected RemainingPath\r
+    Status = EFI_SUCCESS;\r
+  } else {\r
+    Status = TryRemovableDevice (DevicePath, Handle, &NewDevicePath);\r
+    if (!EFI_ERROR (Status)) {\r
+      return BdsConnectDevicePath (NewDevicePath, Handle, RemainingDevicePath);\r
+    }\r
+  }\r
+\r
+  if (RemainingDevicePath) {\r
+    *RemainingDevicePath = Remaining;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+BOOLEAN\r
+BdsFileSystemSupport (\r
+  IN EFI_DEVICE_PATH *DevicePath,\r
+  IN EFI_HANDLE Handle,\r
+  IN EFI_DEVICE_PATH *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL     *FsProtocol;\r
+\r
+  Status = gBS->HandleProtocol (Handle,&gEfiSimpleFileSystemProtocolGuid, (VOID **)&FsProtocol);\r
+\r
+  return (!EFI_ERROR(Status) && IS_DEVICE_PATH_NODE(RemainingDevicePath,MEDIA_DEVICE_PATH,MEDIA_FILEPATH_DP));\r
+}\r
+\r
+EFI_STATUS\r
+BdsFileSystemLoadImage (\r
+  IN     EFI_DEVICE_PATH *DevicePath,\r
+  IN     EFI_HANDLE Handle,\r
+  IN     EFI_DEVICE_PATH *RemainingDevicePath,\r
+  IN     EFI_ALLOCATE_TYPE     Type,\r
+  IN OUT EFI_PHYSICAL_ADDRESS* Image,\r
+  OUT    UINTN                 *ImageSize\r
+  )\r
+{\r
+  FILEPATH_DEVICE_PATH*             FilePathDevicePath;\r
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL     *FsProtocol;\r
+  EFI_FILE_PROTOCOL                   *Fs;\r
+  EFI_STATUS Status;\r
+  EFI_FILE_INFO       *FileInfo;\r
+  EFI_FILE_PROTOCOL   *File;\r
+  UINTN               Size;\r
+\r
+  ASSERT (IS_DEVICE_PATH_NODE(RemainingDevicePath,MEDIA_DEVICE_PATH,MEDIA_FILEPATH_DP));\r
+\r
+  FilePathDevicePath = (FILEPATH_DEVICE_PATH*)RemainingDevicePath;\r
+\r
+  Status = gBS->HandleProtocol(Handle,&gEfiSimpleFileSystemProtocolGuid, (VOID **)&FsProtocol);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  // Try to Open the volume and get root directory\r
+  Status = FsProtocol->OpenVolume (FsProtocol, &Fs);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  File = NULL;\r
+  Status = Fs->Open(Fs, &File, FilePathDevicePath->PathName, EFI_FILE_MODE_READ, 0);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Size = 0;\r
+  File->GetInfo(File, &gEfiFileInfoGuid, &Size, NULL);\r
+  FileInfo = AllocatePool (Size);\r
+  Status = File->GetInfo(File, &gEfiFileInfoGuid, &Size, FileInfo);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  // Get the file size\r
+  Size = FileInfo->FileSize;\r
+  if (ImageSize) {\r
+    *ImageSize = Size;\r
+  }\r
+  FreePool(FileInfo);\r
+\r
+  Status = gBS->AllocatePages (Type, EfiBootServicesCode, EFI_SIZE_TO_PAGES(Size), Image);\r
+  // Try to allocate in any pages if failed to allocate memory at the defined location\r
+  if ((Status == EFI_OUT_OF_RESOURCES) && (Type != AllocateAnyPages)) {\r
+    Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesCode, EFI_SIZE_TO_PAGES(Size), Image);\r
+  }\r
+  if (!EFI_ERROR(Status)) {\r
+    Status = File->Read (File, &Size, (VOID*)(UINTN)(*Image));\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+BOOLEAN\r
+BdsMemoryMapSupport (\r
+  IN EFI_DEVICE_PATH *DevicePath,\r
+  IN EFI_HANDLE Handle,\r
+  IN EFI_DEVICE_PATH *RemainingDevicePath\r
+  )\r
+{\r
+  return IS_DEVICE_PATH_NODE(DevicePath,HARDWARE_DEVICE_PATH,HW_MEMMAP_DP) ||\r
+         IS_DEVICE_PATH_NODE(RemainingDevicePath,HARDWARE_DEVICE_PATH,HW_MEMMAP_DP);\r
+}\r
+\r
+EFI_STATUS\r
+BdsMemoryMapLoadImage (\r
+  IN     EFI_DEVICE_PATH *DevicePath,\r
+  IN     EFI_HANDLE Handle,\r
+  IN     EFI_DEVICE_PATH *RemainingDevicePath,\r
+  IN     EFI_ALLOCATE_TYPE     Type,\r
+  IN OUT EFI_PHYSICAL_ADDRESS* Image,\r
+  OUT    UINTN                 *ImageSize\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  MEMMAP_DEVICE_PATH*   MemMapPathDevicePath;\r
+  UINTN                 Size;\r
+\r
+  if (IS_DEVICE_PATH_NODE(RemainingDevicePath,HARDWARE_DEVICE_PATH,HW_MEMMAP_DP)) {\r
+    MemMapPathDevicePath = (MEMMAP_DEVICE_PATH*)RemainingDevicePath;\r
+  } else {\r
+    ASSERT (IS_DEVICE_PATH_NODE(DevicePath,HARDWARE_DEVICE_PATH,HW_MEMMAP_DP));\r
+    MemMapPathDevicePath = (MEMMAP_DEVICE_PATH*)DevicePath;\r
+  }\r
+\r
+  Size = MemMapPathDevicePath->EndingAddress - MemMapPathDevicePath->StartingAddress;\r
+  if (Size == 0) {\r
+      return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = gBS->AllocatePages (Type, EfiBootServicesCode, EFI_SIZE_TO_PAGES(Size), Image);\r
+  // Try to allocate in any pages if failed to allocate memory at the defined location\r
+  if ((Status == EFI_OUT_OF_RESOURCES) && (Type != AllocateAnyPages)) {\r
+    Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesCode, EFI_SIZE_TO_PAGES(Size), Image);\r
+  }\r
+  if (!EFI_ERROR(Status)) {\r
+    CopyMem ((VOID*)(UINTN)(*Image), (CONST VOID*)(UINTN)MemMapPathDevicePath->StartingAddress, Size);\r
+\r
+    if (ImageSize != NULL) {\r
+        *ImageSize = Size;\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+BOOLEAN\r
+BdsFirmwareVolumeSupport (\r
+  IN EFI_DEVICE_PATH *DevicePath,\r
+  IN EFI_HANDLE Handle,\r
+  IN EFI_DEVICE_PATH *RemainingDevicePath\r
+  )\r
+{\r
+  return IS_DEVICE_PATH_NODE(RemainingDevicePath, MEDIA_DEVICE_PATH, MEDIA_PIWG_FW_FILE_DP);\r
+}\r
+\r
+EFI_STATUS\r
+BdsFirmwareVolumeLoadImage (\r
+  IN     EFI_DEVICE_PATH *DevicePath,\r
+  IN     EFI_HANDLE Handle,\r
+  IN     EFI_DEVICE_PATH *RemainingDevicePath,\r
+  IN     EFI_ALLOCATE_TYPE     Type,\r
+  IN OUT EFI_PHYSICAL_ADDRESS* Image,\r
+  OUT    UINTN                 *ImageSize\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_FIRMWARE_VOLUME2_PROTOCOL     *FwVol;\r
+  EFI_GUID                          *FvNameGuid;\r
+  EFI_SECTION_TYPE                  SectionType;\r
+  EFI_FV_FILETYPE                   FvType;\r
+  EFI_FV_FILE_ATTRIBUTES            Attrib;\r
+  UINT32                            AuthenticationStatus;\r
+  VOID* ImageBuffer;\r
+\r
+  ASSERT (IS_DEVICE_PATH_NODE(RemainingDevicePath, MEDIA_DEVICE_PATH, MEDIA_PIWG_FW_FILE_DP));\r
+\r
+  Status = gBS->HandleProtocol(Handle,&gEfiFirmwareVolume2ProtocolGuid, (VOID **)&FwVol);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  FvNameGuid = EfiGetNameGuidFromFwVolDevicePathNode ((CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)RemainingDevicePath);\r
+  if (FvNameGuid == NULL) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  SectionType = EFI_SECTION_PE32;\r
+  AuthenticationStatus = 0;\r
+  //Note: ReadSection at the opposite of ReadFile does not allow to pass ImageBuffer == NULL to get the size of the file.\r
+  ImageBuffer = NULL;\r
+  Status = FwVol->ReadSection (\r
+                    FwVol,\r
+                    FvNameGuid,\r
+                    SectionType,\r
+                    0,\r
+                    &ImageBuffer,\r
+                    ImageSize,\r
+                    &AuthenticationStatus\r
+                    );\r
+  if (!EFI_ERROR (Status)) {\r
+#if 0\r
+    // In case the buffer has some address requirements, we must copy the buffer to a buffer following the requirements\r
+    if (Type != AllocateAnyPages) {\r
+      Status = gBS->AllocatePages (Type, EfiBootServicesCode, EFI_SIZE_TO_PAGES(*ImageSize),Image);\r
+      if (!EFI_ERROR(Status)) {\r
+        CopyMem ((VOID*)(UINTN)(*Image), ImageBuffer, *ImageSize);\r
+        FreePool (ImageBuffer);\r
+      }\r
+    }\r
+#else\r
+    // We must copy the buffer into a page allocations. Otherwise, the caller could call gBS->FreePages() on the pool allocation\r
+    Status = gBS->AllocatePages (Type, EfiBootServicesCode, EFI_SIZE_TO_PAGES(*ImageSize), Image);\r
+    // Try to allocate in any pages if failed to allocate memory at the defined location\r
+    if ((Status == EFI_OUT_OF_RESOURCES) && (Type != AllocateAnyPages)) {\r
+      Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesCode, EFI_SIZE_TO_PAGES(*ImageSize), Image);\r
+    }\r
+    if (!EFI_ERROR(Status)) {\r
+      CopyMem ((VOID*)(UINTN)(*Image), ImageBuffer, *ImageSize);\r
+      FreePool (ImageBuffer);\r
+    }\r
+#endif\r
+  } else {\r
+    // Try a raw file, since a PE32 SECTION does not exist\r
+    Status = FwVol->ReadFile (\r
+                        FwVol,\r
+                        FvNameGuid,\r
+                        NULL,\r
+                        ImageSize,\r
+                        &FvType,\r
+                        &Attrib,\r
+                        &AuthenticationStatus\r
+                        );\r
+    if (!EFI_ERROR(Status)) {\r
+      Status = gBS->AllocatePages (Type, EfiBootServicesCode, EFI_SIZE_TO_PAGES(*ImageSize), Image);\r
+      // Try to allocate in any pages if failed to allocate memory at the defined location\r
+      if ((Status == EFI_OUT_OF_RESOURCES) && (Type != AllocateAnyPages)) {\r
+        Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesCode, EFI_SIZE_TO_PAGES(*ImageSize), Image);\r
+      }\r
+      if (!EFI_ERROR(Status)) {\r
+        Status = FwVol->ReadFile (\r
+                                FwVol,\r
+                                FvNameGuid,\r
+                                (VOID*)(UINTN)(*Image),\r
+                                ImageSize,\r
+                                &FvType,\r
+                                &Attrib,\r
+                                &AuthenticationStatus\r
+                                );\r
+      }\r
+    }\r
+  }\r
+  return Status;\r
+}\r
+\r
+BOOLEAN\r
+BdsPxeSupport (\r
+  IN EFI_DEVICE_PATH*           DevicePath,\r
+  IN EFI_HANDLE                 Handle,\r
+  IN EFI_DEVICE_PATH*           RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_PXE_BASE_CODE_PROTOCOL* PxeBcProtocol;\r
+\r
+  if (!IsDevicePathEnd(RemainingDevicePath)) {\r
+    return FALSE;\r
+  }\r
+\r
+  Status = gBS->HandleProtocol (Handle, &gEfiPxeBaseCodeProtocolGuid, (VOID **)&PxeBcProtocol);\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  } else {\r
+    return TRUE;\r
+  }\r
+}\r
+\r
+EFI_STATUS\r
+BdsPxeLoadImage (\r
+  IN     EFI_DEVICE_PATH*       DevicePath,\r
+  IN     EFI_HANDLE             Handle,\r
+  IN     EFI_DEVICE_PATH*       RemainingDevicePath,\r
+  IN     EFI_ALLOCATE_TYPE      Type,\r
+  IN OUT EFI_PHYSICAL_ADDRESS   *Image,\r
+  OUT    UINTN                  *ImageSize\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_LOAD_FILE_PROTOCOL  *LoadFileProtocol;\r
+  UINTN                   BufferSize;\r
+\r
+  // Get Load File Protocol attached to the PXE protocol\r
+  Status = gBS->HandleProtocol (Handle, &gEfiLoadFileProtocolGuid, (VOID **)&LoadFileProtocol);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = LoadFileProtocol->LoadFile (LoadFileProtocol, DevicePath, TRUE, &BufferSize, NULL);\r
+  if (Status == EFI_BUFFER_TOO_SMALL) {\r
+    Status = gBS->AllocatePages (Type, EfiBootServicesCode, EFI_SIZE_TO_PAGES(BufferSize), Image);\r
+    if (EFI_ERROR(Status)) {\r
+      return Status;\r
+    }\r
+\r
+    Status = LoadFileProtocol->LoadFile (LoadFileProtocol, DevicePath, TRUE, &BufferSize, (VOID*)(UINTN)(*Image));\r
+    if (!EFI_ERROR(Status) && (ImageSize != NULL)) {\r
+      *ImageSize = BufferSize;\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+BOOLEAN\r
+BdsTftpSupport (\r
+  IN EFI_DEVICE_PATH*           DevicePath,\r
+  IN EFI_HANDLE                 Handle,\r
+  IN EFI_DEVICE_PATH*           RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_DEVICE_PATH  *NextDevicePath;\r
+  EFI_PXE_BASE_CODE_PROTOCOL  *PxeBcProtocol;\r
+\r
+  // Validate the Remaining Device Path\r
+  if (IsDevicePathEnd(RemainingDevicePath)) {\r
+    return FALSE;\r
+  }\r
+  if (!IS_DEVICE_PATH_NODE(RemainingDevicePath,MESSAGING_DEVICE_PATH,MSG_IPv4_DP) &&\r
+      !IS_DEVICE_PATH_NODE(RemainingDevicePath,MESSAGING_DEVICE_PATH,MSG_IPv6_DP)) {\r
+    return FALSE;\r
+  }\r
+  NextDevicePath = NextDevicePathNode (RemainingDevicePath);\r
+  if (IsDevicePathEnd(NextDevicePath)) {\r
+    return FALSE;\r
+  }\r
+  if (!IS_DEVICE_PATH_NODE(NextDevicePath,MEDIA_DEVICE_PATH,MEDIA_FILEPATH_DP)) {\r
+    return FALSE;\r
+  }\r
+\r
+  Status = gBS->HandleProtocol (Handle, &gEfiPxeBaseCodeProtocolGuid, (VOID **)&PxeBcProtocol);\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  } else {\r
+    return TRUE;\r
+  }\r
+}\r
+\r
+EFI_STATUS\r
+BdsTftpLoadImage (\r
+  IN     EFI_DEVICE_PATH*       DevicePath,\r
+  IN     EFI_HANDLE             Handle,\r
+  IN     EFI_DEVICE_PATH*       RemainingDevicePath,\r
+  IN     EFI_ALLOCATE_TYPE      Type,\r
+  IN OUT EFI_PHYSICAL_ADDRESS   *Image,\r
+  OUT    UINTN                  *ImageSize\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_PXE_BASE_CODE_PROTOCOL  *Pxe;\r
+  UINT64                      TftpBufferSize;\r
+  VOID*                       TftpBuffer;\r
+  EFI_IP_ADDRESS              ServerIp;\r
+  IPv4_DEVICE_PATH*           IPv4DevicePathNode;\r
+  FILEPATH_DEVICE_PATH*       FilePathDevicePath;\r
+  EFI_IP_ADDRESS              LocalIp;\r
+\r
+  ASSERT(IS_DEVICE_PATH_NODE(RemainingDevicePath,MESSAGING_DEVICE_PATH,MSG_IPv4_DP));\r
+\r
+  IPv4DevicePathNode = (IPv4_DEVICE_PATH*)RemainingDevicePath;\r
+  FilePathDevicePath = (FILEPATH_DEVICE_PATH*)(IPv4DevicePathNode + 1);\r
+\r
+  Status = gBS->LocateProtocol (&gEfiPxeBaseCodeProtocolGuid, NULL, (VOID **)&Pxe);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = Pxe->Start (Pxe, FALSE);\r
+  if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) {\r
+    return Status;\r
+  }\r
+\r
+  if (!IPv4DevicePathNode->StaticIpAddress) {\r
+    Status = Pxe->Dhcp(Pxe, TRUE);\r
+  } else {\r
+    CopyMem (&LocalIp.v4, &IPv4DevicePathNode->LocalIpAddress, sizeof (EFI_IPv4_ADDRESS));\r
+    Status = Pxe->SetStationIp (Pxe, &LocalIp, NULL);\r
+  }\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  CopyMem (&ServerIp.v4, &IPv4DevicePathNode->RemoteIpAddress, sizeof (EFI_IPv4_ADDRESS));\r
+\r
+  Status = Pxe->Mtftp (\r
+                  Pxe,\r
+                  EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE,\r
+                  NULL,\r
+                  FALSE,\r
+                  &TftpBufferSize,\r
+                  NULL,\r
+                  &ServerIp,\r
+                  (UINT8 *)FilePathDevicePath->PathName,\r
+                  NULL,\r
+                  TRUE\r
+                  );\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  // Allocate a buffer to hold the whole file.\r
+  TftpBuffer = AllocatePool(TftpBufferSize);\r
+  if (TftpBuffer == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Status = Pxe->Mtftp (\r
+                  Pxe,\r
+                  EFI_PXE_BASE_CODE_TFTP_READ_FILE,\r
+                  TftpBuffer,\r
+                  FALSE,\r
+                  &TftpBufferSize,\r
+                  NULL,\r
+                  &ServerIp,\r
+                  (UINT8 *)FilePathDevicePath->PathName,\r
+                  NULL,\r
+                  FALSE\r
+                  );\r
+  if (EFI_ERROR(Status)) {\r
+    FreePool(TftpBuffer);\r
+  } else if (ImageSize != NULL) {\r
+    *ImageSize = (UINTN)TftpBufferSize;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+BDS_FILE_LOADER FileLoaders[] = {\r
+    { BdsFileSystemSupport, BdsFileSystemLoadImage },\r
+    { BdsFirmwareVolumeSupport, BdsFirmwareVolumeLoadImage },\r
+    //{ BdsLoadFileSupport, BdsLoadFileLoadImage },\r
+    { BdsMemoryMapSupport, BdsMemoryMapLoadImage },\r
+    { BdsPxeSupport, BdsPxeLoadImage },\r
+    { BdsTftpSupport, BdsTftpLoadImage },\r
+    { NULL, NULL }\r
+};\r
+\r
+EFI_STATUS\r
+BdsLoadImage (\r
+  IN     EFI_DEVICE_PATH       *DevicePath,\r
+  IN     EFI_ALLOCATE_TYPE     Type,\r
+  IN OUT EFI_PHYSICAL_ADDRESS* Image,\r
+  OUT    UINTN                 *FileSize\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+  EFI_HANDLE      Handle;\r
+  EFI_DEVICE_PATH *RemainingDevicePath;\r
+  BDS_FILE_LOADER*  FileLoader;\r
+\r
+  Status = BdsConnectDevicePath (DevicePath, &Handle, &RemainingDevicePath);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  FileLoader = FileLoaders;\r
+  while (FileLoader->Support != NULL) {\r
+    if (FileLoader->Support (DevicePath, Handle, RemainingDevicePath)) {\r
+      return FileLoader->LoadImage (DevicePath, Handle, RemainingDevicePath, Type, Image, FileSize);\r
+    }\r
+    FileLoader++;\r
+  }\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Start an EFI Application from a Device Path\r
+\r
+  @param  ParentImageHandle     Handle of the calling image\r
+  @param  DevicePath            Location of the EFI Application\r
+\r
+  @retval EFI_SUCCESS           All drivers have been connected\r
+  @retval EFI_NOT_FOUND         The Linux kernel Device Path has not been found\r
+  @retval EFI_OUT_OF_RESOURCES  There is not enough resource memory to store the matching results.\r
+\r
+**/\r
+EFI_STATUS\r
+BdsStartEfiApplication (\r
+  IN EFI_HANDLE                  ParentImageHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL    *DevicePath,\r
+  IN UINTN                       LoadOptionsSize,\r
+  IN VOID*                       LoadOptions\r
+  )\r
+{\r
+  EFI_STATUS                   Status;\r
+  EFI_HANDLE                   ImageHandle;\r
+  EFI_PHYSICAL_ADDRESS         BinaryBuffer;\r
+  UINTN                        BinarySize;\r
+  EFI_LOADED_IMAGE_PROTOCOL*   LoadedImage;\r
+\r
+  // Find the nearest supported file loader\r
+  Status = BdsLoadImage (DevicePath, AllocateAnyPages, &BinaryBuffer, &BinarySize);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  // Load the image from the Buffer with Boot Services function\r
+  Status = gBS->LoadImage (TRUE, ParentImageHandle, DevicePath, (VOID*)(UINTN)BinaryBuffer, BinarySize, &ImageHandle);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  // Passed LoadOptions to the EFI Application\r
+  if (LoadOptionsSize != 0) {\r
+    Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);\r
+    if (EFI_ERROR(Status)) {\r
+      return Status;\r
+    }\r
+\r
+    LoadedImage->LoadOptionsSize  = LoadOptionsSize;\r
+    LoadedImage->LoadOptions      = LoadOptions;\r
+  }\r
+\r
+  // Before calling the image, enable the Watchdog Timer for  the 5 Minute period\r
+  gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);\r
+  // Start the image\r
+  Status = gBS->StartImage (ImageHandle, NULL, NULL);\r
+  // Clear the Watchdog Timer after the image returns\r
+  gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);\r
+\r
+  return Status;\r
+}\r
index 29cc12bd33d6c522b8c25dc8111a534cc1ea4ad4..5016bedcd48e9dc9bd0dbc794503051d51db3a90 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 "BdsInternal.h"
-
-#include <Library/DxeServicesTableLib.h>
-#include <Library/HobLib.h>
-#include <Library/TimerLib.h>
-#include <Library/PrintLib.h>
-#include <Library/SerialPortLib.h>
-
-STATIC CHAR8 *mTokenList[] = {
-  /*"SEC",*/
-  "PEI",
-  "DXE",
-  "BDS",
-  NULL
-};
-
-EFI_STATUS
-ShutdownUefiBootServices (
-  VOID
-  )
-{
-  EFI_STATUS              Status;
-  UINTN                   MemoryMapSize;
-  EFI_MEMORY_DESCRIPTOR   *MemoryMap;
-  UINTN                   MapKey;
-  UINTN                   DescriptorSize;
-  UINT32                  DescriptorVersion;
-  UINTN                   Pages;
-
-  MemoryMap = NULL;
-  MemoryMapSize = 0;
-  Pages = 0;
-
-  do {
-    Status = gBS->GetMemoryMap (
-                    &MemoryMapSize,
-                    MemoryMap,
-                    &MapKey,
-                    &DescriptorSize,
-                    &DescriptorVersion
-                    );
-    if (Status == EFI_BUFFER_TOO_SMALL) {
-
-      Pages = EFI_SIZE_TO_PAGES (MemoryMapSize) + 1;
-      MemoryMap = AllocatePages (Pages);
-
-      //
-      // Get System MemoryMap
-      //
-      Status = gBS->GetMemoryMap (
-                      &MemoryMapSize,
-                      MemoryMap,
-                      &MapKey,
-                      &DescriptorSize,
-                      &DescriptorVersion
-                      );
-    }
-
-    // Don't do anything between the GetMemoryMap() and ExitBootServices()
-    if (!EFI_ERROR(Status)) {
-      Status = gBS->ExitBootServices (gImageHandle, MapKey);
-      if (EFI_ERROR(Status)) {
-        FreePages (MemoryMap, Pages);
-        MemoryMap = NULL;
-        MemoryMapSize = 0;
-      }
-    }
-  } while (EFI_ERROR(Status));
-
-  return Status;
-}
-
-/**
-  Connect all DXE drivers
-
-  @retval EFI_SUCCESS           All drivers have been connected
-  @retval EFI_NOT_FOUND         No handles match the search.
-  @retval EFI_OUT_OF_RESOURCES  There is not resource pool memory to store the matching results.
-
-**/
-EFI_STATUS
-BdsConnectAllDrivers (
-  VOID
-  )
-{
-  UINTN                     HandleCount, Index;
-  EFI_HANDLE                *HandleBuffer;
-  EFI_STATUS                Status;
-
-  do {
-    // Locate all the driver handles
-    Status = gBS->LocateHandleBuffer (
-                AllHandles,
-                NULL,
-                NULL,
-                &HandleCount,
-                &HandleBuffer
-                );
-    if (EFI_ERROR (Status)) {
-      break;
-    }
-
-    // Connect every handles
-    for (Index = 0; Index < HandleCount; Index++) {
-      gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
-    }
-
-    if (HandleBuffer != NULL) {
-      FreePool (HandleBuffer);
-    }
-
-    // Check if new handles have been created after the start of the previous handles
-    Status = gDS->Dispatch ();
-  } while (!EFI_ERROR(Status));
-
-  return EFI_SUCCESS;
-}
-
-STATIC
-EFI_STATUS
-InsertSystemMemoryResources (
-  LIST_ENTRY *ResourceList,
-  EFI_HOB_RESOURCE_DESCRIPTOR *ResHob
-  )
-{
-  BDS_SYSTEM_MEMORY_RESOURCE  *NewResource;
-  LIST_ENTRY                  *Link;
-  LIST_ENTRY                  *NextLink;
-  LIST_ENTRY                  AttachedResources;
-  BDS_SYSTEM_MEMORY_RESOURCE  *Resource;
-  EFI_PHYSICAL_ADDRESS        NewResourceEnd;
-
-  if (IsListEmpty (ResourceList)) {
-    NewResource = AllocateZeroPool (sizeof(BDS_SYSTEM_MEMORY_RESOURCE));
-    NewResource->PhysicalStart = ResHob->PhysicalStart;
-    NewResource->ResourceLength = ResHob->ResourceLength;
-    InsertTailList (ResourceList, &NewResource->Link);
-    return EFI_SUCCESS;
-  }
-
-  InitializeListHead (&AttachedResources);
-
-  Link = ResourceList->ForwardLink;
-  ASSERT (Link != NULL);
-  while (Link != ResourceList) {
-    Resource = (BDS_SYSTEM_MEMORY_RESOURCE*)Link;
-
-    // Sanity Check. The resources should not overlapped.
-    ASSERT(!((ResHob->PhysicalStart >= Resource->PhysicalStart) && (ResHob->PhysicalStart < (Resource->PhysicalStart + Resource->ResourceLength))));
-    ASSERT(!((ResHob->PhysicalStart + ResHob->ResourceLength - 1 >= Resource->PhysicalStart) &&
-        ((ResHob->PhysicalStart + ResHob->ResourceLength - 1) < (Resource->PhysicalStart + Resource->ResourceLength))));
-
-    // The new resource is attached after this resource descriptor
-    if (ResHob->PhysicalStart == Resource->PhysicalStart + Resource->ResourceLength) {
-      Resource->ResourceLength =  Resource->ResourceLength + ResHob->ResourceLength;
-
-      NextLink = RemoveEntryList (&Resource->Link);
-      InsertTailList (&AttachedResources, &Resource->Link);
-      Link = NextLink;
-    }
-    // The new resource is attached before this resource descriptor
-    else if (ResHob->PhysicalStart + ResHob->ResourceLength == Resource->PhysicalStart) {
-      Resource->PhysicalStart = ResHob->PhysicalStart;
-      Resource->ResourceLength =  Resource->ResourceLength + ResHob->ResourceLength;
-
-      NextLink = RemoveEntryList (&Resource->Link);
-      InsertTailList (&AttachedResources, &Resource->Link);
-      Link = NextLink;
-    } else {
-      Link = Link->ForwardLink;
-    }
-  }
-
-  if (!IsListEmpty (&AttachedResources)) {
-    // See if we can merge the attached resource with other resources
-
-    NewResource = (BDS_SYSTEM_MEMORY_RESOURCE*)GetFirstNode (&AttachedResources);
-    Link = RemoveEntryList (&NewResource->Link);
-    while (!IsListEmpty (&AttachedResources)) {
-      // Merge resources
-      Resource = (BDS_SYSTEM_MEMORY_RESOURCE*)Link;
-
-      // Ensure they overlap each other
-      ASSERT(
-          ((NewResource->PhysicalStart >= Resource->PhysicalStart) && (NewResource->PhysicalStart < (Resource->PhysicalStart + Resource->ResourceLength))) ||
-          (((NewResource->PhysicalStart + NewResource->ResourceLength) >= Resource->PhysicalStart) && ((NewResource->PhysicalStart + NewResource->ResourceLength) < (Resource->PhysicalStart + Resource->ResourceLength)))
-      );
-
-      NewResourceEnd = MAX (NewResource->PhysicalStart + NewResource->ResourceLength, Resource->PhysicalStart + Resource->ResourceLength);
-      NewResource->PhysicalStart = MIN (NewResource->PhysicalStart, Resource->PhysicalStart);
-      NewResource->ResourceLength = NewResourceEnd - NewResource->PhysicalStart;
-
-      Link = RemoveEntryList (Link);
-    }
-  } else {
-    // None of the Resource of the list is attached to this ResHob. Create a new entry for it
-    NewResource = AllocateZeroPool (sizeof(BDS_SYSTEM_MEMORY_RESOURCE));
-    NewResource->PhysicalStart = ResHob->PhysicalStart;
-    NewResource->ResourceLength = ResHob->ResourceLength;
-  }
-  InsertTailList (ResourceList, &NewResource->Link);
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-GetSystemMemoryResources (
-  IN  LIST_ENTRY *ResourceList
-  )
-{
-  EFI_HOB_RESOURCE_DESCRIPTOR *ResHob;
-
-  InitializeListHead (ResourceList);
-
-  // Find the first System Memory Resource Descriptor
-  ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetFirstHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR);
-  while ((ResHob != NULL) && (ResHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY)) {
-    ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,(VOID *)((UINTN)ResHob + ResHob->Header.HobLength));
-  }
-
-  // Did not find any
-  if (ResHob == NULL) {
-    return EFI_NOT_FOUND;
-  } else {
-    InsertSystemMemoryResources (ResourceList, ResHob);
-  }
-
-  ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,(VOID *)((UINTN)ResHob + ResHob->Header.HobLength));
-  while (ResHob != NULL) {
-    if (ResHob->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {
-      InsertSystemMemoryResources (ResourceList, ResHob);
-    }
-    ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,(VOID *)((UINTN)ResHob + ResHob->Header.HobLength));
-  }
-
-  return EFI_SUCCESS;
-}
-
-VOID
-PrintPerformance (
-  VOID
-  )
-{
-  UINTN       Key;
-  CONST VOID  *Handle;
-  CONST CHAR8 *Token, *Module;
-  UINT64      Start, Stop, TimeStamp;
-  UINT64      Delta, TicksPerSecond, Milliseconds;
-  UINTN       Index;
-  CHAR8       Buffer[100];
-  UINTN       CharCount;
-  BOOLEAN     CountUp;
-
-  TicksPerSecond = GetPerformanceCounterProperties (&Start, &Stop);
-  if (Start < Stop) {
-    CountUp = TRUE;
-  } else {
-    CountUp = FALSE;
-  }
-
-  TimeStamp = 0;
-  Key       = 0;
-  do {
-    Key = GetPerformanceMeasurement (Key, (CONST VOID **)&Handle, &Token, &Module, &Start, &Stop);
-    if (Key != 0) {
-      for (Index = 0; mTokenList[Index] != NULL; Index++) {
-        if (AsciiStriCmp (mTokenList[Index], Token) == 0) {
-          Delta = CountUp?(Stop - Start):(Start - Stop);
-          TimeStamp += Delta;
-          Milliseconds = DivU64x64Remainder (MultU64x32 (Delta, 1000), TicksPerSecond, NULL);
-          CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"%6a %6ld ms\n", Token, Milliseconds);
-          SerialPortWrite ((UINT8 *) Buffer, CharCount);
-          break;
-        }
-      }
-    }
-  } while (Key != 0);
-
-  CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Total Time = %ld ms\n\n", DivU64x64Remainder (MultU64x32 (TimeStamp, 1000), TicksPerSecond, NULL));
-  SerialPortWrite ((UINT8 *) Buffer, CharCount);
-}
-
-EFI_STATUS
-GetEnvironmentVariable (
-  IN     CONST CHAR16*   VariableName,
-  IN     VOID*           DefaultValue,
-  IN OUT UINTN*          Size,
-  OUT    VOID**          Value
-  )
-{
-  EFI_STATUS  Status;
-  UINTN       VariableSize;
-
-  // Try to get the variable size.
-  *Value = NULL;
-  VariableSize = 0;
-  Status = gRT->GetVariable ((CHAR16 *) VariableName, &gEfiGlobalVariableGuid, NULL, &VariableSize, *Value);
-  if (Status == EFI_NOT_FOUND) {
-    if ((DefaultValue != NULL) && (Size != NULL) && (*Size != 0)) {
-      // If the environment variable does not exist yet then set it with the default value
-      Status = gRT->SetVariable (
-                    (CHAR16*)VariableName,
-                    &gEfiGlobalVariableGuid,
-                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
-                    *Size,
-                    DefaultValue
-                    );
-      *Value = DefaultValue;
-    } else {
-      return EFI_NOT_FOUND;
-    }
-  } else if (Status == EFI_BUFFER_TOO_SMALL) {
-    // Get the environment variable value
-    *Value = AllocatePool (VariableSize);
-    if (*Value == NULL) {
-      return EFI_OUT_OF_RESOURCES;
-    }
-
-    Status = gRT->GetVariable ((CHAR16 *)VariableName, &gEfiGlobalVariableGuid, NULL, &VariableSize, *Value);
-    if (EFI_ERROR (Status)) {
-      FreePool(*Value);
-      return EFI_INVALID_PARAMETER;
-    }
-
-    if (Size) {
-      *Size = VariableSize;
-    }
-  } else {
-    *Value = DefaultValue;
-    return Status;
-  }
-
-  return EFI_SUCCESS;
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include "BdsInternal.h"\r
+\r
+#include <Library/DxeServicesTableLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/SerialPortLib.h>\r
+\r
+STATIC CHAR8 *mTokenList[] = {\r
+  /*"SEC",*/\r
+  "PEI",\r
+  "DXE",\r
+  "BDS",\r
+  NULL\r
+};\r
+\r
+EFI_STATUS\r
+ShutdownUefiBootServices (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  UINTN                   MemoryMapSize;\r
+  EFI_MEMORY_DESCRIPTOR   *MemoryMap;\r
+  UINTN                   MapKey;\r
+  UINTN                   DescriptorSize;\r
+  UINT32                  DescriptorVersion;\r
+  UINTN                   Pages;\r
+\r
+  MemoryMap = NULL;\r
+  MemoryMapSize = 0;\r
+  Pages = 0;\r
+\r
+  do {\r
+    Status = gBS->GetMemoryMap (\r
+                    &MemoryMapSize,\r
+                    MemoryMap,\r
+                    &MapKey,\r
+                    &DescriptorSize,\r
+                    &DescriptorVersion\r
+                    );\r
+    if (Status == EFI_BUFFER_TOO_SMALL) {\r
+\r
+      Pages = EFI_SIZE_TO_PAGES (MemoryMapSize) + 1;\r
+      MemoryMap = AllocatePages (Pages);\r
+\r
+      //\r
+      // Get System MemoryMap\r
+      //\r
+      Status = gBS->GetMemoryMap (\r
+                      &MemoryMapSize,\r
+                      MemoryMap,\r
+                      &MapKey,\r
+                      &DescriptorSize,\r
+                      &DescriptorVersion\r
+                      );\r
+    }\r
+\r
+    // Don't do anything between the GetMemoryMap() and ExitBootServices()\r
+    if (!EFI_ERROR(Status)) {\r
+      Status = gBS->ExitBootServices (gImageHandle, MapKey);\r
+      if (EFI_ERROR(Status)) {\r
+        FreePages (MemoryMap, Pages);\r
+        MemoryMap = NULL;\r
+        MemoryMapSize = 0;\r
+      }\r
+    }\r
+  } while (EFI_ERROR(Status));\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Connect all DXE drivers\r
+\r
+  @retval EFI_SUCCESS           All drivers have been connected\r
+  @retval EFI_NOT_FOUND         No handles match the search.\r
+  @retval EFI_OUT_OF_RESOURCES  There is not resource pool memory to store the matching results.\r
+\r
+**/\r
+EFI_STATUS\r
+BdsConnectAllDrivers (\r
+  VOID\r
+  )\r
+{\r
+  UINTN                     HandleCount, Index;\r
+  EFI_HANDLE                *HandleBuffer;\r
+  EFI_STATUS                Status;\r
+\r
+  do {\r
+    // Locate all the driver handles\r
+    Status = gBS->LocateHandleBuffer (\r
+                AllHandles,\r
+                NULL,\r
+                NULL,\r
+                &HandleCount,\r
+                &HandleBuffer\r
+                );\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
+\r
+    // Connect every handles\r
+    for (Index = 0; Index < HandleCount; Index++) {\r
+      gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);\r
+    }\r
+\r
+    if (HandleBuffer != NULL) {\r
+      FreePool (HandleBuffer);\r
+    }\r
+\r
+    // Check if new handles have been created after the start of the previous handles\r
+    Status = gDS->Dispatch ();\r
+  } while (!EFI_ERROR(Status));\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+InsertSystemMemoryResources (\r
+  LIST_ENTRY *ResourceList,\r
+  EFI_HOB_RESOURCE_DESCRIPTOR *ResHob\r
+  )\r
+{\r
+  BDS_SYSTEM_MEMORY_RESOURCE  *NewResource;\r
+  LIST_ENTRY                  *Link;\r
+  LIST_ENTRY                  *NextLink;\r
+  LIST_ENTRY                  AttachedResources;\r
+  BDS_SYSTEM_MEMORY_RESOURCE  *Resource;\r
+  EFI_PHYSICAL_ADDRESS        NewResourceEnd;\r
+\r
+  if (IsListEmpty (ResourceList)) {\r
+    NewResource = AllocateZeroPool (sizeof(BDS_SYSTEM_MEMORY_RESOURCE));\r
+    NewResource->PhysicalStart = ResHob->PhysicalStart;\r
+    NewResource->ResourceLength = ResHob->ResourceLength;\r
+    InsertTailList (ResourceList, &NewResource->Link);\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  InitializeListHead (&AttachedResources);\r
+\r
+  Link = ResourceList->ForwardLink;\r
+  ASSERT (Link != NULL);\r
+  while (Link != ResourceList) {\r
+    Resource = (BDS_SYSTEM_MEMORY_RESOURCE*)Link;\r
+\r
+    // Sanity Check. The resources should not overlapped.\r
+    ASSERT(!((ResHob->PhysicalStart >= Resource->PhysicalStart) && (ResHob->PhysicalStart < (Resource->PhysicalStart + Resource->ResourceLength))));\r
+    ASSERT(!((ResHob->PhysicalStart + ResHob->ResourceLength - 1 >= Resource->PhysicalStart) &&\r
+        ((ResHob->PhysicalStart + ResHob->ResourceLength - 1) < (Resource->PhysicalStart + Resource->ResourceLength))));\r
+\r
+    // The new resource is attached after this resource descriptor\r
+    if (ResHob->PhysicalStart == Resource->PhysicalStart + Resource->ResourceLength) {\r
+      Resource->ResourceLength =  Resource->ResourceLength + ResHob->ResourceLength;\r
+\r
+      NextLink = RemoveEntryList (&Resource->Link);\r
+      InsertTailList (&AttachedResources, &Resource->Link);\r
+      Link = NextLink;\r
+    }\r
+    // The new resource is attached before this resource descriptor\r
+    else if (ResHob->PhysicalStart + ResHob->ResourceLength == Resource->PhysicalStart) {\r
+      Resource->PhysicalStart = ResHob->PhysicalStart;\r
+      Resource->ResourceLength =  Resource->ResourceLength + ResHob->ResourceLength;\r
+\r
+      NextLink = RemoveEntryList (&Resource->Link);\r
+      InsertTailList (&AttachedResources, &Resource->Link);\r
+      Link = NextLink;\r
+    } else {\r
+      Link = Link->ForwardLink;\r
+    }\r
+  }\r
+\r
+  if (!IsListEmpty (&AttachedResources)) {\r
+    // See if we can merge the attached resource with other resources\r
+\r
+    NewResource = (BDS_SYSTEM_MEMORY_RESOURCE*)GetFirstNode (&AttachedResources);\r
+    Link = RemoveEntryList (&NewResource->Link);\r
+    while (!IsListEmpty (&AttachedResources)) {\r
+      // Merge resources\r
+      Resource = (BDS_SYSTEM_MEMORY_RESOURCE*)Link;\r
+\r
+      // Ensure they overlap each other\r
+      ASSERT(\r
+          ((NewResource->PhysicalStart >= Resource->PhysicalStart) && (NewResource->PhysicalStart < (Resource->PhysicalStart + Resource->ResourceLength))) ||\r
+          (((NewResource->PhysicalStart + NewResource->ResourceLength) >= Resource->PhysicalStart) && ((NewResource->PhysicalStart + NewResource->ResourceLength) < (Resource->PhysicalStart + Resource->ResourceLength)))\r
+      );\r
+\r
+      NewResourceEnd = MAX (NewResource->PhysicalStart + NewResource->ResourceLength, Resource->PhysicalStart + Resource->ResourceLength);\r
+      NewResource->PhysicalStart = MIN (NewResource->PhysicalStart, Resource->PhysicalStart);\r
+      NewResource->ResourceLength = NewResourceEnd - NewResource->PhysicalStart;\r
+\r
+      Link = RemoveEntryList (Link);\r
+    }\r
+  } else {\r
+    // None of the Resource of the list is attached to this ResHob. Create a new entry for it\r
+    NewResource = AllocateZeroPool (sizeof(BDS_SYSTEM_MEMORY_RESOURCE));\r
+    NewResource->PhysicalStart = ResHob->PhysicalStart;\r
+    NewResource->ResourceLength = ResHob->ResourceLength;\r
+  }\r
+  InsertTailList (ResourceList, &NewResource->Link);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+GetSystemMemoryResources (\r
+  IN  LIST_ENTRY *ResourceList\r
+  )\r
+{\r
+  EFI_HOB_RESOURCE_DESCRIPTOR *ResHob;\r
+\r
+  InitializeListHead (ResourceList);\r
+\r
+  // Find the first System Memory Resource Descriptor\r
+  ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetFirstHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR);\r
+  while ((ResHob != NULL) && (ResHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY)) {\r
+    ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,(VOID *)((UINTN)ResHob + ResHob->Header.HobLength));\r
+  }\r
+\r
+  // Did not find any\r
+  if (ResHob == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  } else {\r
+    InsertSystemMemoryResources (ResourceList, ResHob);\r
+  }\r
+\r
+  ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,(VOID *)((UINTN)ResHob + ResHob->Header.HobLength));\r
+  while (ResHob != NULL) {\r
+    if (ResHob->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {\r
+      InsertSystemMemoryResources (ResourceList, ResHob);\r
+    }\r
+    ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,(VOID *)((UINTN)ResHob + ResHob->Header.HobLength));\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+VOID\r
+PrintPerformance (\r
+  VOID\r
+  )\r
+{\r
+  UINTN       Key;\r
+  CONST VOID  *Handle;\r
+  CONST CHAR8 *Token, *Module;\r
+  UINT64      Start, Stop, TimeStamp;\r
+  UINT64      Delta, TicksPerSecond, Milliseconds;\r
+  UINTN       Index;\r
+  CHAR8       Buffer[100];\r
+  UINTN       CharCount;\r
+  BOOLEAN     CountUp;\r
+\r
+  TicksPerSecond = GetPerformanceCounterProperties (&Start, &Stop);\r
+  if (Start < Stop) {\r
+    CountUp = TRUE;\r
+  } else {\r
+    CountUp = FALSE;\r
+  }\r
+\r
+  TimeStamp = 0;\r
+  Key       = 0;\r
+  do {\r
+    Key = GetPerformanceMeasurement (Key, (CONST VOID **)&Handle, &Token, &Module, &Start, &Stop);\r
+    if (Key != 0) {\r
+      for (Index = 0; mTokenList[Index] != NULL; Index++) {\r
+        if (AsciiStriCmp (mTokenList[Index], Token) == 0) {\r
+          Delta = CountUp?(Stop - Start):(Start - Stop);\r
+          TimeStamp += Delta;\r
+          Milliseconds = DivU64x64Remainder (MultU64x32 (Delta, 1000), TicksPerSecond, NULL);\r
+          CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"%6a %6ld ms\n", Token, Milliseconds);\r
+          SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
+          break;\r
+        }\r
+      }\r
+    }\r
+  } while (Key != 0);\r
+\r
+  CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Total Time = %ld ms\n\n", DivU64x64Remainder (MultU64x32 (TimeStamp, 1000), TicksPerSecond, NULL));\r
+  SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
+}\r
+\r
+EFI_STATUS\r
+GetEnvironmentVariable (\r
+  IN     CONST CHAR16*   VariableName,\r
+  IN     VOID*           DefaultValue,\r
+  IN OUT UINTN*          Size,\r
+  OUT    VOID**          Value\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       VariableSize;\r
+\r
+  // Try to get the variable size.\r
+  *Value = NULL;\r
+  VariableSize = 0;\r
+  Status = gRT->GetVariable ((CHAR16 *) VariableName, &gEfiGlobalVariableGuid, NULL, &VariableSize, *Value);\r
+  if (Status == EFI_NOT_FOUND) {\r
+    if ((DefaultValue != NULL) && (Size != NULL) && (*Size != 0)) {\r
+      // If the environment variable does not exist yet then set it with the default value\r
+      Status = gRT->SetVariable (\r
+                    (CHAR16*)VariableName,\r
+                    &gEfiGlobalVariableGuid,\r
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                    *Size,\r
+                    DefaultValue\r
+                    );\r
+      *Value = DefaultValue;\r
+    } else {\r
+      return EFI_NOT_FOUND;\r
+    }\r
+  } else if (Status == EFI_BUFFER_TOO_SMALL) {\r
+    // Get the environment variable value\r
+    *Value = AllocatePool (VariableSize);\r
+    if (*Value == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    Status = gRT->GetVariable ((CHAR16 *)VariableName, &gEfiGlobalVariableGuid, NULL, &VariableSize, *Value);\r
+    if (EFI_ERROR (Status)) {\r
+      FreePool(*Value);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    if (Size) {\r
+      *Size = VariableSize;\r
+    }\r
+  } else {\r
+    *Value = DefaultValue;\r
+    return Status;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
index 85f9f41598cfadf11f0933f03dcd00ddb27e3ed6..5ae46f86e8a3e1be6aebb08db23a66ce59622790 100644 (file)
@@ -1,98 +1,98 @@
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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.             
-*
-**/
-
-#ifndef __BDS_INTERNAL_H__
-#define __BDS_INTERNAL_H__
-
-#include <PiDxe.h>
-#include <Library/ArmLib.h>
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/HobLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiLib.h>
-#include <Library/DevicePathLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/DebugLib.h>
-#include <Library/BdsLib.h>
-#include <Library/PcdLib.h>
-#include <Library/PerformanceLib.h>
-#include <Library/PrintLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-
-#include <Guid/ArmMpCoreInfo.h>
-#include <Guid/GlobalVariable.h>
-#include <Guid/FileInfo.h>
-
-#include <Protocol/DevicePath.h>
-#include <Protocol/DevicePathFromText.h>
-#include <Protocol/SimpleFileSystem.h>
-#include <Protocol/FirmwareVolume2.h>
-#include <Protocol/LoadFile.h>
-#include <Protocol/PxeBaseCode.h>
-
-#include <Uefi.h>
-
-typedef BOOLEAN (*BDS_FILE_LOADER_SUPPORT) (
-  IN EFI_DEVICE_PATH            *DevicePath,
-  IN EFI_HANDLE                 Handle,
-  IN EFI_DEVICE_PATH            *RemainingDevicePath
-  );
-
-typedef EFI_STATUS (*BDS_FILE_LOADER_LOAD_IMAGE) (
-  IN     EFI_DEVICE_PATH        *DevicePath,
-  IN     EFI_HANDLE             Handle,
-  IN     EFI_DEVICE_PATH        *RemainingDevicePath,
-  IN     EFI_ALLOCATE_TYPE      Type,
-  IN OUT EFI_PHYSICAL_ADDRESS*  Image,
-  OUT    UINTN                  *ImageSize
-  );
-
-typedef struct {
-  BDS_FILE_LOADER_SUPPORT     Support;
-  BDS_FILE_LOADER_LOAD_IMAGE  LoadImage;
-} BDS_FILE_LOADER;
-
-typedef struct _BDS_SYSTEM_MEMORY_RESOURCE {
-  LIST_ENTRY                  Link; // This attribute must be the first entry of this structure (to avoid pointer computation)
-  EFI_PHYSICAL_ADDRESS        PhysicalStart;
-  UINT64                      ResourceLength;
-} BDS_SYSTEM_MEMORY_RESOURCE;
-
-
-// BdsHelper.c
-EFI_STATUS
-ShutdownUefiBootServices (
-  VOID
-  );
-
-EFI_STATUS
-GetSystemMemoryResources (
-  LIST_ENTRY *ResourceList
-  );
-
-VOID
-PrintPerformance (
-  VOID
-  );
-
-EFI_STATUS
-BdsLoadImage (
-  IN     EFI_DEVICE_PATH       *DevicePath,
-  IN     EFI_ALLOCATE_TYPE     Type,
-  IN OUT EFI_PHYSICAL_ADDRESS* Image,
-  OUT    UINTN                 *FileSize
-  );
-
-#endif
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#ifndef __BDS_INTERNAL_H__\r
+#define __BDS_INTERNAL_H__\r
+\r
+#include <PiDxe.h>\r
+#include <Library/ArmLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BdsLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/PerformanceLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+\r
+#include <Guid/ArmMpCoreInfo.h>\r
+#include <Guid/GlobalVariable.h>\r
+#include <Guid/FileInfo.h>\r
+\r
+#include <Protocol/DevicePath.h>\r
+#include <Protocol/DevicePathFromText.h>\r
+#include <Protocol/SimpleFileSystem.h>\r
+#include <Protocol/FirmwareVolume2.h>\r
+#include <Protocol/LoadFile.h>\r
+#include <Protocol/PxeBaseCode.h>\r
+\r
+#include <Uefi.h>\r
+\r
+typedef BOOLEAN (*BDS_FILE_LOADER_SUPPORT) (\r
+  IN EFI_DEVICE_PATH            *DevicePath,\r
+  IN EFI_HANDLE                 Handle,\r
+  IN EFI_DEVICE_PATH            *RemainingDevicePath\r
+  );\r
+\r
+typedef EFI_STATUS (*BDS_FILE_LOADER_LOAD_IMAGE) (\r
+  IN     EFI_DEVICE_PATH        *DevicePath,\r
+  IN     EFI_HANDLE             Handle,\r
+  IN     EFI_DEVICE_PATH        *RemainingDevicePath,\r
+  IN     EFI_ALLOCATE_TYPE      Type,\r
+  IN OUT EFI_PHYSICAL_ADDRESS*  Image,\r
+  OUT    UINTN                  *ImageSize\r
+  );\r
+\r
+typedef struct {\r
+  BDS_FILE_LOADER_SUPPORT     Support;\r
+  BDS_FILE_LOADER_LOAD_IMAGE  LoadImage;\r
+} BDS_FILE_LOADER;\r
+\r
+typedef struct _BDS_SYSTEM_MEMORY_RESOURCE {\r
+  LIST_ENTRY                  Link; // This attribute must be the first entry of this structure (to avoid pointer computation)\r
+  EFI_PHYSICAL_ADDRESS        PhysicalStart;\r
+  UINT64                      ResourceLength;\r
+} BDS_SYSTEM_MEMORY_RESOURCE;\r
+\r
+\r
+// BdsHelper.c\r
+EFI_STATUS\r
+ShutdownUefiBootServices (\r
+  VOID\r
+  );\r
+\r
+EFI_STATUS\r
+GetSystemMemoryResources (\r
+  LIST_ENTRY *ResourceList\r
+  );\r
+\r
+VOID\r
+PrintPerformance (\r
+  VOID\r
+  );\r
+\r
+EFI_STATUS\r
+BdsLoadImage (\r
+  IN     EFI_DEVICE_PATH       *DevicePath,\r
+  IN     EFI_ALLOCATE_TYPE     Type,\r
+  IN OUT EFI_PHYSICAL_ADDRESS* Image,\r
+  OUT    UINTN                 *FileSize\r
+  );\r
+\r
+#endif\r
index 9dee03a7957ee981eb3b5141110c3da7900e7784..a79f166b40f21d2c076549e0479058f3b0e45d06 100644 (file)
@@ -1,77 +1,77 @@
-#/* @file
-#  
-#  Copyright (c) 2011-2012, ARM Limited. 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                      = BdsLib
-  FILE_GUID                      = ddbf73a0-bb25-11df-8e4e-0002a5d5c51b
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = BdsLib
-
-[Sources.common]
-  BdsFilePath.c
-  BdsAppLoader.c
-  BdsHelper.c
-  BdsLoadOption.c
-
-  BdsLinuxLoader.c
-  BdsLinuxAtag.c
-  BdsLinuxFdt.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  ArmPkg/ArmPkg.dec
-
-[LibraryClasses]
-  ArmLib
-  BaseLib
-  DebugLib
-  DevicePathLib
-  HobLib
-  PerformanceLib
-  SerialPortLib
-  FdtLib
-
-[Guids]
-  gEfiFileInfoGuid
-  gArmMpCoreInfoGuid
-
-[Protocols]
-  gEfiBdsArchProtocolGuid                       
-  gEfiDevicePathProtocolGuid
-  gEfiDevicePathFromTextProtocolGuid
-  gEfiSimpleFileSystemProtocolGuid
-  gEfiFirmwareVolume2ProtocolGuid
-  gEfiLoadFileProtocolGuid
-  gEfiPxeBaseCodeProtocolGuid
-  gEfiDiskIoProtocolGuid
-  gEfiUsbIoProtocolGuid
-  gEfiLoadedImageProtocolGuid
-    
-[FeaturePcd]  
-
-[FixedPcd]
-  gArmTokenSpaceGuid.PcdSystemMemoryBase
-  gArmTokenSpaceGuid.PcdSystemMemorySize
-
-  gArmTokenSpaceGuid.PcdArmMachineType
-  gArmTokenSpaceGuid.PcdArmLinuxFdtMaxOffset
-  gArmTokenSpaceGuid.PcdArmLinuxKernelFixedOffset
-  gArmTokenSpaceGuid.PcdArmLinuxKernelMaxOffset
-  gArmTokenSpaceGuid.PcdArmLinuxAtagMaxOffset
-  
-[Depex]
-  TRUE
+#/* @file\r
+#  \r
+#  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+#*/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = BdsLib\r
+  FILE_GUID                      = ddbf73a0-bb25-11df-8e4e-0002a5d5c51b\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = BdsLib\r
+\r
+[Sources.common]\r
+  BdsFilePath.c\r
+  BdsAppLoader.c\r
+  BdsHelper.c\r
+  BdsLoadOption.c\r
+\r
+  BdsLinuxLoader.c\r
+  BdsLinuxAtag.c\r
+  BdsLinuxFdt.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+\r
+[LibraryClasses]\r
+  ArmLib\r
+  BaseLib\r
+  DebugLib\r
+  DevicePathLib\r
+  HobLib\r
+  PerformanceLib\r
+  SerialPortLib\r
+  FdtLib\r
+\r
+[Guids]\r
+  gEfiFileInfoGuid\r
+  gArmMpCoreInfoGuid\r
+\r
+[Protocols]\r
+  gEfiBdsArchProtocolGuid                       \r
+  gEfiDevicePathProtocolGuid\r
+  gEfiDevicePathFromTextProtocolGuid\r
+  gEfiSimpleFileSystemProtocolGuid\r
+  gEfiFirmwareVolume2ProtocolGuid\r
+  gEfiLoadFileProtocolGuid\r
+  gEfiPxeBaseCodeProtocolGuid\r
+  gEfiDiskIoProtocolGuid\r
+  gEfiUsbIoProtocolGuid\r
+  gEfiLoadedImageProtocolGuid\r
+    \r
+[FeaturePcd]  \r
+\r
+[FixedPcd]\r
+  gArmTokenSpaceGuid.PcdSystemMemoryBase\r
+  gArmTokenSpaceGuid.PcdSystemMemorySize\r
+\r
+  gArmTokenSpaceGuid.PcdArmMachineType\r
+  gArmTokenSpaceGuid.PcdArmLinuxFdtMaxOffset\r
+  gArmTokenSpaceGuid.PcdArmLinuxKernelFixedOffset\r
+  gArmTokenSpaceGuid.PcdArmLinuxKernelMaxOffset\r
+  gArmTokenSpaceGuid.PcdArmLinuxAtagMaxOffset\r
+  \r
+[Depex]\r
+  TRUE\r
index b59df07622e0e33453a3d912b687ee27040cdf73..8946b142365b2f3061f44a2d727baabb6e8e595e 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 "BdsInternal.h"
-#include "BdsLinuxLoader.h"
-
-// Point to the current ATAG
-STATIC LINUX_ATAG *mLinuxKernelCurrentAtag;
-
-STATIC
-VOID
-SetupCoreTag (
-  IN UINT32 PageSize
-  )
-{
-  mLinuxKernelCurrentAtag->header.size = tag_size(LINUX_ATAG_CORE);
-  mLinuxKernelCurrentAtag->header.type = ATAG_CORE;
-
-  mLinuxKernelCurrentAtag->body.core_tag.flags    = 1;            /* ensure read-only */
-  mLinuxKernelCurrentAtag->body.core_tag.pagesize = PageSize;     /* systems PageSize (4k) */
-  mLinuxKernelCurrentAtag->body.core_tag.rootdev  = 0;            /* zero root device (typically overridden from kernel command line )*/
-
-  // move pointer to next tag
-  mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);
-}
-
-STATIC
-VOID
-SetupMemTag (
-  IN UINTN StartAddress,
-  IN UINT32 Size
-  )
-{
-  mLinuxKernelCurrentAtag->header.size = tag_size(LINUX_ATAG_MEM);
-  mLinuxKernelCurrentAtag->header.type = ATAG_MEM;
-
-  mLinuxKernelCurrentAtag->body.mem_tag.start = StartAddress;    /* Start of memory chunk for AtagMem */
-  mLinuxKernelCurrentAtag->body.mem_tag.size  = Size;             /* Size of memory chunk for AtagMem */
-
-  // move pointer to next tag
-  mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);
-}
-
-STATIC
-VOID
-SetupCmdlineTag (
-  IN CONST CHAR8 *CmdLine
-  )
-{
-  UINT32 LineLength;
-
-  // Increment the line length by 1 to account for the null string terminator character
-  LineLength = AsciiStrLen(CmdLine) + 1;
-
-  /* Check for NULL strings.
-   * Do not insert a tag for an empty CommandLine, don't even modify the tag address pointer.
-   * Remember, you have at least one null string terminator character.
-   */
-  if(LineLength > 1) {
-    mLinuxKernelCurrentAtag->header.size = ((UINT32)sizeof(LINUX_ATAG_HEADER) + LineLength + (UINT32)3) >> 2;
-    mLinuxKernelCurrentAtag->header.type = ATAG_CMDLINE;
-
-    /* place CommandLine into tag */
-    AsciiStrCpy(mLinuxKernelCurrentAtag->body.cmdline_tag.cmdline, CmdLine);
-
-    // move pointer to next tag
-    mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);
-  }
-}
-
-STATIC
-VOID
-SetupInitrdTag (
-  IN UINT32 InitrdImage,
-  IN UINT32 InitrdImageSize
-  )
-{
-  mLinuxKernelCurrentAtag->header.size = tag_size(LINUX_ATAG_INITRD2);
-  mLinuxKernelCurrentAtag->header.type = ATAG_INITRD2;
-
-  mLinuxKernelCurrentAtag->body.initrd2_tag.start = InitrdImage;
-  mLinuxKernelCurrentAtag->body.initrd2_tag.size = InitrdImageSize;
-
-  // Move pointer to next tag
-  mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);
-}
-STATIC
-VOID
-SetupEndTag (
-  VOID
-  )
-{
-  // Empty tag ends list; this has zero length and no body
-  mLinuxKernelCurrentAtag->header.type = ATAG_NONE;
-  mLinuxKernelCurrentAtag->header.size = 0;
-
-  /* We can not calculate the next address by using the standard macro:
-   * Params = next_tag_address(Params);
-   * because it relies on the header.size, which here it is 0 (zero).
-   * The easiest way is to add the sizeof(mLinuxKernelCurrentAtag->header).
-   */
-  mLinuxKernelCurrentAtag = (LINUX_ATAG*)((UINT32)mLinuxKernelCurrentAtag + sizeof(mLinuxKernelCurrentAtag->header));
-}
-
-EFI_STATUS
-PrepareAtagList (
-  IN  CONST CHAR8*          CommandLineString,
-  IN  EFI_PHYSICAL_ADDRESS  InitrdImage,
-  IN  UINTN                 InitrdImageSize,
-  OUT EFI_PHYSICAL_ADDRESS  *AtagBase,
-  OUT UINT32                *AtagSize
-  )
-{
-  EFI_STATUS                  Status;
-  LIST_ENTRY                  *ResourceLink;
-  LIST_ENTRY                  ResourceList;
-  EFI_PHYSICAL_ADDRESS        AtagStartAddress;
-  BDS_SYSTEM_MEMORY_RESOURCE  *Resource;
-
-  AtagStartAddress = LINUX_ATAG_MAX_OFFSET;
-  Status = gBS->AllocatePages (AllocateMaxAddress, EfiBootServicesData, EFI_SIZE_TO_PAGES(ATAG_MAX_SIZE), &AtagStartAddress);
-  if (EFI_ERROR(Status)) {
-    DEBUG ((EFI_D_WARN, "Warning: Failed to allocate Atag at 0x%lX (%r). The Atag will be allocated somewhere else in System Memory.\n", AtagStartAddress, Status));
-    Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesData, EFI_SIZE_TO_PAGES(ATAG_MAX_SIZE), &AtagStartAddress);
-    ASSERT_EFI_ERROR(Status);
-  }
-
-  // Ready to setup the atag list
-  mLinuxKernelCurrentAtag = (LINUX_ATAG*)(UINTN)AtagStartAddress;
-
-  // Standard core tag 4k PageSize
-  SetupCoreTag( (UINT32)SIZE_4KB );
-
-  // Physical memory setup
-  GetSystemMemoryResources (&ResourceList);
-  ResourceLink = ResourceList.ForwardLink;
-  while (ResourceLink != NULL && ResourceLink != &ResourceList) {
-    Resource = (BDS_SYSTEM_MEMORY_RESOURCE*)ResourceLink;
-    DEBUG((EFI_D_INFO,"- [0x%08X,0x%08X]\n",(UINT32)Resource->PhysicalStart,(UINT32)Resource->PhysicalStart+(UINT32)Resource->ResourceLength));
-    SetupMemTag( (UINT32)Resource->PhysicalStart, (UINT32)Resource->ResourceLength );
-    ResourceLink = ResourceLink->ForwardLink;
-  }
-
-  // CommandLine setting root device
-  if (CommandLineString) {
-    SetupCmdlineTag (CommandLineString);
-  }
-
-  if (InitrdImageSize > 0 && InitrdImage != 0) {
-    SetupInitrdTag ((UINT32)InitrdImage, (UINT32)InitrdImageSize);
-  }
-
-  // End of tags
-  SetupEndTag();
-
-  // Calculate atag list size
-  *AtagBase = AtagStartAddress;
-  *AtagSize = (UINT32)mLinuxKernelCurrentAtag - (UINT32)AtagStartAddress + 1;
-
-  return EFI_SUCCESS;
-}
-
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include "BdsInternal.h"\r
+#include "BdsLinuxLoader.h"\r
+\r
+// Point to the current ATAG\r
+STATIC LINUX_ATAG *mLinuxKernelCurrentAtag;\r
+\r
+STATIC\r
+VOID\r
+SetupCoreTag (\r
+  IN UINT32 PageSize\r
+  )\r
+{\r
+  mLinuxKernelCurrentAtag->header.size = tag_size(LINUX_ATAG_CORE);\r
+  mLinuxKernelCurrentAtag->header.type = ATAG_CORE;\r
+\r
+  mLinuxKernelCurrentAtag->body.core_tag.flags    = 1;            /* ensure read-only */\r
+  mLinuxKernelCurrentAtag->body.core_tag.pagesize = PageSize;     /* systems PageSize (4k) */\r
+  mLinuxKernelCurrentAtag->body.core_tag.rootdev  = 0;            /* zero root device (typically overridden from kernel command line )*/\r
+\r
+  // move pointer to next tag\r
+  mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);\r
+}\r
+\r
+STATIC\r
+VOID\r
+SetupMemTag (\r
+  IN UINTN StartAddress,\r
+  IN UINT32 Size\r
+  )\r
+{\r
+  mLinuxKernelCurrentAtag->header.size = tag_size(LINUX_ATAG_MEM);\r
+  mLinuxKernelCurrentAtag->header.type = ATAG_MEM;\r
+\r
+  mLinuxKernelCurrentAtag->body.mem_tag.start = StartAddress;    /* Start of memory chunk for AtagMem */\r
+  mLinuxKernelCurrentAtag->body.mem_tag.size  = Size;             /* Size of memory chunk for AtagMem */\r
+\r
+  // move pointer to next tag\r
+  mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);\r
+}\r
+\r
+STATIC\r
+VOID\r
+SetupCmdlineTag (\r
+  IN CONST CHAR8 *CmdLine\r
+  )\r
+{\r
+  UINT32 LineLength;\r
+\r
+  // Increment the line length by 1 to account for the null string terminator character\r
+  LineLength = AsciiStrLen(CmdLine) + 1;\r
+\r
+  /* Check for NULL strings.\r
+   * Do not insert a tag for an empty CommandLine, don't even modify the tag address pointer.\r
+   * Remember, you have at least one null string terminator character.\r
+   */\r
+  if(LineLength > 1) {\r
+    mLinuxKernelCurrentAtag->header.size = ((UINT32)sizeof(LINUX_ATAG_HEADER) + LineLength + (UINT32)3) >> 2;\r
+    mLinuxKernelCurrentAtag->header.type = ATAG_CMDLINE;\r
+\r
+    /* place CommandLine into tag */\r
+    AsciiStrCpy(mLinuxKernelCurrentAtag->body.cmdline_tag.cmdline, CmdLine);\r
+\r
+    // move pointer to next tag\r
+    mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);\r
+  }\r
+}\r
+\r
+STATIC\r
+VOID\r
+SetupInitrdTag (\r
+  IN UINT32 InitrdImage,\r
+  IN UINT32 InitrdImageSize\r
+  )\r
+{\r
+  mLinuxKernelCurrentAtag->header.size = tag_size(LINUX_ATAG_INITRD2);\r
+  mLinuxKernelCurrentAtag->header.type = ATAG_INITRD2;\r
+\r
+  mLinuxKernelCurrentAtag->body.initrd2_tag.start = InitrdImage;\r
+  mLinuxKernelCurrentAtag->body.initrd2_tag.size = InitrdImageSize;\r
+\r
+  // Move pointer to next tag\r
+  mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);\r
+}\r
+STATIC\r
+VOID\r
+SetupEndTag (\r
+  VOID\r
+  )\r
+{\r
+  // Empty tag ends list; this has zero length and no body\r
+  mLinuxKernelCurrentAtag->header.type = ATAG_NONE;\r
+  mLinuxKernelCurrentAtag->header.size = 0;\r
+\r
+  /* We can not calculate the next address by using the standard macro:\r
+   * Params = next_tag_address(Params);\r
+   * because it relies on the header.size, which here it is 0 (zero).\r
+   * The easiest way is to add the sizeof(mLinuxKernelCurrentAtag->header).\r
+   */\r
+  mLinuxKernelCurrentAtag = (LINUX_ATAG*)((UINT32)mLinuxKernelCurrentAtag + sizeof(mLinuxKernelCurrentAtag->header));\r
+}\r
+\r
+EFI_STATUS\r
+PrepareAtagList (\r
+  IN  CONST CHAR8*          CommandLineString,\r
+  IN  EFI_PHYSICAL_ADDRESS  InitrdImage,\r
+  IN  UINTN                 InitrdImageSize,\r
+  OUT EFI_PHYSICAL_ADDRESS  *AtagBase,\r
+  OUT UINT32                *AtagSize\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  LIST_ENTRY                  *ResourceLink;\r
+  LIST_ENTRY                  ResourceList;\r
+  EFI_PHYSICAL_ADDRESS        AtagStartAddress;\r
+  BDS_SYSTEM_MEMORY_RESOURCE  *Resource;\r
+\r
+  AtagStartAddress = LINUX_ATAG_MAX_OFFSET;\r
+  Status = gBS->AllocatePages (AllocateMaxAddress, EfiBootServicesData, EFI_SIZE_TO_PAGES(ATAG_MAX_SIZE), &AtagStartAddress);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG ((EFI_D_WARN, "Warning: Failed to allocate Atag at 0x%lX (%r). The Atag will be allocated somewhere else in System Memory.\n", AtagStartAddress, Status));\r
+    Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesData, EFI_SIZE_TO_PAGES(ATAG_MAX_SIZE), &AtagStartAddress);\r
+    ASSERT_EFI_ERROR(Status);\r
+  }\r
+\r
+  // Ready to setup the atag list\r
+  mLinuxKernelCurrentAtag = (LINUX_ATAG*)(UINTN)AtagStartAddress;\r
+\r
+  // Standard core tag 4k PageSize\r
+  SetupCoreTag( (UINT32)SIZE_4KB );\r
+\r
+  // Physical memory setup\r
+  GetSystemMemoryResources (&ResourceList);\r
+  ResourceLink = ResourceList.ForwardLink;\r
+  while (ResourceLink != NULL && ResourceLink != &ResourceList) {\r
+    Resource = (BDS_SYSTEM_MEMORY_RESOURCE*)ResourceLink;\r
+    DEBUG((EFI_D_INFO,"- [0x%08X,0x%08X]\n",(UINT32)Resource->PhysicalStart,(UINT32)Resource->PhysicalStart+(UINT32)Resource->ResourceLength));\r
+    SetupMemTag( (UINT32)Resource->PhysicalStart, (UINT32)Resource->ResourceLength );\r
+    ResourceLink = ResourceLink->ForwardLink;\r
+  }\r
+\r
+  // CommandLine setting root device\r
+  if (CommandLineString) {\r
+    SetupCmdlineTag (CommandLineString);\r
+  }\r
+\r
+  if (InitrdImageSize > 0 && InitrdImage != 0) {\r
+    SetupInitrdTag ((UINT32)InitrdImage, (UINT32)InitrdImageSize);\r
+  }\r
+\r
+  // End of tags\r
+  SetupEndTag();\r
+\r
+  // Calculate atag list size\r
+  *AtagBase = AtagStartAddress;\r
+  *AtagSize = (UINT32)mLinuxKernelCurrentAtag - (UINT32)AtagStartAddress + 1;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
index 901781f2f852bc158e6ef64e9c40edefed00b85e..e3249e130775d7f0fe4282651e2a14b5b3d514e5 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 "BdsInternal.h"
-#include "BdsLinuxLoader.h"
-
-#define ALIGN32_BELOW(addr)   ALIGN_POINTER(addr - 32,32)
-
-STATIC
-EFI_STATUS
-PreparePlatformHardware (
-  VOID
-  )
-{
-  //Note: Interrupts will be disabled by the GIC driver when ExitBootServices() will be called.
-
-  // Clean, invalidate, disable data cache
-  ArmDisableDataCache();
-  ArmCleanInvalidateDataCache();
-
-  // Invalidate and disable the Instruction cache
-  ArmDisableInstructionCache ();
-  ArmInvalidateInstructionCache ();
-
-  // Turn off MMU
-  ArmDisableMmu();
-
-  return EFI_SUCCESS;
-}
-
-STATIC
-EFI_STATUS
-StartLinux (
-  IN  EFI_PHYSICAL_ADDRESS  LinuxImage,
-  IN  UINTN                 LinuxImageSize,
-  IN  EFI_PHYSICAL_ADDRESS  KernelParamsAddress,
-  IN  UINTN                 KernelParamsSize,
-  IN  UINT32                MachineType
-  )
-{
-  EFI_STATUS            Status;
-  LINUX_KERNEL          LinuxKernel;
-
-  // Shut down UEFI boot services. ExitBootServices() will notify every driver that created an event on
-  // ExitBootServices event. Example the Interrupt DXE driver will disable the interrupts on this event.
-  Status = ShutdownUefiBootServices ();
-  if(EFI_ERROR(Status)) {
-    DEBUG((EFI_D_ERROR,"ERROR: Can not shutdown UEFI boot services. Status=0x%X\n", Status));
-    goto Exit;
-  }
-
-  // Move the kernel parameters to any address inside the first 1MB.
-  // This is necessary because the ARM Linux kernel requires
-  // the FTD / ATAG List to reside entirely inside the first 1MB of
-  // physical memory.
-  //Note: There is no requirement on the alignment
-  if (MachineType != ARM_FDT_MACHINE_TYPE) {
-    if (((UINTN)KernelParamsAddress > LINUX_ATAG_MAX_OFFSET) && (KernelParamsSize < PcdGet32(PcdArmLinuxAtagMaxOffset))) {
-      KernelParamsAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)CopyMem (ALIGN32_BELOW(LINUX_ATAG_MAX_OFFSET - KernelParamsSize), (VOID*)(UINTN)KernelParamsAddress, KernelParamsSize);
-    }
-  } else {
-    if (((UINTN)KernelParamsAddress > LINUX_FDT_MAX_OFFSET) && (KernelParamsSize < PcdGet32(PcdArmLinuxFdtMaxOffset))) {
-      KernelParamsAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)CopyMem (ALIGN32_BELOW(LINUX_FDT_MAX_OFFSET - KernelParamsSize), (VOID*)(UINTN)KernelParamsAddress, KernelParamsSize);
-    }
-  }
-
-  if ((UINTN)LinuxImage > LINUX_KERNEL_MAX_OFFSET) {
-    //Note: There is no requirement on the alignment
-    LinuxKernel = (LINUX_KERNEL)CopyMem (ALIGN32_BELOW(LINUX_KERNEL_MAX_OFFSET - LinuxImageSize), (VOID*)(UINTN)LinuxImage, LinuxImageSize);
-  } else {
-    LinuxKernel = (LINUX_KERNEL)(UINTN)LinuxImage;
-  }
-
-  // Check if the Linux Image is a uImage
-  if (*(UINT32*)LinuxKernel == LINUX_UIMAGE_SIGNATURE) {
-    // Assume the Image Entry Point is just after the uImage header (64-byte size)
-    LinuxKernel = (LINUX_KERNEL)((UINTN)LinuxKernel + 64);
-    LinuxImageSize -= 64;
-  }
-
-  //TODO: Check there is no overlapping between kernel and Atag
-
-  //
-  // Switch off interrupts, caches, mmu, etc
-  //
-  Status = PreparePlatformHardware ();
-  ASSERT_EFI_ERROR(Status);
-
-  // Register and print out performance information
-  PERF_END (NULL, "BDS", NULL, 0);
-  if (PerformanceMeasurementEnabled ()) {
-    PrintPerformance ();
-  }
-
-  //
-  // Start the Linux Kernel
-  //
-
-  // Outside BootServices, so can't use Print();
-  DEBUG((EFI_D_ERROR, "\nStarting the kernel:\n\n"));
-
-  // Jump to kernel with register set
-  LinuxKernel ((UINTN)0, MachineType, (UINTN)KernelParamsAddress);
-
-  // Kernel should never exit
-  // After Life services are not provided
-  ASSERT(FALSE);
-
-Exit:
-  // Only be here if we fail to start Linux
-  Print (L"ERROR  : Can not start the kernel. Status=0x%X\n", Status);
-
-  // Free Runtimee Memory (kernel and FDT)
-  return Status;
-}
-
-/**
-  Start a Linux kernel from a Device Path
-
-  @param  LinuxKernel           Device Path to the Linux Kernel
-  @param  Parameters            Linux kernel arguments
-  @param  Fdt                   Device Path to the Flat Device Tree
-
-  @retval EFI_SUCCESS           All drivers have been connected
-  @retval EFI_NOT_FOUND         The Linux kernel Device Path has not been found
-  @retval EFI_OUT_OF_RESOURCES  There is not enough resource memory to store the matching results.
-
-**/
-EFI_STATUS
-BdsBootLinuxAtag (
-  IN  EFI_DEVICE_PATH_PROTOCOL* LinuxKernelDevicePath,
-  IN  EFI_DEVICE_PATH_PROTOCOL* InitrdDevicePath,
-  IN  CONST CHAR8*              CommandLineArguments
-  )
-{
-  EFI_STATUS            Status;
-  UINT32                LinuxImageSize;
-  UINT32                InitrdImageSize = 0;
-  UINT32                AtagSize;
-  EFI_PHYSICAL_ADDRESS  AtagBase;
-  EFI_PHYSICAL_ADDRESS  LinuxImage;
-  EFI_PHYSICAL_ADDRESS  InitrdImage;
-
-  PERF_START (NULL, "BDS", NULL, 0);
-
-  // Load the Linux kernel from a device path
-  LinuxImage = LINUX_KERNEL_MAX_OFFSET;
-  Status = BdsLoadImage (LinuxKernelDevicePath, AllocateMaxAddress, &LinuxImage, &LinuxImageSize);
-  if (EFI_ERROR(Status)) {
-    Print (L"ERROR: Did not find Linux kernel.\n");
-    return Status;
-  }
-
-  if (InitrdDevicePath) {
-    // Load the initrd near to the Linux kernel
-    InitrdImage = LINUX_KERNEL_MAX_OFFSET;
-    Status = BdsLoadImage (InitrdDevicePath, AllocateMaxAddress, &InitrdImage, &InitrdImageSize);
-    if (Status == EFI_OUT_OF_RESOURCES) {
-      Status = BdsLoadImage (InitrdDevicePath, AllocateAnyPages, &InitrdImage, &InitrdImageSize);
-    }
-    if (EFI_ERROR(Status)) {
-      Print (L"ERROR: Did not find initrd image.\n");
-      return Status;
-    }
-    
-    // Check if the initrd is a uInitrd
-    if (*(UINT32*)((UINTN)InitrdImage) == LINUX_UIMAGE_SIGNATURE) {
-      // Skip the 64-byte image header
-      InitrdImage = (EFI_PHYSICAL_ADDRESS)((UINTN)InitrdImage + 64);
-      InitrdImageSize -= 64;
-    }
-  }
-
-  //
-  // Setup the Linux Kernel Parameters
-  //
-  // By setting address=0 we leave the memory allocation to the function
-  Status = PrepareAtagList (CommandLineArguments, InitrdImage, InitrdImageSize, &AtagBase, &AtagSize);
-  if (EFI_ERROR(Status)) {
-    Print(L"ERROR: Can not prepare ATAG list. Status=0x%X\n", Status);
-    return Status;
-  }
-
-  return StartLinux (LinuxImage, LinuxImageSize, AtagBase, AtagSize, PcdGet32(PcdArmMachineType));
-}
-
-/**
-  Start a Linux kernel from a Device Path
-
-  @param  LinuxKernel           Device Path to the Linux Kernel
-  @param  Parameters            Linux kernel arguments
-  @param  Fdt                   Device Path to the Flat Device Tree
-
-  @retval EFI_SUCCESS           All drivers have been connected
-  @retval EFI_NOT_FOUND         The Linux kernel Device Path has not been found
-  @retval EFI_OUT_OF_RESOURCES  There is not enough resource memory to store the matching results.
-
-**/
-EFI_STATUS
-BdsBootLinuxFdt (
-  IN  EFI_DEVICE_PATH_PROTOCOL* LinuxKernelDevicePath,
-  IN  EFI_DEVICE_PATH_PROTOCOL* InitrdDevicePath,
-  IN  CONST CHAR8*              CommandLineArguments,
-  IN  EFI_DEVICE_PATH_PROTOCOL* FdtDevicePath
-  )
-{
-  EFI_STATUS            Status;
-  UINT32                LinuxImageSize;
-  UINT32                InitrdImageSize = 0;
-  UINT32                FdtBlobSize;
-  EFI_PHYSICAL_ADDRESS  FdtBlobBase;
-  EFI_PHYSICAL_ADDRESS  LinuxImage;
-  EFI_PHYSICAL_ADDRESS  InitrdImage;
-
-  PERF_START (NULL, "BDS", NULL, 0);
-
-  // Load the Linux kernel from a device path
-  LinuxImage = LINUX_KERNEL_MAX_OFFSET;
-  Status = BdsLoadImage (LinuxKernelDevicePath, AllocateMaxAddress, &LinuxImage, &LinuxImageSize);
-  if (EFI_ERROR(Status)) {
-    Print (L"ERROR: Did not find Linux kernel.\n");
-    return Status;
-  }
-
-  if (InitrdDevicePath) {
-    InitrdImage = LINUX_KERNEL_MAX_OFFSET;
-    Status = BdsLoadImage (InitrdDevicePath, AllocateMaxAddress, &InitrdImage, &InitrdImageSize);
-    if (Status == EFI_OUT_OF_RESOURCES) {
-      Status = BdsLoadImage (InitrdDevicePath, AllocateAnyPages, &InitrdImage, &InitrdImageSize);
-    }
-    if (EFI_ERROR(Status)) {
-      Print (L"ERROR: Did not find initrd image.\n");
-      return Status;
-    }
-
-    // Check if the initrd is a uInitrd
-    if (*(UINT32*)((UINTN)InitrdImage) == LINUX_UIMAGE_SIGNATURE) {
-      // Skip the 64-byte image header
-      InitrdImage = (EFI_PHYSICAL_ADDRESS)((UINTN)InitrdImage + 64);
-      InitrdImageSize -= 64;
-    }
-  }
-
-  // Load the FDT binary from a device path. The FDT will be reloaded later to a more appropriate location for the Linux kernel.
-  FdtBlobBase = 0;
-  Status = BdsLoadImage (FdtDevicePath, AllocateAnyPages, &FdtBlobBase, &FdtBlobSize);
-  if (EFI_ERROR(Status)) {
-    Print (L"ERROR: Did not find Device Tree blob.\n");
-    return Status;
-  }
-
-  // Update the Fdt with the Initrd information. The FDT will increase in size.
-  // By setting address=0 we leave the memory allocation to the function
-  Status = PrepareFdt (CommandLineArguments, InitrdImage, InitrdImageSize, &FdtBlobBase, &FdtBlobSize);
-  if (EFI_ERROR(Status)) {
-    Print(L"ERROR: Can not load kernel with FDT. Status=%r\n", Status);
-    return Status;
-  }
-
-  return StartLinux (LinuxImage, LinuxImageSize, FdtBlobBase, FdtBlobSize, ARM_FDT_MACHINE_TYPE);
-}
-
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include "BdsInternal.h"\r
+#include "BdsLinuxLoader.h"\r
+\r
+#define ALIGN32_BELOW(addr)   ALIGN_POINTER(addr - 32,32)\r
+\r
+STATIC\r
+EFI_STATUS\r
+PreparePlatformHardware (\r
+  VOID\r
+  )\r
+{\r
+  //Note: Interrupts will be disabled by the GIC driver when ExitBootServices() will be called.\r
+\r
+  // Clean, invalidate, disable data cache\r
+  ArmDisableDataCache();\r
+  ArmCleanInvalidateDataCache();\r
+\r
+  // Invalidate and disable the Instruction cache\r
+  ArmDisableInstructionCache ();\r
+  ArmInvalidateInstructionCache ();\r
+\r
+  // Turn off MMU\r
+  ArmDisableMmu();\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+StartLinux (\r
+  IN  EFI_PHYSICAL_ADDRESS  LinuxImage,\r
+  IN  UINTN                 LinuxImageSize,\r
+  IN  EFI_PHYSICAL_ADDRESS  KernelParamsAddress,\r
+  IN  UINTN                 KernelParamsSize,\r
+  IN  UINT32                MachineType\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  LINUX_KERNEL          LinuxKernel;\r
+\r
+  // Shut down UEFI boot services. ExitBootServices() will notify every driver that created an event on\r
+  // ExitBootServices event. Example the Interrupt DXE driver will disable the interrupts on this event.\r
+  Status = ShutdownUefiBootServices ();\r
+  if(EFI_ERROR(Status)) {\r
+    DEBUG((EFI_D_ERROR,"ERROR: Can not shutdown UEFI boot services. Status=0x%X\n", Status));\r
+    goto Exit;\r
+  }\r
+\r
+  // Move the kernel parameters to any address inside the first 1MB.\r
+  // This is necessary because the ARM Linux kernel requires\r
+  // the FTD / ATAG List to reside entirely inside the first 1MB of\r
+  // physical memory.\r
+  //Note: There is no requirement on the alignment\r
+  if (MachineType != ARM_FDT_MACHINE_TYPE) {\r
+    if (((UINTN)KernelParamsAddress > LINUX_ATAG_MAX_OFFSET) && (KernelParamsSize < PcdGet32(PcdArmLinuxAtagMaxOffset))) {\r
+      KernelParamsAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)CopyMem (ALIGN32_BELOW(LINUX_ATAG_MAX_OFFSET - KernelParamsSize), (VOID*)(UINTN)KernelParamsAddress, KernelParamsSize);\r
+    }\r
+  } else {\r
+    if (((UINTN)KernelParamsAddress > LINUX_FDT_MAX_OFFSET) && (KernelParamsSize < PcdGet32(PcdArmLinuxFdtMaxOffset))) {\r
+      KernelParamsAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)CopyMem (ALIGN32_BELOW(LINUX_FDT_MAX_OFFSET - KernelParamsSize), (VOID*)(UINTN)KernelParamsAddress, KernelParamsSize);\r
+    }\r
+  }\r
+\r
+  if ((UINTN)LinuxImage > LINUX_KERNEL_MAX_OFFSET) {\r
+    //Note: There is no requirement on the alignment\r
+    LinuxKernel = (LINUX_KERNEL)CopyMem (ALIGN32_BELOW(LINUX_KERNEL_MAX_OFFSET - LinuxImageSize), (VOID*)(UINTN)LinuxImage, LinuxImageSize);\r
+  } else {\r
+    LinuxKernel = (LINUX_KERNEL)(UINTN)LinuxImage;\r
+  }\r
+\r
+  // Check if the Linux Image is a uImage\r
+  if (*(UINT32*)LinuxKernel == LINUX_UIMAGE_SIGNATURE) {\r
+    // Assume the Image Entry Point is just after the uImage header (64-byte size)\r
+    LinuxKernel = (LINUX_KERNEL)((UINTN)LinuxKernel + 64);\r
+    LinuxImageSize -= 64;\r
+  }\r
+\r
+  //TODO: Check there is no overlapping between kernel and Atag\r
+\r
+  //\r
+  // Switch off interrupts, caches, mmu, etc\r
+  //\r
+  Status = PreparePlatformHardware ();\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  // Register and print out performance information\r
+  PERF_END (NULL, "BDS", NULL, 0);\r
+  if (PerformanceMeasurementEnabled ()) {\r
+    PrintPerformance ();\r
+  }\r
+\r
+  //\r
+  // Start the Linux Kernel\r
+  //\r
+\r
+  // Outside BootServices, so can't use Print();\r
+  DEBUG((EFI_D_ERROR, "\nStarting the kernel:\n\n"));\r
+\r
+  // Jump to kernel with register set\r
+  LinuxKernel ((UINTN)0, MachineType, (UINTN)KernelParamsAddress);\r
+\r
+  // Kernel should never exit\r
+  // After Life services are not provided\r
+  ASSERT(FALSE);\r
+\r
+Exit:\r
+  // Only be here if we fail to start Linux\r
+  Print (L"ERROR  : Can not start the kernel. Status=0x%X\n", Status);\r
+\r
+  // Free Runtimee Memory (kernel and FDT)\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Start a Linux kernel from a Device Path\r
+\r
+  @param  LinuxKernel           Device Path to the Linux Kernel\r
+  @param  Parameters            Linux kernel arguments\r
+  @param  Fdt                   Device Path to the Flat Device Tree\r
+\r
+  @retval EFI_SUCCESS           All drivers have been connected\r
+  @retval EFI_NOT_FOUND         The Linux kernel Device Path has not been found\r
+  @retval EFI_OUT_OF_RESOURCES  There is not enough resource memory to store the matching results.\r
+\r
+**/\r
+EFI_STATUS\r
+BdsBootLinuxAtag (\r
+  IN  EFI_DEVICE_PATH_PROTOCOL* LinuxKernelDevicePath,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL* InitrdDevicePath,\r
+  IN  CONST CHAR8*              CommandLineArguments\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  UINT32                LinuxImageSize;\r
+  UINT32                InitrdImageSize = 0;\r
+  UINT32                AtagSize;\r
+  EFI_PHYSICAL_ADDRESS  AtagBase;\r
+  EFI_PHYSICAL_ADDRESS  LinuxImage;\r
+  EFI_PHYSICAL_ADDRESS  InitrdImage;\r
+\r
+  PERF_START (NULL, "BDS", NULL, 0);\r
+\r
+  // Load the Linux kernel from a device path\r
+  LinuxImage = LINUX_KERNEL_MAX_OFFSET;\r
+  Status = BdsLoadImage (LinuxKernelDevicePath, AllocateMaxAddress, &LinuxImage, &LinuxImageSize);\r
+  if (EFI_ERROR(Status)) {\r
+    Print (L"ERROR: Did not find Linux kernel.\n");\r
+    return Status;\r
+  }\r
+\r
+  if (InitrdDevicePath) {\r
+    // Load the initrd near to the Linux kernel\r
+    InitrdImage = LINUX_KERNEL_MAX_OFFSET;\r
+    Status = BdsLoadImage (InitrdDevicePath, AllocateMaxAddress, &InitrdImage, &InitrdImageSize);\r
+    if (Status == EFI_OUT_OF_RESOURCES) {\r
+      Status = BdsLoadImage (InitrdDevicePath, AllocateAnyPages, &InitrdImage, &InitrdImageSize);\r
+    }\r
+    if (EFI_ERROR(Status)) {\r
+      Print (L"ERROR: Did not find initrd image.\n");\r
+      return Status;\r
+    }\r
+    \r
+    // Check if the initrd is a uInitrd\r
+    if (*(UINT32*)((UINTN)InitrdImage) == LINUX_UIMAGE_SIGNATURE) {\r
+      // Skip the 64-byte image header\r
+      InitrdImage = (EFI_PHYSICAL_ADDRESS)((UINTN)InitrdImage + 64);\r
+      InitrdImageSize -= 64;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Setup the Linux Kernel Parameters\r
+  //\r
\r
+  // By setting address=0 we leave the memory allocation to the function\r
+  Status = PrepareAtagList (CommandLineArguments, InitrdImage, InitrdImageSize, &AtagBase, &AtagSize);\r
+  if (EFI_ERROR(Status)) {\r
+    Print(L"ERROR: Can not prepare ATAG list. Status=0x%X\n", Status);\r
+    return Status;\r
+  }\r
+\r
+  return StartLinux (LinuxImage, LinuxImageSize, AtagBase, AtagSize, PcdGet32(PcdArmMachineType));\r
+}\r
+\r
+/**\r
+  Start a Linux kernel from a Device Path\r
+\r
+  @param  LinuxKernel           Device Path to the Linux Kernel\r
+  @param  Parameters            Linux kernel arguments\r
+  @param  Fdt                   Device Path to the Flat Device Tree\r
+\r
+  @retval EFI_SUCCESS           All drivers have been connected\r
+  @retval EFI_NOT_FOUND         The Linux kernel Device Path has not been found\r
+  @retval EFI_OUT_OF_RESOURCES  There is not enough resource memory to store the matching results.\r
+\r
+**/\r
+EFI_STATUS\r
+BdsBootLinuxFdt (\r
+  IN  EFI_DEVICE_PATH_PROTOCOL* LinuxKernelDevicePath,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL* InitrdDevicePath,\r
+  IN  CONST CHAR8*              CommandLineArguments,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL* FdtDevicePath\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  UINT32                LinuxImageSize;\r
+  UINT32                InitrdImageSize = 0;\r
+  UINT32                FdtBlobSize;\r
+  EFI_PHYSICAL_ADDRESS  FdtBlobBase;\r
+  EFI_PHYSICAL_ADDRESS  LinuxImage;\r
+  EFI_PHYSICAL_ADDRESS  InitrdImage;\r
+\r
+  PERF_START (NULL, "BDS", NULL, 0);\r
+\r
+  // Load the Linux kernel from a device path\r
+  LinuxImage = LINUX_KERNEL_MAX_OFFSET;\r
+  Status = BdsLoadImage (LinuxKernelDevicePath, AllocateMaxAddress, &LinuxImage, &LinuxImageSize);\r
+  if (EFI_ERROR(Status)) {\r
+    Print (L"ERROR: Did not find Linux kernel.\n");\r
+    return Status;\r
+  }\r
+\r
+  if (InitrdDevicePath) {\r
+    InitrdImage = LINUX_KERNEL_MAX_OFFSET;\r
+    Status = BdsLoadImage (InitrdDevicePath, AllocateMaxAddress, &InitrdImage, &InitrdImageSize);\r
+    if (Status == EFI_OUT_OF_RESOURCES) {\r
+      Status = BdsLoadImage (InitrdDevicePath, AllocateAnyPages, &InitrdImage, &InitrdImageSize);\r
+    }\r
+    if (EFI_ERROR(Status)) {\r
+      Print (L"ERROR: Did not find initrd image.\n");\r
+      return Status;\r
+    }\r
+\r
+    // Check if the initrd is a uInitrd\r
+    if (*(UINT32*)((UINTN)InitrdImage) == LINUX_UIMAGE_SIGNATURE) {\r
+      // Skip the 64-byte image header\r
+      InitrdImage = (EFI_PHYSICAL_ADDRESS)((UINTN)InitrdImage + 64);\r
+      InitrdImageSize -= 64;\r
+    }\r
+  }\r
+\r
+  // Load the FDT binary from a device path. The FDT will be reloaded later to a more appropriate location for the Linux kernel.\r
+  FdtBlobBase = 0;\r
+  Status = BdsLoadImage (FdtDevicePath, AllocateAnyPages, &FdtBlobBase, &FdtBlobSize);\r
+  if (EFI_ERROR(Status)) {\r
+    Print (L"ERROR: Did not find Device Tree blob.\n");\r
+    return Status;\r
+  }\r
+\r
+  // Update the Fdt with the Initrd information. The FDT will increase in size.\r
+  // By setting address=0 we leave the memory allocation to the function\r
+  Status = PrepareFdt (CommandLineArguments, InitrdImage, InitrdImageSize, &FdtBlobBase, &FdtBlobSize);\r
+  if (EFI_ERROR(Status)) {\r
+    Print(L"ERROR: Can not load kernel with FDT. Status=%r\n", Status);\r
+    return Status;\r
+  }\r
+\r
+  return StartLinux (LinuxImage, LinuxImageSize, FdtBlobBase, FdtBlobSize, ARM_FDT_MACHINE_TYPE);\r
+}\r
+\r
index a9b7037d19cd080bc40b1f80e6cb9cddb9fcc723..a3ecddc4f1e04c52b271186de328a570ae9a081d 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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.             
-*
-**/
-
-#ifndef __BDSLINUXLOADER_H
-#define __BDSLINUXLOADER_H
-
-#define LINUX_UIMAGE_SIGNATURE    0x56190527
-#define LINUX_KERNEL_MAX_OFFSET   (PcdGet32(PcdSystemMemoryBase) + PcdGet32(PcdArmLinuxKernelMaxOffset))
-#define LINUX_ATAG_MAX_OFFSET     (PcdGet32(PcdSystemMemoryBase) + PcdGet32(PcdArmLinuxAtagMaxOffset))
-#define LINUX_FDT_MAX_OFFSET      (PcdGet32(PcdSystemMemoryBase) + PcdGet32(PcdArmLinuxFdtMaxOffset))
-
-// Additional size that could be used for FDT entries added by the UEFI OS Loader
-// Estimation based on: EDID (300bytes) + bootargs (200bytes) + initrd region (20bytes)
-//                      + system memory region (20bytes) + mp_core entries (200 bytes)
-#define FDT_ADDITIONAL_ENTRIES_SIZE     0x300
-
-#define ARM_FDT_MACHINE_TYPE            0xFFFFFFFF
-
-typedef VOID (*LINUX_KERNEL)(UINT32 Zero, UINT32 Arch, UINTN ParametersBase);
-
-//
-// ATAG Definitions
-//
-
-#define ATAG_MAX_SIZE        0x3000
-
-/* ATAG : list of possible tags */
-#define ATAG_NONE            0x00000000
-#define ATAG_CORE            0x54410001
-#define ATAG_MEM             0x54410002
-#define ATAG_VIDEOTEXT       0x54410003
-#define ATAG_RAMDISK         0x54410004
-#define ATAG_INITRD2         0x54420005
-#define ATAG_SERIAL          0x54410006
-#define ATAG_REVISION        0x54410007
-#define ATAG_VIDEOLFB        0x54410008
-#define ATAG_CMDLINE         0x54410009
-#define ATAG_ARM_MP_CORE     0x5441000A
-
-#define next_tag_address(t)  ((LINUX_ATAG*)((UINT32)(t) + (((t)->header.size) << 2) ))
-#define tag_size(type)       ((UINT32)((sizeof(LINUX_ATAG_HEADER) + sizeof(type)) >> 2))
-
-typedef struct {
-  UINT32  size; /* length of tag in words including this header */
-  UINT32  type;  /* tag type */
-} LINUX_ATAG_HEADER;
-
-typedef struct {
-  UINT32  flags;
-  UINT32  pagesize;
-  UINT32  rootdev;
-} LINUX_ATAG_CORE;
-
-typedef struct {
-  UINT32  size;
-  UINTN  start;
-} LINUX_ATAG_MEM;
-
-typedef struct {
-  UINT8   x;
-  UINT8   y;
-  UINT16  video_page;
-  UINT8   video_mode;
-  UINT8   video_cols;
-  UINT16  video_ega_bx;
-  UINT8   video_lines;
-  UINT8   video_isvga;
-  UINT16  video_points;
-} LINUX_ATAG_VIDEOTEXT;
-
-typedef struct {
-  UINT32  flags;
-  UINT32  size;
-  UINTN  start;
-} LINUX_ATAG_RAMDISK;
-
-typedef struct {
-  UINT32  start;
-  UINT32  size;
-} LINUX_ATAG_INITRD2;
-
-typedef struct {
-  UINT32  low;
-  UINT32  high;
-} LINUX_ATAG_SERIALNR;
-
-typedef struct {
-  UINT32  rev;
-} LINUX_ATAG_REVISION;
-
-typedef struct {
-  UINT16  lfb_width;
-  UINT16  lfb_height;
-  UINT16  lfb_depth;
-  UINT16  lfb_linelength;
-  UINT32  lfb_base;
-  UINT32  lfb_size;
-  UINT8   red_size;
-  UINT8   red_pos;
-  UINT8   green_size;
-  UINT8   green_pos;
-  UINT8   blue_size;
-  UINT8   blue_pos;
-  UINT8   rsvd_size;
-  UINT8   rsvd_pos;
-} LINUX_ATAG_VIDEOLFB;
-
-typedef struct {
-  CHAR8   cmdline[1];
-} LINUX_ATAG_CMDLINE;
-
-typedef struct {
-  LINUX_ATAG_HEADER header;
-  union {
-    LINUX_ATAG_CORE         core_tag;
-    LINUX_ATAG_MEM          mem_tag;
-    LINUX_ATAG_VIDEOTEXT    videotext_tag;
-    LINUX_ATAG_RAMDISK      ramdisk_tag;
-    LINUX_ATAG_INITRD2      initrd2_tag;
-    LINUX_ATAG_SERIALNR     serialnr_tag;
-    LINUX_ATAG_REVISION     revision_tag;
-    LINUX_ATAG_VIDEOLFB     videolfb_tag;
-    LINUX_ATAG_CMDLINE      cmdline_tag;
-  } body;
-} LINUX_ATAG;
-
-EFI_STATUS
-PrepareAtagList (
-  IN  CONST CHAR8*          CommandLineString,
-  IN  EFI_PHYSICAL_ADDRESS  InitrdImage,
-  IN  UINTN                 InitrdImageSize,
-  OUT EFI_PHYSICAL_ADDRESS  *AtagBase,
-  OUT UINT32                *AtagSize
-  );
-
-EFI_STATUS
-PrepareFdt (
-  IN     CONST CHAR8*         CommandLineArguments,
-  IN     EFI_PHYSICAL_ADDRESS InitrdImage,
-  IN     UINTN                InitrdImageSize,
-  IN OUT EFI_PHYSICAL_ADDRESS *FdtBlobBase,
-  IN OUT UINT32               *FdtBlobSize
-  );
-
-#endif
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#ifndef __BDSLINUXLOADER_H\r
+#define __BDSLINUXLOADER_H\r
+\r
+#define LINUX_UIMAGE_SIGNATURE    0x56190527\r
+#define LINUX_KERNEL_MAX_OFFSET   (PcdGet32(PcdSystemMemoryBase) + PcdGet32(PcdArmLinuxKernelMaxOffset))\r
+#define LINUX_ATAG_MAX_OFFSET     (PcdGet32(PcdSystemMemoryBase) + PcdGet32(PcdArmLinuxAtagMaxOffset))\r
+#define LINUX_FDT_MAX_OFFSET      (PcdGet32(PcdSystemMemoryBase) + PcdGet32(PcdArmLinuxFdtMaxOffset))\r
+\r
+// Additional size that could be used for FDT entries added by the UEFI OS Loader\r
+// Estimation based on: EDID (300bytes) + bootargs (200bytes) + initrd region (20bytes)\r
+//                      + system memory region (20bytes) + mp_core entries (200 bytes)\r
+#define FDT_ADDITIONAL_ENTRIES_SIZE     0x300\r
+\r
+#define ARM_FDT_MACHINE_TYPE            0xFFFFFFFF\r
+\r
+typedef VOID (*LINUX_KERNEL)(UINT32 Zero, UINT32 Arch, UINTN ParametersBase);\r
+\r
+//\r
+// ATAG Definitions\r
+//\r
+\r
+#define ATAG_MAX_SIZE        0x3000\r
+\r
+/* ATAG : list of possible tags */\r
+#define ATAG_NONE            0x00000000\r
+#define ATAG_CORE            0x54410001\r
+#define ATAG_MEM             0x54410002\r
+#define ATAG_VIDEOTEXT       0x54410003\r
+#define ATAG_RAMDISK         0x54410004\r
+#define ATAG_INITRD2         0x54420005\r
+#define ATAG_SERIAL          0x54410006\r
+#define ATAG_REVISION        0x54410007\r
+#define ATAG_VIDEOLFB        0x54410008\r
+#define ATAG_CMDLINE         0x54410009\r
+#define ATAG_ARM_MP_CORE     0x5441000A\r
+\r
+#define next_tag_address(t)  ((LINUX_ATAG*)((UINT32)(t) + (((t)->header.size) << 2) ))\r
+#define tag_size(type)       ((UINT32)((sizeof(LINUX_ATAG_HEADER) + sizeof(type)) >> 2))\r
+\r
+typedef struct {\r
+  UINT32  size; /* length of tag in words including this header */\r
+  UINT32  type;  /* tag type */\r
+} LINUX_ATAG_HEADER;\r
+\r
+typedef struct {\r
+  UINT32  flags;\r
+  UINT32  pagesize;\r
+  UINT32  rootdev;\r
+} LINUX_ATAG_CORE;\r
+\r
+typedef struct {\r
+  UINT32  size;\r
+  UINTN  start;\r
+} LINUX_ATAG_MEM;\r
+\r
+typedef struct {\r
+  UINT8   x;\r
+  UINT8   y;\r
+  UINT16  video_page;\r
+  UINT8   video_mode;\r
+  UINT8   video_cols;\r
+  UINT16  video_ega_bx;\r
+  UINT8   video_lines;\r
+  UINT8   video_isvga;\r
+  UINT16  video_points;\r
+} LINUX_ATAG_VIDEOTEXT;\r
+\r
+typedef struct {\r
+  UINT32  flags;\r
+  UINT32  size;\r
+  UINTN  start;\r
+} LINUX_ATAG_RAMDISK;\r
+\r
+typedef struct {\r
+  UINT32  start;\r
+  UINT32  size;\r
+} LINUX_ATAG_INITRD2;\r
+\r
+typedef struct {\r
+  UINT32  low;\r
+  UINT32  high;\r
+} LINUX_ATAG_SERIALNR;\r
+\r
+typedef struct {\r
+  UINT32  rev;\r
+} LINUX_ATAG_REVISION;\r
+\r
+typedef struct {\r
+  UINT16  lfb_width;\r
+  UINT16  lfb_height;\r
+  UINT16  lfb_depth;\r
+  UINT16  lfb_linelength;\r
+  UINT32  lfb_base;\r
+  UINT32  lfb_size;\r
+  UINT8   red_size;\r
+  UINT8   red_pos;\r
+  UINT8   green_size;\r
+  UINT8   green_pos;\r
+  UINT8   blue_size;\r
+  UINT8   blue_pos;\r
+  UINT8   rsvd_size;\r
+  UINT8   rsvd_pos;\r
+} LINUX_ATAG_VIDEOLFB;\r
+\r
+typedef struct {\r
+  CHAR8   cmdline[1];\r
+} LINUX_ATAG_CMDLINE;\r
+\r
+typedef struct {\r
+  LINUX_ATAG_HEADER header;\r
+  union {\r
+    LINUX_ATAG_CORE         core_tag;\r
+    LINUX_ATAG_MEM          mem_tag;\r
+    LINUX_ATAG_VIDEOTEXT    videotext_tag;\r
+    LINUX_ATAG_RAMDISK      ramdisk_tag;\r
+    LINUX_ATAG_INITRD2      initrd2_tag;\r
+    LINUX_ATAG_SERIALNR     serialnr_tag;\r
+    LINUX_ATAG_REVISION     revision_tag;\r
+    LINUX_ATAG_VIDEOLFB     videolfb_tag;\r
+    LINUX_ATAG_CMDLINE      cmdline_tag;\r
+  } body;\r
+} LINUX_ATAG;\r
+\r
+EFI_STATUS\r
+PrepareAtagList (\r
+  IN  CONST CHAR8*          CommandLineString,\r
+  IN  EFI_PHYSICAL_ADDRESS  InitrdImage,\r
+  IN  UINTN                 InitrdImageSize,\r
+  OUT EFI_PHYSICAL_ADDRESS  *AtagBase,\r
+  OUT UINT32                *AtagSize\r
+  );\r
+\r
+EFI_STATUS\r
+PrepareFdt (\r
+  IN     CONST CHAR8*         CommandLineArguments,\r
+  IN     EFI_PHYSICAL_ADDRESS InitrdImage,\r
+  IN     UINTN                InitrdImageSize,\r
+  IN OUT EFI_PHYSICAL_ADDRESS *FdtBlobBase,\r
+  IN OUT UINT32               *FdtBlobSize\r
+  );\r
+\r
+#endif\r
index 8abbc9b5cd0498916b2b1d1f7b71595a185de679..3f4566ffab133e06396d896213274e2d5bd89ad6 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 "BdsInternal.h"
-
-EFI_STATUS
-BootOptionParseLoadOption (
-  IN     EFI_LOAD_OPTION EfiLoadOption,
-  IN     UINTN           EfiLoadOptionSize,
-  IN OUT BDS_LOAD_OPTION **BdsLoadOption
-  )
-{
-  BDS_LOAD_OPTION *LoadOption;
-  UINTN           DescriptionLength;
-
-  if (EfiLoadOption == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  if (EfiLoadOptionSize < sizeof(UINT32) + sizeof(UINT16) + sizeof(CHAR16) + sizeof(EFI_DEVICE_PATH_PROTOCOL)) {
-    return EFI_BAD_BUFFER_SIZE;
-  }
-
-  if (*BdsLoadOption == NULL) {
-    LoadOption = (BDS_LOAD_OPTION*)AllocateZeroPool (sizeof(BDS_LOAD_OPTION));
-    if (LoadOption == NULL) {
-      return EFI_OUT_OF_RESOURCES;
-    }
-  } else {
-    LoadOption = *BdsLoadOption;
-  }
-
-  LoadOption->LoadOption     = EfiLoadOption;
-  LoadOption->LoadOptionSize = EfiLoadOptionSize;
-
-  LoadOption->Attributes         = *(UINT32*)EfiLoadOption;
-  LoadOption->FilePathListLength = *(UINT16*)(EfiLoadOption + sizeof(UINT32));
-  LoadOption->Description        = (CHAR16*)(EfiLoadOption + sizeof(UINT32) + sizeof(UINT16));
-  DescriptionLength              = StrSize (LoadOption->Description);
-  LoadOption->FilePathList       = (EFI_DEVICE_PATH_PROTOCOL*)(EfiLoadOption + sizeof(UINT32) + sizeof(UINT16) + DescriptionLength);
-
-  // If ((End of EfiLoadOptiony - Start of EfiLoadOption) == EfiLoadOptionSize) then No Optional Data
-  if ((UINTN)((UINTN)LoadOption->FilePathList + LoadOption->FilePathListLength - (UINTN)EfiLoadOption) == EfiLoadOptionSize) {
-    LoadOption->OptionalData     = NULL;
-    LoadOption->OptionalDataSize = 0;
-  } else {
-    LoadOption->OptionalData     = (VOID*)((UINTN)(LoadOption->FilePathList) + LoadOption->FilePathListLength);
-    LoadOption->OptionalDataSize = EfiLoadOptionSize - ((UINTN)LoadOption->OptionalData - (UINTN)EfiLoadOption);
-  }
-
-  if (*BdsLoadOption == NULL) {
-    *BdsLoadOption = LoadOption;
-  }
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-BootOptionFromLoadOptionVariable (
-  IN  CHAR16*           BootVariableName,
-  OUT BDS_LOAD_OPTION** BdsLoadOption
-  )
-{
-  EFI_STATUS            Status;
-  EFI_LOAD_OPTION       EfiLoadOption;
-  UINTN                 EfiLoadOptionSize;
-
-  Status = GetEnvironmentVariable (BootVariableName, NULL, &EfiLoadOptionSize, (VOID**)&EfiLoadOption);
-  if (!EFI_ERROR(Status)) {
-    *BdsLoadOption = NULL;
-    Status = BootOptionParseLoadOption (EfiLoadOption, EfiLoadOptionSize, BdsLoadOption);
-  }
-
-  return Status;
-}
-
-EFI_STATUS
-BootOptionFromLoadOptionIndex (
-  IN  UINT16            LoadOptionIndex,
-  OUT BDS_LOAD_OPTION **BdsLoadOption
-  )
-{
-  CHAR16        BootVariableName[9];
-  EFI_STATUS    Status;
-
-  UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", LoadOptionIndex);
-
-  Status = BootOptionFromLoadOptionVariable (BootVariableName, BdsLoadOption);
-  if (!EFI_ERROR(Status)) {
-    (*BdsLoadOption)->LoadOptionIndex = LoadOptionIndex;
-  }
-
-  return Status;
-}
-
-EFI_STATUS
-BootOptionToLoadOptionVariable (
-  IN BDS_LOAD_OPTION*   BdsLoadOption
-  )
-{
-  EFI_STATUS                    Status;
-  UINTN                         DescriptionSize;
-  //UINT16                        FilePathListLength;
-  EFI_DEVICE_PATH_PROTOCOL*     DevicePathNode;
-  UINTN                         NodeLength;
-  UINT8*                        EfiLoadOptionPtr;
-  VOID*                         OldLoadOption;
-  CHAR16                        BootVariableName[9];
-  UINTN                         BootOrderSize;
-  UINT16*                       BootOrder;
-
-  // If we are overwriting an existent Boot Option then we have to free previously allocated memory
-  if (BdsLoadOption->LoadOptionSize > 0) {
-    OldLoadOption = BdsLoadOption->LoadOption;
-  } else {
-    OldLoadOption = NULL;
-
-    // If this function is called at the creation of the Boot Device entry (not at the update) the
-    // BootOption->LoadOptionSize must be zero then we get a new BootIndex for this entry
-    BdsLoadOption->LoadOptionIndex = BootOptionAllocateBootIndex ();
-
-    //TODO: Add to the the Boot Entry List
-  }
-
-  DescriptionSize = StrSize(BdsLoadOption->Description);
-
-  // Ensure the FilePathListLength information is correct
-  ASSERT (GetDevicePathSize (BdsLoadOption->FilePathList) == BdsLoadOption->FilePathListLength);
-
-  // Allocate the memory for the EFI Load Option
-  BdsLoadOption->LoadOptionSize = sizeof(UINT32) + sizeof(UINT16) + DescriptionSize + BdsLoadOption->FilePathListLength + BdsLoadOption->OptionalDataSize;
-
-  BdsLoadOption->LoadOption = (EFI_LOAD_OPTION)AllocateZeroPool (BdsLoadOption->LoadOptionSize);
-  if (BdsLoadOption->LoadOption == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  EfiLoadOptionPtr = BdsLoadOption->LoadOption;
-
-  //
-  // Populate the EFI Load Option and BDS Boot Option structures
-  //
-
-  // Attributes fields
-  *(UINT32*)EfiLoadOptionPtr = BdsLoadOption->Attributes;
-  EfiLoadOptionPtr += sizeof(UINT32);
-
-  // FilePath List fields
-  *(UINT16*)EfiLoadOptionPtr = BdsLoadOption->FilePathListLength;
-  EfiLoadOptionPtr += sizeof(UINT16);
-
-  // Boot description fields
-  CopyMem (EfiLoadOptionPtr, BdsLoadOption->Description, DescriptionSize);
-  EfiLoadOptionPtr += DescriptionSize;
-
-  // File path fields
-  DevicePathNode = BdsLoadOption->FilePathList;
-  while (!IsDevicePathEndType (DevicePathNode)) {
-    NodeLength = DevicePathNodeLength(DevicePathNode);
-    CopyMem (EfiLoadOptionPtr, DevicePathNode, NodeLength);
-    EfiLoadOptionPtr += NodeLength;
-    DevicePathNode = NextDevicePathNode (DevicePathNode);
-  }
-
-  // Set the End Device Path Type
-  SetDevicePathEndNode (EfiLoadOptionPtr);
-  EfiLoadOptionPtr += sizeof(EFI_DEVICE_PATH);
-
-  // Fill the Optional Data
-  if (BdsLoadOption->OptionalDataSize > 0) {
-    CopyMem (EfiLoadOptionPtr, BdsLoadOption->OptionalData, BdsLoadOption->OptionalDataSize);
-  }
-
-  // Case where the fields have been updated
-  if (OldLoadOption) {
-    // Now, the old data has been copied to the new allocated packed structure, we need to update the pointers of BdsLoadOption
-    BootOptionParseLoadOption (BdsLoadOption->LoadOption, BdsLoadOption->LoadOptionSize, &BdsLoadOption);
-    // Free the old packed structure
-    FreePool (OldLoadOption);
-  }
-
-  // Create/Update Boot#### environment variable
-  UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BdsLoadOption->LoadOptionIndex);
-  Status = gRT->SetVariable (
-      BootVariableName,
-      &gEfiGlobalVariableGuid,
-      EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
-      BdsLoadOption->LoadOptionSize,
-      BdsLoadOption->LoadOption
-      );
-
-  // When it is a new entry we must add the entry to the BootOrder
-  if (OldLoadOption == NULL) {
-    // Add the new Boot Index to the list
-    Status = GetEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder);
-    if (!EFI_ERROR(Status)) {
-      BootOrder = ReallocatePool (BootOrderSize, BootOrderSize + sizeof(UINT16), BootOrder);
-      // Add the new index at the end
-      BootOrder[BootOrderSize / sizeof(UINT16)] = BdsLoadOption->LoadOptionIndex;
-      BootOrderSize += sizeof(UINT16);
-    } else {
-      // BootOrder does not exist. Create it
-      BootOrderSize = sizeof(UINT16);
-      BootOrder = &(BdsLoadOption->LoadOptionIndex);
-    }
-
-    // Update (or Create) the BootOrder environment variable
-    gRT->SetVariable (
-        L"BootOrder",
-        &gEfiGlobalVariableGuid,
-        EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
-        BootOrderSize,
-        BootOrder
-        );
-    DEBUG((EFI_D_ERROR,"Create %s\n",BootVariableName));
-
-    // Free memory allocated by GetEnvironmentVariable
-    if (!EFI_ERROR(Status)) {
-      FreePool (BootOrder);
-    }
-  } else {
-    DEBUG((EFI_D_ERROR,"Update %s\n",BootVariableName));
-  }
-
-  return EFI_SUCCESS;
-}
-
-UINT16
-BootOptionAllocateBootIndex (
-  VOID
-  )
-{
-  EFI_STATUS        Status;
-  UINTN             Index;
-  UINT32            BootIndex;
-  UINT16            *BootOrder;
-  UINTN             BootOrderSize;
-  BOOLEAN           Found;
-
-  // Get the Boot Option Order from the environment variable
-  Status = GetEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder);
-  if (!EFI_ERROR(Status)) {
-    for (BootIndex = 0; BootIndex <= 0xFFFF; BootIndex++) {
-      Found = FALSE;
-      for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {
-        if (BootOrder[Index] == BootIndex) {
-          Found = TRUE;
-          break;
-        }
-      }
-      if (!Found) {
-        return BootIndex;
-      }
-    }
-    FreePool (BootOrder);
-  }
-  // Return the first index
-  return 0;
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*\r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*\r
+**/\r
+\r
+#include "BdsInternal.h"\r
+\r
+EFI_STATUS\r
+BootOptionParseLoadOption (\r
+  IN     EFI_LOAD_OPTION EfiLoadOption,\r
+  IN     UINTN           EfiLoadOptionSize,\r
+  IN OUT BDS_LOAD_OPTION **BdsLoadOption\r
+  )\r
+{\r
+  BDS_LOAD_OPTION *LoadOption;\r
+  UINTN           DescriptionLength;\r
+\r
+  if (EfiLoadOption == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (EfiLoadOptionSize < sizeof(UINT32) + sizeof(UINT16) + sizeof(CHAR16) + sizeof(EFI_DEVICE_PATH_PROTOCOL)) {\r
+    return EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  if (*BdsLoadOption == NULL) {\r
+    LoadOption = (BDS_LOAD_OPTION*)AllocateZeroPool (sizeof(BDS_LOAD_OPTION));\r
+    if (LoadOption == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  } else {\r
+    LoadOption = *BdsLoadOption;\r
+  }\r
+\r
+  LoadOption->LoadOption     = EfiLoadOption;\r
+  LoadOption->LoadOptionSize = EfiLoadOptionSize;\r
+\r
+  LoadOption->Attributes         = *(UINT32*)EfiLoadOption;\r
+  LoadOption->FilePathListLength = *(UINT16*)(EfiLoadOption + sizeof(UINT32));\r
+  LoadOption->Description        = (CHAR16*)(EfiLoadOption + sizeof(UINT32) + sizeof(UINT16));\r
+  DescriptionLength              = StrSize (LoadOption->Description);\r
+  LoadOption->FilePathList       = (EFI_DEVICE_PATH_PROTOCOL*)(EfiLoadOption + sizeof(UINT32) + sizeof(UINT16) + DescriptionLength);\r
+\r
+  // If ((End of EfiLoadOptiony - Start of EfiLoadOption) == EfiLoadOptionSize) then No Optional Data\r
+  if ((UINTN)((UINTN)LoadOption->FilePathList + LoadOption->FilePathListLength - (UINTN)EfiLoadOption) == EfiLoadOptionSize) {\r
+    LoadOption->OptionalData     = NULL;\r
+    LoadOption->OptionalDataSize = 0;\r
+  } else {\r
+    LoadOption->OptionalData     = (VOID*)((UINTN)(LoadOption->FilePathList) + LoadOption->FilePathListLength);\r
+    LoadOption->OptionalDataSize = EfiLoadOptionSize - ((UINTN)LoadOption->OptionalData - (UINTN)EfiLoadOption);\r
+  }\r
+\r
+  if (*BdsLoadOption == NULL) {\r
+    *BdsLoadOption = LoadOption;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+BootOptionFromLoadOptionVariable (\r
+  IN  CHAR16*           BootVariableName,\r
+  OUT BDS_LOAD_OPTION** BdsLoadOption\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_LOAD_OPTION       EfiLoadOption;\r
+  UINTN                 EfiLoadOptionSize;\r
+\r
+  Status = GetEnvironmentVariable (BootVariableName, NULL, &EfiLoadOptionSize, (VOID**)&EfiLoadOption);\r
+  if (!EFI_ERROR(Status)) {\r
+    *BdsLoadOption = NULL;\r
+    Status = BootOptionParseLoadOption (EfiLoadOption, EfiLoadOptionSize, BdsLoadOption);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+BootOptionFromLoadOptionIndex (\r
+  IN  UINT16            LoadOptionIndex,\r
+  OUT BDS_LOAD_OPTION **BdsLoadOption\r
+  )\r
+{\r
+  CHAR16        BootVariableName[9];\r
+  EFI_STATUS    Status;\r
+\r
+  UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", LoadOptionIndex);\r
+\r
+  Status = BootOptionFromLoadOptionVariable (BootVariableName, BdsLoadOption);\r
+  if (!EFI_ERROR(Status)) {\r
+    (*BdsLoadOption)->LoadOptionIndex = LoadOptionIndex;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+BootOptionToLoadOptionVariable (\r
+  IN BDS_LOAD_OPTION*   BdsLoadOption\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  UINTN                         DescriptionSize;\r
+  //UINT16                        FilePathListLength;\r
+  EFI_DEVICE_PATH_PROTOCOL*     DevicePathNode;\r
+  UINTN                         NodeLength;\r
+  UINT8*                        EfiLoadOptionPtr;\r
+  VOID*                         OldLoadOption;\r
+  CHAR16                        BootVariableName[9];\r
+  UINTN                         BootOrderSize;\r
+  UINT16*                       BootOrder;\r
+\r
+  // If we are overwriting an existent Boot Option then we have to free previously allocated memory\r
+  if (BdsLoadOption->LoadOptionSize > 0) {\r
+    OldLoadOption = BdsLoadOption->LoadOption;\r
+  } else {\r
+    OldLoadOption = NULL;\r
+\r
+    // If this function is called at the creation of the Boot Device entry (not at the update) the\r
+    // BootOption->LoadOptionSize must be zero then we get a new BootIndex for this entry\r
+    BdsLoadOption->LoadOptionIndex = BootOptionAllocateBootIndex ();\r
+\r
+    //TODO: Add to the the Boot Entry List\r
+  }\r
+\r
+  DescriptionSize = StrSize(BdsLoadOption->Description);\r
+\r
+  // Ensure the FilePathListLength information is correct\r
+  ASSERT (GetDevicePathSize (BdsLoadOption->FilePathList) == BdsLoadOption->FilePathListLength);\r
+\r
+  // Allocate the memory for the EFI Load Option\r
+  BdsLoadOption->LoadOptionSize = sizeof(UINT32) + sizeof(UINT16) + DescriptionSize + BdsLoadOption->FilePathListLength + BdsLoadOption->OptionalDataSize;\r
+\r
+  BdsLoadOption->LoadOption = (EFI_LOAD_OPTION)AllocateZeroPool (BdsLoadOption->LoadOptionSize);\r
+  if (BdsLoadOption->LoadOption == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  EfiLoadOptionPtr = BdsLoadOption->LoadOption;\r
+\r
+  //\r
+  // Populate the EFI Load Option and BDS Boot Option structures\r
+  //\r
+\r
+  // Attributes fields\r
+  *(UINT32*)EfiLoadOptionPtr = BdsLoadOption->Attributes;\r
+  EfiLoadOptionPtr += sizeof(UINT32);\r
+\r
+  // FilePath List fields\r
+  *(UINT16*)EfiLoadOptionPtr = BdsLoadOption->FilePathListLength;\r
+  EfiLoadOptionPtr += sizeof(UINT16);\r
+\r
+  // Boot description fields\r
+  CopyMem (EfiLoadOptionPtr, BdsLoadOption->Description, DescriptionSize);\r
+  EfiLoadOptionPtr += DescriptionSize;\r
+\r
+  // File path fields\r
+  DevicePathNode = BdsLoadOption->FilePathList;\r
+  while (!IsDevicePathEndType (DevicePathNode)) {\r
+    NodeLength = DevicePathNodeLength(DevicePathNode);\r
+    CopyMem (EfiLoadOptionPtr, DevicePathNode, NodeLength);\r
+    EfiLoadOptionPtr += NodeLength;\r
+    DevicePathNode = NextDevicePathNode (DevicePathNode);\r
+  }\r
+\r
+  // Set the End Device Path Type\r
+  SetDevicePathEndNode (EfiLoadOptionPtr);\r
+  EfiLoadOptionPtr += sizeof(EFI_DEVICE_PATH);\r
+\r
+  // Fill the Optional Data\r
+  if (BdsLoadOption->OptionalDataSize > 0) {\r
+    CopyMem (EfiLoadOptionPtr, BdsLoadOption->OptionalData, BdsLoadOption->OptionalDataSize);\r
+  }\r
+\r
+  // Case where the fields have been updated\r
+  if (OldLoadOption) {\r
+    // Now, the old data has been copied to the new allocated packed structure, we need to update the pointers of BdsLoadOption\r
+    BootOptionParseLoadOption (BdsLoadOption->LoadOption, BdsLoadOption->LoadOptionSize, &BdsLoadOption);\r
+    // Free the old packed structure\r
+    FreePool (OldLoadOption);\r
+  }\r
+\r
+  // Create/Update Boot#### environment variable\r
+  UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BdsLoadOption->LoadOptionIndex);\r
+  Status = gRT->SetVariable (\r
+      BootVariableName,\r
+      &gEfiGlobalVariableGuid,\r
+      EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+      BdsLoadOption->LoadOptionSize,\r
+      BdsLoadOption->LoadOption\r
+      );\r
+\r
+  // When it is a new entry we must add the entry to the BootOrder\r
+  if (OldLoadOption == NULL) {\r
+    // Add the new Boot Index to the list\r
+    Status = GetEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder);\r
+    if (!EFI_ERROR(Status)) {\r
+      BootOrder = ReallocatePool (BootOrderSize, BootOrderSize + sizeof(UINT16), BootOrder);\r
+      // Add the new index at the end\r
+      BootOrder[BootOrderSize / sizeof(UINT16)] = BdsLoadOption->LoadOptionIndex;\r
+      BootOrderSize += sizeof(UINT16);\r
+    } else {\r
+      // BootOrder does not exist. Create it\r
+      BootOrderSize = sizeof(UINT16);\r
+      BootOrder = &(BdsLoadOption->LoadOptionIndex);\r
+    }\r
+\r
+    // Update (or Create) the BootOrder environment variable\r
+    gRT->SetVariable (\r
+        L"BootOrder",\r
+        &gEfiGlobalVariableGuid,\r
+        EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+        BootOrderSize,\r
+        BootOrder\r
+        );\r
+    DEBUG((EFI_D_ERROR,"Create %s\n",BootVariableName));\r
+\r
+    // Free memory allocated by GetEnvironmentVariable\r
+    if (!EFI_ERROR(Status)) {\r
+      FreePool (BootOrder);\r
+    }\r
+  } else {\r
+    DEBUG((EFI_D_ERROR,"Update %s\n",BootVariableName));\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+UINT16\r
+BootOptionAllocateBootIndex (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS        Status;\r
+  UINTN             Index;\r
+  UINT32            BootIndex;\r
+  UINT16            *BootOrder;\r
+  UINTN             BootOrderSize;\r
+  BOOLEAN           Found;\r
+\r
+  // Get the Boot Option Order from the environment variable\r
+  Status = GetEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder);\r
+  if (!EFI_ERROR(Status)) {\r
+    for (BootIndex = 0; BootIndex <= 0xFFFF; BootIndex++) {\r
+      Found = FALSE;\r
+      for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {\r
+        if (BootOrder[Index] == BootIndex) {\r
+          Found = TRUE;\r
+          break;\r
+        }\r
+      }\r
+      if (!Found) {\r
+        return BootIndex;\r
+      }\r
+    }\r
+    FreePool (BootOrder);\r
+  }\r
+  // Return the first index\r
+  return 0;\r
+}\r
index eb0a650624b2941763ac75d6ed3aaf73c1f205be..6e42dcd14ee34f7fb6694454e65e26fe0b9bb364 100644 (file)
@@ -1,99 +1,99 @@
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-/**
-  University of Illinois/NCSA
-  Open Source License
-  
-  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
-  All rights reserved.
-  
-  Developed by:
-  
-      LLVM Team
-  
-      University of Illinois at Urbana-Champaign
-  
-      http://llvm.org
-  
-  Permission is hereby granted, free of charge, to any person obtaining a copy of
-  this software and associated documentation files (the "Software"), to deal with
-  the Software without restriction, including without limitation the rights to
-  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-  of the Software, and to permit persons to whom the Software is furnished to do
-  so, subject to the following conditions:
-  
-      * Redistributions of source code must retain the above copyright notice,
-        this list of conditions and the following disclaimers.
-  
-      * Redistributions in binary form must reproduce the above copyright notice,
-        this list of conditions and the following disclaimers in the
-        documentation and/or other materials provided with the distribution.
-  
-      * Neither the names of the LLVM Team, University of Illinois at
-        Urbana-Champaign, nor the names of its contributors may be used to
-        endorse or promote products derived from this Software without specific
-        prior written permission.
-  
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-  SOFTWARE.
-**/
-
-#include <Base.h>
-#include <Library/DebugLib.h>
-
-#define CHAR_BIT  8
-
-typedef union {
-    INT64   all;
-    struct {
-        UINT32 low;
-        INT32  high;
-    };
-} dwords;
-
-typedef union {
-    UINT64  all;
-    struct {
-        UINT32 low;
-        UINT32 high;
-    };
-} udwords;
-
-// __aeabi_ return values
-typedef struct {
-  UINT64  Quotent;
-  UINT64  Remainder;
-} ulldiv_t;
-
-typedef struct {
-  INT64   Quotent;
-  INT64   Remainder;
-} lldiv_t;
-
-typedef struct {
-  UINT32  Quotent;
-  UINT32  Remainder;
-} uidiv_return;
-
-#if __GNUC__
-  #define COUNT_LEADING_ZEROS(_a)   __builtin_clz((_a))
-  #define COUNT_TRAILING_ZEROS(_a)  __builtin_ctz((_a))
-#else
-#error COUNT_LEADING_ZEROS() and COUNT_TRAILING_ZEROS() macros not ported to your compiler
-#endif
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+/**\r
+  University of Illinois/NCSA\r
+  Open Source License\r
+  \r
+  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.\r
+  All rights reserved.\r
+  \r
+  Developed by:\r
+  \r
+      LLVM Team\r
+  \r
+      University of Illinois at Urbana-Champaign\r
+  \r
+      http://llvm.org\r
+  \r
+  Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+  this software and associated documentation files (the "Software"), to deal with\r
+  the Software without restriction, including without limitation the rights to\r
+  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+  of the Software, and to permit persons to whom the Software is furnished to do\r
+  so, subject to the following conditions:\r
+  \r
+      * Redistributions of source code must retain the above copyright notice,\r
+        this list of conditions and the following disclaimers.\r
+  \r
+      * Redistributions in binary form must reproduce the above copyright notice,\r
+        this list of conditions and the following disclaimers in the\r
+        documentation and/or other materials provided with the distribution.\r
+  \r
+      * Neither the names of the LLVM Team, University of Illinois at\r
+        Urbana-Champaign, nor the names of its contributors may be used to\r
+        endorse or promote products derived from this Software without specific\r
+        prior written permission.\r
+  \r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE\r
+  SOFTWARE.\r
+**/\r
+\r
+#include <Base.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#define CHAR_BIT  8\r
+\r
+typedef union {\r
+    INT64   all;\r
+    struct {\r
+        UINT32 low;\r
+        INT32  high;\r
+    };\r
+} dwords;\r
+\r
+typedef union {\r
+    UINT64  all;\r
+    struct {\r
+        UINT32 low;\r
+        UINT32 high;\r
+    };\r
+} udwords;\r
+\r
+// __aeabi_ return values\r
+typedef struct {\r
+  UINT64  Quotent;\r
+  UINT64  Remainder;\r
+} ulldiv_t;\r
+\r
+typedef struct {\r
+  INT64   Quotent;\r
+  INT64   Remainder;\r
+} lldiv_t;\r
+\r
+typedef struct {\r
+  UINT32  Quotent;\r
+  UINT32  Remainder;\r
+} uidiv_return;\r
+\r
+#if __GNUC__\r
+  #define COUNT_LEADING_ZEROS(_a)   __builtin_clz((_a))\r
+  #define COUNT_TRAILING_ZEROS(_a)  __builtin_ctz((_a))\r
+#else\r
+#error COUNT_LEADING_ZEROS() and COUNT_TRAILING_ZEROS() macros not ported to your compiler\r
+#endif\r
index 5578797125d27e6ca54fbf9bfcd18368889b6676..cec0c55f1e42b9e5859f4c1b9dd12b9e96237fc8 100644 (file)
@@ -1,35 +1,35 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__ashldi3)
-  
-ASM_PFX(__ashldi3):
-  cmp  r2, #31
-  bls  L2
-  cmp  r2, #63
-  subls  r2, r2, #32
-  movls  r2, r0, asl r2
-  movhi  r2, #0
-  mov  r1, r2
-  mov  r0, #0
-  bx  lr
-L2:
-  cmp  r2, #0
-  rsbne  r3, r2, #32
-  movne  r3, r0, lsr r3
-  movne  r0, r0, asl r2
-  orrne  r1, r3, r1, asl r2
-  bx  lr
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__ashldi3)\r
+  \r
+ASM_PFX(__ashldi3):\r
+  cmp  r2, #31\r
+  bls  L2\r
+  cmp  r2, #63\r
+  subls  r2, r2, #32\r
+  movls  r2, r0, asl r2\r
+  movhi  r2, #0\r
+  mov  r1, r2\r
+  mov  r0, #0\r
+  bx  lr\r
+L2:\r
+  cmp  r2, #0\r
+  rsbne  r3, r2, #32\r
+  movne  r3, r0, lsr r3\r
+  movne  r0, r0, asl r2\r
+  orrne  r1, r3, r1, asl r2\r
+  bx  lr\r
index 80ec5a60082f08f5307520506178bf3b89573654..526fcab65cc8e4bfaa631cf4ec9f62841cbecb81 100644 (file)
@@ -1,83 +1,83 @@
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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.
-
-**/
-/**
-  University of Illinois/NCSA
-  Open Source License
-  
-  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
-  All rights reserved.
-  
-  Developed by:
-  
-      LLVM Team
-  
-      University of Illinois at Urbana-Champaign
-  
-      http://llvm.org
-  
-  Permission is hereby granted, free of charge, to any person obtaining a copy of
-  this software and associated documentation files (the "Software"), to deal with
-  the Software without restriction, including without limitation the rights to
-  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-  of the Software, and to permit persons to whom the Software is furnished to do
-  so, subject to the following conditions:
-  
-      * Redistributions of source code must retain the above copyright notice,
-        this list of conditions and the following disclaimers.
-  
-      * Redistributions in binary form must reproduce the above copyright notice,
-        this list of conditions and the following disclaimers in the
-        documentation and/or other materials provided with the distribution.
-  
-      * Neither the names of the LLVM Team, University of Illinois at
-        Urbana-Champaign, nor the names of its contributors may be used to
-        endorse or promote products derived from this Software without specific
-        prior written permission.
-  
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-  SOFTWARE.
-**/
-
-#include "Llvm_int_lib.h"
-
-// Returns: a << b
-
-// Precondition:  0 <= b < bits_in_dword
-
-INT64
-__ashldi3(INT64 a, INT32 b)
-{
-    const int bits_in_word = (int)(sizeof(INT32) * CHAR_BIT);
-    dwords input;
-    dwords result;
-    input.all = a;
-    if (b & bits_in_word)  // bits_in_word <= b < bits_in_dword
-    {
-        result.low = 0;
-        result.high = input.low << (b - bits_in_word);
-    }
-    else  // 0 <= b < bits_in_word
-    {
-        if (b == 0)
-            return a;
-        result.low  = input.low << b;
-        result.high = (input.high << b) | (input.low >> (bits_in_word - b));
-    }
-    return result.all;
-}
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+/**\r
+  University of Illinois/NCSA\r
+  Open Source License\r
+  \r
+  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.\r
+  All rights reserved.\r
+  \r
+  Developed by:\r
+  \r
+      LLVM Team\r
+  \r
+      University of Illinois at Urbana-Champaign\r
+  \r
+      http://llvm.org\r
+  \r
+  Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+  this software and associated documentation files (the "Software"), to deal with\r
+  the Software without restriction, including without limitation the rights to\r
+  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+  of the Software, and to permit persons to whom the Software is furnished to do\r
+  so, subject to the following conditions:\r
+  \r
+      * Redistributions of source code must retain the above copyright notice,\r
+        this list of conditions and the following disclaimers.\r
+  \r
+      * Redistributions in binary form must reproduce the above copyright notice,\r
+        this list of conditions and the following disclaimers in the\r
+        documentation and/or other materials provided with the distribution.\r
+  \r
+      * Neither the names of the LLVM Team, University of Illinois at\r
+        Urbana-Champaign, nor the names of its contributors may be used to\r
+        endorse or promote products derived from this Software without specific\r
+        prior written permission.\r
+  \r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE\r
+  SOFTWARE.\r
+**/\r
+\r
+#include "Llvm_int_lib.h"\r
+\r
+// Returns: a << b\r
+\r
+// Precondition:  0 <= b < bits_in_dword\r
+\r
+INT64\r
+__ashldi3(INT64 a, INT32 b)\r
+{\r
+    const int bits_in_word = (int)(sizeof(INT32) * CHAR_BIT);\r
+    dwords input;\r
+    dwords result;\r
+    input.all = a;\r
+    if (b & bits_in_word)  // bits_in_word <= b < bits_in_dword\r
+    {\r
+        result.low = 0;\r
+        result.high = input.low << (b - bits_in_word);\r
+    }\r
+    else  // 0 <= b < bits_in_word\r
+    {\r
+        if (b == 0)\r
+            return a;\r
+        result.low  = input.low << b;\r
+        result.high = (input.high << b) | (input.low >> (bits_in_word - b));\r
+    }\r
+    return result.all;\r
+}\r
index defd1f081c12940a0e381c95ffb9f7e6f938e6be..09c927ca6b7eacaea69d994aa55feaad4cf0c962 100644 (file)
@@ -1,36 +1,36 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__ashrdi3)
-
-ASM_PFX(__ashrdi3):
-  cmp  r2, #31
-  bls  L2
-  cmp  r2, #63
-  subls  r2, r2, #32
-  mov  ip, r1, asr #31
-  movls  r2, r1, asr r2
-  movhi  r2, ip
-  mov  r0, r2
-  mov  r1, ip
-  bx  lr
-L2:
-  cmp  r2, #0
-  rsbne  r3, r2, #32
-  movne  r3, r1, asl r3
-  movne  r1, r1, asr r2
-  orrne  r0, r3, r0, lsr r2
-  bx  lr
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__ashrdi3)\r
+\r
+ASM_PFX(__ashrdi3):\r
+  cmp  r2, #31\r
+  bls  L2\r
+  cmp  r2, #63\r
+  subls  r2, r2, #32\r
+  mov  ip, r1, asr #31\r
+  movls  r2, r1, asr r2\r
+  movhi  r2, ip\r
+  mov  r0, r2\r
+  mov  r1, ip\r
+  bx  lr\r
+L2:\r
+  cmp  r2, #0\r
+  rsbne  r3, r2, #32\r
+  movne  r3, r1, asl r3\r
+  movne  r1, r1, asr r2\r
+  orrne  r0, r3, r0, lsr r2\r
+  bx  lr\r
index 703a37fd724af06d62fa92f32778e23dfe6f3430..229531ed26d5686fc5602dbec527dcd7d9bf203e 100644 (file)
@@ -1,84 +1,84 @@
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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.
-
-**/
-/**
-  University of Illinois/NCSA
-  Open Source License
-  
-  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
-  All rights reserved.
-  
-  Developed by:
-  
-      LLVM Team
-  
-      University of Illinois at Urbana-Champaign
-  
-      http://llvm.org
-  
-  Permission is hereby granted, free of charge, to any person obtaining a copy of
-  this software and associated documentation files (the "Software"), to deal with
-  the Software without restriction, including without limitation the rights to
-  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-  of the Software, and to permit persons to whom the Software is furnished to do
-  so, subject to the following conditions:
-  
-      * Redistributions of source code must retain the above copyright notice,
-        this list of conditions and the following disclaimers.
-  
-      * Redistributions in binary form must reproduce the above copyright notice,
-        this list of conditions and the following disclaimers in the
-        documentation and/or other materials provided with the distribution.
-  
-      * Neither the names of the LLVM Team, University of Illinois at
-        Urbana-Champaign, nor the names of its contributors may be used to
-        endorse or promote products derived from this Software without specific
-        prior written permission.
-  
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-  SOFTWARE.
-**/
-
-#include "Llvm_int_lib.h"
-
-// Returns: arithmetic a >> b
-
-// Precondition:  0 <= b < bits_in_dword
-
-INT64
-__ashrdi3(INT64 a, INT32 b)
-{
-    const int bits_in_word = (int)(sizeof(INT32) * CHAR_BIT);
-    dwords input;
-    dwords result;
-    input.all = a;
-    if (b & bits_in_word)  // bits_in_word <= b < bits_in_dword
-    {
-        // result.high = input.high < 0 ? -1 : 0
-        result.high = input.high >> (bits_in_word - 1);
-        result.low = input.high >> (b - bits_in_word);
-    }
-    else  // 0 <= b < bits_in_word
-    {
-        if (b == 0)
-            return a;
-        result.high  = input.high >> b;
-        result.low = (input.high << (bits_in_word - b)) | (input.low >> b);
-    }
-    return result.all;
-}
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+/**\r
+  University of Illinois/NCSA\r
+  Open Source License\r
+  \r
+  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.\r
+  All rights reserved.\r
+  \r
+  Developed by:\r
+  \r
+      LLVM Team\r
+  \r
+      University of Illinois at Urbana-Champaign\r
+  \r
+      http://llvm.org\r
+  \r
+  Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+  this software and associated documentation files (the "Software"), to deal with\r
+  the Software without restriction, including without limitation the rights to\r
+  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+  of the Software, and to permit persons to whom the Software is furnished to do\r
+  so, subject to the following conditions:\r
+  \r
+      * Redistributions of source code must retain the above copyright notice,\r
+        this list of conditions and the following disclaimers.\r
+  \r
+      * Redistributions in binary form must reproduce the above copyright notice,\r
+        this list of conditions and the following disclaimers in the\r
+        documentation and/or other materials provided with the distribution.\r
+  \r
+      * Neither the names of the LLVM Team, University of Illinois at\r
+        Urbana-Champaign, nor the names of its contributors may be used to\r
+        endorse or promote products derived from this Software without specific\r
+        prior written permission.\r
+  \r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE\r
+  SOFTWARE.\r
+**/\r
+\r
+#include "Llvm_int_lib.h"\r
+\r
+// Returns: arithmetic a >> b\r
+\r
+// Precondition:  0 <= b < bits_in_dword\r
+\r
+INT64\r
+__ashrdi3(INT64 a, INT32 b)\r
+{\r
+    const int bits_in_word = (int)(sizeof(INT32) * CHAR_BIT);\r
+    dwords input;\r
+    dwords result;\r
+    input.all = a;\r
+    if (b & bits_in_word)  // bits_in_word <= b < bits_in_dword\r
+    {\r
+        // result.high = input.high < 0 ? -1 : 0\r
+        result.high = input.high >> (bits_in_word - 1);\r
+        result.low = input.high >> (b - bits_in_word);\r
+    }\r
+    else  // 0 <= b < bits_in_word\r
+    {\r
+        if (b == 0)\r
+            return a;\r
+        result.high  = input.high >> b;\r
+        result.low = (input.high << (bits_in_word - b)) | (input.low >> b);\r
+    }\r
+    return result.all;\r
+}\r
index 11ea95cef47014009c00b2b7f7db1c2128d7153f..942344674a0dfbd3568ba577646a771007b5ba0a 100644 (file)
@@ -1,57 +1,57 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__clzsi2)
-
-ASM_PFX(__clzsi2):
-  @ frame_needed = 1, uses_anonymous_args = 0
-  stmfd  sp!, {r7, lr}
-  add  r7, sp, #0
-  movs  r3, r0, lsr #16
-  movne  r3, #16
-  moveq  r3, #0
-  movne  r9, #0
-  moveq  r9, #16
-  mov  r3, r0, lsr r3
-  tst  r3, #65280
-  movne  r0, #8
-  moveq  r0, #0
-  movne  lr, #0
-  moveq  lr, #8
-  mov  r3, r3, lsr r0
-  tst  r3, #240
-  movne  r0, #4
-  moveq  r0, #0
-  movne  ip, #0
-  moveq  ip, #4
-  mov  r3, r3, lsr r0
-  tst  r3, #12
-  movne  r0, #2
-  moveq  r0, #0
-  movne  r1, #0
-  moveq  r1, #2
-  mov  r2, r3, lsr r0
-  add  r3, lr, r9
-  add  r0, r3, ip
-  add  r1, r0, r1
-  mov  r0, r2, lsr #1
-  eor  r0, r0, #1
-  ands  r0, r0, #1
-  mvnne  r0, #0
-  rsb  r3, r2, #2
-  and  r0, r0, r3
-  add  r0, r1, r0
-  ldmfd  sp!, {r7, pc}
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__clzsi2)\r
+\r
+ASM_PFX(__clzsi2):\r
+  @ frame_needed = 1, uses_anonymous_args = 0\r
+  stmfd  sp!, {r7, lr}\r
+  add  r7, sp, #0\r
+  movs  r3, r0, lsr #16\r
+  movne  r3, #16\r
+  moveq  r3, #0\r
+  movne  r9, #0\r
+  moveq  r9, #16\r
+  mov  r3, r0, lsr r3\r
+  tst  r3, #65280\r
+  movne  r0, #8\r
+  moveq  r0, #0\r
+  movne  lr, #0\r
+  moveq  lr, #8\r
+  mov  r3, r3, lsr r0\r
+  tst  r3, #240\r
+  movne  r0, #4\r
+  moveq  r0, #0\r
+  movne  ip, #0\r
+  moveq  ip, #4\r
+  mov  r3, r3, lsr r0\r
+  tst  r3, #12\r
+  movne  r0, #2\r
+  moveq  r0, #0\r
+  movne  r1, #0\r
+  moveq  r1, #2\r
+  mov  r2, r3, lsr r0\r
+  add  r3, lr, r9\r
+  add  r0, r3, ip\r
+  add  r1, r0, r1\r
+  mov  r0, r2, lsr #1\r
+  eor  r0, r0, #1\r
+  ands  r0, r0, #1\r
+  mvnne  r0, #0\r
+  rsb  r3, r2, #2\r
+  and  r0, r0, r3\r
+  add  r0, r1, r0\r
+  ldmfd  sp!, {r7, pc}\r
index 196f23f8ccdd02d81ebe7cccd57ba2ab1548b63f..50ae87a6cc709888eb6dfb3cb156c34ed15a5eb3 100644 (file)
@@ -1,96 +1,96 @@
-/** @file
-  Compiler intrinsic to return the number of leading zeros, ported from LLVM code.
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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.
-
-**/
-/**
-  University of Illinois/NCSA
-  Open Source License
-  
-  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
-  All rights reserved.
-  
-  Developed by:
-  
-      LLVM Team
-  
-      University of Illinois at Urbana-Champaign
-  
-      http://llvm.org
-  
-  Permission is hereby granted, free of charge, to any person obtaining a copy of
-  this software and associated documentation files (the "Software"), to deal with
-  the Software without restriction, including without limitation the rights to
-  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-  of the Software, and to permit persons to whom the Software is furnished to do
-  so, subject to the following conditions:
-  
-      * Redistributions of source code must retain the above copyright notice,
-        this list of conditions and the following disclaimers.
-  
-      * Redistributions in binary form must reproduce the above copyright notice,
-        this list of conditions and the following disclaimers in the
-        documentation and/or other materials provided with the distribution.
-  
-      * Neither the names of the LLVM Team, University of Illinois at
-        Urbana-Champaign, nor the names of its contributors may be used to
-        endorse or promote products derived from this Software without specific
-        prior written permission.
-  
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-  SOFTWARE.
-**/
-
-
-#include "Llvm_int_lib.h"
-
-// Returns: the number of leading 0-bits
-
-// Precondition: a != 0
-
-INT32
-__clzsi2(INT32 a)
-{
-    UINT32 x = (UINT32)a;
-    INT32 t = ((x & 0xFFFF0000) == 0) << 4;  // if (x is small) t = 16 else 0
-    x >>= 16 - t;      // x = [0 - 0xFFFF]
-    UINT32 r = t;       // r = [0, 16]
-    // return r + clz(x)
-    t = ((x & 0xFF00) == 0) << 3;
-    x >>= 8 - t;       // x = [0 - 0xFF]
-    r += t;            // r = [0, 8, 16, 24]
-    // return r + clz(x)
-    t = ((x & 0xF0) == 0) << 2;
-    x >>= 4 - t;       // x = [0 - 0xF]
-    r += t;            // r = [0, 4, 8, 12, 16, 20, 24, 28]
-    // return r + clz(x)
-    t = ((x & 0xC) == 0) << 1;
-    x >>= 2 - t;       // x = [0 - 3]
-    r += t;            // r = [0 - 30] and is even
-    // return r + clz(x)
-//     switch (x)
-//     {
-//     case 0:
-//         return r + 2;
-//     case 1:
-//         return r + 1;
-//     case 2:
-//     case 3:
-//         return r;
-//     }
-    return r + ((2 - x) & -((x & 2) == 0));
-}
+/** @file\r
+  Compiler intrinsic to return the number of leading zeros, ported from LLVM code.\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+/**\r
+  University of Illinois/NCSA\r
+  Open Source License\r
+  \r
+  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.\r
+  All rights reserved.\r
+  \r
+  Developed by:\r
+  \r
+      LLVM Team\r
+  \r
+      University of Illinois at Urbana-Champaign\r
+  \r
+      http://llvm.org\r
+  \r
+  Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+  this software and associated documentation files (the "Software"), to deal with\r
+  the Software without restriction, including without limitation the rights to\r
+  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+  of the Software, and to permit persons to whom the Software is furnished to do\r
+  so, subject to the following conditions:\r
+  \r
+      * Redistributions of source code must retain the above copyright notice,\r
+        this list of conditions and the following disclaimers.\r
+  \r
+      * Redistributions in binary form must reproduce the above copyright notice,\r
+        this list of conditions and the following disclaimers in the\r
+        documentation and/or other materials provided with the distribution.\r
+  \r
+      * Neither the names of the LLVM Team, University of Illinois at\r
+        Urbana-Champaign, nor the names of its contributors may be used to\r
+        endorse or promote products derived from this Software without specific\r
+        prior written permission.\r
+  \r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE\r
+  SOFTWARE.\r
+**/\r
+\r
+\r
+#include "Llvm_int_lib.h"\r
+\r
+// Returns: the number of leading 0-bits\r
+\r
+// Precondition: a != 0\r
+\r
+INT32\r
+__clzsi2(INT32 a)\r
+{\r
+    UINT32 x = (UINT32)a;\r
+    INT32 t = ((x & 0xFFFF0000) == 0) << 4;  // if (x is small) t = 16 else 0\r
+    x >>= 16 - t;      // x = [0 - 0xFFFF]\r
+    UINT32 r = t;       // r = [0, 16]\r
+    // return r + clz(x)\r
+    t = ((x & 0xFF00) == 0) << 3;\r
+    x >>= 8 - t;       // x = [0 - 0xFF]\r
+    r += t;            // r = [0, 8, 16, 24]\r
+    // return r + clz(x)\r
+    t = ((x & 0xF0) == 0) << 2;\r
+    x >>= 4 - t;       // x = [0 - 0xF]\r
+    r += t;            // r = [0, 4, 8, 12, 16, 20, 24, 28]\r
+    // return r + clz(x)\r
+    t = ((x & 0xC) == 0) << 1;\r
+    x >>= 2 - t;       // x = [0 - 3]\r
+    r += t;            // r = [0 - 30] and is even\r
+    // return r + clz(x)\r
+//     switch (x)\r
+//     {\r
+//     case 0:\r
+//         return r + 2;\r
+//     case 1:\r
+//         return r + 1;\r
+//     case 2:\r
+//     case 3:\r
+//         return r;\r
+//     }\r
+    return r + ((2 - x) & -((x & 2) == 0));\r
+}\r
index 0c8e78d961df9a9877955a3bec1c5da477b5dc32..d530025a1df4a6007be55d2ec76745793228d7ec 100644 (file)
@@ -1,49 +1,49 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__ctzsi2)
-  
-ASM_PFX(__ctzsi2):
-  uxth  r3, r0
-  cmp  r3, #0
-  moveq  ip, #16
-  movne  ip, #0
-  @ lr needed for prologue
-  mov  r0, r0, lsr ip
-  tst  r0, #255
-  movne  r3, #0
-  moveq  r3, #8
-  mov  r0, r0, lsr r3
-  tst  r0, #15
-  movne  r1, #0
-  moveq  r1, #4
-  add  r3, r3, ip
-  mov  r0, r0, lsr r1
-  tst  r0, #3
-  movne  r2, #0
-  moveq  r2, #2
-  add  r3, r3, r1
-  mov  r0, r0, lsr r2
-  and  r0, r0, #3
-  add  r2, r3, r2
-  eor  r3, r0, #1
-  mov  r0, r0, lsr #1
-  ands  r3, r3, #1
-  mvnne  r3, #0
-  rsb  r0, r0, #2
-  and  r0, r3, r0
-  add  r0, r2, r0
-  bx  lr
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__ctzsi2)\r
+  \r
+ASM_PFX(__ctzsi2):\r
+  uxth  r3, r0\r
+  cmp  r3, #0\r
+  moveq  ip, #16\r
+  movne  ip, #0\r
+  @ lr needed for prologue\r
+  mov  r0, r0, lsr ip\r
+  tst  r0, #255\r
+  movne  r3, #0\r
+  moveq  r3, #8\r
+  mov  r0, r0, lsr r3\r
+  tst  r0, #15\r
+  movne  r1, #0\r
+  moveq  r1, #4\r
+  add  r3, r3, ip\r
+  mov  r0, r0, lsr r1\r
+  tst  r0, #3\r
+  movne  r2, #0\r
+  moveq  r2, #2\r
+  add  r3, r3, r1\r
+  mov  r0, r0, lsr r2\r
+  and  r0, r0, #3\r
+  add  r2, r3, r2\r
+  eor  r3, r0, #1\r
+  mov  r0, r0, lsr #1\r
+  ands  r3, r3, #1\r
+  mvnne  r3, #0\r
+  rsb  r0, r0, #2\r
+  and  r0, r3, r0\r
+  add  r0, r2, r0\r
+  bx  lr\r
index 425d8b9e4472ef5afed71e4e29aa8157617d5dda..71f303b344c71d5e275cec673d7874b567521db6 100644 (file)
@@ -1,98 +1,98 @@
-/** @file
-  Compiler intrinsic to return the number of trailing zeros, ported from LLVM code.
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  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.
-
-**/
-/**
-  University of Illinois/NCSA
-  Open Source License
-  
-  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
-  All rights reserved.
-  
-  Developed by:
-  
-      LLVM Team
-  
-      University of Illinois at Urbana-Champaign
-  
-      http://llvm.org
-  
-  Permission is hereby granted, free of charge, to any person obtaining a copy of
-  this software and associated documentation files (the "Software"), to deal with
-  the Software without restriction, including without limitation the rights to
-  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-  of the Software, and to permit persons to whom the Software is furnished to do
-  so, subject to the following conditions:
-  
-      * Redistributions of source code must retain the above copyright notice,
-        this list of conditions and the following disclaimers.
-  
-      * Redistributions in binary form must reproduce the above copyright notice,
-        this list of conditions and the following disclaimers in the
-        documentation and/or other materials provided with the distribution.
-  
-      * Neither the names of the LLVM Team, University of Illinois at
-        Urbana-Champaign, nor the names of its contributors may be used to
-        endorse or promote products derived from this Software without specific
-        prior written permission.
-  
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-  SOFTWARE.
-**/
-
-
-#include "Llvm_int_lib.h"
-
-// Returns: the number of trailing 0-bits
-
-// Precondition: a != 0
-
-INT32
-__ctzsi2(INT32 a)
-{
-    UINT32 x = (UINT32)a;
-    INT32 t = ((x & 0x0000FFFF) == 0) << 4;  // if (x has no small bits) t = 16 else 0
-    x >>= t;           // x = [0 - 0xFFFF] + higher garbage bits
-    UINT32 r = t;       // r = [0, 16]
-    // return r + ctz(x)
-    t = ((x & 0x00FF) == 0) << 3;
-    x >>= t;           // x = [0 - 0xFF] + higher garbage bits
-    r += t;            // r = [0, 8, 16, 24]
-    // return r + ctz(x)
-    t = ((x & 0x0F) == 0) << 2;
-    x >>= t;           // x = [0 - 0xF] + higher garbage bits
-    r += t;            // r = [0, 4, 8, 12, 16, 20, 24, 28]
-    // return r + ctz(x)
-    t = ((x & 0x3) == 0) << 1;
-    x >>= t;
-    x &= 3;            // x = [0 - 3]
-    r += t;            // r = [0 - 30] and is even
-    // return r + ctz(x)
-//  The branch-less return statement below is equivalent
-//  to the following switch statement:
-//     switch (x)
-//     {
-//     case 0:
-//         return r + 2;
-//     case 2:
-//         return r + 1;
-//     case 1:
-//     case 3:
-//         return r;
-//     }
-    return r + ((2 - (x >> 1)) & -((x & 1) == 0));
-}
+/** @file\r
+  Compiler intrinsic to return the number of trailing zeros, ported from LLVM code.\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+/**\r
+  University of Illinois/NCSA\r
+  Open Source License\r
+  \r
+  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.\r
+  All rights reserved.\r
+  \r
+  Developed by:\r
+  \r
+      LLVM Team\r
+  \r
+      University of Illinois at Urbana-Champaign\r
+  \r
+      http://llvm.org\r
+  \r
+  Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+  this software and associated documentation files (the "Software"), to deal with\r
+  the Software without restriction, including without limitation the rights to\r
+  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+  of the Software, and to permit persons to whom the Software is furnished to do\r
+  so, subject to the following conditions:\r
+  \r
+      * Redistributions of source code must retain the above copyright notice,\r
+        this list of conditions and the following disclaimers.\r
+  \r
+      * Redistributions in binary form must reproduce the above copyright notice,\r
+        this list of conditions and the following disclaimers in the\r
+        documentation and/or other materials provided with the distribution.\r
+  \r
+      * Neither the names of the LLVM Team, University of Illinois at\r
+        Urbana-Champaign, nor the names of its contributors may be used to\r
+        endorse or promote products derived from this Software without specific\r
+        prior written permission.\r
+  \r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE\r
+  SOFTWARE.\r
+**/\r
+\r
+\r
+#include "Llvm_int_lib.h"\r
+\r
+// Returns: the number of trailing 0-bits\r
+\r
+// Precondition: a != 0\r
+\r
+INT32\r
+__ctzsi2(INT32 a)\r
+{\r
+    UINT32 x = (UINT32)a;\r
+    INT32 t = ((x & 0x0000FFFF) == 0) << 4;  // if (x has no small bits) t = 16 else 0\r
+    x >>= t;           // x = [0 - 0xFFFF] + higher garbage bits\r
+    UINT32 r = t;       // r = [0, 16]\r
+    // return r + ctz(x)\r
+    t = ((x & 0x00FF) == 0) << 3;\r
+    x >>= t;           // x = [0 - 0xFF] + higher garbage bits\r
+    r += t;            // r = [0, 8, 16, 24]\r
+    // return r + ctz(x)\r
+    t = ((x & 0x0F) == 0) << 2;\r
+    x >>= t;           // x = [0 - 0xF] + higher garbage bits\r
+    r += t;            // r = [0, 4, 8, 12, 16, 20, 24, 28]\r
+    // return r + ctz(x)\r
+    t = ((x & 0x3) == 0) << 1;\r
+    x >>= t;\r
+    x &= 3;            // x = [0 - 3]\r
+    r += t;            // r = [0 - 30] and is even\r
+    // return r + ctz(x)\r
+//  The branch-less return statement below is equivalent\r
+//  to the following switch statement:\r
+//     switch (x)\r
+//     {\r
+//     case 0:\r
+//         return r + 2;\r
+//     case 2:\r
+//         return r + 1;\r
+//     case 1:\r
+//     case 3:\r
+//         return r;\r
+//     }\r
+    return r + ((2 - (x >> 1)) & -((x & 1) == 0));\r
+}\r
index 3534eaba23cde382aee1bc771cd49914268597c5..faf70dbf459864d1cec79c70078cbff0f1e1cb36 100644 (file)
-#------------------------------------------------------------------------------
-#
-# Copyright (c) 2011, ARM. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-.text
-.align 2
-GCC_ASM_EXPORT(__aeabi_uidiv)
-GCC_ASM_EXPORT(__aeabi_uidivmod)
-GCC_ASM_EXPORT(__aeabi_idiv)
-GCC_ASM_EXPORT(__aeabi_idivmod)
-
-#    AREA  Math, CODE, READONLY
-
-#
-#UINT32
-#EFIAPI
-#__aeabi_uidivmode (
-#  IN UINT32  Dividen
-#  IN UINT32  Divisor
-#  );
-#
-
-ASM_PFX(__aeabi_uidiv):
-ASM_PFX(__aeabi_uidivmod):
-  rsbs    r12, r1, r0, LSR #4
-  mov     r2, #0
-  bcc     ASM_PFX(__arm_div4)
-  rsbs    r12, r1, r0, LSR #8
-  bcc     ASM_PFX(__arm_div8)
-  mov     r3, #0
-  b       ASM_PFX(__arm_div_large)
-
-#
-#INT32
-#EFIAPI
-#__aeabi_idivmode (
-#  IN INT32  Dividen
-#  IN INT32  Divisor
-#  );
-#
-ASM_PFX(__aeabi_idiv):
-ASM_PFX(__aeabi_idivmod):
-  orrs    r12, r0, r1
-  bmi     ASM_PFX(__arm_div_negative)
-  rsbs    r12, r1, r0, LSR #1
-  mov     r2, #0
-  bcc     ASM_PFX(__arm_div1)
-  rsbs    r12, r1, r0, LSR #4
-  bcc     ASM_PFX(__arm_div4)
-  rsbs    r12, r1, r0, LSR #8
-  bcc     ASM_PFX(__arm_div8)
-  mov     r3, #0
-  b       ASM_PFX(__arm_div_large)
-ASM_PFX(__arm_div8):
-  rsbs    r12, r1, r0, LSR #7
-  subcs   r0, r0, r1, LSL #7
-  adc     r2, r2, r2
-  rsbs    r12, r1, r0,LSR #6
-  subcs   r0, r0, r1, LSL #6
-  adc     r2, r2, r2
-  rsbs    r12, r1, r0, LSR #5
-  subcs   r0, r0, r1, LSL #5
-  adc     r2, r2, r2
-  rsbs    r12, r1, r0, LSR #4
-  subcs   r0, r0, r1, LSL #4
-  adc     r2, r2, r2
-ASM_PFX(__arm_div4):
-  rsbs    r12, r1, r0, LSR #3
-  subcs   r0, r0, r1, LSL #3
-  adc     r2, r2, r2
-  rsbs    r12, r1, r0, LSR #2
-  subcs   r0, r0, r1, LSL #2
-  adcs    r2, r2, r2
-  rsbs    r12, r1, r0, LSR #1
-  subcs   r0, r0, r1, LSL #1
-  adc     r2, r2, r2
-ASM_PFX(__arm_div1):
-  subs    r1, r0, r1
-  movcc   r1, r0
-  adc     r0, r2, r2
-  bx      r14
-ASM_PFX(__arm_div_negative):
-  ands    r2, r1, #0x80000000
-  rsbmi   r1, r1, #0
-  eors    r3, r2, r0, ASR #32
-  rsbcs   r0, r0, #0
-  rsbs    r12, r1, r0, LSR #4
-  bcc     label1
-  rsbs    r12, r1, r0, LSR #8
-  bcc     label2
-ASM_PFX(__arm_div_large):
-  lsl     r1, r1, #6
-  rsbs    r12, r1, r0, LSR #8
-  orr     r2, r2, #0xfc000000
-  bcc     label2
-  lsl     r1, r1, #6
-  rsbs    r12, r1, r0, LSR #8
-  orr     r2, r2, #0x3f00000
-  bcc     label2
-  lsl     r1, r1, #6
-  rsbs    r12, r1, r0, LSR #8
-  orr     r2, r2, #0xfc000
-  orrcs   r2, r2, #0x3f00
-  lslcs   r1, r1, #6
-  rsbs    r12, r1, #0
-  bcs     ASM_PFX(__aeabi_idiv0)
-label3:
-  lsrcs   r1, r1, #6
-label2:
-  rsbs    r12, r1, r0, LSR #7
-  subcs   r0, r0, r1, LSL #7
-  adc     r2, r2, r2
-  rsbs    r12, r1, r0, LSR #6
-  subcs   r0, r0, r1, LSL #6
-  adc     r2, r2, r2
-  rsbs    r12, r1, r0, LSR #5
-  subcs   r0, r0, r1, LSL #5
-  adc     r2, r2, r2
-  rsbs    r12, r1, r0, LSR #4
-  subcs   r0, r0, r1, LSL #4
-  adc     r2, r2, r2
-label1:
-  rsbs    r12, r1, r0, LSR #3
-  subcs   r0, r0, r1, LSL #3
-  adc     r2, r2, r2
-  rsbs    r12, r1, r0, LSR #2
-  subcs   r0, r0, r1, LSL #2
-  adcs    r2, r2, r2
-  bcs     label3
-  rsbs    r12, r1, r0, LSR #1
-  subcs   r0, r0, r1, LSL #1
-  adc     r2, r2, r2
-  subs    r1, r0, r1
-  movcc   r1, r0
-  adc     r0, r2, r2
-  asrs    r3, r3, #31
-  rsbmi   r0, r0, #0
-  rsbcs   r1, r1, #0
-  bx      r14
-
-  @ What to do about division by zero?  For now, just return.
-ASM_PFX(__aeabi_idiv0):
-  bx      r14
+#------------------------------------------------------------------------------\r
+#\r
+# Copyright (c) 2011, ARM. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+.text\r
+.align 2\r
+GCC_ASM_EXPORT(__aeabi_uidiv)\r
+GCC_ASM_EXPORT(__aeabi_uidivmod)\r
+GCC_ASM_EXPORT(__aeabi_idiv)\r
+GCC_ASM_EXPORT(__aeabi_idivmod)\r
+\r
+#    AREA  Math, CODE, READONLY\r
+\r
+#\r
+#UINT32\r
+#EFIAPI\r
+#__aeabi_uidivmode (\r
+#  IN UINT32  Dividen\r
+#  IN UINT32  Divisor\r
+#  );\r
+#\r
+\r
+ASM_PFX(__aeabi_uidiv):\r
+ASM_PFX(__aeabi_uidivmod):\r
+  rsbs    r12, r1, r0, LSR #4\r
+  mov     r2, #0\r
+  bcc     ASM_PFX(__arm_div4)\r
+  rsbs    r12, r1, r0, LSR #8\r
+  bcc     ASM_PFX(__arm_div8)\r
+  mov     r3, #0\r
+  b       ASM_PFX(__arm_div_large)\r
+\r
+#\r
+#INT32\r
+#EFIAPI\r
+#__aeabi_idivmode (\r
+#  IN INT32  Dividen\r
+#  IN INT32  Divisor\r
+#  );\r
+#\r
+ASM_PFX(__aeabi_idiv):\r
+ASM_PFX(__aeabi_idivmod):\r
+  orrs    r12, r0, r1\r
+  bmi     ASM_PFX(__arm_div_negative)\r
+  rsbs    r12, r1, r0, LSR #1\r
+  mov     r2, #0\r
+  bcc     ASM_PFX(__arm_div1)\r
+  rsbs    r12, r1, r0, LSR #4\r
+  bcc     ASM_PFX(__arm_div4)\r
+  rsbs    r12, r1, r0, LSR #8\r
+  bcc     ASM_PFX(__arm_div8)\r
+  mov     r3, #0\r
+  b       ASM_PFX(__arm_div_large)\r
+ASM_PFX(__arm_div8):\r
+  rsbs    r12, r1, r0, LSR #7\r
+  subcs   r0, r0, r1, LSL #7\r
+  adc     r2, r2, r2\r
+  rsbs    r12, r1, r0,LSR #6\r
+  subcs   r0, r0, r1, LSL #6\r
+  adc     r2, r2, r2\r
+  rsbs    r12, r1, r0, LSR #5\r
+  subcs   r0, r0, r1, LSL #5\r
+  adc     r2, r2, r2\r
+  rsbs    r12, r1, r0, LSR #4\r
+  subcs   r0, r0, r1, LSL #4\r
+  adc     r2, r2, r2\r
+ASM_PFX(__arm_div4):\r
+  rsbs    r12, r1, r0, LSR #3\r
+  subcs   r0, r0, r1, LSL #3\r
+  adc     r2, r2, r2\r
+  rsbs    r12, r1, r0, LSR #2\r
+  subcs   r0, r0, r1, LSL #2\r
+  adcs    r2, r2, r2\r
+  rsbs    r12, r1, r0, LSR #1\r
+  subcs   r0, r0, r1, LSL #1\r
+  adc     r2, r2, r2\r
+ASM_PFX(__arm_div1):\r
+  subs    r1, r0, r1\r
+  movcc   r1, r0\r
+  adc     r0, r2, r2\r
+  bx      r14\r
+ASM_PFX(__arm_div_negative):\r
+  ands    r2, r1, #0x80000000\r
+  rsbmi   r1, r1, #0\r
+  eors    r3, r2, r0, ASR #32\r
+  rsbcs   r0, r0, #0\r
+  rsbs    r12, r1, r0, LSR #4\r
+  bcc     label1\r
+  rsbs    r12, r1, r0, LSR #8\r
+  bcc     label2\r
+ASM_PFX(__arm_div_large):\r
+  lsl     r1, r1, #6\r
+  rsbs    r12, r1, r0, LSR #8\r
+  orr     r2, r2, #0xfc000000\r
+  bcc     label2\r
+  lsl     r1, r1, #6\r
+  rsbs    r12, r1, r0, LSR #8\r
+  orr     r2, r2, #0x3f00000\r
+  bcc     label2\r
+  lsl     r1, r1, #6\r
+  rsbs    r12, r1, r0, LSR #8\r
+  orr     r2, r2, #0xfc000\r
+  orrcs   r2, r2, #0x3f00\r
+  lslcs   r1, r1, #6\r
+  rsbs    r12, r1, #0\r
+  bcs     ASM_PFX(__aeabi_idiv0)\r
+label3:\r
+  lsrcs   r1, r1, #6\r
+label2:\r
+  rsbs    r12, r1, r0, LSR #7\r
+  subcs   r0, r0, r1, LSL #7\r
+  adc     r2, r2, r2\r
+  rsbs    r12, r1, r0, LSR #6\r
+  subcs   r0, r0, r1, LSL #6\r
+  adc     r2, r2, r2\r
+  rsbs    r12, r1, r0, LSR #5\r
+  subcs   r0, r0, r1, LSL #5\r
+  adc     r2, r2, r2\r
+  rsbs    r12, r1, r0, LSR #4\r
+  subcs   r0, r0, r1, LSL #4\r
+  adc     r2, r2, r2\r
+label1:\r
+  rsbs    r12, r1, r0, LSR #3\r
+  subcs   r0, r0, r1, LSL #3\r
+  adc     r2, r2, r2\r
+  rsbs    r12, r1, r0, LSR #2\r
+  subcs   r0, r0, r1, LSL #2\r
+  adcs    r2, r2, r2\r
+  bcs     label3\r
+  rsbs    r12, r1, r0, LSR #1\r
+  subcs   r0, r0, r1, LSL #1\r
+  adc     r2, r2, r2\r
+  subs    r1, r0, r1\r
+  movcc   r1, r0\r
+  adc     r0, r2, r2\r
+  asrs    r3, r3, #31\r
+  rsbmi   r0, r0, #0\r
+  rsbcs   r1, r1, #0\r
+  bx      r14\r
+\r
+  @ What to do about division by zero?  For now, just return.\r
+ASM_PFX(__aeabi_idiv0):\r
+  bx      r14\r
index e38105dd6305deaa927f957493e8279df3239a26..13f701358ec604745b49478ab02ff81d720aa840 100644 (file)
-//------------------------------------------------------------------------------ 
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-
-    EXPORT  __aeabi_uidiv
-    EXPORT  __aeabi_uidivmod
-    EXPORT  __aeabi_idiv
-    EXPORT  __aeabi_idivmod
-           
-    AREA  Math, CODE, READONLY
-
-;
-;UINT32
-;EFIAPI
-;__aeabi_uidivmode (
-;  IN UINT32  Dividen
-;  IN UINT32  Divisor
-;  );
-;
-
-__aeabi_uidiv
-__aeabi_uidivmod
-    RSBS    r12, r1, r0, LSR #4
-    MOV     r2, #0
-    BCC     __arm_div4
-    RSBS    r12, r1, r0, LSR #8
-    BCC     __arm_div8
-    MOV     r3, #0
-    B       __arm_div_large
-
-;
-;INT32
-;EFIAPI
-;__aeabi_idivmode (
-;  IN INT32  Dividen
-;  IN INT32  Divisor
-;  );
-;
-__aeabi_idiv
-__aeabi_idivmod
-    ORRS    r12, r0, r1
-    BMI     __arm_div_negative
-    RSBS    r12, r1, r0, LSR #1
-    MOV     r2, #0
-    BCC     __arm_div1
-    RSBS    r12, r1, r0, LSR #4
-    BCC     __arm_div4
-    RSBS    r12, r1, r0, LSR #8
-    BCC     __arm_div8
-    MOV     r3, #0
-    B       __arm_div_large
-__arm_div8
-    RSBS    r12, r1, r0, LSR #7
-    SUBCS   r0, r0, r1, LSL #7
-    ADC     r2, r2, r2
-    RSBS    r12, r1, r0,LSR #6
-    SUBCS   r0, r0, r1, LSL #6
-    ADC     r2, r2, r2
-    RSBS    r12, r1, r0, LSR #5
-    SUBCS   r0, r0, r1, LSL #5
-    ADC     r2, r2, r2
-    RSBS    r12, r1, r0, LSR #4
-    SUBCS   r0, r0, r1, LSL #4
-    ADC     r2, r2, r2
-__arm_div4
-    RSBS    r12, r1, r0, LSR #3
-    SUBCS   r0, r0, r1, LSL #3
-    ADC     r2, r2, r2
-    RSBS    r12, r1, r0, LSR #2
-    SUBCS   r0, r0, r1, LSL #2
-    ADCS    r2, r2, r2
-    RSBS    r12, r1, r0, LSR #1
-    SUBCS   r0, r0, r1, LSL #1
-    ADC     r2, r2, r2
-__arm_div1
-    SUBS    r1, r0, r1
-    MOVCC   r1, r0
-    ADC     r0, r2, r2
-    BX      r14
-__arm_div_negative
-    ANDS    r2, r1, #0x80000000
-    RSBMI   r1, r1, #0
-    EORS    r3, r2, r0, ASR #32
-    RSBCS   r0, r0, #0
-    RSBS    r12, r1, r0, LSR #4
-    BCC     label1
-    RSBS    r12, r1, r0, LSR #8
-    BCC     label2
-__arm_div_large
-    LSL     r1, r1, #6
-    RSBS    r12, r1, r0, LSR #8
-    ORR     r2, r2, #0xfc000000
-    BCC     label2
-    LSL     r1, r1, #6
-    RSBS    r12, r1, r0, LSR #8
-    ORR     r2, r2, #0x3f00000
-    BCC     label2
-    LSL     r1, r1, #6
-    RSBS    r12, r1, r0, LSR #8
-    ORR     r2, r2, #0xfc000
-    ORRCS   r2, r2, #0x3f00
-    LSLCS   r1, r1, #6
-    RSBS    r12, r1, #0
-    BCS     __aeabi_idiv0
-label3
-    LSRCS   r1, r1, #6
-label2
-    RSBS    r12, r1, r0, LSR #7
-    SUBCS   r0, r0, r1, LSL #7
-    ADC     r2, r2, r2
-    RSBS    r12, r1, r0, LSR #6
-    SUBCS   r0, r0, r1, LSL #6
-    ADC     r2, r2, r2
-    RSBS    r12, r1, r0, LSR #5
-    SUBCS   r0, r0, r1, LSL #5
-    ADC     r2, r2, r2
-    RSBS    r12, r1, r0, LSR #4
-    SUBCS   r0, r0, r1, LSL #4
-    ADC     r2, r2, r2
-label1
-    RSBS    r12, r1, r0, LSR #3
-    SUBCS   r0, r0, r1, LSL #3
-    ADC     r2, r2, r2
-    RSBS    r12, r1, r0, LSR #2
-    SUBCS   r0, r0, r1, LSL #2
-    ADCS    r2, r2, r2
-    BCS     label3
-    RSBS    r12, r1, r0, LSR #1
-    SUBCS   r0, r0, r1, LSL #1
-    ADC     r2, r2, r2
-    SUBS    r1, r0, r1
-    MOVCC   r1, r0
-    ADC     r0, r2, r2
-    ASRS    r3, r3, #31
-    RSBMI   r0, r0, #0
-    RSBCS   r1, r1, #0
-    BX      r14
-
-    ; What to do about division by zero?  For now, just return.
-__aeabi_idiv0
-    BX      r14
-    END
-
+//------------------------------------------------------------------------------ \r
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+\r
+    EXPORT  __aeabi_uidiv\r
+    EXPORT  __aeabi_uidivmod\r
+    EXPORT  __aeabi_idiv\r
+    EXPORT  __aeabi_idivmod\r
+           \r
+    AREA  Math, CODE, READONLY\r
+\r
+;\r
+;UINT32\r
+;EFIAPI\r
+;__aeabi_uidivmode (\r
+;  IN UINT32  Dividen\r
+;  IN UINT32  Divisor\r
+;  );\r
+;\r
+\r
+__aeabi_uidiv\r
+__aeabi_uidivmod\r
+    RSBS    r12, r1, r0, LSR #4\r
+    MOV     r2, #0\r
+    BCC     __arm_div4\r
+    RSBS    r12, r1, r0, LSR #8\r
+    BCC     __arm_div8\r
+    MOV     r3, #0\r
+    B       __arm_div_large\r
+\r
+;\r
+;INT32\r
+;EFIAPI\r
+;__aeabi_idivmode (\r
+;  IN INT32  Dividen\r
+;  IN INT32  Divisor\r
+;  );\r
+;\r
+__aeabi_idiv\r
+__aeabi_idivmod\r
+    ORRS    r12, r0, r1\r
+    BMI     __arm_div_negative\r
+    RSBS    r12, r1, r0, LSR #1\r
+    MOV     r2, #0\r
+    BCC     __arm_div1\r
+    RSBS    r12, r1, r0, LSR #4\r
+    BCC     __arm_div4\r
+    RSBS    r12, r1, r0, LSR #8\r
+    BCC     __arm_div8\r
+    MOV     r3, #0\r
+    B       __arm_div_large\r
+__arm_div8\r
+    RSBS    r12, r1, r0, LSR #7\r
+    SUBCS   r0, r0, r1, LSL #7\r
+    ADC     r2, r2, r2\r
+    RSBS    r12, r1, r0,LSR #6\r
+    SUBCS   r0, r0, r1, LSL #6\r
+    ADC     r2, r2, r2\r
+    RSBS    r12, r1, r0, LSR #5\r
+    SUBCS   r0, r0, r1, LSL #5\r
+    ADC     r2, r2, r2\r
+    RSBS    r12, r1, r0, LSR #4\r
+    SUBCS   r0, r0, r1, LSL #4\r
+    ADC     r2, r2, r2\r
+__arm_div4\r
+    RSBS    r12, r1, r0, LSR #3\r
+    SUBCS   r0, r0, r1, LSL #3\r
+    ADC     r2, r2, r2\r
+    RSBS    r12, r1, r0, LSR #2\r
+    SUBCS   r0, r0, r1, LSL #2\r
+    ADCS    r2, r2, r2\r
+    RSBS    r12, r1, r0, LSR #1\r
+    SUBCS   r0, r0, r1, LSL #1\r
+    ADC     r2, r2, r2\r
+__arm_div1\r
+    SUBS    r1, r0, r1\r
+    MOVCC   r1, r0\r
+    ADC     r0, r2, r2\r
+    BX      r14\r
+__arm_div_negative\r
+    ANDS    r2, r1, #0x80000000\r
+    RSBMI   r1, r1, #0\r
+    EORS    r3, r2, r0, ASR #32\r
+    RSBCS   r0, r0, #0\r
+    RSBS    r12, r1, r0, LSR #4\r
+    BCC     label1\r
+    RSBS    r12, r1, r0, LSR #8\r
+    BCC     label2\r
+__arm_div_large\r
+    LSL     r1, r1, #6\r
+    RSBS    r12, r1, r0, LSR #8\r
+    ORR     r2, r2, #0xfc000000\r
+    BCC     label2\r
+    LSL     r1, r1, #6\r
+    RSBS    r12, r1, r0, LSR #8\r
+    ORR     r2, r2, #0x3f00000\r
+    BCC     label2\r
+    LSL     r1, r1, #6\r
+    RSBS    r12, r1, r0, LSR #8\r
+    ORR     r2, r2, #0xfc000\r
+    ORRCS   r2, r2, #0x3f00\r
+    LSLCS   r1, r1, #6\r
+    RSBS    r12, r1, #0\r
+    BCS     __aeabi_idiv0\r
+label3\r
+    LSRCS   r1, r1, #6\r
+label2\r
+    RSBS    r12, r1, r0, LSR #7\r
+    SUBCS   r0, r0, r1, LSL #7\r
+    ADC     r2, r2, r2\r
+    RSBS    r12, r1, r0, LSR #6\r
+    SUBCS   r0, r0, r1, LSL #6\r
+    ADC     r2, r2, r2\r
+    RSBS    r12, r1, r0, LSR #5\r
+    SUBCS   r0, r0, r1, LSL #5\r
+    ADC     r2, r2, r2\r
+    RSBS    r12, r1, r0, LSR #4\r
+    SUBCS   r0, r0, r1, LSL #4\r
+    ADC     r2, r2, r2\r
+label1\r
+    RSBS    r12, r1, r0, LSR #3\r
+    SUBCS   r0, r0, r1, LSL #3\r
+    ADC     r2, r2, r2\r
+    RSBS    r12, r1, r0, LSR #2\r
+    SUBCS   r0, r0, r1, LSL #2\r
+    ADCS    r2, r2, r2\r
+    BCS     label3\r
+    RSBS    r12, r1, r0, LSR #1\r
+    SUBCS   r0, r0, r1, LSL #1\r
+    ADC     r2, r2, r2\r
+    SUBS    r1, r0, r1\r
+    MOVCC   r1, r0\r
+    ADC     r0, r2, r2\r
+    ASRS    r3, r3, #31\r
+    RSBMI   r0, r0, #0\r
+    RSBCS   r1, r1, #0\r
+    BX      r14\r
+\r
+    ; What to do about division by zero?  For now, just return.\r
+__aeabi_idiv0\r
+    BX      r14\r
\r
+    END\r
+\r
index 342f376bb02d087c1a2eb3b1edcbe9c8ba2b97c7..7be2e2886aaecfe21a302387adcee6e1e4b15a3c 100644 (file)
@@ -1,49 +1,49 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__divdi3)
-  
-ASM_PFX(__divdi3):
-  @ args = 0, pretend = 0, frame = 0
-  @ frame_needed = 1, uses_anonymous_args = 0
-  stmfd  sp!, {r4, r5, r7, lr}
-  mov  r4, r3, asr #31
-  add  r7, sp, #8
-  stmfd  sp!, {r10, r11}
-  mov  r10, r1, asr #31
-  sub  sp, sp, #8
-  mov  r11, r10
-  mov  r5, r4
-  eor  r0, r0, r10
-  eor  r1, r1, r10
-  eor  r2, r2, r4
-  eor  r3, r3, r4
-  subs  r2, r2, r4
-  sbc  r3, r3, r5
-  mov  ip, #0
-  subs  r0, r0, r10
-  sbc  r1, r1, r11
-  str  ip, [sp, #0]
-  bl  ASM_PFX(__udivmoddi4)
-  eor  r2, r10, r4
-  eor  r3, r10, r4
-  eor  r0, r0, r2
-  eor  r1, r1, r3
-  subs  r0, r0, r2
-  sbc  r1, r1, r3
-  sub  sp, r7, #16
-  ldmfd  sp!, {r10, r11}
-  ldmfd  sp!, {r4, r5, r7, pc}
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__divdi3)\r
+  \r
+ASM_PFX(__divdi3):\r
+  @ args = 0, pretend = 0, frame = 0\r
+  @ frame_needed = 1, uses_anonymous_args = 0\r
+  stmfd  sp!, {r4, r5, r7, lr}\r
+  mov  r4, r3, asr #31\r
+  add  r7, sp, #8\r
+  stmfd  sp!, {r10, r11}\r
+  mov  r10, r1, asr #31\r
+  sub  sp, sp, #8\r
+  mov  r11, r10\r
+  mov  r5, r4\r
+  eor  r0, r0, r10\r
+  eor  r1, r1, r10\r
+  eor  r2, r2, r4\r
+  eor  r3, r3, r4\r
+  subs  r2, r2, r4\r
+  sbc  r3, r3, r5\r
+  mov  ip, #0\r
+  subs  r0, r0, r10\r
+  sbc  r1, r1, r11\r
+  str  ip, [sp, #0]\r
+  bl  ASM_PFX(__udivmoddi4)\r
+  eor  r2, r10, r4\r
+  eor  r3, r10, r4\r
+  eor  r0, r0, r2\r
+  eor  r1, r1, r3\r
+  subs  r0, r0, r2\r
+  sbc  r1, r1, r3\r
+  sub  sp, r7, #16\r
+  ldmfd  sp!, {r10, r11}\r
+  ldmfd  sp!, {r4, r5, r7, pc}\r
index 4d790b8f9c2dfc446c92d3d663ca9a66231a29f8..e86bd1361e8f42e3c96b818933dc5789fef28b78 100644 (file)
@@ -1,77 +1,77 @@
-/** @file
-  Compiler intrinsic for 64-bit compare, ported from LLVM code.
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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.
-
-**/
-/**
-  University of Illinois/NCSA
-  Open Source License
-  
-  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
-  All rights reserved.
-  
-  Developed by:
-  
-      LLVM Team
-  
-      University of Illinois at Urbana-Champaign
-  
-      http://llvm.org
-  
-  Permission is hereby granted, free of charge, to any person obtaining a copy of
-  this software and associated documentation files (the "Software"), to deal with
-  the Software without restriction, including without limitation the rights to
-  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-  of the Software, and to permit persons to whom the Software is furnished to do
-  so, subject to the following conditions:
-  
-      * Redistributions of source code must retain the above copyright notice,
-        this list of conditions and the following disclaimers.
-  
-      * Redistributions in binary form must reproduce the above copyright notice,
-        this list of conditions and the following disclaimers in the
-        documentation and/or other materials provided with the distribution.
-  
-      * Neither the names of the LLVM Team, University of Illinois at
-        Urbana-Champaign, nor the names of its contributors may be used to
-        endorse or promote products derived from this Software without specific
-        prior written permission.
-  
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-  SOFTWARE.
-**/
-
-
-#include "Llvm_int_lib.h"
-
-UINT64 __udivmoddi4(UINT64 a, UINT64 b, UINT64* rem);
-
-// Returns: a / b
-
-INT64
-__divdi3(INT64 a, INT64 b)
-{
-    const int bits_in_dword_m1 = (int)(sizeof(INT64) * CHAR_BIT) - 1;
-    INT64 s_a = a >> bits_in_dword_m1;           // s_a = a < 0 ? -1 : 0
-    INT64 s_b = b >> bits_in_dword_m1;           // s_b = b < 0 ? -1 : 0
-    a = (a ^ s_a) - s_a;                         // negate if s_a == -1
-    b = (b ^ s_b) - s_b;                         // negate if s_b == -1
-    s_a ^= s_b;                                  // sign of quotient
-    return (__udivmoddi4(a, b, (UINT64*)0) ^ s_a) - s_a;  // negate if s_a == -1
-}
-
-
+/** @file\r
+  Compiler intrinsic for 64-bit compare, ported from LLVM code.\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+/**\r
+  University of Illinois/NCSA\r
+  Open Source License\r
+  \r
+  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.\r
+  All rights reserved.\r
+  \r
+  Developed by:\r
+  \r
+      LLVM Team\r
+  \r
+      University of Illinois at Urbana-Champaign\r
+  \r
+      http://llvm.org\r
+  \r
+  Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+  this software and associated documentation files (the "Software"), to deal with\r
+  the Software without restriction, including without limitation the rights to\r
+  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+  of the Software, and to permit persons to whom the Software is furnished to do\r
+  so, subject to the following conditions:\r
+  \r
+      * Redistributions of source code must retain the above copyright notice,\r
+        this list of conditions and the following disclaimers.\r
+  \r
+      * Redistributions in binary form must reproduce the above copyright notice,\r
+        this list of conditions and the following disclaimers in the\r
+        documentation and/or other materials provided with the distribution.\r
+  \r
+      * Neither the names of the LLVM Team, University of Illinois at\r
+        Urbana-Champaign, nor the names of its contributors may be used to\r
+        endorse or promote products derived from this Software without specific\r
+        prior written permission.\r
+  \r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE\r
+  SOFTWARE.\r
+**/\r
+\r
+\r
+#include "Llvm_int_lib.h"\r
+\r
+UINT64 __udivmoddi4(UINT64 a, UINT64 b, UINT64* rem);\r
+\r
+// Returns: a / b\r
+\r
+INT64\r
+__divdi3(INT64 a, INT64 b)\r
+{\r
+    const int bits_in_dword_m1 = (int)(sizeof(INT64) * CHAR_BIT) - 1;\r
+    INT64 s_a = a >> bits_in_dword_m1;           // s_a = a < 0 ? -1 : 0\r
+    INT64 s_b = b >> bits_in_dword_m1;           // s_b = b < 0 ? -1 : 0\r
+    a = (a ^ s_a) - s_a;                         // negate if s_a == -1\r
+    b = (b ^ s_b) - s_b;                         // negate if s_b == -1\r
+    s_a ^= s_b;                                  // sign of quotient\r
+    return (__udivmoddi4(a, b, (UINT64*)0) ^ s_a) - s_a;  // negate if s_a == -1\r
+}\r
+\r
+\r
index 3976fda1486298ea8f1bc2cc9f73404d6a893850..b74cbb64397c8d1728415a9460a8e8417e6b564c 100644 (file)
@@ -1,32 +1,32 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__divsi3)
-  
-ASM_PFX(__divsi3):
-  eor  r3, r0, r0, asr #31
-  eor  r2, r1, r1, asr #31
-  stmfd  sp!, {r4, r5, r7, lr}
-  mov  r5, r0, asr #31
-  add  r7, sp, #8
-  mov  r4, r1, asr #31
-  sub  r0, r3, r0, asr #31
-  sub  r1, r2, r1, asr #31
-  bl  ASM_PFX(__udivsi3)
-  eor  r1, r5, r4
-  eor  r0, r0, r1
-  rsb  r0, r1, r0
-  ldmfd  sp!, {r4, r5, r7, pc}
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__divsi3)\r
+  \r
+ASM_PFX(__divsi3):\r
+  eor  r3, r0, r0, asr #31\r
+  eor  r2, r1, r1, asr #31\r
+  stmfd  sp!, {r4, r5, r7, lr}\r
+  mov  r5, r0, asr #31\r
+  add  r7, sp, #8\r
+  mov  r4, r1, asr #31\r
+  sub  r0, r3, r0, asr #31\r
+  sub  r1, r2, r1, asr #31\r
+  bl  ASM_PFX(__udivsi3)\r
+  eor  r1, r5, r4\r
+  eor  r0, r0, r1\r
+  rsb  r0, r1, r0\r
+  ldmfd  sp!, {r4, r5, r7, pc}\r
index 4a19e15a3092fc254f83977229360c601201c71d..b322f9a57a443a472ef048fb29cdb647f76c3e8f 100644 (file)
@@ -1,78 +1,78 @@
-/** @file
-  Compiler intrinsic for 32--bit unsigned division, ported from LLVM code.
-
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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.
-
-**/
-/**
-  University of Illinois/NCSA
-  Open Source License
-  
-  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
-  All rights reserved.
-  
-  Developed by:
-  
-      LLVM Team
-  
-      University of Illinois at Urbana-Champaign
-  
-      http://llvm.org
-  
-  Permission is hereby granted, free of charge, to any person obtaining a copy of
-  this software and associated documentation files (the "Software"), to deal with
-  the Software without restriction, including without limitation the rights to
-  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-  of the Software, and to permit persons to whom the Software is furnished to do
-  so, subject to the following conditions:
-  
-      * Redistributions of source code must retain the above copyright notice,
-        this list of conditions and the following disclaimers.
-  
-      * Redistributions in binary form must reproduce the above copyright notice,
-        this list of conditions and the following disclaimers in the
-        documentation and/or other materials provided with the distribution.
-  
-      * Neither the names of the LLVM Team, University of Illinois at
-        Urbana-Champaign, nor the names of its contributors may be used to
-        endorse or promote products derived from this Software without specific
-        prior written permission.
-  
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-  SOFTWARE.
-**/
-
-
-#include "Llvm_int_lib.h"
-
-UINT32 __udivsi3(UINT32 n, UINT32 d);
-
-// Returns: a / b
-
-INT32
-__divsi3(INT32 a, INT32 b)
-{
-    const int bits_in_word_m1 = (int)(sizeof(INT32) * CHAR_BIT) - 1;
-    INT32 s_a = a >> bits_in_word_m1;           // s_a = a < 0 ? -1 : 0
-    INT32 s_b = b >> bits_in_word_m1;           // s_b = b < 0 ? -1 : 0
-    a = (a ^ s_a) - s_a;                         // negate if s_a == -1
-    b = (b ^ s_b) - s_b;                         // negate if s_b == -1
-    s_a ^= s_b;                                  // sign of quotient
-    return (__udivsi3(a, b) ^ s_a) - s_a;        // negate if s_a == -1
-}
-
-
+/** @file\r
+  Compiler intrinsic for 32--bit unsigned division, ported from LLVM code.\r
+\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+/**\r
+  University of Illinois/NCSA\r
+  Open Source License\r
+  \r
+  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.\r
+  All rights reserved.\r
+  \r
+  Developed by:\r
+  \r
+      LLVM Team\r
+  \r
+      University of Illinois at Urbana-Champaign\r
+  \r
+      http://llvm.org\r
+  \r
+  Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+  this software and associated documentation files (the "Software"), to deal with\r
+  the Software without restriction, including without limitation the rights to\r
+  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+  of the Software, and to permit persons to whom the Software is furnished to do\r
+  so, subject to the following conditions:\r
+  \r
+      * Redistributions of source code must retain the above copyright notice,\r
+        this list of conditions and the following disclaimers.\r
+  \r
+      * Redistributions in binary form must reproduce the above copyright notice,\r
+        this list of conditions and the following disclaimers in the\r
+        documentation and/or other materials provided with the distribution.\r
+  \r
+      * Neither the names of the LLVM Team, University of Illinois at\r
+        Urbana-Champaign, nor the names of its contributors may be used to\r
+        endorse or promote products derived from this Software without specific\r
+        prior written permission.\r
+  \r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE\r
+  SOFTWARE.\r
+**/\r
+\r
+\r
+#include "Llvm_int_lib.h"\r
+\r
+UINT32 __udivsi3(UINT32 n, UINT32 d);\r
+\r
+// Returns: a / b\r
+\r
+INT32\r
+__divsi3(INT32 a, INT32 b)\r
+{\r
+    const int bits_in_word_m1 = (int)(sizeof(INT32) * CHAR_BIT) - 1;\r
+    INT32 s_a = a >> bits_in_word_m1;           // s_a = a < 0 ? -1 : 0\r
+    INT32 s_b = b >> bits_in_word_m1;           // s_b = b < 0 ? -1 : 0\r
+    a = (a ^ s_a) - s_a;                         // negate if s_a == -1\r
+    b = (b ^ s_b) - s_b;                         // negate if s_b == -1\r
+    s_a ^= s_b;                                  // sign of quotient\r
+    return (__udivsi3(a, b) ^ s_a) - s_a;        // negate if s_a == -1\r
+}\r
+\r
+\r
index 1821816ab7cb91355f78083d27636a560ae46f3e..069438c9200b2639c0e1c43dfef46a8ff4c68aed 100644 (file)
@@ -1,41 +1,41 @@
-//------------------------------------------------------------------------------ 
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-
-    EXPORT  __aeabi_lasr
-           
-    AREA    Math, CODE, READONLY
-
-;
-;UINT32
-;EFIAPI
-;__aeabi_lasr (
-;  IN UINT32  Dividen
-;  IN UINT32  Divisor
-;  );
-;
-__aeabi_lasr
-    SUBS     r3,r2,#0x20
-    BPL      {pc} + 0x18  ; 0x1c
-    RSB      r3,r2,#0x20
-    LSR      r0,r0,r2
-    ORR      r0,r0,r1,LSL r3
-    ASR      r1,r1,r2
-    BX       lr
-    ASR      r0,r1,r3
-    ASR      r1,r1,#31
-    BX       lr
-    
-    END
-
+//------------------------------------------------------------------------------ \r
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+\r
+    EXPORT  __aeabi_lasr\r
+           \r
+    AREA    Math, CODE, READONLY\r
+\r
+;\r
+;UINT32\r
+;EFIAPI\r
+;__aeabi_lasr (\r
+;  IN UINT32  Dividen\r
+;  IN UINT32  Divisor\r
+;  );\r
+;\r
+__aeabi_lasr\r
+    SUBS     r3,r2,#0x20\r
+    BPL      {pc} + 0x18  ; 0x1c\r
+    RSB      r3,r2,#0x20\r
+    LSR      r0,r0,r2\r
+    ORR      r0,r0,r1,LSL r3\r
+    ASR      r1,r1,r2\r
+    BX       lr\r
+    ASR      r0,r1,r3\r
+    ASR      r1,r1,#31\r
+    BX       lr\r
+    \r
+    END\r
+\r
index 02ecdfe8d7df7149f3ee31889e551b8d5d6f5b2a..510778ab07df6b48d9a0f6ecbd59ed204922318a 100755 (executable)
@@ -1,59 +1,59 @@
-//------------------------------------------------------------------------------ 
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__aeabi_ldivmod)
-
-//
-// A pair of (unsigned) long longs is returned in {{r0, r1}, {r2, r3}}, 
-//  the quotient in {r0, r1}, and the remainder in {r2, r3}.
-//
-//__value_in_regs lldiv_t
-//EFIAPI
-//__aeabi_ldivmod (
-//  IN UINT64  Dividen
-//  IN UINT64  Divisor
-//  )//
-//
-
-ASM_PFX(__aeabi_ldivmod):
-    push     {r4,lr}
-    asrs     r4,r1,#1
-    eor      r4,r4,r3,LSR #1
-    bpl      L_Test1
-    rsbs     r0,r0,#0
-    rsc      r1,r1,#0
-L_Test1:
-    tst      r3,r3
-    bpl      L_Test2
-    rsbs     r2,r2,#0
-    rsc      r3,r3,#0
-L_Test2:
-    bl       ASM_PFX(__aeabi_uldivmod)  
-    tst      r4,#0x40000000
-    beq      L_Test3
-    rsbs     r0,r0,#0
-    rsc      r1,r1,#0
-L_Test3:
-    tst      r4,#0x80000000
-    beq      L_Exit
-    rsbs     r2,r2,#0
-    rsc      r3,r3,#0
-L_Exit:
-    pop      {r4,pc}
-
-
+//------------------------------------------------------------------------------ \r
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__aeabi_ldivmod)\r
+\r
+//\r
+// A pair of (unsigned) long longs is returned in {{r0, r1}, {r2, r3}}, \r
+//  the quotient in {r0, r1}, and the remainder in {r2, r3}.\r
+//\r
+//__value_in_regs lldiv_t\r
+//EFIAPI\r
+//__aeabi_ldivmod (\r
+//  IN UINT64  Dividen\r
+//  IN UINT64  Divisor\r
+//  )//\r
+//\r
+\r
+ASM_PFX(__aeabi_ldivmod):\r
+    push     {r4,lr}\r
+    asrs     r4,r1,#1\r
+    eor      r4,r4,r3,LSR #1\r
+    bpl      L_Test1\r
+    rsbs     r0,r0,#0\r
+    rsc      r1,r1,#0\r
+L_Test1:\r
+    tst      r3,r3\r
+    bpl      L_Test2\r
+    rsbs     r2,r2,#0\r
+    rsc      r3,r3,#0\r
+L_Test2:\r
+    bl       ASM_PFX(__aeabi_uldivmod)  \r
+    tst      r4,#0x40000000\r
+    beq      L_Test3\r
+    rsbs     r0,r0,#0\r
+    rsc      r1,r1,#0\r
+L_Test3:\r
+    tst      r4,#0x80000000\r
+    beq      L_Exit\r
+    rsbs     r2,r2,#0\r
+    rsc      r3,r3,#0\r
+L_Exit:\r
+    pop      {r4,pc}\r
\r
+\r
+\r
index 32b65df52141614cbdeede84dfaf0a04773c6a4d..0059c2f6f91f030a8d517505602b5231e91ee069 100644 (file)
@@ -1,58 +1,58 @@
-//------------------------------------------------------------------------------ 
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-
-    EXPORT  __aeabi_ldivmod
-    EXTERN  __aeabi_uldivmod
-           
-    AREA    Math, CODE, READONLY
-
-;
-;UINT32
-;EFIAPI
-;__aeabi_uidivmode (
-;  IN UINT32  Dividen
-;  IN UINT32  Divisor
-;  );
-;
-
-__aeabi_ldivmod
-    PUSH     {r4,lr}
-    ASRS     r4,r1,#1
-    EOR      r4,r4,r3,LSR #1
-    BPL      L_Test1
-    RSBS     r0,r0,#0
-    RSC      r1,r1,#0
-L_Test1
-    TST      r3,r3
-    BPL      L_Test2
-    RSBS     r2,r2,#0
-    RSC      r3,r3,#0
-L_Test2
-    BL       __aeabi_uldivmod  ;
-    TST      r4,#0x40000000
-    BEQ      L_Test3
-    RSBS     r0,r0,#0
-    RSC      r1,r1,#0
-L_Test3
-    TST      r4,#0x80000000
-    BEQ      L_Exit
-    RSBS     r2,r2,#0
-    RSC      r3,r3,#0
-L_Exit
-    POP      {r4,pc}
-    END
-
-
+//------------------------------------------------------------------------------ \r
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+\r
+    EXPORT  __aeabi_ldivmod\r
+    EXTERN  __aeabi_uldivmod\r
+           \r
+    AREA    Math, CODE, READONLY\r
+\r
+;\r
+;UINT32\r
+;EFIAPI\r
+;__aeabi_uidivmode (\r
+;  IN UINT32  Dividen\r
+;  IN UINT32  Divisor\r
+;  );\r
+;\r
+\r
+__aeabi_ldivmod\r
+    PUSH     {r4,lr}\r
+    ASRS     r4,r1,#1\r
+    EOR      r4,r4,r3,LSR #1\r
+    BPL      L_Test1\r
+    RSBS     r0,r0,#0\r
+    RSC      r1,r1,#0\r
+L_Test1\r
+    TST      r3,r3\r
+    BPL      L_Test2\r
+    RSBS     r2,r2,#0\r
+    RSC      r3,r3,#0\r
+L_Test2\r
+    BL       __aeabi_uldivmod  ;\r
+    TST      r4,#0x40000000\r
+    BEQ      L_Test3\r
+    RSBS     r0,r0,#0\r
+    RSC      r1,r1,#0\r
+L_Test3\r
+    TST      r4,#0x80000000\r
+    BEQ      L_Exit\r
+    RSBS     r2,r2,#0\r
+    RSC      r3,r3,#0\r
+L_Exit\r
+    POP      {r4,pc}\r
\r
+    END\r
+\r
+\r
index 099693949fbf3e33d0531194d8bcb780f2714d02..43d9e729cfb7577c83ce99e6cb4b5313c308fc51 100644 (file)
@@ -1,43 +1,43 @@
-//------------------------------------------------------------------------------ 
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-
-    EXPORT  __aeabi_llsl
-
-    AREA    Math, CODE, READONLY
-
-;
-;VOID
-;EFIAPI
-;__aeabi_llsl (
-; IN  VOID    *Destination,
-; IN  VOID    *Source,
-; IN  UINT32  Size
-; );
-;
-
-__aeabi_llsl
-    SUBS     r3,r2,#0x20
-    BPL      {pc} + 0x18  ; 0x1c
-    RSB      r3,r2,#0x20
-    LSL      r1,r1,r2
-    ORR      r1,r1,r0,LSR r3
-    LSL      r0,r0,r2
-    BX       lr
-    LSL      r1,r0,r3
-    MOV      r0,#0
-    BX       lr
-
-    END
-
+//------------------------------------------------------------------------------ \r
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+\r
+    EXPORT  __aeabi_llsl\r
+\r
+    AREA    Math, CODE, READONLY\r
+\r
+;\r
+;VOID\r
+;EFIAPI\r
+;__aeabi_llsl (\r
+; IN  VOID    *Destination,\r
+; IN  VOID    *Source,\r
+; IN  UINT32  Size\r
+; );\r
+;\r
+\r
+__aeabi_llsl\r
+    SUBS     r3,r2,#0x20\r
+    BPL      {pc} + 0x18  ; 0x1c\r
+    RSB      r3,r2,#0x20\r
+    LSL      r1,r1,r2\r
+    ORR      r1,r1,r0,LSR r3\r
+    LSL      r0,r0,r2\r
+    BX       lr\r
+    LSL      r1,r0,r3\r
+    MOV      r0,#0\r
+    BX       lr\r
+\r
+    END\r
+\r
index 8f1af0ed440b78df26a2416eb31b2b3da2d6fc05..de9a2186c2375854f37fefbd8b7eb628c550757e 100644 (file)
@@ -1,44 +1,44 @@
-//------------------------------------------------------------------------------ 
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-
-    EXPORT  __aeabi_llsr
-
-    AREA    Math, CODE, READONLY
-
-;
-;VOID
-;EFIAPI
-;__aeabi_llsr (
-; IN  VOID    *Destination,
-; IN  VOID    *Source,
-; IN  UINT32  Size
-; );
-;
-__aeabi_llsr
-    SUBS     r3,r2,#0x20
-    BPL      {pc} + 0x18  ; 0x1c
-    RSB      r3,r2,#0x20
-    LSR      r0,r0,r2
-    ORR      r0,r0,r1,LSL r3
-    LSR      r1,r1,r2
-    BX       lr
-    LSR      r0,r1,r3
-    MOV      r1,#0
-    BX       lr
-
-    END
-
-
-
+//------------------------------------------------------------------------------ \r
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+\r
+    EXPORT  __aeabi_llsr\r
+\r
+    AREA    Math, CODE, READONLY\r
+\r
+;\r
+;VOID\r
+;EFIAPI\r
+;__aeabi_llsr (\r
+; IN  VOID    *Destination,\r
+; IN  VOID    *Source,\r
+; IN  UINT32  Size\r
+; );\r
+;\r
+__aeabi_llsr\r
+    SUBS     r3,r2,#0x20\r
+    BPL      {pc} + 0x18  ; 0x1c\r
+    RSB      r3,r2,#0x20\r
+    LSR      r0,r0,r2\r
+    ORR      r0,r0,r1,LSL r3\r
+    LSR      r1,r1,r2\r
+    BX       lr\r
+    LSR      r0,r1,r3\r
+    MOV      r1,#0\r
+    BX       lr\r
+\r
+    END\r
+\r
+\r
+\r
index 73d83599bafad8b1a106345dfeca6a1184c7fcf6..efec070c010959a673e92f52d7bce9386a150802 100644 (file)
@@ -1,35 +1,35 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__lshrdi3)
-  
-ASM_PFX(__lshrdi3):
-  cmp  r2, #31
-  bls  L2
-  cmp  r2, #63
-  subls  r2, r2, #32
-  movls  r2, r1, lsr r2
-  movhi  r2, #0
-  mov  r0, r2
-  mov  r1, #0
-  bx  lr
-L2:
-  cmp  r2, #0
-  rsbne  r3, r2, #32
-  movne  r3, r1, asl r3
-  movne  r1, r1, lsr r2
-  orrne  r0, r3, r0, lsr r2
-  bx  lr
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__lshrdi3)\r
+  \r
+ASM_PFX(__lshrdi3):\r
+  cmp  r2, #31\r
+  bls  L2\r
+  cmp  r2, #63\r
+  subls  r2, r2, #32\r
+  movls  r2, r1, lsr r2\r
+  movhi  r2, #0\r
+  mov  r0, r2\r
+  mov  r1, #0\r
+  bx  lr\r
+L2:\r
+  cmp  r2, #0\r
+  rsbne  r3, r2, #32\r
+  movne  r3, r1, asl r3\r
+  movne  r1, r1, lsr r2\r
+  orrne  r0, r3, r0, lsr r2\r
+  bx  lr\r
index 4353be9dec5758c60ca14b6815b895243e0fb86b..47c80c2d233a37f3737581f1c4eae745bea5cd25 100644 (file)
@@ -1,83 +1,83 @@
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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.
-
-**/
-/**
-  University of Illinois/NCSA
-  Open Source License
-  
-  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
-  All rights reserved.
-  
-  Developed by:
-  
-      LLVM Team
-  
-      University of Illinois at Urbana-Champaign
-  
-      http://llvm.org
-  
-  Permission is hereby granted, free of charge, to any person obtaining a copy of
-  this software and associated documentation files (the "Software"), to deal with
-  the Software without restriction, including without limitation the rights to
-  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-  of the Software, and to permit persons to whom the Software is furnished to do
-  so, subject to the following conditions:
-  
-      * Redistributions of source code must retain the above copyright notice,
-        this list of conditions and the following disclaimers.
-  
-      * Redistributions in binary form must reproduce the above copyright notice,
-        this list of conditions and the following disclaimers in the
-        documentation and/or other materials provided with the distribution.
-  
-      * Neither the names of the LLVM Team, University of Illinois at
-        Urbana-Champaign, nor the names of its contributors may be used to
-        endorse or promote products derived from this Software without specific
-        prior written permission.
-  
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-  SOFTWARE.
-**/
-
-#include "Llvm_int_lib.h"
-
-// Returns: logical a >> b
-
-// Precondition:  0 <= b < bits_in_dword
-
-INT64
-__lshrdi3(INT64 a, INT32 b)
-{
-    const int bits_in_word = (int)(sizeof(INT32) * CHAR_BIT);
-    udwords input;
-    udwords result;
-    input.all = a;
-    if (b & bits_in_word)  // bits_in_word <= b < bits_in_dword
-    {
-        result.high = 0;
-        result.low = input.high >> (b - bits_in_word);
-    }
-    else  // 0 <= b < bits_in_word
-    {
-        if (b == 0)
-            return a;
-        result.high  = input.high >> b;
-        result.low = (input.high << (bits_in_word - b)) | (input.low >> b);
-    }
-    return result.all;
-}
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+/**\r
+  University of Illinois/NCSA\r
+  Open Source License\r
+  \r
+  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.\r
+  All rights reserved.\r
+  \r
+  Developed by:\r
+  \r
+      LLVM Team\r
+  \r
+      University of Illinois at Urbana-Champaign\r
+  \r
+      http://llvm.org\r
+  \r
+  Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+  this software and associated documentation files (the "Software"), to deal with\r
+  the Software without restriction, including without limitation the rights to\r
+  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+  of the Software, and to permit persons to whom the Software is furnished to do\r
+  so, subject to the following conditions:\r
+  \r
+      * Redistributions of source code must retain the above copyright notice,\r
+        this list of conditions and the following disclaimers.\r
+  \r
+      * Redistributions in binary form must reproduce the above copyright notice,\r
+        this list of conditions and the following disclaimers in the\r
+        documentation and/or other materials provided with the distribution.\r
+  \r
+      * Neither the names of the LLVM Team, University of Illinois at\r
+        Urbana-Champaign, nor the names of its contributors may be used to\r
+        endorse or promote products derived from this Software without specific\r
+        prior written permission.\r
+  \r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE\r
+  SOFTWARE.\r
+**/\r
+\r
+#include "Llvm_int_lib.h"\r
+\r
+// Returns: logical a >> b\r
+\r
+// Precondition:  0 <= b < bits_in_dword\r
+\r
+INT64\r
+__lshrdi3(INT64 a, INT32 b)\r
+{\r
+    const int bits_in_word = (int)(sizeof(INT32) * CHAR_BIT);\r
+    udwords input;\r
+    udwords result;\r
+    input.all = a;\r
+    if (b & bits_in_word)  // bits_in_word <= b < bits_in_dword\r
+    {\r
+        result.high = 0;\r
+        result.low = input.high >> (b - bits_in_word);\r
+    }\r
+    else  // 0 <= b < bits_in_word\r
+    {\r
+        if (b == 0)\r
+            return a;\r
+        result.high  = input.high >> b;\r
+        result.low = (input.high << (bits_in_word - b)) | (input.low >> b);\r
+    }\r
+    return result.all;\r
+}\r
index 18299326ca3e4c0e6877cd34039120a63263f5fc..07e0cd6bb4f0e105c4811c4322e127e718aa4db9 100644 (file)
@@ -1,34 +1,34 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(memcpy)
-
-ASM_PFX(memcpy):
-  stmfd  sp!, {r7, lr}
-  mov  ip, #0
-  add  r7, sp, #0
-  mov  lr, r0
-  b  L4
-L5:
-  ldrb  r3, [r1], #1  @ zero_extendqisi2
-  add  ip, ip, #1
-  and  r3, r3, #255
-  strb  r3, [lr], #1
-L4:
-  cmp  ip, r2
-  bne  L5
-  ldmfd  sp!, {r7, pc}
-
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(memcpy)\r
+\r
+ASM_PFX(memcpy):\r
+  stmfd  sp!, {r7, lr}\r
+  mov  ip, #0\r
+  add  r7, sp, #0\r
+  mov  lr, r0\r
+  b  L4\r
+L5:\r
+  ldrb  r3, [r1], #1  @ zero_extendqisi2\r
+  add  ip, ip, #1\r
+  and  r3, r3, #255\r
+  strb  r3, [lr], #1\r
+L4:\r
+  cmp  ip, r2\r
+  bne  L5\r
+  ldmfd  sp!, {r7, pc}\r
+\r
index aef8a5c11c02b504987e6fbee9c101eebbd23f19..e01b80d4bcaffc151220bc1a7556f8de8ddb951d 100644 (file)
@@ -1,40 +1,40 @@
-//------------------------------------------------------------------------------ 
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-
-    EXPORT  __aeabi_memcpy
-
-    AREA    Memcpy, CODE, READONLY
-
-;
-;VOID
-;EFIAPI
-;__aeabi_memcpy (
-; IN  VOID    *Destination,
-; IN  VOID    *Source,
-; IN  UINT32  Size
-; );
-;
-__aeabi_memcpy
-    CMP     r2, #0
-    BXEQ    r14
-loop
-    LDRB    r3, [r1], #1
-    STRB    r3, [r0], #1
-    SUBS    r2, r2, #1
-    BXEQ    r14
-    B       loop
-        
-    END
-
+//------------------------------------------------------------------------------ \r
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+\r
+    EXPORT  __aeabi_memcpy\r
+\r
+    AREA    Memcpy, CODE, READONLY\r
+\r
+;\r
+;VOID\r
+;EFIAPI\r
+;__aeabi_memcpy (\r
+; IN  VOID    *Destination,\r
+; IN  VOID    *Source,\r
+; IN  UINT32  Size\r
+; );\r
+;\r
+__aeabi_memcpy\r
+    CMP     r2, #0\r
+    BXEQ    r14\r
+loop\r
+    LDRB    r3, [r1], #1\r
+    STRB    r3, [r0], #1\r
+    SUBS    r2, r2, #1\r
+    BXEQ    r14\r
+    B       loop\r
+        \r
+    END\r
+\r
index a3cd58aba18bf7be7bddc0ae3d9c9ce0879e595a..9780060c1cde407dd9ac32b8612e228f6f406427 100644 (file)
@@ -1,61 +1,61 @@
-//------------------------------------------------------------------------------ 
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-
-    EXPORT  __aeabi_memcpy4
-
-    AREA    Memcpy4, CODE, READONLY
-
-;
-;VOID
-;EFIAPI
-;__aeabi_memcpy (
-; IN  VOID    *Destination,
-; IN  VOID    *Source,
-; IN  UINT32  Size
-; );
-;
-__aeabi_memcpy4
-    stmdb   sp!, {r4, lr}
-    subs    r2, r2, #32     ; 0x20
-    bcc     memcpy4_label2
-memcpy4_label1
-    ldmcsia r1!, {r3, r4, ip, lr}
-    stmcsia r0!, {r3, r4, ip, lr}
-    ldmcsia r1!, {r3, r4, ip, lr}
-    stmcsia r0!, {r3, r4, ip, lr}
-    subcss  r2, r2, #32     ; 0x20
-    bcs     memcpy4_label1
-memcpy4_label2
-    movs    ip, r2, lsl #28
-    ldmcsia r1!, {r3, r4, ip, lr}
-    stmcsia r0!, {r3, r4, ip, lr}
-    ldmmiia r1!, {r3, r4}
-    stmmiia r0!, {r3, r4}
-    ldmia   sp!, {r4, lr}
-    movs    ip, r2, lsl #30
-    ldrcs   r3, [r1], #4
-    strcs   r3, [r0], #4
-    bxeq    lr
-
-_memcpy4_lastbytes_aligned
-    movs    r2, r2, lsl #31
-    ldrcsh  r3, [r1], #2
-    ldrmib  r2, [r1], #1
-    strcsh  r3, [r0], #2
-    strmib  r2, [r0], #1
-    bx      lr
-
-    END
-
+//------------------------------------------------------------------------------ \r
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+\r
+    EXPORT  __aeabi_memcpy4\r
+\r
+    AREA    Memcpy4, CODE, READONLY\r
+\r
+;\r
+;VOID\r
+;EFIAPI\r
+;__aeabi_memcpy (\r
+; IN  VOID    *Destination,\r
+; IN  VOID    *Source,\r
+; IN  UINT32  Size\r
+; );\r
+;\r
+__aeabi_memcpy4\r
+    stmdb   sp!, {r4, lr}\r
+    subs    r2, r2, #32     ; 0x20\r
+    bcc     memcpy4_label2\r
+memcpy4_label1\r
+    ldmcsia r1!, {r3, r4, ip, lr}\r
+    stmcsia r0!, {r3, r4, ip, lr}\r
+    ldmcsia r1!, {r3, r4, ip, lr}\r
+    stmcsia r0!, {r3, r4, ip, lr}\r
+    subcss  r2, r2, #32     ; 0x20\r
+    bcs     memcpy4_label1\r
+memcpy4_label2\r
+    movs    ip, r2, lsl #28\r
+    ldmcsia r1!, {r3, r4, ip, lr}\r
+    stmcsia r0!, {r3, r4, ip, lr}\r
+    ldmmiia r1!, {r3, r4}\r
+    stmmiia r0!, {r3, r4}\r
+    ldmia   sp!, {r4, lr}\r
+    movs    ip, r2, lsl #30\r
+    ldrcs   r3, [r1], #4\r
+    strcs   r3, [r0], #4\r
+    bxeq    lr\r
+\r
+_memcpy4_lastbytes_aligned\r
+    movs    r2, r2, lsl #31\r
+    ldrcsh  r3, [r1], #2\r
+    ldrmib  r2, [r1], #1\r
+    strcsh  r3, [r0], #2\r
+    strmib  r2, [r0], #1\r
+    bx      lr\r
+\r
+    END\r
+\r
index d84429ef7f8d982e75789baa501fb19f209211f3..ae5c990f5795a540e848dc0941b87ca14098cbb9 100755 (executable)
@@ -1,54 +1,54 @@
-//------------------------------------------------------------------------------ 
-//
-// Copyright (c) 2011, ARM Limited. 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.
-//
-//------------------------------------------------------------------------------
-
-
-    EXPORT  __aeabi_memmove
-
-    AREA    Memmove, CODE, READONLY
-
-;
-;VOID
-;EFIAPI
-;__aeabi_memmove (
-; IN  VOID          *Destination,
-; IN  CONST VOID    *Source,
-; IN  UINT32        Size
-; );
-;
-__aeabi_memmove
-  CMP     r2, #0
-  BXEQ    r14
-  CMP     r0, r1
-  BXEQ    r14
-  BHI     memmove_backward
-  BLS     memmove_forward
-
-memmove_forward
-  LDRB    r3, [r1], #1
-  STRB    r3, [r0], #1
-  SUBS    r2, r2, #1
-  BXEQ    r14
-  B       memmove_forward
-
-memmove_backward
-  add     r0, r2
-  add     r1, r2
-memmove_backward_loop
-  LDRB    r3, [r1], #-1
-  STRB    r3, [r0], #-1
-  SUBS    r2, r2, #-1
-  BXEQ    r14
-  B       memmove_backward_loop
-
-  END
+//------------------------------------------------------------------------------ \r
+//\r
+// Copyright (c) 2011, ARM Limited. All rights reserved.\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+\r
+    EXPORT  __aeabi_memmove\r
+\r
+    AREA    Memmove, CODE, READONLY\r
+\r
+;\r
+;VOID\r
+;EFIAPI\r
+;__aeabi_memmove (\r
+; IN  VOID          *Destination,\r
+; IN  CONST VOID    *Source,\r
+; IN  UINT32        Size\r
+; );\r
+;\r
+__aeabi_memmove\r
+  CMP     r2, #0\r
+  BXEQ    r14\r
+  CMP     r0, r1\r
+  BXEQ    r14\r
+  BHI     memmove_backward\r
+  BLS     memmove_forward\r
+\r
+memmove_forward\r
+  LDRB    r3, [r1], #1\r
+  STRB    r3, [r0], #1\r
+  SUBS    r2, r2, #1\r
+  BXEQ    r14\r
+  B       memmove_forward\r
+\r
+memmove_backward\r
+  add     r0, r2\r
+  add     r1, r2\r
+memmove_backward_loop\r
+  LDRB    r3, [r1], #-1\r
+  STRB    r3, [r0], #-1\r
+  SUBS    r2, r2, #-1\r
+  BXEQ    r14\r
+  B       memmove_backward_loop\r
+\r
+  END\r
index 35783620c7283dac2c6576771606bcbfa19db775..7b1cf8d972505b317f218bf87c5c2884d42136e1 100644 (file)
@@ -1,38 +1,38 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT (memset)
-
-
-ASM_PFX(memset):
-
-  @ args = 0, pretend = 0, frame = 0
-  @ frame_needed = 1, uses_anonymous_args = 0
-  stmfd  sp!, {r7, lr}
-  mov  ip, #0
-  add  r7, sp, #0
-  mov  lr, r0
-  b  L9
-L10:
-  and  r3, r1, #255
-  add  ip, ip, #1
-  strb  r3, [lr], #1
-L9:
-  cmp  ip, r2
-  bne  L10
-  ldmfd  sp!, {r7, pc}
-
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT (memset)\r
+\r
+\r
+ASM_PFX(memset):\r
+\r
+  @ args = 0, pretend = 0, frame = 0\r
+  @ frame_needed = 1, uses_anonymous_args = 0\r
+  stmfd  sp!, {r7, lr}\r
+  mov  ip, #0\r
+  add  r7, sp, #0\r
+  mov  lr, r0\r
+  b  L9\r
+L10:\r
+  and  r3, r1, #255\r
+  add  ip, ip, #1\r
+  strb  r3, [lr], #1\r
+L9:\r
+  cmp  ip, r2\r
+  bne  L10\r
+  ldmfd  sp!, {r7, pc}\r
+\r
index d567cd54e76e84b756f6acfd2fb00e700b84f9be..74e02430483cf0c090cd8e09350f19fa58b5c904 100755 (executable)
@@ -1,59 +1,59 @@
-//------------------------------------------------------------------------------
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-
-    EXPORT  __aeabi_memset
-    EXPORT  __aeabi_memclr
-    EXPORT  __aeabi_memclr4
-
-    AREA    Memset, CODE, READONLY
-
-;
-;VOID
-;EFIAPI
-;__aeabi_memset (
-; IN  VOID    *Destination,
-; IN  UINT32  Character,
-; IN  UINT32  Size
-; );
-;
-__aeabi_memset
-
-  ; args = 0, pretend = 0, frame = 0
-  ; frame_needed = 1, uses_anonymous_args = 0
-  stmfd  sp!, {r7, lr}
-  mov  ip, #0
-  add  r7, sp, #0
-  mov  lr, r0
-  b  L9
-L10
-  and  r3, r1, #255
-  add  ip, ip, #1
-  strb  r3, [lr], #1
-L9
-  cmp  ip, r2
-  bne  L10
-  ldmfd  sp!, {r7, pc}
-
-__aeabi_memclr
-  mov   r2, r1
-  mov   r1, #0
-  b     __aeabi_memset
-
-__aeabi_memclr4
-  mov   r2, r1
-  mov   r1, #0
-  b     __aeabi_memset
-
-  END
+//------------------------------------------------------------------------------\r
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+\r
+    EXPORT  __aeabi_memset\r
+    EXPORT  __aeabi_memclr\r
+    EXPORT  __aeabi_memclr4\r
+\r
+    AREA    Memset, CODE, READONLY\r
+\r
+;\r
+;VOID\r
+;EFIAPI\r
+;__aeabi_memset (\r
+; IN  VOID    *Destination,\r
+; IN  UINT32  Character,\r
+; IN  UINT32  Size\r
+; );\r
+;\r
+__aeabi_memset\r
+\r
+  ; args = 0, pretend = 0, frame = 0\r
+  ; frame_needed = 1, uses_anonymous_args = 0\r
+  stmfd  sp!, {r7, lr}\r
+  mov  ip, #0\r
+  add  r7, sp, #0\r
+  mov  lr, r0\r
+  b  L9\r
+L10\r
+  and  r3, r1, #255\r
+  add  ip, ip, #1\r
+  strb  r3, [lr], #1\r
+L9\r
+  cmp  ip, r2\r
+  bne  L10\r
+  ldmfd  sp!, {r7, pc}\r
+\r
+__aeabi_memclr\r
+  mov   r2, r1\r
+  mov   r1, #0\r
+  b     __aeabi_memset\r
+\r
+__aeabi_memclr4\r
+  mov   r2, r1\r
+  mov   r1, #0\r
+  b     __aeabi_memset\r
+\r
+  END\r
index 75572c82b64806855b2fe42e824a5920e727073f..e058ea44686dfce79acb143926f4037d747cf9c3 100644 (file)
@@ -1,46 +1,46 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__moddi3)
-
-ASM_PFX(__moddi3):
-  stmfd  sp!, {r4, r5, r7, lr}
-  mov  r4, r1, asr #31
-  add  r7, sp, #8
-  stmfd  sp!, {r10, r11}
-  mov  r10, r3, asr #31
-  sub  sp, sp, #16
-  mov  r5, r4
-  mov  r11, r10
-  eor  r0, r0, r4
-  eor  r1, r1, r4
-  eor  r2, r2, r10
-  eor  r3, r3, r10
-  add  ip, sp, #8
-  subs  r0, r0, r4
-  sbc  r1, r1, r5
-  subs  r2, r2, r10
-  sbc  r3, r3, r11
-  str  ip, [sp, #0]
-  bl  ASM_PFX(__udivmoddi4)
-  ldrd  r0, [sp, #8]
-  eor  r0, r0, r4
-  eor  r1, r1, r4
-  subs  r0, r0, r4
-  sbc  r1, r1, r5
-  sub  sp, r7, #16
-  ldmfd  sp!, {r10, r11}
-  ldmfd  sp!, {r4, r5, r7, pc}
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__moddi3)\r
+\r
+ASM_PFX(__moddi3):\r
+  stmfd  sp!, {r4, r5, r7, lr}\r
+  mov  r4, r1, asr #31\r
+  add  r7, sp, #8\r
+  stmfd  sp!, {r10, r11}\r
+  mov  r10, r3, asr #31\r
+  sub  sp, sp, #16\r
+  mov  r5, r4\r
+  mov  r11, r10\r
+  eor  r0, r0, r4\r
+  eor  r1, r1, r4\r
+  eor  r2, r2, r10\r
+  eor  r3, r3, r10\r
+  add  ip, sp, #8\r
+  subs  r0, r0, r4\r
+  sbc  r1, r1, r5\r
+  subs  r2, r2, r10\r
+  sbc  r3, r3, r11\r
+  str  ip, [sp, #0]\r
+  bl  ASM_PFX(__udivmoddi4)\r
+  ldrd  r0, [sp, #8]\r
+  eor  r0, r0, r4\r
+  eor  r1, r1, r4\r
+  subs  r0, r0, r4\r
+  sbc  r1, r1, r5\r
+  sub  sp, r7, #16\r
+  ldmfd  sp!, {r10, r11}\r
+  ldmfd  sp!, {r4, r5, r7, pc}\r
index f9e5afe912d7a7a069843c3450abff2b588450bd..972fc065e9c504b29850f6eb402038c55f7073e2 100644 (file)
@@ -1,77 +1,77 @@
-/** @file
-  Compiler intrinsic for 64-bit mod, ported from LLVM code.
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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.
-
-**/
-/**
-  University of Illinois/NCSA
-  Open Source License
-  
-  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
-  All rights reserved.
-  
-  Developed by:
-  
-      LLVM Team
-  
-      University of Illinois at Urbana-Champaign
-  
-      http://llvm.org
-  
-  Permission is hereby granted, free of charge, to any person obtaining a copy of
-  this software and associated documentation files (the "Software"), to deal with
-  the Software without restriction, including without limitation the rights to
-  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-  of the Software, and to permit persons to whom the Software is furnished to do
-  so, subject to the following conditions:
-  
-      * Redistributions of source code must retain the above copyright notice,
-        this list of conditions and the following disclaimers.
-  
-      * Redistributions in binary form must reproduce the above copyright notice,
-        this list of conditions and the following disclaimers in the
-        documentation and/or other materials provided with the distribution.
-  
-      * Neither the names of the LLVM Team, University of Illinois at
-        Urbana-Champaign, nor the names of its contributors may be used to
-        endorse or promote products derived from this Software without specific
-        prior written permission.
-  
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-  SOFTWARE.
-**/
-
-
-#include "Llvm_int_lib.h"
-
-UINT64 __udivmoddi4(UINT64 a, UINT64 b, UINT64* rem);
-
-// Returns: a % b
-
-INT64
-__moddi3(INT64 a, INT64 b)
-{
-    const int bits_in_dword_m1 = (int)(sizeof(INT64) * CHAR_BIT) - 1;
-    INT64 s = b >> bits_in_dword_m1;  // s = b < 0 ? -1 : 0
-    b = (b ^ s) - s;                   // negate if s == -1
-    s = a >> bits_in_dword_m1;         // s = a < 0 ? -1 : 0
-    a = (a ^ s) - s;                   // negate if s == -1
-    INT64 r;
-    __udivmoddi4(a, b, (UINT64*)&r);
-    return (r ^ s) - s;                // negate if s == -1
-}
-
+/** @file\r
+  Compiler intrinsic for 64-bit mod, ported from LLVM code.\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+/**\r
+  University of Illinois/NCSA\r
+  Open Source License\r
+  \r
+  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.\r
+  All rights reserved.\r
+  \r
+  Developed by:\r
+  \r
+      LLVM Team\r
+  \r
+      University of Illinois at Urbana-Champaign\r
+  \r
+      http://llvm.org\r
+  \r
+  Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+  this software and associated documentation files (the "Software"), to deal with\r
+  the Software without restriction, including without limitation the rights to\r
+  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+  of the Software, and to permit persons to whom the Software is furnished to do\r
+  so, subject to the following conditions:\r
+  \r
+      * Redistributions of source code must retain the above copyright notice,\r
+        this list of conditions and the following disclaimers.\r
+  \r
+      * Redistributions in binary form must reproduce the above copyright notice,\r
+        this list of conditions and the following disclaimers in the\r
+        documentation and/or other materials provided with the distribution.\r
+  \r
+      * Neither the names of the LLVM Team, University of Illinois at\r
+        Urbana-Champaign, nor the names of its contributors may be used to\r
+        endorse or promote products derived from this Software without specific\r
+        prior written permission.\r
+  \r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE\r
+  SOFTWARE.\r
+**/\r
+\r
+\r
+#include "Llvm_int_lib.h"\r
+\r
+UINT64 __udivmoddi4(UINT64 a, UINT64 b, UINT64* rem);\r
+\r
+// Returns: a % b\r
+\r
+INT64\r
+__moddi3(INT64 a, INT64 b)\r
+{\r
+    const int bits_in_dword_m1 = (int)(sizeof(INT64) * CHAR_BIT) - 1;\r
+    INT64 s = b >> bits_in_dword_m1;  // s = b < 0 ? -1 : 0\r
+    b = (b ^ s) - s;                   // negate if s == -1\r
+    s = a >> bits_in_dword_m1;         // s = a < 0 ? -1 : 0\r
+    a = (a ^ s) - s;                   // negate if s == -1\r
+    INT64 r;\r
+    __udivmoddi4(a, b, (UINT64*)&r);\r
+    return (r ^ s) - s;                // negate if s == -1\r
+}\r
+\r
index eb698d604fe888bc5b99eef5bb282588f9f3c29b..07f8ef72f7ea485e3bce841e2c959ff68468eac2 100644 (file)
@@ -1,27 +1,27 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__modsi3)
-
-ASM_PFX(__modsi3):
-  stmfd  sp!, {r4, r5, r7, lr}
-  add  r7, sp, #8
-  mov  r5, r0
-  mov  r4, r1
-  bl  ___divsi3
-  mul  r0, r4, r0
-  rsb  r0, r0, r5
-  ldmfd  sp!, {r4, r5, r7, pc}
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__modsi3)\r
+\r
+ASM_PFX(__modsi3):\r
+  stmfd  sp!, {r4, r5, r7, lr}\r
+  add  r7, sp, #8\r
+  mov  r5, r0\r
+  mov  r4, r1\r
+  bl  ___divsi3\r
+  mul  r0, r4, r0\r
+  rsb  r0, r0, r5\r
+  ldmfd  sp!, {r4, r5, r7, pc}\r
index 68373d9c20860c39d378046f84d8e074ef1b1564..9bdf077fbe2bca5dac0d0c53fd8e3970c0299902 100644 (file)
@@ -1,70 +1,70 @@
-/** @file
-  Compiler intrinsic for 32-bit mod, ported from LLVM code.
-
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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.
-
-**/
-/**
-  University of Illinois/NCSA
-  Open Source License
-  
-  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
-  All rights reserved.
-  
-  Developed by:
-  
-      LLVM Team
-  
-      University of Illinois at Urbana-Champaign
-  
-      http://llvm.org
-  
-  Permission is hereby granted, free of charge, to any person obtaining a copy of
-  this software and associated documentation files (the "Software"), to deal with
-  the Software without restriction, including without limitation the rights to
-  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-  of the Software, and to permit persons to whom the Software is furnished to do
-  so, subject to the following conditions:
-  
-      * Redistributions of source code must retain the above copyright notice,
-        this list of conditions and the following disclaimers.
-  
-      * Redistributions in binary form must reproduce the above copyright notice,
-        this list of conditions and the following disclaimers in the
-        documentation and/or other materials provided with the distribution.
-  
-      * Neither the names of the LLVM Team, University of Illinois at
-        Urbana-Champaign, nor the names of its contributors may be used to
-        endorse or promote products derived from this Software without specific
-        prior written permission.
-  
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-  SOFTWARE.
-**/
-
-
-#include "Llvm_int_lib.h"
-
-// Returns: a % b
-
-INT32
-__modsi3(INT32 a, INT32 b)
-{
-    return a - (a / b) * b;
-}
-
-
+/** @file\r
+  Compiler intrinsic for 32-bit mod, ported from LLVM code.\r
+\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+/**\r
+  University of Illinois/NCSA\r
+  Open Source License\r
+  \r
+  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.\r
+  All rights reserved.\r
+  \r
+  Developed by:\r
+  \r
+      LLVM Team\r
+  \r
+      University of Illinois at Urbana-Champaign\r
+  \r
+      http://llvm.org\r
+  \r
+  Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+  this software and associated documentation files (the "Software"), to deal with\r
+  the Software without restriction, including without limitation the rights to\r
+  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+  of the Software, and to permit persons to whom the Software is furnished to do\r
+  so, subject to the following conditions:\r
+  \r
+      * Redistributions of source code must retain the above copyright notice,\r
+        this list of conditions and the following disclaimers.\r
+  \r
+      * Redistributions in binary form must reproduce the above copyright notice,\r
+        this list of conditions and the following disclaimers in the\r
+        documentation and/or other materials provided with the distribution.\r
+  \r
+      * Neither the names of the LLVM Team, University of Illinois at\r
+        Urbana-Champaign, nor the names of its contributors may be used to\r
+        endorse or promote products derived from this Software without specific\r
+        prior written permission.\r
+  \r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE\r
+  SOFTWARE.\r
+**/\r
+\r
+\r
+#include "Llvm_int_lib.h"\r
+\r
+// Returns: a % b\r
+\r
+INT32\r
+__modsi3(INT32 a, INT32 b)\r
+{\r
+    return a - (a / b) * b;\r
+}\r
+\r
+\r
index 36956c24e25d9fe65c8703b34dd33e80df42145d..e8ac1ffffc49cc7a3d0de52dcde7c0599780ef47 100644 (file)
@@ -1,58 +1,58 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__muldi3)
-
-ASM_PFX(__muldi3):
-  stmfd  sp!, {r4, r5, r6, r7, lr}
-  add  r7, sp, #12
-  stmfd  sp!, {r8, r10, r11}
-  ldr  r11, L4
-  mov  r4, r0, lsr #16
-  and  r8, r0, r11
-  and  ip, r2, r11
-  mul  lr, ip, r8
-  mul  ip, r4, ip
-  sub  sp, sp, #8
-  add  r10, ip, lr, lsr #16
-  and  ip, r10, r11
-  and  lr, lr, r11
-  mov  r6, r2, lsr #16
-  str  r4, [sp, #4]
-  add  r4, lr, ip, asl #16
-  mul  ip, r8, r6
-  mov  r5, r10, lsr #16
-  add  r10, ip, r4, lsr #16
-  and  ip, r10, r11
-  and  lr, r4, r11
-  add  r4, lr, ip, asl #16
-  mul  r0, r3, r0
-  add  ip, r5, r10, lsr #16
-  ldr  r5, [sp, #4]
-  mla  r0, r2, r1, r0
-  mla  r5, r6, r5, ip
-  mov  r10, r4
-  add  r11, r0, r5
-  mov  r1, r11
-  mov  r0, r4
-  sub  sp, r7, #24
-  ldmfd  sp!, {r8, r10, r11}
-  ldmfd  sp!, {r4, r5, r6, r7, pc}
-  .p2align 2
-L5:
-  .align 2
-L4:
-  .long  65535
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__muldi3)\r
+\r
+ASM_PFX(__muldi3):\r
+  stmfd  sp!, {r4, r5, r6, r7, lr}\r
+  add  r7, sp, #12\r
+  stmfd  sp!, {r8, r10, r11}\r
+  ldr  r11, L4\r
+  mov  r4, r0, lsr #16\r
+  and  r8, r0, r11\r
+  and  ip, r2, r11\r
+  mul  lr, ip, r8\r
+  mul  ip, r4, ip\r
+  sub  sp, sp, #8\r
+  add  r10, ip, lr, lsr #16\r
+  and  ip, r10, r11\r
+  and  lr, lr, r11\r
+  mov  r6, r2, lsr #16\r
+  str  r4, [sp, #4]\r
+  add  r4, lr, ip, asl #16\r
+  mul  ip, r8, r6\r
+  mov  r5, r10, lsr #16\r
+  add  r10, ip, r4, lsr #16\r
+  and  ip, r10, r11\r
+  and  lr, r4, r11\r
+  add  r4, lr, ip, asl #16\r
+  mul  r0, r3, r0\r
+  add  ip, r5, r10, lsr #16\r
+  ldr  r5, [sp, #4]\r
+  mla  r0, r2, r1, r0\r
+  mla  r5, r6, r5, ip\r
+  mov  r10, r4\r
+  add  r11, r0, r5\r
+  mov  r1, r11\r
+  mov  r0, r4\r
+  sub  sp, r7, #24\r
+  ldmfd  sp!, {r8, r10, r11}\r
+  ldmfd  sp!, {r4, r5, r6, r7, pc}\r
+  .p2align 2\r
+L5:\r
+  .align 2\r
+L4:\r
+  .long  65535\r
index d48bd22b43a6d0585df167143255f6c5b5fdd37a..67d0e4eed5902c2a5d52c1b7aa6daadd3dc1a7bf 100644 (file)
@@ -1,98 +1,98 @@
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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.
-
-**/
-/**
-  University of Illinois/NCSA
-  Open Source License
-  
-  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
-  All rights reserved.
-  
-  Developed by:
-  
-      LLVM Team
-  
-      University of Illinois at Urbana-Champaign
-  
-      http://llvm.org
-  
-  Permission is hereby granted, free of charge, to any person obtaining a copy of
-  this software and associated documentation files (the "Software"), to deal with
-  the Software without restriction, including without limitation the rights to
-  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-  of the Software, and to permit persons to whom the Software is furnished to do
-  so, subject to the following conditions:
-  
-      * Redistributions of source code must retain the above copyright notice,
-        this list of conditions and the following disclaimers.
-  
-      * Redistributions in binary form must reproduce the above copyright notice,
-        this list of conditions and the following disclaimers in the
-        documentation and/or other materials provided with the distribution.
-  
-      * Neither the names of the LLVM Team, University of Illinois at
-        Urbana-Champaign, nor the names of its contributors may be used to
-        endorse or promote products derived from this Software without specific
-        prior written permission.
-  
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-  SOFTWARE.
-**/
-
-#include <Base.h>
-#include "Llvm_int_lib.h"
-
-
-// Returns: a * b
-
-static
-INT64
-__muldsi3(UINT32 a, UINT32 b)
-{
-    dwords r;
-    const int bits_in_word_2 = (int)(sizeof(INT32) * CHAR_BIT) / 2;
-    const UINT32 lower_mask = (UINT32)~0 >> bits_in_word_2;
-    r.low = (a & lower_mask) * (b & lower_mask);
-    UINT32 t = r.low >> bits_in_word_2;
-    r.low &= lower_mask;
-    t += (a >> bits_in_word_2) * (b & lower_mask);
-    r.low += (t & lower_mask) << bits_in_word_2;
-    r.high = t >> bits_in_word_2;
-    t = r.low >> bits_in_word_2;
-    r.low &= lower_mask;
-    t += (b >> bits_in_word_2) * (a & lower_mask);
-    r.low += (t & lower_mask) << bits_in_word_2;
-    r.high += t >> bits_in_word_2;
-    r.high += (a >> bits_in_word_2) * (b >> bits_in_word_2);
-    return r.all;
-}
-
-// Returns: a * b
-
-INT64
-__muldi3(INT64 a, INT64 b)
-{
-    dwords x;
-    x.all = a;
-    dwords y;
-    y.all = b;
-    dwords r;
-    r.all = __muldsi3(x.low, y.low);
-    r.high += x.high * y.low + x.low * y.high;
-    return r.all;
-}
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+/**\r
+  University of Illinois/NCSA\r
+  Open Source License\r
+  \r
+  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.\r
+  All rights reserved.\r
+  \r
+  Developed by:\r
+  \r
+      LLVM Team\r
+  \r
+      University of Illinois at Urbana-Champaign\r
+  \r
+      http://llvm.org\r
+  \r
+  Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+  this software and associated documentation files (the "Software"), to deal with\r
+  the Software without restriction, including without limitation the rights to\r
+  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+  of the Software, and to permit persons to whom the Software is furnished to do\r
+  so, subject to the following conditions:\r
+  \r
+      * Redistributions of source code must retain the above copyright notice,\r
+        this list of conditions and the following disclaimers.\r
+  \r
+      * Redistributions in binary form must reproduce the above copyright notice,\r
+        this list of conditions and the following disclaimers in the\r
+        documentation and/or other materials provided with the distribution.\r
+  \r
+      * Neither the names of the LLVM Team, University of Illinois at\r
+        Urbana-Champaign, nor the names of its contributors may be used to\r
+        endorse or promote products derived from this Software without specific\r
+        prior written permission.\r
+  \r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE\r
+  SOFTWARE.\r
+**/\r
+\r
+#include <Base.h>\r
+#include "Llvm_int_lib.h"\r
+\r
+\r
+// Returns: a * b\r
+\r
+static\r
+INT64\r
+__muldsi3(UINT32 a, UINT32 b)\r
+{\r
+    dwords r;\r
+    const int bits_in_word_2 = (int)(sizeof(INT32) * CHAR_BIT) / 2;\r
+    const UINT32 lower_mask = (UINT32)~0 >> bits_in_word_2;\r
+    r.low = (a & lower_mask) * (b & lower_mask);\r
+    UINT32 t = r.low >> bits_in_word_2;\r
+    r.low &= lower_mask;\r
+    t += (a >> bits_in_word_2) * (b & lower_mask);\r
+    r.low += (t & lower_mask) << bits_in_word_2;\r
+    r.high = t >> bits_in_word_2;\r
+    t = r.low >> bits_in_word_2;\r
+    r.low &= lower_mask;\r
+    t += (b >> bits_in_word_2) * (a & lower_mask);\r
+    r.low += (t & lower_mask) << bits_in_word_2;\r
+    r.high += t >> bits_in_word_2;\r
+    r.high += (a >> bits_in_word_2) * (b >> bits_in_word_2);\r
+    return r.all;\r
+}\r
+\r
+// Returns: a * b\r
+\r
+INT64\r
+__muldi3(INT64 a, INT64 b)\r
+{\r
+    dwords x;\r
+    x.all = a;\r
+    dwords y;\r
+    y.all = b;\r
+    dwords r;\r
+    r.all = __muldsi3(x.low, y.low);\r
+    r.high += x.high * y.low + x.low * y.high;\r
+    return r.all;\r
+}\r
index 5d369e9afbad98277850facca70b74be2adb4690..489763648982ceb16032e4c879dcff2010c07a5e 100644 (file)
@@ -1,49 +1,49 @@
-//------------------------------------------------------------------------------ 
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-
-  EXPORT  __ARM_ll_mullu
-  EXPORT  __aeabi_lmul
-       
-  AREA  Math, CODE, READONLY
-
-;
-;INT64
-;EFIAPI
-;__aeabi_lmul (
-;  IN INT64   Multiplicand
-;  IN INT32   Multiplier
-;  );
-;
-__ARM_ll_mullu
-  mov     r3, #0
-// Make upper part of INT64 Multiplier 0 and use __aeabi_lmul
-
-;
-;INT64
-;EFIAPI
-;__aeabi_lmul (
-;  IN INT64   Multiplicand
-;  IN INT64   Multiplier
-;  );
-;
-__aeabi_lmul
-  stmdb   sp!, {lr}
-  mov     lr, r0
-  umull   r0, ip, r2, lr
-  mla     r1, r2, r1, ip
-  mla     r1, r3, lr, r1
-  ldmia   sp!, {pc}
-  
-  END
+//------------------------------------------------------------------------------ \r
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+\r
+  EXPORT  __ARM_ll_mullu\r
+  EXPORT  __aeabi_lmul\r
+       \r
+  AREA  Math, CODE, READONLY\r
+\r
+;\r
+;INT64\r
+;EFIAPI\r
+;__aeabi_lmul (\r
+;  IN INT64   Multiplicand\r
+;  IN INT32   Multiplier\r
+;  );\r
+;\r
+__ARM_ll_mullu\r
+  mov     r3, #0\r
+// Make upper part of INT64 Multiplier 0 and use __aeabi_lmul\r
+\r
+;\r
+;INT64\r
+;EFIAPI\r
+;__aeabi_lmul (\r
+;  IN INT64   Multiplicand\r
+;  IN INT64   Multiplier\r
+;  );\r
+;\r
+__aeabi_lmul\r
+  stmdb   sp!, {lr}\r
+  mov     lr, r0\r
+  umull   r0, ip, r2, lr\r
+  mla     r1, r2, r1, ip\r
+  mla     r1, r3, lr, r1\r
+  ldmia   sp!, {pc}\r
+  \r
+  END\r
index 8d34c5de52c9f18f385211848c8aaa5f37e0d4cd..2c8a0318d55d491cb201cbf1ce06f1a9c3dba236 100644 (file)
@@ -1,29 +1,29 @@
-///------------------------------------------------------------------------------ 
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-
-
-    EXPORT  __ARM_switch8
-
-    AREA  ArmSwitch, CODE, READONLY
-  
-__ARM_switch8
-  LDRB    r12,[lr,#-1]
-  CMP      r3,r12
-  LDRBCC  r3,[lr,r3]
-  LDRBCS  r3,[lr,r12]
-  ADD      r12,lr,r3,LSL #1
-  BX      r12
-  
-    END
+///------------------------------------------------------------------------------ \r
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+\r
+\r
+    EXPORT  __ARM_switch8\r
+\r
+    AREA  ArmSwitch, CODE, READONLY\r
+  \r
+__ARM_switch8\r
+  LDRB    r12,[lr,#-1]\r
+  CMP      r3,r12\r
+  LDRBCC  r3,[lr,r3]\r
+  LDRBCS  r3,[lr,r12]\r
+  ADD      r12,lr,r3,LSL #1\r
+  BX      r12\r
+  \r
+    END\r
index 97ebf79351baac9f3c9a44e6201c14cf2ad057b1..ce6904e0c16ca5255d8b27e24defbbcff92ac023 100644 (file)
@@ -1,31 +1,31 @@
-#/** @file
-#  Compiler intrinsic for ARM compiler
-#
-#  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#  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.;
-#
-#**/
-#        
-
-.text
-.p2align 2
-
-GCC_ASM_EXPORT(__switch16)
-
-ASM_PFX(__switch16):
-    ldrh      ip, [lr, #-1]
-    cmp       r0, ip
-    add       r0, lr, r0, lsl #1
-    ldrccsh   r0, [r0, #1]
-    add       ip, lr, ip, lsl #1
-    ldrcssh   r0, [ip, #1]
-    add       ip, lr, r0, lsl #1
-    bx        ip
-
-
+#/** @file\r
+#  Compiler intrinsic for ARM compiler\r
+#\r
+#  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.;\r
+#\r
+#**/\r
+#        \r
+\r
+.text\r
+.p2align 2\r
+\r
+GCC_ASM_EXPORT(__switch16)\r
+\r
+ASM_PFX(__switch16):\r
+    ldrh      ip, [lr, #-1]\r
+    cmp       r0, ip\r
+    add       r0, lr, r0, lsl #1\r
+    ldrccsh   r0, [r0, #1]\r
+    add       ip, lr, ip, lsl #1\r
+    ldrcssh   r0, [ip, #1]\r
+    add       ip, lr, r0, lsl #1\r
+    bx        ip\r
+\r
+\r
index e0fd100aa590e1840bad025af19c7fa1c8da92aa..63aed6e6b00828773eb88b23dc8fe7ec6c3229b9 100644 (file)
@@ -1,30 +1,30 @@
-#/** @file
-#  Compiler intrinsic for ARM compiler
-#
-#  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#  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.;
-#
-#**/
-#        
-
-.text
-.p2align 2
-
-GCC_ASM_EXPORT(__switch32)
-
-ASM_PFX(__switch32):    
-    ldr     ip, [lr, #-1]
-    cmp     r0, ip
-    add     r0, lr, r0, lsl #2
-    ldrcc   r0, [r0, #3]
-    add     ip, lr, ip, lsl #2
-    ldrcs   r0, [ip, #3]
-    add     ip, lr, r0
-    bx      ip
-
+#/** @file\r
+#  Compiler intrinsic for ARM compiler\r
+#\r
+#  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.;\r
+#\r
+#**/\r
+#        \r
+\r
+.text\r
+.p2align 2\r
+\r
+GCC_ASM_EXPORT(__switch32)\r
+\r
+ASM_PFX(__switch32):    \r
+    ldr     ip, [lr, #-1]\r
+    cmp     r0, ip\r
+    add     r0, lr, r0, lsl #2\r
+    ldrcc   r0, [r0, #3]\r
+    add     ip, lr, ip, lsl #2\r
+    ldrcs   r0, [ip, #3]\r
+    add     ip, lr, r0\r
+    bx      ip\r
+\r
index ea3340c9a5979c16991d99172858e58a1d1e0855..688e106a96f4615196c9c38dbb9d26758952bfa9 100644 (file)
@@ -1,28 +1,28 @@
-#/** @file
-#  Compiler intrinsic for ARM compiler
-#
-#  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#  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.;
-#
-#**/
-#        
-
-.text
-.p2align 2
-
-GCC_ASM_EXPORT(__switch8)
-
-ASM_PFX(__switch8):
-    ldrb      ip, [lr, #-1]
-    cmp       r0, ip
-    ldrccsb   r0, [lr, r0]
-    ldrcssb   r0, [lr, ip]
-    add       ip, lr, r0, lsl #1
-    bx        ip
-
+#/** @file\r
+#  Compiler intrinsic for ARM compiler\r
+#\r
+#  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http)://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.;\r
+#\r
+#**/\r
+#        \r
+\r
+.text\r
+.p2align 2\r
+\r
+GCC_ASM_EXPORT(__switch8)\r
+\r
+ASM_PFX(__switch8):\r
+    ldrb      ip, [lr, #-1]\r
+    cmp       r0, ip\r
+    ldrccsb   r0, [lr, r0]\r
+    ldrcssb   r0, [lr, ip]\r
+    add       ip, lr, r0, lsl #1\r
+    bx        ip\r
+\r
index 83636e1f5080b4f8be0e0d636878d9f7691984e8..254b054353a5e6cae40b5fe191d27b16abe29f35 100644 (file)
@@ -1,29 +1,29 @@
-#/** @file
-#  Compiler intrinsic for ARM compiler
-#
-#  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#  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.;
-#
-#**/
-#        
-
-.text
-.p2align 2
-
-GCC_ASM_EXPORT(__switchu8)
-
-
-ASM_PFX(__switchu8):
-    ldrb      ip,[lr,#-1]
-    cmp       r0,ip
-    ldrccb    r0,[lr,r0]
-    ldrcsb    r0,[lr,ip]
-    add       ip,lr,r0,LSL #1
-    bx        ip
-
+#/** @file\r
+#  Compiler intrinsic for ARM compiler\r
+#\r
+#  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http)://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.;\r
+#\r
+#**/\r
+#        \r
+\r
+.text\r
+.p2align 2\r
+\r
+GCC_ASM_EXPORT(__switchu8)\r
+\r
+\r
+ASM_PFX(__switchu8):\r
+    ldrb      ip,[lr,#-1]\r
+    cmp       r0,ip\r
+    ldrccb    r0,[lr,r0]\r
+    ldrcsb    r0,[lr,ip]\r
+    add       ip,lr,r0,LSL #1\r
+    bx        ip\r
+\r
index e85be6cae00e24af7450e4c05bd2c25dc551e830..f448ed58ccfd1eec89107fd2cd4c852c5a7b7482 100644 (file)
@@ -1,38 +1,38 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__ucmpdi2)
-  
-ASM_PFX(__ucmpdi2):
-  stmfd  sp!, {r4, r5, r8, lr}
-  cmp  r1, r3
-  mov  r8, r0
-  mov  r4, r2
-  mov  r5, r3
-  bcc  L2
-  bhi  L4
-  cmp  r0, r2
-  bcc  L2
-  movls  r0, #1
-  bls  L8
-  b  L4
-L2:
-  mov  r0, #0
-  b  L8
-L4:
-  mov  r0, #2
-L8:
-  ldmfd  sp!, {r4, r5, r8, pc}
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__ucmpdi2)\r
+  \r
+ASM_PFX(__ucmpdi2):\r
+  stmfd  sp!, {r4, r5, r8, lr}\r
+  cmp  r1, r3\r
+  mov  r8, r0\r
+  mov  r4, r2\r
+  mov  r5, r3\r
+  bcc  L2\r
+  bhi  L4\r
+  cmp  r0, r2\r
+  bcc  L2\r
+  movls  r0, #1\r
+  bls  L8\r
+  b  L4\r
+L2:\r
+  mov  r0, #0\r
+  b  L8\r
+L4:\r
+  mov  r0, #2\r
+L8:\r
+  ldmfd  sp!, {r4, r5, r8, pc}\r
index 25a821ef8f90baf255956b953563a05b64b04360..70d5a531b94b182a79f2d513a15aa44f2b51fade 100644 (file)
@@ -1,82 +1,82 @@
-/** @file
-  Compiler intrinsic for 64-bit compare, ported from LLVM code.
-
-  Copyright (c) 2008-2009, Apple Inc. All rights reserved.<BR>
-  
-  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.
-
-**/
-/**
-  University of Illinois/NCSA
-  Open Source License
-  
-  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
-  All rights reserved.
-  
-  Developed by:
-  
-      LLVM Team
-  
-      University of Illinois at Urbana-Champaign
-  
-      http://llvm.org
-  
-  Permission is hereby granted, free of charge, to any person obtaining a copy of
-  this software and associated documentation files (the "Software"), to deal with
-  the Software without restriction, including without limitation the rights to
-  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-  of the Software, and to permit persons to whom the Software is furnished to do
-  so, subject to the following conditions:
-  
-      * Redistributions of source code must retain the above copyright notice,
-        this list of conditions and the following disclaimers.
-  
-      * Redistributions in binary form must reproduce the above copyright notice,
-        this list of conditions and the following disclaimers in the
-        documentation and/or other materials provided with the distribution.
-  
-      * Neither the names of the LLVM Team, University of Illinois at
-        Urbana-Champaign, nor the names of its contributors may be used to
-        endorse or promote products derived from this Software without specific
-        prior written permission.
-  
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-  SOFTWARE.
-**/
-
-
-#include "Llvm_int_lib.h"
-
-
-// Returns:  if (a <  b) returns 0
-//           if (a == b) returns 1
-//           if (a >  b) returns 2
-
-UINT32
-__ucmpdi2(UINT64 a, UINT64 b)
-{
-    udwords x;
-    x.all = a;
-    udwords y;
-    y.all = b;
-    if (x.high < y.high)
-        return 0;
-    if (x.high > y.high)
-        return 2;
-    if (x.low < y.low)
-        return 0;
-    if (x.low > y.low)
-        return 2;
-    return 1;
-}
+/** @file\r
+  Compiler intrinsic for 64-bit compare, ported from LLVM code.\r
+\r
+  Copyright (c) 2008-2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+/**\r
+  University of Illinois/NCSA\r
+  Open Source License\r
+  \r
+  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.\r
+  All rights reserved.\r
+  \r
+  Developed by:\r
+  \r
+      LLVM Team\r
+  \r
+      University of Illinois at Urbana-Champaign\r
+  \r
+      http://llvm.org\r
+  \r
+  Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+  this software and associated documentation files (the "Software"), to deal with\r
+  the Software without restriction, including without limitation the rights to\r
+  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+  of the Software, and to permit persons to whom the Software is furnished to do\r
+  so, subject to the following conditions:\r
+  \r
+      * Redistributions of source code must retain the above copyright notice,\r
+        this list of conditions and the following disclaimers.\r
+  \r
+      * Redistributions in binary form must reproduce the above copyright notice,\r
+        this list of conditions and the following disclaimers in the\r
+        documentation and/or other materials provided with the distribution.\r
+  \r
+      * Neither the names of the LLVM Team, University of Illinois at\r
+        Urbana-Champaign, nor the names of its contributors may be used to\r
+        endorse or promote products derived from this Software without specific\r
+        prior written permission.\r
+  \r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE\r
+  SOFTWARE.\r
+**/\r
+\r
+\r
+#include "Llvm_int_lib.h"\r
+\r
+\r
+// Returns:  if (a <  b) returns 0\r
+//           if (a == b) returns 1\r
+//           if (a >  b) returns 2\r
+\r
+UINT32\r
+__ucmpdi2(UINT64 a, UINT64 b)\r
+{\r
+    udwords x;\r
+    x.all = a;\r
+    udwords y;\r
+    y.all = b;\r
+    if (x.high < y.high)\r
+        return 0;\r
+    if (x.high > y.high)\r
+        return 2;\r
+    if (x.low < y.low)\r
+        return 0;\r
+    if (x.low > y.low)\r
+        return 2;\r
+    return 1;\r
+}\r
index a8b9702707165564cbb592b4b500b09e79bd4309..f274901fa43703a3ef3292d8b9e34ac888f74da7 100644 (file)
@@ -1,27 +1,27 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__udivdi3)
-
-ASM_PFX(__udivdi3):
-  stmfd  sp!, {r7, lr}
-  add  r7, sp, #0
-  sub  sp, sp, #8
-  mov  ip, #0
-  str  ip, [sp, #0]
-  bl  ASM_PFX(__udivmoddi4)
-  sub  sp, r7, #0
-  ldmfd  sp!, {r7, pc}
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__udivdi3)\r
+\r
+ASM_PFX(__udivdi3):\r
+  stmfd  sp!, {r7, lr}\r
+  add  r7, sp, #0\r
+  sub  sp, sp, #8\r
+  mov  ip, #0\r
+  str  ip, [sp, #0]\r
+  bl  ASM_PFX(__udivmoddi4)\r
+  sub  sp, r7, #0\r
+  ldmfd  sp!, {r7, pc}\r
index b24606f09ca15118c598072151faffb2c3aef223..a8d9b09671c2fd56dcf8de010bb004acecb8788f 100644 (file)
@@ -1,71 +1,71 @@
-/** @file
-  Compiler intrinsic for 64-bit unisigned div, ported from LLVM code.
-
-  Copyright (c) 2008-2009, Apple Inc. All rights reserved.<BR>
-  
-  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.
-
-**/
-/**
-  University of Illinois/NCSA
-  Open Source License
-  
-  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
-  All rights reserved.
-  
-  Developed by:
-  
-      LLVM Team
-  
-      University of Illinois at Urbana-Champaign
-  
-      http://llvm.org
-  
-  Permission is hereby granted, free of charge, to any person obtaining a copy of
-  this software and associated documentation files (the "Software"), to deal with
-  the Software without restriction, including without limitation the rights to
-  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-  of the Software, and to permit persons to whom the Software is furnished to do
-  so, subject to the following conditions:
-  
-      * Redistributions of source code must retain the above copyright notice,
-        this list of conditions and the following disclaimers.
-  
-      * Redistributions in binary form must reproduce the above copyright notice,
-        this list of conditions and the following disclaimers in the
-        documentation and/or other materials provided with the distribution.
-  
-      * Neither the names of the LLVM Team, University of Illinois at
-        Urbana-Champaign, nor the names of its contributors may be used to
-        endorse or promote products derived from this Software without specific
-        prior written permission.
-  
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-  SOFTWARE.
-**/
-
-
-#include "Llvm_int_lib.h"
-
-UINT64 __udivmoddi4 (UINT64 a, UINT64 b, UINT64 *rem);
-
-// Returns: a / b
-
-UINT64
-__udivdi3(UINT64 a, UINT64 b)
-{
-    return __udivmoddi4(a, b, 0);
-}
-
-
+/** @file\r
+  Compiler intrinsic for 64-bit unisigned div, ported from LLVM code.\r
+\r
+  Copyright (c) 2008-2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+/**\r
+  University of Illinois/NCSA\r
+  Open Source License\r
+  \r
+  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.\r
+  All rights reserved.\r
+  \r
+  Developed by:\r
+  \r
+      LLVM Team\r
+  \r
+      University of Illinois at Urbana-Champaign\r
+  \r
+      http://llvm.org\r
+  \r
+  Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+  this software and associated documentation files (the "Software"), to deal with\r
+  the Software without restriction, including without limitation the rights to\r
+  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+  of the Software, and to permit persons to whom the Software is furnished to do\r
+  so, subject to the following conditions:\r
+  \r
+      * Redistributions of source code must retain the above copyright notice,\r
+        this list of conditions and the following disclaimers.\r
+  \r
+      * Redistributions in binary form must reproduce the above copyright notice,\r
+        this list of conditions and the following disclaimers in the\r
+        documentation and/or other materials provided with the distribution.\r
+  \r
+      * Neither the names of the LLVM Team, University of Illinois at\r
+        Urbana-Champaign, nor the names of its contributors may be used to\r
+        endorse or promote products derived from this Software without specific\r
+        prior written permission.\r
+  \r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE\r
+  SOFTWARE.\r
+**/\r
+\r
+\r
+#include "Llvm_int_lib.h"\r
+\r
+UINT64 __udivmoddi4 (UINT64 a, UINT64 b, UINT64 *rem);\r
+\r
+// Returns: a / b\r
+\r
+UINT64\r
+__udivdi3(UINT64 a, UINT64 b)\r
+{\r
+    return __udivmoddi4(a, b, 0);\r
+}\r
+\r
+\r
index cadc1d291ac13a724f1c8b560b13a5a687ea5769..1c0f2eae672266e725ac56ff68c77f22f82d55a3 100644 (file)
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__udivmoddi4)
-  
-ASM_PFX(__udivmoddi4):
-  stmfd  sp!, {r4, r5, r6, r7, lr}
-  add  r7, sp, #12
-  stmfd  sp!, {r10, r11}
-  sub  sp, sp, #20
-  stmia  sp, {r2-r3}
-  ldr  r6, [sp, #48]
-  orrs  r2, r2, r3
-  mov  r10, r0
-  mov  r11, r1
-  beq  L2
-  subs  ip, r1, #0
-  bne  L4
-  cmp  r3, #0
-  bne  L6
-  cmp  r6, #0
-  beq  L8
-  mov  r1, r2
-  bl  ASM_PFX(__umodsi3)
-  mov  r1, #0
-  stmia  r6, {r0-r1}
-L8:
-  ldr  r1, [sp, #0]
-  mov  r0, r10
-  b  L45
-L6:
-  cmp  r6, #0
-  movne  r1, #0
-  stmneia  r6, {r0-r1}
-  b  L2
-L4:
-  ldr  r1, [sp, #0]
-  cmp  r1, #0
-  bne  L12
-  ldr  r2, [sp, #4]
-  cmp  r2, #0
-  bne  L14
-  cmp  r6, #0
-  beq  L16
-  mov  r1, r2
-  mov  r0, r11
-  bl  ASM_PFX(__umodsi3)
-  mov  r1, #0
-  stmia  r6, {r0-r1}
-L16:
-  ldr  r1, [sp, #4]
-  mov  r0, r11
-L45:
-  bl  ASM_PFX(__udivsi3)
-L46:
-  mov  r10, r0
-  mov  r11, #0
-  b  L10
-L14:
-  subs  r1, r0, #0
-  bne  L18
-  cmp  r6, #0
-  beq  L16
-  ldr  r1, [sp, #4]
-  mov  r0, r11
-  bl  ASM_PFX(__umodsi3)
-  mov  r4, r10
-  mov  r5, r0
-  stmia  r6, {r4-r5}
-  b  L16
-L18:
-  sub  r3, r2, #1
-  tst  r2, r3
-  bne  L22
-  cmp  r6, #0
-  movne  r4, r0
-  andne  r5, ip, r3
-  stmneia  r6, {r4-r5}
-L24:
-  rsb  r3, r2, #0
-  and  r3, r2, r3
-  clz  r3, r3
-  rsb  r3, r3, #31
-  mov  r0, ip, lsr r3
-  b  L46
-L22:
-  clz  r2, r2
-  clz  r3, ip
-  rsb  r3, r3, r2
-  cmp  r3, #30
-  bhi  L48
-  rsb  r2, r3, #31
-  add  lr, r3, #1
-  mov  r3, r1, asl r2
-  str  r3, [sp, #12]
-  mov  r3, r1, lsr lr
-  ldr  r0, [sp, #0]
-  mov  r5, ip, lsr lr
-  orr  r4, r3, ip, asl r2
-  str  r0, [sp, #8]
-  b  L29
-L12:
-  ldr  r3, [sp, #4]
-  cmp  r3, #0
-  bne  L30
-  sub  r3, r1, #1
-  tst  r1, r3
-  bne  L32
-  cmp  r6, #0
-  andne  r3, r3, r0
-  movne  r2, r3
-  movne  r3, #0
-  stmneia  r6, {r2-r3}
-L34:
-  cmp  r1, #1
-  beq  L10
-  rsb  r3, r1, #0
-  and  r3, r1, r3
-  clz  r3, r3
-  rsb  r0, r3, #31
-  mov  r1, ip, lsr r0
-  rsb  r3, r0, #32
-  mov  r0, r10, lsr r0
-  orr  ip, r0, ip, asl r3
-  str  r1, [sp, #12]
-  str  ip, [sp, #8]
-  ldrd  r10, [sp, #8]
-  b  L10
-L32:
-  clz  r2, r1
-  clz  r3, ip
-  rsb  r3, r3, r2
-  rsb  r4, r3, #31
-  mov  r2, r0, asl r4
-  mvn  r1, r3
-  and  r2, r2, r1, asr #31
-  add  lr, r3, #33
-  str  r2, [sp, #8]
-  add  r2, r3, #1
-  mov  r3, r3, asr #31
-  and  r0, r3, r0, asl r1
-  mov  r3, r10, lsr r2
-  orr  r3, r3, ip, asl r4
-  and  r3, r3, r1, asr #31
-  orr  r0, r0, r3
-  mov  r3, ip, lsr lr
-  str  r0, [sp, #12]
-  mov  r0, r10, lsr lr
-  and  r5, r3, r2, asr #31
-  rsb  r3, lr, #31
-  mov  r3, r3, asr #31
-  orr  r0, r0, ip, asl r1
-  and  r3, r3, ip, lsr r2
-  and  r0, r0, r2, asr #31
-  orr  r4, r3, r0
-  b  L29
-L30:
-  clz  r2, r3
-  clz  r3, ip
-  rsb  r3, r3, r2
-  cmp  r3, #31
-  bls  L37
-L48:
-  cmp  r6, #0
-  stmneia  r6, {r10-r11}
-  b  L2
-L37:
-  rsb  r1, r3, #31
-  mov  r0, r0, asl r1
-  add  lr, r3, #1
-  mov  r2, #0
-  str  r0, [sp, #12]
-  mov  r0, r10, lsr lr
-  str  r2, [sp, #8]
-  sub  r2, r3, #31
-  and  r0, r0, r2, asr #31
-  mov  r3, ip, lsr lr
-  orr  r4, r0, ip, asl r1
-  and  r5, r3, r2, asr #31
-L29:
-  mov  ip, #0
-  mov  r10, ip
-  b  L40
-L41:
-  ldr  r1, [sp, #12]
-  ldr  r2, [sp, #8]
-  mov  r3, r4, lsr #31
-  orr  r5, r3, r5, asl #1
-  mov  r3, r1, lsr #31
-  orr  r4, r3, r4, asl #1
-  mov  r3, r2, lsr #31
-  orr  r0, r3, r1, asl #1
-  orr  r1, ip, r2, asl #1
-  ldmia  sp, {r2-r3}
-  str  r0, [sp, #12]
-  subs  r2, r2, r4
-  sbc  r3, r3, r5
-  str  r1, [sp, #8]
-  subs  r0, r2, #1
-  sbc  r1, r3, #0
-  mov  r2, r1, asr #31
-  ldmia  sp, {r0-r1}
-  mov  r3, r2
-  and  ip, r2, #1
-  and  r3, r3, r1
-  and  r2, r2, r0
-  subs  r4, r4, r2
-  sbc  r5, r5, r3
-  add  r10, r10, #1
-L40:
-  cmp  r10, lr
-  bne  L41
-  ldrd  r0, [sp, #8]
-  adds  r0, r0, r0
-  adc  r1, r1, r1
-  cmp  r6, #0
-  orr  r10, r0, ip
-  mov  r11, r1
-  stmneia  r6, {r4-r5}
-  b  L10
-L2:
-  mov  r10, #0
-  mov  r11, #0
-L10:
-  mov  r0, r10
-  mov  r1, r11
-  sub  sp, r7, #20
-  ldmfd  sp!, {r10, r11}
-  ldmfd  sp!, {r4, r5, r6, r7, pc}
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__udivmoddi4)\r
+  \r
+ASM_PFX(__udivmoddi4):\r
+  stmfd  sp!, {r4, r5, r6, r7, lr}\r
+  add  r7, sp, #12\r
+  stmfd  sp!, {r10, r11}\r
+  sub  sp, sp, #20\r
+  stmia  sp, {r2-r3}\r
+  ldr  r6, [sp, #48]\r
+  orrs  r2, r2, r3\r
+  mov  r10, r0\r
+  mov  r11, r1\r
+  beq  L2\r
+  subs  ip, r1, #0\r
+  bne  L4\r
+  cmp  r3, #0\r
+  bne  L6\r
+  cmp  r6, #0\r
+  beq  L8\r
+  mov  r1, r2\r
+  bl  ASM_PFX(__umodsi3)\r
+  mov  r1, #0\r
+  stmia  r6, {r0-r1}\r
+L8:\r
+  ldr  r1, [sp, #0]\r
+  mov  r0, r10\r
+  b  L45\r
+L6:\r
+  cmp  r6, #0\r
+  movne  r1, #0\r
+  stmneia  r6, {r0-r1}\r
+  b  L2\r
+L4:\r
+  ldr  r1, [sp, #0]\r
+  cmp  r1, #0\r
+  bne  L12\r
+  ldr  r2, [sp, #4]\r
+  cmp  r2, #0\r
+  bne  L14\r
+  cmp  r6, #0\r
+  beq  L16\r
+  mov  r1, r2\r
+  mov  r0, r11\r
+  bl  ASM_PFX(__umodsi3)\r
+  mov  r1, #0\r
+  stmia  r6, {r0-r1}\r
+L16:\r
+  ldr  r1, [sp, #4]\r
+  mov  r0, r11\r
+L45:\r
+  bl  ASM_PFX(__udivsi3)\r
+L46:\r
+  mov  r10, r0\r
+  mov  r11, #0\r
+  b  L10\r
+L14:\r
+  subs  r1, r0, #0\r
+  bne  L18\r
+  cmp  r6, #0\r
+  beq  L16\r
+  ldr  r1, [sp, #4]\r
+  mov  r0, r11\r
+  bl  ASM_PFX(__umodsi3)\r
+  mov  r4, r10\r
+  mov  r5, r0\r
+  stmia  r6, {r4-r5}\r
+  b  L16\r
+L18:\r
+  sub  r3, r2, #1\r
+  tst  r2, r3\r
+  bne  L22\r
+  cmp  r6, #0\r
+  movne  r4, r0\r
+  andne  r5, ip, r3\r
+  stmneia  r6, {r4-r5}\r
+L24:\r
+  rsb  r3, r2, #0\r
+  and  r3, r2, r3\r
+  clz  r3, r3\r
+  rsb  r3, r3, #31\r
+  mov  r0, ip, lsr r3\r
+  b  L46\r
+L22:\r
+  clz  r2, r2\r
+  clz  r3, ip\r
+  rsb  r3, r3, r2\r
+  cmp  r3, #30\r
+  bhi  L48\r
+  rsb  r2, r3, #31\r
+  add  lr, r3, #1\r
+  mov  r3, r1, asl r2\r
+  str  r3, [sp, #12]\r
+  mov  r3, r1, lsr lr\r
+  ldr  r0, [sp, #0]\r
+  mov  r5, ip, lsr lr\r
+  orr  r4, r3, ip, asl r2\r
+  str  r0, [sp, #8]\r
+  b  L29\r
+L12:\r
+  ldr  r3, [sp, #4]\r
+  cmp  r3, #0\r
+  bne  L30\r
+  sub  r3, r1, #1\r
+  tst  r1, r3\r
+  bne  L32\r
+  cmp  r6, #0\r
+  andne  r3, r3, r0\r
+  movne  r2, r3\r
+  movne  r3, #0\r
+  stmneia  r6, {r2-r3}\r
+L34:\r
+  cmp  r1, #1\r
+  beq  L10\r
+  rsb  r3, r1, #0\r
+  and  r3, r1, r3\r
+  clz  r3, r3\r
+  rsb  r0, r3, #31\r
+  mov  r1, ip, lsr r0\r
+  rsb  r3, r0, #32\r
+  mov  r0, r10, lsr r0\r
+  orr  ip, r0, ip, asl r3\r
+  str  r1, [sp, #12]\r
+  str  ip, [sp, #8]\r
+  ldrd  r10, [sp, #8]\r
+  b  L10\r
+L32:\r
+  clz  r2, r1\r
+  clz  r3, ip\r
+  rsb  r3, r3, r2\r
+  rsb  r4, r3, #31\r
+  mov  r2, r0, asl r4\r
+  mvn  r1, r3\r
+  and  r2, r2, r1, asr #31\r
+  add  lr, r3, #33\r
+  str  r2, [sp, #8]\r
+  add  r2, r3, #1\r
+  mov  r3, r3, asr #31\r
+  and  r0, r3, r0, asl r1\r
+  mov  r3, r10, lsr r2\r
+  orr  r3, r3, ip, asl r4\r
+  and  r3, r3, r1, asr #31\r
+  orr  r0, r0, r3\r
+  mov  r3, ip, lsr lr\r
+  str  r0, [sp, #12]\r
+  mov  r0, r10, lsr lr\r
+  and  r5, r3, r2, asr #31\r
+  rsb  r3, lr, #31\r
+  mov  r3, r3, asr #31\r
+  orr  r0, r0, ip, asl r1\r
+  and  r3, r3, ip, lsr r2\r
+  and  r0, r0, r2, asr #31\r
+  orr  r4, r3, r0\r
+  b  L29\r
+L30:\r
+  clz  r2, r3\r
+  clz  r3, ip\r
+  rsb  r3, r3, r2\r
+  cmp  r3, #31\r
+  bls  L37\r
+L48:\r
+  cmp  r6, #0\r
+  stmneia  r6, {r10-r11}\r
+  b  L2\r
+L37:\r
+  rsb  r1, r3, #31\r
+  mov  r0, r0, asl r1\r
+  add  lr, r3, #1\r
+  mov  r2, #0\r
+  str  r0, [sp, #12]\r
+  mov  r0, r10, lsr lr\r
+  str  r2, [sp, #8]\r
+  sub  r2, r3, #31\r
+  and  r0, r0, r2, asr #31\r
+  mov  r3, ip, lsr lr\r
+  orr  r4, r0, ip, asl r1\r
+  and  r5, r3, r2, asr #31\r
+L29:\r
+  mov  ip, #0\r
+  mov  r10, ip\r
+  b  L40\r
+L41:\r
+  ldr  r1, [sp, #12]\r
+  ldr  r2, [sp, #8]\r
+  mov  r3, r4, lsr #31\r
+  orr  r5, r3, r5, asl #1\r
+  mov  r3, r1, lsr #31\r
+  orr  r4, r3, r4, asl #1\r
+  mov  r3, r2, lsr #31\r
+  orr  r0, r3, r1, asl #1\r
+  orr  r1, ip, r2, asl #1\r
+  ldmia  sp, {r2-r3}\r
+  str  r0, [sp, #12]\r
+  subs  r2, r2, r4\r
+  sbc  r3, r3, r5\r
+  str  r1, [sp, #8]\r
+  subs  r0, r2, #1\r
+  sbc  r1, r3, #0\r
+  mov  r2, r1, asr #31\r
+  ldmia  sp, {r0-r1}\r
+  mov  r3, r2\r
+  and  ip, r2, #1\r
+  and  r3, r3, r1\r
+  and  r2, r2, r0\r
+  subs  r4, r4, r2\r
+  sbc  r5, r5, r3\r
+  add  r10, r10, #1\r
+L40:\r
+  cmp  r10, lr\r
+  bne  L41\r
+  ldrd  r0, [sp, #8]\r
+  adds  r0, r0, r0\r
+  adc  r1, r1, r1\r
+  cmp  r6, #0\r
+  orr  r10, r0, ip\r
+  mov  r11, r1\r
+  stmneia  r6, {r4-r5}\r
+  b  L10\r
+L2:\r
+  mov  r10, #0\r
+  mov  r11, #0\r
+L10:\r
+  mov  r0, r10\r
+  mov  r1, r11\r
+  sub  sp, r7, #20\r
+  ldmfd  sp!, {r10, r11}\r
+  ldmfd  sp!, {r4, r5, r6, r7, pc}\r
index de226474004f6d588d3f526b01feb0a9ce2d98a4..829482ddf5ab319a7e984005dd9bc431c6ee0af5 100644 (file)
-/** @file
-  Compiler intrinsic for 64-bit compare, ported from LLVM code.
-
-  Copyright (c) 2008-2009, Apple Inc. All rights reserved.<BR>
-  
-  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.
-
-**/
-/**
-  University of Illinois/NCSA
-  Open Source License
-  
-  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
-  All rights reserved.
-  
-  Developed by:
-  
-      LLVM Team
-  
-      University of Illinois at Urbana-Champaign
-  
-      http://llvm.org
-  
-  Permission is hereby granted, free of charge, to any person obtaining a copy of
-  this software and associated documentation files (the "Software"), to deal with
-  the Software without restriction, including without limitation the rights to
-  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-  of the Software, and to permit persons to whom the Software is furnished to do
-  so, subject to the following conditions:
-  
-      * Redistributions of source code must retain the above copyright notice,
-        this list of conditions and the following disclaimers.
-  
-      * Redistributions in binary form must reproduce the above copyright notice,
-        this list of conditions and the following disclaimers in the
-        documentation and/or other materials provided with the distribution.
-  
-      * Neither the names of the LLVM Team, University of Illinois at
-        Urbana-Champaign, nor the names of its contributors may be used to
-        endorse or promote products derived from this Software without specific
-        prior written permission.
-  
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-  SOFTWARE.
-**/
-
-
-#include "Llvm_int_lib.h"
-
-// Effects: if rem != 0, *rem = a % b
-// Returns: a / b
-
-// Translated from Figure 3-40 of The PowerPC Compiler Writer's Guide
-
-UINT64
-__udivmoddi4 (UINT64 a, UINT64 b, UINT64* rem)
-{
-    const unsigned n_uword_bits = sizeof(UINT32) * CHAR_BIT;
-    const unsigned n_udword_bits = sizeof(UINT64) * CHAR_BIT;
-    udwords n;
-    n.all = a;
-    udwords d;
-    d.all = b;
-    udwords q;
-    udwords r;
-    unsigned sr;
-    
-    if (b == 0) {
-//      ASSERT (FALSE);
-      return 0;
-    }
-    
-    // special cases, X is unknown, K != 0
-    if (n.high == 0)
-    {
-        if (d.high == 0)
-        {
-            // 0 X
-            // ---
-            // 0 X
-            if (rem)
-                *rem = n.low % d.low;
-            return n.low / d.low;
-        }
-        // 0 X
-        // ---
-        // K X
-        if (rem)
-            *rem = n.low;
-        return 0;
-    }
-    // n.high != 0
-    if (d.low == 0)
-    {
-        if (d.high == 0)
-        {
-            // K X
-            // ---
-            // 0 0
-            if (rem)
-                *rem = n.high % d.low;
-            return n.high / d.low;
-        }
-        // d.high != 0
-        if (n.low == 0)
-        {
-            // K 0
-            // ---
-            // K 0
-            if (rem)
-            {
-                r.high = n.high % d.high;
-                r.low = 0;
-                *rem = r.all;
-            }
-            return n.high / d.high;
-        }
-        // K K
-        // ---
-        // K 0
-        if ((d.high & (d.high - 1)) == 0)     // if d is a power of 2
-        {
-            if (rem)
-            {
-                r.low = n.low;
-                r.high = n.high & (d.high - 1);
-                *rem = r.all;
-            }
-            return n.high >> COUNT_TRAILING_ZEROS(d.high);
-        }
-        // K K
-        // ---
-        // K 0
-        sr = COUNT_LEADING_ZEROS(d.high) - COUNT_LEADING_ZEROS(n.high);
-        // 0 <= sr <= n_uword_bits - 2 or sr large
-        if (sr > n_uword_bits - 2)
-        {
-           if (rem)
-                *rem = n.all;
-            return 0;
-        }
-        ++sr;
-        // 1 <= sr <= n_uword_bits - 1
-        // q.all = n.all << (n_udword_bits - sr);
-        q.low = 0;
-        q.high = n.low << (n_uword_bits - sr);
-        // r.all = n.all >> sr;
-        r.high = n.high >> sr;
-        r.low = (n.high << (n_uword_bits - sr)) | (n.low >> sr);
-    }
-    else  // d.low != 0
-    {
-        if (d.high == 0)
-        {
-            // K X
-            // ---
-            // 0 K
-            if ((d.low & (d.low - 1)) == 0)     // if d is a power of 2
-            {
-                if (rem)
-                    *rem = n.low & (d.low - 1);
-                if (d.low == 1)
-                    return n.all;
-                unsigned sr = COUNT_TRAILING_ZEROS(d.low);
-                q.high = n.high >> sr;
-                q.low = (n.high << (n_uword_bits - sr)) | (n.low >> sr);
-                return q.all;
-            }
-            // K X
-            // ---
-            // 0 K
-            sr = 1 + n_uword_bits + COUNT_LEADING_ZEROS(d.low) - COUNT_LEADING_ZEROS(n.high);
-            // 2 <= sr <= n_udword_bits - 1
-            // q.all = n.all << (n_udword_bits - sr);
-            // r.all = n.all >> sr;
-            // if (sr == n_uword_bits)
-            // {
-            //     q.low = 0;
-            //     q.high = n.low;
-            //     r.high = 0;
-            //     r.low = n.high;
-            // }
-            // else if (sr < n_uword_bits)  // 2 <= sr <= n_uword_bits - 1
-            // {
-            //     q.low = 0;
-            //     q.high = n.low << (n_uword_bits - sr);
-            //     r.high = n.high >> sr;
-            //     r.low = (n.high << (n_uword_bits - sr)) | (n.low >> sr);
-            // }
-            // else              // n_uword_bits + 1 <= sr <= n_udword_bits - 1
-            // {
-            //     q.low = n.low << (n_udword_bits - sr);
-            //     q.high = (n.high << (n_udword_bits - sr)) |
-            //              (n.low >> (sr - n_uword_bits));
-            //     r.high = 0;
-            //     r.low = n.high >> (sr - n_uword_bits);
-            // }
-            q.low =  (n.low << (n_udword_bits - sr)) &
-                     ((INT32)(n_uword_bits - sr) >> (n_uword_bits-1));
-            q.high = ((n.low << ( n_uword_bits - sr))                       &
-                     ((INT32)(sr - n_uword_bits - 1) >> (n_uword_bits-1))) |
-                     (((n.high << (n_udword_bits - sr))                     |
-                     (n.low >> (sr - n_uword_bits)))                        &
-                     ((INT32)(n_uword_bits - sr) >> (n_uword_bits-1)));
-            r.high = (n.high >> sr) &
-                     ((INT32)(sr - n_uword_bits) >> (n_uword_bits-1));
-            r.low =  ((n.high >> (sr - n_uword_bits))                       &
-                     ((INT32)(n_uword_bits - sr - 1) >> (n_uword_bits-1))) |
-                     (((n.high << (n_uword_bits - sr))                      |
-                     (n.low >> sr))                                         &
-                     ((INT32)(sr - n_uword_bits) >> (n_uword_bits-1)));
-        }
-        else
-        {
-            // K X
-            // ---
-            // K K
-            sr = COUNT_LEADING_ZEROS(d.high) - COUNT_LEADING_ZEROS(n.high);
-            // 0 <= sr <= n_uword_bits - 1 or sr large
-            if (sr > n_uword_bits - 1)
-            {
-               if (rem)
-                    *rem = n.all;
-                return 0;
-            }
-            ++sr;
-            // 1 <= sr <= n_uword_bits
-            // q.all = n.all << (n_udword_bits - sr);
-            q.low = 0;
-            q.high = n.low << (n_uword_bits - sr);
-            // r.all = n.all >> sr;
-            // if (sr < n_uword_bits)
-            // {
-            //     r.high = n.high >> sr;
-            //     r.low = (n.high << (n_uword_bits - sr)) | (n.low >> sr);
-            // }
-            // else
-            // {
-            //     r.high = 0;
-            //     r.low = n.high;
-            // }
-            r.high = (n.high >> sr) &
-                     ((INT32)(sr - n_uword_bits) >> (n_uword_bits-1));
-            r.low = (n.high << (n_uword_bits - sr)) |
-                    ((n.low >> sr)                  &
-                    ((INT32)(sr - n_uword_bits) >> (n_uword_bits-1)));
-        }
-    }
-    // Not a special case
-    // q and r are initialized with:
-    // q.all = n.all << (n_udword_bits - sr);
-    // r.all = n.all >> sr;
-    // 1 <= sr <= n_udword_bits - 1
-    UINT32 carry = 0;
-    for (; sr > 0; --sr)
-    {
-        // r:q = ((r:q)  << 1) | carry
-        r.high = (r.high << 1) | (r.low  >> (n_uword_bits - 1));
-        r.low  = (r.low  << 1) | (q.high >> (n_uword_bits - 1));
-        q.high = (q.high << 1) | (q.low  >> (n_uword_bits - 1));
-        q.low  = (q.low  << 1) | carry;
-        // carry = 0;
-        // if (r.all >= d.all)
-        // {
-        //      r.all -= d.all;
-        //      carry = 1;
-        // }
-        const INT64 s = (INT64)(d.all - r.all - 1) >> (n_udword_bits - 1);
-        carry = s & 1;
-        r.all -= d.all & s;
-    }
-    q.all = (q.all << 1) | carry;
-    if (rem)
-        *rem = r.all;
-    return q.all;
-}
+/** @file\r
+  Compiler intrinsic for 64-bit compare, ported from LLVM code.\r
+\r
+  Copyright (c) 2008-2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+/**\r
+  University of Illinois/NCSA\r
+  Open Source License\r
+  \r
+  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.\r
+  All rights reserved.\r
+  \r
+  Developed by:\r
+  \r
+      LLVM Team\r
+  \r
+      University of Illinois at Urbana-Champaign\r
+  \r
+      http://llvm.org\r
+  \r
+  Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+  this software and associated documentation files (the "Software"), to deal with\r
+  the Software without restriction, including without limitation the rights to\r
+  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+  of the Software, and to permit persons to whom the Software is furnished to do\r
+  so, subject to the following conditions:\r
+  \r
+      * Redistributions of source code must retain the above copyright notice,\r
+        this list of conditions and the following disclaimers.\r
+  \r
+      * Redistributions in binary form must reproduce the above copyright notice,\r
+        this list of conditions and the following disclaimers in the\r
+        documentation and/or other materials provided with the distribution.\r
+  \r
+      * Neither the names of the LLVM Team, University of Illinois at\r
+        Urbana-Champaign, nor the names of its contributors may be used to\r
+        endorse or promote products derived from this Software without specific\r
+        prior written permission.\r
+  \r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE\r
+  SOFTWARE.\r
+**/\r
+\r
+\r
+#include "Llvm_int_lib.h"\r
+\r
+// Effects: if rem != 0, *rem = a % b\r
+// Returns: a / b\r
+\r
+// Translated from Figure 3-40 of The PowerPC Compiler Writer's Guide\r
+\r
+UINT64\r
+__udivmoddi4 (UINT64 a, UINT64 b, UINT64* rem)\r
+{\r
+    const unsigned n_uword_bits = sizeof(UINT32) * CHAR_BIT;\r
+    const unsigned n_udword_bits = sizeof(UINT64) * CHAR_BIT;\r
+    udwords n;\r
+    n.all = a;\r
+    udwords d;\r
+    d.all = b;\r
+    udwords q;\r
+    udwords r;\r
+    unsigned sr;\r
+    \r
+    if (b == 0) {\r
+//      ASSERT (FALSE);\r
+      return 0;\r
+    }\r
+    \r
+    // special cases, X is unknown, K != 0\r
+    if (n.high == 0)\r
+    {\r
+        if (d.high == 0)\r
+        {\r
+            // 0 X\r
+            // ---\r
+            // 0 X\r
+            if (rem)\r
+                *rem = n.low % d.low;\r
+            return n.low / d.low;\r
+        }\r
+        // 0 X\r
+        // ---\r
+        // K X\r
+        if (rem)\r
+            *rem = n.low;\r
+        return 0;\r
+    }\r
+    // n.high != 0\r
+    if (d.low == 0)\r
+    {\r
+        if (d.high == 0)\r
+        {\r
+            // K X\r
+            // ---\r
+            // 0 0\r
+            if (rem)\r
+                *rem = n.high % d.low;\r
+            return n.high / d.low;\r
+        }\r
+        // d.high != 0\r
+        if (n.low == 0)\r
+        {\r
+            // K 0\r
+            // ---\r
+            // K 0\r
+            if (rem)\r
+            {\r
+                r.high = n.high % d.high;\r
+                r.low = 0;\r
+                *rem = r.all;\r
+            }\r
+            return n.high / d.high;\r
+        }\r
+        // K K\r
+        // ---\r
+        // K 0\r
+        if ((d.high & (d.high - 1)) == 0)     // if d is a power of 2\r
+        {\r
+            if (rem)\r
+            {\r
+                r.low = n.low;\r
+                r.high = n.high & (d.high - 1);\r
+                *rem = r.all;\r
+            }\r
+            return n.high >> COUNT_TRAILING_ZEROS(d.high);\r
+        }\r
+        // K K\r
+        // ---\r
+        // K 0\r
+        sr = COUNT_LEADING_ZEROS(d.high) - COUNT_LEADING_ZEROS(n.high);\r
+        // 0 <= sr <= n_uword_bits - 2 or sr large\r
+        if (sr > n_uword_bits - 2)\r
+        {\r
+           if (rem)\r
+                *rem = n.all;\r
+            return 0;\r
+        }\r
+        ++sr;\r
+        // 1 <= sr <= n_uword_bits - 1\r
+        // q.all = n.all << (n_udword_bits - sr);\r
+        q.low = 0;\r
+        q.high = n.low << (n_uword_bits - sr);\r
+        // r.all = n.all >> sr;\r
+        r.high = n.high >> sr;\r
+        r.low = (n.high << (n_uword_bits - sr)) | (n.low >> sr);\r
+    }\r
+    else  // d.low != 0\r
+    {\r
+        if (d.high == 0)\r
+        {\r
+            // K X\r
+            // ---\r
+            // 0 K\r
+            if ((d.low & (d.low - 1)) == 0)     // if d is a power of 2\r
+            {\r
+                if (rem)\r
+                    *rem = n.low & (d.low - 1);\r
+                if (d.low == 1)\r
+                    return n.all;\r
+                unsigned sr = COUNT_TRAILING_ZEROS(d.low);\r
+                q.high = n.high >> sr;\r
+                q.low = (n.high << (n_uword_bits - sr)) | (n.low >> sr);\r
+                return q.all;\r
+            }\r
+            // K X\r
+            // ---\r
+            // 0 K\r
+            sr = 1 + n_uword_bits + COUNT_LEADING_ZEROS(d.low) - COUNT_LEADING_ZEROS(n.high);\r
+            // 2 <= sr <= n_udword_bits - 1\r
+            // q.all = n.all << (n_udword_bits - sr);\r
+            // r.all = n.all >> sr;\r
+            // if (sr == n_uword_bits)\r
+            // {\r
+            //     q.low = 0;\r
+            //     q.high = n.low;\r
+            //     r.high = 0;\r
+            //     r.low = n.high;\r
+            // }\r
+            // else if (sr < n_uword_bits)  // 2 <= sr <= n_uword_bits - 1\r
+            // {\r
+            //     q.low = 0;\r
+            //     q.high = n.low << (n_uword_bits - sr);\r
+            //     r.high = n.high >> sr;\r
+            //     r.low = (n.high << (n_uword_bits - sr)) | (n.low >> sr);\r
+            // }\r
+            // else              // n_uword_bits + 1 <= sr <= n_udword_bits - 1\r
+            // {\r
+            //     q.low = n.low << (n_udword_bits - sr);\r
+            //     q.high = (n.high << (n_udword_bits - sr)) |\r
+            //              (n.low >> (sr - n_uword_bits));\r
+            //     r.high = 0;\r
+            //     r.low = n.high >> (sr - n_uword_bits);\r
+            // }\r
+            q.low =  (n.low << (n_udword_bits - sr)) &\r
+                     ((INT32)(n_uword_bits - sr) >> (n_uword_bits-1));\r
+            q.high = ((n.low << ( n_uword_bits - sr))                       &\r
+                     ((INT32)(sr - n_uword_bits - 1) >> (n_uword_bits-1))) |\r
+                     (((n.high << (n_udword_bits - sr))                     |\r
+                     (n.low >> (sr - n_uword_bits)))                        &\r
+                     ((INT32)(n_uword_bits - sr) >> (n_uword_bits-1)));\r
+            r.high = (n.high >> sr) &\r
+                     ((INT32)(sr - n_uword_bits) >> (n_uword_bits-1));\r
+            r.low =  ((n.high >> (sr - n_uword_bits))                       &\r
+                     ((INT32)(n_uword_bits - sr - 1) >> (n_uword_bits-1))) |\r
+                     (((n.high << (n_uword_bits - sr))                      |\r
+                     (n.low >> sr))                                         &\r
+                     ((INT32)(sr - n_uword_bits) >> (n_uword_bits-1)));\r
+        }\r
+        else\r
+        {\r
+            // K X\r
+            // ---\r
+            // K K\r
+            sr = COUNT_LEADING_ZEROS(d.high) - COUNT_LEADING_ZEROS(n.high);\r
+            // 0 <= sr <= n_uword_bits - 1 or sr large\r
+            if (sr > n_uword_bits - 1)\r
+            {\r
+               if (rem)\r
+                    *rem = n.all;\r
+                return 0;\r
+            }\r
+            ++sr;\r
+            // 1 <= sr <= n_uword_bits\r
+            // q.all = n.all << (n_udword_bits - sr);\r
+            q.low = 0;\r
+            q.high = n.low << (n_uword_bits - sr);\r
+            // r.all = n.all >> sr;\r
+            // if (sr < n_uword_bits)\r
+            // {\r
+            //     r.high = n.high >> sr;\r
+            //     r.low = (n.high << (n_uword_bits - sr)) | (n.low >> sr);\r
+            // }\r
+            // else\r
+            // {\r
+            //     r.high = 0;\r
+            //     r.low = n.high;\r
+            // }\r
+            r.high = (n.high >> sr) &\r
+                     ((INT32)(sr - n_uword_bits) >> (n_uword_bits-1));\r
+            r.low = (n.high << (n_uword_bits - sr)) |\r
+                    ((n.low >> sr)                  &\r
+                    ((INT32)(sr - n_uword_bits) >> (n_uword_bits-1)));\r
+        }\r
+    }\r
+    // Not a special case\r
+    // q and r are initialized with:\r
+    // q.all = n.all << (n_udword_bits - sr);\r
+    // r.all = n.all >> sr;\r
+    // 1 <= sr <= n_udword_bits - 1\r
+    UINT32 carry = 0;\r
+    for (; sr > 0; --sr)\r
+    {\r
+        // r:q = ((r:q)  << 1) | carry\r
+        r.high = (r.high << 1) | (r.low  >> (n_uword_bits - 1));\r
+        r.low  = (r.low  << 1) | (q.high >> (n_uword_bits - 1));\r
+        q.high = (q.high << 1) | (q.low  >> (n_uword_bits - 1));\r
+        q.low  = (q.low  << 1) | carry;\r
+        // carry = 0;\r
+        // if (r.all >= d.all)\r
+        // {\r
+        //      r.all -= d.all;\r
+        //      carry = 1;\r
+        // }\r
+        const INT64 s = (INT64)(d.all - r.all - 1) >> (n_udword_bits - 1);\r
+        carry = s & 1;\r
+        r.all -= d.all & s;\r
+    }\r
+    q.all = (q.all << 1) | carry;\r
+    if (rem)\r
+        *rem = r.all;\r
+    return q.all;\r
+}\r
index 92c9cad960177927ab70d355a69ad67e6060b84a..a9223d7fb56b917c5f623cacb35c67e0339aefd8 100644 (file)
@@ -1,57 +1,57 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__udivsi3)
-
-ASM_PFX(__udivsi3):
-  cmp  r1, #0
-  cmpne  r0, #0
-  stmfd  sp!, {r4, r5, r7, lr}
-  add  r7, sp, #8
-  beq  L2
-  clz  r2, r1
-  clz  r3, r0
-  rsb  r3, r3, r2
-  cmp  r3, #31
-  bhi  L2
-  ldmeqfd  sp!, {r4, r5, r7, pc}
-  add  r5, r3, #1
-  rsb  r3, r3, #31
-  mov  lr, #0
-  mov  r2, r0, asl r3
-  mov  ip, r0, lsr r5
-  mov  r4, lr
-  b  L8
-L9:
-  mov  r0, r2, lsr #31
-  orr  ip, r0, ip, asl #1
-  orr  r2, r3, lr
-  rsb  r3, ip, r1
-  sub  r3, r3, #1
-  and  r0, r1, r3, asr #31
-  mov  lr, r3, lsr #31
-  rsb  ip, r0, ip
-  add  r4, r4, #1
-L8:
-  cmp  r4, r5
-  mov  r3, r2, asl #1
-  bne  L9
-  orr  r0, r3, lr
-  ldmfd  sp!, {r4, r5, r7, pc}
-L2:
-  mov  r0, #0
-  ldmfd  sp!, {r4, r5, r7, pc}
-
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__udivsi3)\r
+\r
+ASM_PFX(__udivsi3):\r
+  cmp  r1, #0\r
+  cmpne  r0, #0\r
+  stmfd  sp!, {r4, r5, r7, lr}\r
+  add  r7, sp, #8\r
+  beq  L2\r
+  clz  r2, r1\r
+  clz  r3, r0\r
+  rsb  r3, r3, r2\r
+  cmp  r3, #31\r
+  bhi  L2\r
+  ldmeqfd  sp!, {r4, r5, r7, pc}\r
+  add  r5, r3, #1\r
+  rsb  r3, r3, #31\r
+  mov  lr, #0\r
+  mov  r2, r0, asl r3\r
+  mov  ip, r0, lsr r5\r
+  mov  r4, lr\r
+  b  L8\r
+L9:\r
+  mov  r0, r2, lsr #31\r
+  orr  ip, r0, ip, asl #1\r
+  orr  r2, r3, lr\r
+  rsb  r3, ip, r1\r
+  sub  r3, r3, #1\r
+  and  r0, r1, r3, asr #31\r
+  mov  lr, r3, lsr #31\r
+  rsb  ip, r0, ip\r
+  add  r4, r4, #1\r
+L8:\r
+  cmp  r4, r5\r
+  mov  r3, r2, asl #1\r
+  bne  L9\r
+  orr  r0, r3, lr\r
+  ldmfd  sp!, {r4, r5, r7, pc}\r
+L2:\r
+  mov  r0, #0\r
+  ldmfd  sp!, {r4, r5, r7, pc}\r
+\r
index aec1a1ccbfe28cf399050493d151afcdd31981c3..020b3fadc50f2629056366dcc25df81ecddbfda6 100644 (file)
-/** @file
-  Compiler intrinsic for 32-bit unsigned div, ported from LLVM code.
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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.
-
-**/
-/**
-  University of Illinois/NCSA
-  Open Source License
-  
-  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
-  All rights reserved.
-  
-  Developed by:
-  
-      LLVM Team
-  
-      University of Illinois at Urbana-Champaign
-  
-      http://llvm.org
-  
-  Permission is hereby granted, free of charge, to any person obtaining a copy of
-  this software and associated documentation files (the "Software"), to deal with
-  the Software without restriction, including without limitation the rights to
-  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-  of the Software, and to permit persons to whom the Software is furnished to do
-  so, subject to the following conditions:
-  
-      * Redistributions of source code must retain the above copyright notice,
-        this list of conditions and the following disclaimers.
-  
-      * Redistributions in binary form must reproduce the above copyright notice,
-        this list of conditions and the following disclaimers in the
-        documentation and/or other materials provided with the distribution.
-  
-      * Neither the names of the LLVM Team, University of Illinois at
-        Urbana-Champaign, nor the names of its contributors may be used to
-        endorse or promote products derived from this Software without specific
-        prior written permission.
-  
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-  SOFTWARE.
-**/
-
-
-#include "Llvm_int_lib.h"
-
-
-// Returns: n / d
-
-// Translated from Figure 3-40 of The PowerPC Compiler Writer's Guide
-
-UINT32
-__udivsi3(UINT32 n, UINT32 d)
-{
-    const unsigned n_uword_bits = sizeof(UINT32) * CHAR_BIT;
-    UINT32 q;
-    UINT32 r;
-    unsigned sr;
-
-    // special cases
-    if (d == 0) {
-//        ASSERT (FALSE);
-        return 0; // ?!
-        }
-    if (n == 0)
-        return 0;
-
-    sr = COUNT_LEADING_ZEROS(d) - COUNT_LEADING_ZEROS(n);
-    // 0 <= sr <= n_uword_bits - 1 or sr large
-    if (sr > n_uword_bits - 1)  // d > r
-        return 0;
-    if (sr == n_uword_bits - 1)  // d == 1
-        return n;
-    ++sr;
-    // 1 <= sr <= n_uword_bits - 1
-    // Not a special case
-    q = n << (n_uword_bits - sr);
-    r = n >> sr;
-    UINT32 carry = 0;
-    for (; sr > 0; --sr)
-    {
-        // r:q = ((r:q)  << 1) | carry
-        r = (r << 1) | (q >> (n_uword_bits - 1));
-        q = (q << 1) | carry;
-        // carry = 0;
-        // if (r.all >= d.all)
-        // {
-        //      r.all -= d.all;
-        //      carry = 1;
-        // }
-        const INT32 s = (INT32)(d - r - 1) >> (n_uword_bits - 1);
-        carry = s & 1;
-        r -= d & s;
-    }
-    q = (q << 1) | carry;
-    return q;
-}
+/** @file\r
+  Compiler intrinsic for 32-bit unsigned div, ported from LLVM code.\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+/**\r
+  University of Illinois/NCSA\r
+  Open Source License\r
+  \r
+  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.\r
+  All rights reserved.\r
+  \r
+  Developed by:\r
+  \r
+      LLVM Team\r
+  \r
+      University of Illinois at Urbana-Champaign\r
+  \r
+      http://llvm.org\r
+  \r
+  Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+  this software and associated documentation files (the "Software"), to deal with\r
+  the Software without restriction, including without limitation the rights to\r
+  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+  of the Software, and to permit persons to whom the Software is furnished to do\r
+  so, subject to the following conditions:\r
+  \r
+      * Redistributions of source code must retain the above copyright notice,\r
+        this list of conditions and the following disclaimers.\r
+  \r
+      * Redistributions in binary form must reproduce the above copyright notice,\r
+        this list of conditions and the following disclaimers in the\r
+        documentation and/or other materials provided with the distribution.\r
+  \r
+      * Neither the names of the LLVM Team, University of Illinois at\r
+        Urbana-Champaign, nor the names of its contributors may be used to\r
+        endorse or promote products derived from this Software without specific\r
+        prior written permission.\r
+  \r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE\r
+  SOFTWARE.\r
+**/\r
+\r
+\r
+#include "Llvm_int_lib.h"\r
+\r
+\r
+// Returns: n / d\r
+\r
+// Translated from Figure 3-40 of The PowerPC Compiler Writer's Guide\r
+\r
+UINT32\r
+__udivsi3(UINT32 n, UINT32 d)\r
+{\r
+    const unsigned n_uword_bits = sizeof(UINT32) * CHAR_BIT;\r
+    UINT32 q;\r
+    UINT32 r;\r
+    unsigned sr;\r
+\r
+    // special cases\r
+    if (d == 0) {\r
+//        ASSERT (FALSE);\r
+        return 0; // ?!\r
+        }\r
+    if (n == 0)\r
+        return 0;\r
+\r
+    sr = COUNT_LEADING_ZEROS(d) - COUNT_LEADING_ZEROS(n);\r
+    // 0 <= sr <= n_uword_bits - 1 or sr large\r
+    if (sr > n_uword_bits - 1)  // d > r\r
+        return 0;\r
+    if (sr == n_uword_bits - 1)  // d == 1\r
+        return n;\r
+    ++sr;\r
+    // 1 <= sr <= n_uword_bits - 1\r
+    // Not a special case\r
+    q = n << (n_uword_bits - sr);\r
+    r = n >> sr;\r
+    UINT32 carry = 0;\r
+    for (; sr > 0; --sr)\r
+    {\r
+        // r:q = ((r:q)  << 1) | carry\r
+        r = (r << 1) | (q >> (n_uword_bits - 1));\r
+        q = (q << 1) | carry;\r
+        // carry = 0;\r
+        // if (r.all >= d.all)\r
+        // {\r
+        //      r.all -= d.all;\r
+        //      carry = 1;\r
+        // }\r
+        const INT32 s = (INT32)(d - r - 1) >> (n_uword_bits - 1);\r
+        carry = s & 1;\r
+        r -= d & s;\r
+    }\r
+    q = (q << 1) | carry;\r
+    return q;\r
+}\r
index 6b55135f334e8add5310f8c4105f74fe46ecf2f4..75b0bb93a026f3eb0e7613020f64f13dd5001d78 100755 (executable)
-//------------------------------------------------------------------------------ 
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__aeabi_uldivmod)
-
-//        
-//UINT64
-//EFIAPI
-//__aeabi_uldivmod (
-//  IN  UINT64   Dividend  
-//  IN  UINT64   Divisor
-//  )
-//
-ASM_PFX(__aeabi_uldivmod):
-  stmdb   sp!, {r4, r5, r6, lr}
-  mov     r4, r1
-  mov     r5, r0
-  mov     r6, #0  // 0x0
-  orrs    ip, r3, r2, lsr #31
-  bne     ASM_PFX(__aeabi_uldivmod_label1)
-  tst     r2, r2
-  beq     ASM_PFX(_ll_div0)
-  movs    ip, r2, lsr #15
-  addeq   r6, r6, #16     // 0x10
-  mov     ip, r2, lsl r6
-  movs    lr, ip, lsr #23
-  moveq   ip, ip, lsl #8
-  addeq   r6, r6, #8      // 0x8
-  movs    lr, ip, lsr #27
-  moveq   ip, ip, lsl #4
-  addeq   r6, r6, #4      // 0x4
-  movs    lr, ip, lsr #29
-  moveq   ip, ip, lsl #2
-  addeq   r6, r6, #2      // 0x2
-  movs    lr, ip, lsr #30
-  moveq   ip, ip, lsl #1
-  addeq   r6, r6, #1      // 0x1
-  b       ASM_PFX(_ll_udiv_small)
-ASM_PFX(__aeabi_uldivmod_label1):
-  tst     r3, #-2147483648        // 0x80000000
-  bne     ASM_PFX(__aeabi_uldivmod_label2)
-  movs    ip, r3, lsr #15
-  addeq   r6, r6, #16     // 0x10
-  mov     ip, r3, lsl r6
-  movs    lr, ip, lsr #23
-  moveq   ip, ip, lsl #8
-  addeq   r6, r6, #8      // 0x8
-  movs    lr, ip, lsr #27
-  moveq   ip, ip, lsl #4
-  addeq   r6, r6, #4      // 0x4
-  movs    lr, ip, lsr #29
-  moveq   ip, ip, lsl #2
-  addeq   r6, r6, #2      // 0x2
-  movs    lr, ip, lsr #30
-  addeq   r6, r6, #1      // 0x1
-  rsb     r3, r6, #32     // 0x20
-  moveq   ip, ip, lsl #1
-  orr     ip, ip, r2, lsr r3
-  mov     lr, r2, lsl r6
-  b       ASM_PFX(_ll_udiv_big)
-ASM_PFX(__aeabi_uldivmod_label2):
-  mov     ip, r3
-  mov     lr, r2
-  b       ASM_PFX(_ll_udiv_ginormous)
-  
-ASM_PFX(_ll_udiv_small):
-  cmp     r4, ip, lsl #1
-  mov     r3, #0  // 0x0
-  subcs   r4, r4, ip, lsl #1
-  addcs   r3, r3, #2      // 0x2
-  cmp     r4, ip
-  subcs   r4, r4, ip
-  adcs    r3, r3, #0      // 0x0
-  add     r2, r6, #32     // 0x20
-  cmp     r2, #32 // 0x20
-  rsb     ip, ip, #0      // 0x0
-  bcc     ASM_PFX(_ll_udiv_small_label1)
-  orrs    r0, r4, r5, lsr #30
-  moveq   r4, r5
-  moveq   r5, #0  // 0x0
-  subeq   r2, r2, #32     // 0x20
-ASM_PFX(_ll_udiv_small_label1):
-  mov     r1, #0  // 0x0
-  cmp     r2, #16 // 0x10
-  bcc     ASM_PFX(_ll_udiv_small_label2)
-  movs    r0, r4, lsr #14
-  moveq   r4, r4, lsl #16
-  addeq   r1, r1, #16     // 0x10
-ASM_PFX(_ll_udiv_small_label2):
-  sub     lr, r2, r1
-  cmp     lr, #8  // 0x8
-  bcc     ASM_PFX(_ll_udiv_small_label3)
-  movs    r0, r4, lsr #22
-  moveq   r4, r4, lsl #8
-  addeq   r1, r1, #8      // 0x8
-ASM_PFX(_ll_udiv_small_label3):
-  rsb     r0, r1, #32     // 0x20
-  sub     r2, r2, r1
-  orr     r4, r4, r5, lsr r0
-  mov     r5, r5, lsl r1
-  cmp     r2, #1  // 0x1
-  bcc     ASM_PFX(_ll_udiv_small_label5)
-  sub     r2, r2, #1      // 0x1
-  and     r0, r2, #7      // 0x7
-  eor     r0, r0, #7      // 0x7
-  adds    r0, r0, r0, lsl #1
-  add     pc, pc, r0, lsl #2
-  nop                     // (mov r0,r0)
-ASM_PFX(_ll_udiv_small_label4):
-  adcs    r5, r5, r5
-  adcs    r4, ip, r4, lsl #1
-  rsbcc   r4, ip, r4
-  adcs    r5, r5, r5
-  adcs    r4, ip, r4, lsl #1
-  rsbcc   r4, ip, r4
-  adcs    r5, r5, r5
-  adcs    r4, ip, r4, lsl #1
-  rsbcc   r4, ip, r4
-  adcs    r5, r5, r5
-  adcs    r4, ip, r4, lsl #1
-  rsbcc   r4, ip, r4
-  adcs    r5, r5, r5
-  adcs    r4, ip, r4, lsl #1
-  rsbcc   r4, ip, r4
-  adcs    r5, r5, r5
-  adcs    r4, ip, r4, lsl #1
-  rsbcc   r4, ip, r4
-  adcs    r5, r5, r5
-  adcs    r4, ip, r4, lsl #1
-  rsbcc   r4, ip, r4
-  adcs    r5, r5, r5
-  adcs    r4, ip, r4, lsl #1
-  sub     r2, r2, #8      // 0x8
-  tst     r2, r2
-  rsbcc   r4, ip, r4
-  bpl     ASM_PFX(_ll_udiv_small_label4)
-ASM_PFX(_ll_udiv_small_label5):
-  mov     r2, r4, lsr r6
-  bic     r4, r4, r2, lsl r6
-  adcs    r0, r5, r5
-  adc     r1, r4, r4
-  add     r1, r1, r3, lsl r6
-  mov     r3, #0  // 0x0
-  ldmia   sp!, {r4, r5, r6, pc}
-  
-ASM_PFX(_ll_udiv_big):
-  subs    r0, r5, lr
-  mov     r3, #0  // 0x0
-  sbcs    r1, r4, ip
-  movcs   r5, r0
-  movcs   r4, r1
-  adcs    r3, r3, #0      // 0x0
-  subs    r0, r5, lr
-  sbcs    r1, r4, ip
-  movcs   r5, r0
-  movcs   r4, r1
-  adcs    r3, r3, #0      // 0x0
-  subs    r0, r5, lr
-  sbcs    r1, r4, ip
-  movcs   r5, r0
-  movcs   r4, r1
-  adcs    r3, r3, #0      // 0x0
-  mov     r1, #0  // 0x0
-  rsbs    lr, lr, #0      // 0x0
-  rsc     ip, ip, #0      // 0x0
-  cmp     r6, #16 // 0x10
-  bcc     ASM_PFX(_ll_udiv_big_label1)
-  movs    r0, r4, lsr #14
-  moveq   r4, r4, lsl #16
-  addeq   r1, r1, #16     // 0x10
-ASM_PFX(_ll_udiv_big_label1):
-  sub     r2, r6, r1
-  cmp     r2, #8  // 0x8
-  bcc     ASM_PFX(_ll_udiv_big_label2)
-  movs    r0, r4, lsr #22
-  moveq   r4, r4, lsl #8
-  addeq   r1, r1, #8      // 0x8
-ASM_PFX(_ll_udiv_big_label2):
-  rsb     r0, r1, #32     // 0x20
-  sub     r2, r6, r1
-  orr     r4, r4, r5, lsr r0
-  mov     r5, r5, lsl r1
-  cmp     r2, #1  // 0x1
-  bcc     ASM_PFX(_ll_udiv_big_label4)
-  sub     r2, r2, #1      // 0x1
-  and     r0, r2, #3      // 0x3
-  rsb     r0, r0, #3      // 0x3
-  adds    r0, r0, r0, lsl #1
-  add     pc, pc, r0, lsl #3
-  nop                     // (mov r0,r0)
-ASM_PFX(_ll_udiv_big_label3):
-  adcs    r5, r5, r5
-  adcs    r4, r4, r4
-  adcs    r0, lr, r5
-  adcs    r1, ip, r4
-  movcs   r5, r0
-  movcs   r4, r1
-  adcs    r5, r5, r5
-  adcs    r4, r4, r4
-  adcs    r0, lr, r5
-  adcs    r1, ip, r4
-  movcs   r5, r0
-  movcs   r4, r1
-  adcs    r5, r5, r5
-  adcs    r4, r4, r4
-  adcs    r0, lr, r5
-  adcs    r1, ip, r4
-  movcs   r5, r0
-  movcs   r4, r1
-  sub     r2, r2, #4      // 0x4
-  adcs    r5, r5, r5
-  adcs    r4, r4, r4
-  adcs    r0, lr, r5
-  adcs    r1, ip, r4
-  tst     r2, r2
-  movcs   r5, r0
-  movcs   r4, r1
-  bpl     ASM_PFX(_ll_udiv_big_label3)
-ASM_PFX(_ll_udiv_big_label4):
-  mov     r1, #0  // 0x0
-  mov     r2, r5, lsr r6
-  bic     r5, r5, r2, lsl r6
-  adcs    r0, r5, r5
-  adc     r1, r1, #0      // 0x0
-  movs    lr, r3, lsl r6
-  mov     r3, r4, lsr r6
-  bic     r4, r4, r3, lsl r6
-  adc     r1, r1, #0      // 0x0
-  adds    r0, r0, lr
-  orr     r2, r2, r4, ror r6
-  adc     r1, r1, #0      // 0x0
-  ldmia   sp!, {r4, r5, r6, pc}
-  
-ASM_PFX(_ll_udiv_ginormous):
-  subs    r2, r5, lr
-  mov     r1, #0  // 0x0
-  sbcs    r3, r4, ip
-  adc     r0, r1, r1
-  movcc   r2, r5
-  movcc   r3, r4
-  ldmia   sp!, {r4, r5, r6, pc}
-  
-ASM_PFX(_ll_div0):
-  ldmia   sp!, {r4, r5, r6, lr}
-  mov     r0, #0  // 0x0
-  mov     r1, #0  // 0x0
-  b       ASM_PFX(__aeabi_ldiv0)
-  
-ASM_PFX(__aeabi_ldiv0):
-  bx      r14
-
-
+//------------------------------------------------------------------------------ \r
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__aeabi_uldivmod)\r
+\r
+//        \r
+//UINT64\r
+//EFIAPI\r
+//__aeabi_uldivmod (\r
+//  IN  UINT64   Dividend  \r
+//  IN  UINT64   Divisor\r
+//  )\r
+//\r
+ASM_PFX(__aeabi_uldivmod):\r
+  stmdb   sp!, {r4, r5, r6, lr}\r
+  mov     r4, r1\r
+  mov     r5, r0\r
+  mov     r6, #0  // 0x0\r
+  orrs    ip, r3, r2, lsr #31\r
+  bne     ASM_PFX(__aeabi_uldivmod_label1)\r
+  tst     r2, r2\r
+  beq     ASM_PFX(_ll_div0)\r
+  movs    ip, r2, lsr #15\r
+  addeq   r6, r6, #16     // 0x10\r
+  mov     ip, r2, lsl r6\r
+  movs    lr, ip, lsr #23\r
+  moveq   ip, ip, lsl #8\r
+  addeq   r6, r6, #8      // 0x8\r
+  movs    lr, ip, lsr #27\r
+  moveq   ip, ip, lsl #4\r
+  addeq   r6, r6, #4      // 0x4\r
+  movs    lr, ip, lsr #29\r
+  moveq   ip, ip, lsl #2\r
+  addeq   r6, r6, #2      // 0x2\r
+  movs    lr, ip, lsr #30\r
+  moveq   ip, ip, lsl #1\r
+  addeq   r6, r6, #1      // 0x1\r
+  b       ASM_PFX(_ll_udiv_small)\r
+ASM_PFX(__aeabi_uldivmod_label1):\r
+  tst     r3, #-2147483648        // 0x80000000\r
+  bne     ASM_PFX(__aeabi_uldivmod_label2)\r
+  movs    ip, r3, lsr #15\r
+  addeq   r6, r6, #16     // 0x10\r
+  mov     ip, r3, lsl r6\r
+  movs    lr, ip, lsr #23\r
+  moveq   ip, ip, lsl #8\r
+  addeq   r6, r6, #8      // 0x8\r
+  movs    lr, ip, lsr #27\r
+  moveq   ip, ip, lsl #4\r
+  addeq   r6, r6, #4      // 0x4\r
+  movs    lr, ip, lsr #29\r
+  moveq   ip, ip, lsl #2\r
+  addeq   r6, r6, #2      // 0x2\r
+  movs    lr, ip, lsr #30\r
+  addeq   r6, r6, #1      // 0x1\r
+  rsb     r3, r6, #32     // 0x20\r
+  moveq   ip, ip, lsl #1\r
+  orr     ip, ip, r2, lsr r3\r
+  mov     lr, r2, lsl r6\r
+  b       ASM_PFX(_ll_udiv_big)\r
+ASM_PFX(__aeabi_uldivmod_label2):\r
+  mov     ip, r3\r
+  mov     lr, r2\r
+  b       ASM_PFX(_ll_udiv_ginormous)\r
+  \r
+ASM_PFX(_ll_udiv_small):\r
+  cmp     r4, ip, lsl #1\r
+  mov     r3, #0  // 0x0\r
+  subcs   r4, r4, ip, lsl #1\r
+  addcs   r3, r3, #2      // 0x2\r
+  cmp     r4, ip\r
+  subcs   r4, r4, ip\r
+  adcs    r3, r3, #0      // 0x0\r
+  add     r2, r6, #32     // 0x20\r
+  cmp     r2, #32 // 0x20\r
+  rsb     ip, ip, #0      // 0x0\r
+  bcc     ASM_PFX(_ll_udiv_small_label1)\r
+  orrs    r0, r4, r5, lsr #30\r
+  moveq   r4, r5\r
+  moveq   r5, #0  // 0x0\r
+  subeq   r2, r2, #32     // 0x20\r
+ASM_PFX(_ll_udiv_small_label1):\r
+  mov     r1, #0  // 0x0\r
+  cmp     r2, #16 // 0x10\r
+  bcc     ASM_PFX(_ll_udiv_small_label2)\r
+  movs    r0, r4, lsr #14\r
+  moveq   r4, r4, lsl #16\r
+  addeq   r1, r1, #16     // 0x10\r
+ASM_PFX(_ll_udiv_small_label2):\r
+  sub     lr, r2, r1\r
+  cmp     lr, #8  // 0x8\r
+  bcc     ASM_PFX(_ll_udiv_small_label3)\r
+  movs    r0, r4, lsr #22\r
+  moveq   r4, r4, lsl #8\r
+  addeq   r1, r1, #8      // 0x8\r
+ASM_PFX(_ll_udiv_small_label3):\r
+  rsb     r0, r1, #32     // 0x20\r
+  sub     r2, r2, r1\r
+  orr     r4, r4, r5, lsr r0\r
+  mov     r5, r5, lsl r1\r
+  cmp     r2, #1  // 0x1\r
+  bcc     ASM_PFX(_ll_udiv_small_label5)\r
+  sub     r2, r2, #1      // 0x1\r
+  and     r0, r2, #7      // 0x7\r
+  eor     r0, r0, #7      // 0x7\r
+  adds    r0, r0, r0, lsl #1\r
+  add     pc, pc, r0, lsl #2\r
+  nop                     // (mov r0,r0)\r
+ASM_PFX(_ll_udiv_small_label4):\r
+  adcs    r5, r5, r5\r
+  adcs    r4, ip, r4, lsl #1\r
+  rsbcc   r4, ip, r4\r
+  adcs    r5, r5, r5\r
+  adcs    r4, ip, r4, lsl #1\r
+  rsbcc   r4, ip, r4\r
+  adcs    r5, r5, r5\r
+  adcs    r4, ip, r4, lsl #1\r
+  rsbcc   r4, ip, r4\r
+  adcs    r5, r5, r5\r
+  adcs    r4, ip, r4, lsl #1\r
+  rsbcc   r4, ip, r4\r
+  adcs    r5, r5, r5\r
+  adcs    r4, ip, r4, lsl #1\r
+  rsbcc   r4, ip, r4\r
+  adcs    r5, r5, r5\r
+  adcs    r4, ip, r4, lsl #1\r
+  rsbcc   r4, ip, r4\r
+  adcs    r5, r5, r5\r
+  adcs    r4, ip, r4, lsl #1\r
+  rsbcc   r4, ip, r4\r
+  adcs    r5, r5, r5\r
+  adcs    r4, ip, r4, lsl #1\r
+  sub     r2, r2, #8      // 0x8\r
+  tst     r2, r2\r
+  rsbcc   r4, ip, r4\r
+  bpl     ASM_PFX(_ll_udiv_small_label4)\r
+ASM_PFX(_ll_udiv_small_label5):\r
+  mov     r2, r4, lsr r6\r
+  bic     r4, r4, r2, lsl r6\r
+  adcs    r0, r5, r5\r
+  adc     r1, r4, r4\r
+  add     r1, r1, r3, lsl r6\r
+  mov     r3, #0  // 0x0\r
+  ldmia   sp!, {r4, r5, r6, pc}\r
+  \r
+ASM_PFX(_ll_udiv_big):\r
+  subs    r0, r5, lr\r
+  mov     r3, #0  // 0x0\r
+  sbcs    r1, r4, ip\r
+  movcs   r5, r0\r
+  movcs   r4, r1\r
+  adcs    r3, r3, #0      // 0x0\r
+  subs    r0, r5, lr\r
+  sbcs    r1, r4, ip\r
+  movcs   r5, r0\r
+  movcs   r4, r1\r
+  adcs    r3, r3, #0      // 0x0\r
+  subs    r0, r5, lr\r
+  sbcs    r1, r4, ip\r
+  movcs   r5, r0\r
+  movcs   r4, r1\r
+  adcs    r3, r3, #0      // 0x0\r
+  mov     r1, #0  // 0x0\r
+  rsbs    lr, lr, #0      // 0x0\r
+  rsc     ip, ip, #0      // 0x0\r
+  cmp     r6, #16 // 0x10\r
+  bcc     ASM_PFX(_ll_udiv_big_label1)\r
+  movs    r0, r4, lsr #14\r
+  moveq   r4, r4, lsl #16\r
+  addeq   r1, r1, #16     // 0x10\r
+ASM_PFX(_ll_udiv_big_label1):\r
+  sub     r2, r6, r1\r
+  cmp     r2, #8  // 0x8\r
+  bcc     ASM_PFX(_ll_udiv_big_label2)\r
+  movs    r0, r4, lsr #22\r
+  moveq   r4, r4, lsl #8\r
+  addeq   r1, r1, #8      // 0x8\r
+ASM_PFX(_ll_udiv_big_label2):\r
+  rsb     r0, r1, #32     // 0x20\r
+  sub     r2, r6, r1\r
+  orr     r4, r4, r5, lsr r0\r
+  mov     r5, r5, lsl r1\r
+  cmp     r2, #1  // 0x1\r
+  bcc     ASM_PFX(_ll_udiv_big_label4)\r
+  sub     r2, r2, #1      // 0x1\r
+  and     r0, r2, #3      // 0x3\r
+  rsb     r0, r0, #3      // 0x3\r
+  adds    r0, r0, r0, lsl #1\r
+  add     pc, pc, r0, lsl #3\r
+  nop                     // (mov r0,r0)\r
+ASM_PFX(_ll_udiv_big_label3):\r
+  adcs    r5, r5, r5\r
+  adcs    r4, r4, r4\r
+  adcs    r0, lr, r5\r
+  adcs    r1, ip, r4\r
+  movcs   r5, r0\r
+  movcs   r4, r1\r
+  adcs    r5, r5, r5\r
+  adcs    r4, r4, r4\r
+  adcs    r0, lr, r5\r
+  adcs    r1, ip, r4\r
+  movcs   r5, r0\r
+  movcs   r4, r1\r
+  adcs    r5, r5, r5\r
+  adcs    r4, r4, r4\r
+  adcs    r0, lr, r5\r
+  adcs    r1, ip, r4\r
+  movcs   r5, r0\r
+  movcs   r4, r1\r
+  sub     r2, r2, #4      // 0x4\r
+  adcs    r5, r5, r5\r
+  adcs    r4, r4, r4\r
+  adcs    r0, lr, r5\r
+  adcs    r1, ip, r4\r
+  tst     r2, r2\r
+  movcs   r5, r0\r
+  movcs   r4, r1\r
+  bpl     ASM_PFX(_ll_udiv_big_label3)\r
+ASM_PFX(_ll_udiv_big_label4):\r
+  mov     r1, #0  // 0x0\r
+  mov     r2, r5, lsr r6\r
+  bic     r5, r5, r2, lsl r6\r
+  adcs    r0, r5, r5\r
+  adc     r1, r1, #0      // 0x0\r
+  movs    lr, r3, lsl r6\r
+  mov     r3, r4, lsr r6\r
+  bic     r4, r4, r3, lsl r6\r
+  adc     r1, r1, #0      // 0x0\r
+  adds    r0, r0, lr\r
+  orr     r2, r2, r4, ror r6\r
+  adc     r1, r1, #0      // 0x0\r
+  ldmia   sp!, {r4, r5, r6, pc}\r
+  \r
+ASM_PFX(_ll_udiv_ginormous):\r
+  subs    r2, r5, lr\r
+  mov     r1, #0  // 0x0\r
+  sbcs    r3, r4, ip\r
+  adc     r0, r1, r1\r
+  movcc   r2, r5\r
+  movcc   r3, r4\r
+  ldmia   sp!, {r4, r5, r6, pc}\r
+  \r
+ASM_PFX(_ll_div0):\r
+  ldmia   sp!, {r4, r5, r6, lr}\r
+  mov     r0, #0  // 0x0\r
+  mov     r1, #0  // 0x0\r
+  b       ASM_PFX(__aeabi_ldiv0)\r
+  \r
+ASM_PFX(__aeabi_ldiv0):\r
+  bx      r14\r
+\r
+\r
index d792342e1f078efa274758a0a6e20bcc65629f7a..393794c13af76001fcb167864d13ede42095f816 100644 (file)
-//------------------------------------------------------------------------------ 
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-
-
-    EXPORT  __aeabi_uldivmod
-
-    AREA  Uldivmod, CODE, READONLY
-
-;        
-;UINT64
-;EFIAPI
-;__aeabi_uldivmod (
-;  IN  UINT64   Dividend  
-;  IN  UINT64   Divisor
-;  )
-;
-__aeabi_uldivmod
-  stmdb   sp!, {r4, r5, r6, lr}
-  mov     r4, r1
-  mov     r5, r0
-  mov     r6, #0  ; 0x0
-  orrs    ip, r3, r2, lsr #31
-  bne     __aeabi_uldivmod_label1
-  tst     r2, r2
-  beq     _ll_div0
-  movs    ip, r2, lsr #15
-  addeq   r6, r6, #16     ; 0x10
-  mov     ip, r2, lsl r6
-  movs    lr, ip, lsr #23
-  moveq   ip, ip, lsl #8
-  addeq   r6, r6, #8      ; 0x8
-  movs    lr, ip, lsr #27
-  moveq   ip, ip, lsl #4
-  addeq   r6, r6, #4      ; 0x4
-  movs    lr, ip, lsr #29
-  moveq   ip, ip, lsl #2
-  addeq   r6, r6, #2      ; 0x2
-  movs    lr, ip, lsr #30
-  moveq   ip, ip, lsl #1
-  addeq   r6, r6, #1      ; 0x1
-  b       _ll_udiv_small
-__aeabi_uldivmod_label1
-  tst     r3, #-2147483648        ; 0x80000000
-  bne     __aeabi_uldivmod_label2
-  movs    ip, r3, lsr #15
-  addeq   r6, r6, #16     ; 0x10
-  mov     ip, r3, lsl r6
-  movs    lr, ip, lsr #23
-  moveq   ip, ip, lsl #8
-  addeq   r6, r6, #8      ; 0x8
-  movs    lr, ip, lsr #27
-  moveq   ip, ip, lsl #4
-  addeq   r6, r6, #4      ; 0x4
-  movs    lr, ip, lsr #29
-  moveq   ip, ip, lsl #2
-  addeq   r6, r6, #2      ; 0x2
-  movs    lr, ip, lsr #30
-  addeq   r6, r6, #1      ; 0x1
-  rsb     r3, r6, #32     ; 0x20
-  moveq   ip, ip, lsl #1
-  orr     ip, ip, r2, lsr r3
-  mov     lr, r2, lsl r6
-  b       _ll_udiv_big
-__aeabi_uldivmod_label2
-  mov     ip, r3
-  mov     lr, r2
-  b       _ll_udiv_ginormous
-  
-_ll_udiv_small
-  cmp     r4, ip, lsl #1
-  mov     r3, #0  ; 0x0
-  subcs   r4, r4, ip, lsl #1
-  addcs   r3, r3, #2      ; 0x2
-  cmp     r4, ip
-  subcs   r4, r4, ip
-  adcs    r3, r3, #0      ; 0x0
-  add     r2, r6, #32     ; 0x20
-  cmp     r2, #32 ; 0x20
-  rsb     ip, ip, #0      ; 0x0
-  bcc     _ll_udiv_small_label1
-  orrs    r0, r4, r5, lsr #30
-  moveq   r4, r5
-  moveq   r5, #0  ; 0x0
-  subeq   r2, r2, #32     ; 0x20
-_ll_udiv_small_label1
-  mov     r1, #0  ; 0x0
-  cmp     r2, #16 ; 0x10
-  bcc     _ll_udiv_small_label2
-  movs    r0, r4, lsr #14
-  moveq   r4, r4, lsl #16
-  addeq   r1, r1, #16     ; 0x10
-_ll_udiv_small_label2
-  sub     lr, r2, r1
-  cmp     lr, #8  ; 0x8
-  bcc     _ll_udiv_small_label3
-  movs    r0, r4, lsr #22
-  moveq   r4, r4, lsl #8
-  addeq   r1, r1, #8      ; 0x8
-_ll_udiv_small_label3
-  rsb     r0, r1, #32     ; 0x20
-  sub     r2, r2, r1
-  orr     r4, r4, r5, lsr r0
-  mov     r5, r5, lsl r1
-  cmp     r2, #1  ; 0x1
-  bcc     _ll_udiv_small_label5
-  sub     r2, r2, #1      ; 0x1
-  and     r0, r2, #7      ; 0x7
-  eor     r0, r0, #7      ; 0x7
-  adds    r0, r0, r0, lsl #1
-  add     pc, pc, r0, lsl #2
-  nop                     ; (mov r0,r0)
-_ll_udiv_small_label4
-  adcs    r5, r5, r5
-  adcs    r4, ip, r4, lsl #1
-  rsbcc   r4, ip, r4
-  adcs    r5, r5, r5
-  adcs    r4, ip, r4, lsl #1
-  rsbcc   r4, ip, r4
-  adcs    r5, r5, r5
-  adcs    r4, ip, r4, lsl #1
-  rsbcc   r4, ip, r4
-  adcs    r5, r5, r5
-  adcs    r4, ip, r4, lsl #1
-  rsbcc   r4, ip, r4
-  adcs    r5, r5, r5
-  adcs    r4, ip, r4, lsl #1
-  rsbcc   r4, ip, r4
-  adcs    r5, r5, r5
-  adcs    r4, ip, r4, lsl #1
-  rsbcc   r4, ip, r4
-  adcs    r5, r5, r5
-  adcs    r4, ip, r4, lsl #1
-  rsbcc   r4, ip, r4
-  adcs    r5, r5, r5
-  adcs    r4, ip, r4, lsl #1
-  sub     r2, r2, #8      ; 0x8
-  tst     r2, r2
-  rsbcc   r4, ip, r4
-  bpl     _ll_udiv_small_label4
-_ll_udiv_small_label5
-  mov     r2, r4, lsr r6
-  bic     r4, r4, r2, lsl r6
-  adcs    r0, r5, r5
-  adc     r1, r4, r4
-  add     r1, r1, r3, lsl r6
-  mov     r3, #0  ; 0x0
-  ldmia   sp!, {r4, r5, r6, pc}
-  
-_ll_udiv_big
-  subs    r0, r5, lr
-  mov     r3, #0  ; 0x0
-  sbcs    r1, r4, ip
-  movcs   r5, r0
-  movcs   r4, r1
-  adcs    r3, r3, #0      ; 0x0
-  subs    r0, r5, lr
-  sbcs    r1, r4, ip
-  movcs   r5, r0
-  movcs   r4, r1
-  adcs    r3, r3, #0      ; 0x0
-  subs    r0, r5, lr
-  sbcs    r1, r4, ip
-  movcs   r5, r0
-  movcs   r4, r1
-  adcs    r3, r3, #0      ; 0x0
-  mov     r1, #0  ; 0x0
-  rsbs    lr, lr, #0      ; 0x0
-  rsc     ip, ip, #0      ; 0x0
-  cmp     r6, #16 ; 0x10
-  bcc     _ll_udiv_big_label1
-  movs    r0, r4, lsr #14
-  moveq   r4, r4, lsl #16
-  addeq   r1, r1, #16     ; 0x10
-_ll_udiv_big_label1
-  sub     r2, r6, r1
-  cmp     r2, #8  ; 0x8
-  bcc     _ll_udiv_big_label2
-  movs    r0, r4, lsr #22
-  moveq   r4, r4, lsl #8
-  addeq   r1, r1, #8      ; 0x8
-_ll_udiv_big_label2
-  rsb     r0, r1, #32     ; 0x20
-  sub     r2, r6, r1
-  orr     r4, r4, r5, lsr r0
-  mov     r5, r5, lsl r1
-  cmp     r2, #1  ; 0x1
-  bcc     _ll_udiv_big_label4
-  sub     r2, r2, #1      ; 0x1
-  and     r0, r2, #3      ; 0x3
-  rsb     r0, r0, #3      ; 0x3
-  adds    r0, r0, r0, lsl #1
-  add     pc, pc, r0, lsl #3
-  nop                     ; (mov r0,r0)
-_ll_udiv_big_label3
-  adcs    r5, r5, r5
-  adcs    r4, r4, r4
-  adcs    r0, lr, r5
-  adcs    r1, ip, r4
-  movcs   r5, r0
-  movcs   r4, r1
-  adcs    r5, r5, r5
-  adcs    r4, r4, r4
-  adcs    r0, lr, r5
-  adcs    r1, ip, r4
-  movcs   r5, r0
-  movcs   r4, r1
-  adcs    r5, r5, r5
-  adcs    r4, r4, r4
-  adcs    r0, lr, r5
-  adcs    r1, ip, r4
-  movcs   r5, r0
-  movcs   r4, r1
-  sub     r2, r2, #4      ; 0x4
-  adcs    r5, r5, r5
-  adcs    r4, r4, r4
-  adcs    r0, lr, r5
-  adcs    r1, ip, r4
-  tst     r2, r2
-  movcs   r5, r0
-  movcs   r4, r1
-  bpl     _ll_udiv_big_label3
-_ll_udiv_big_label4
-  mov     r1, #0  ; 0x0
-  mov     r2, r5, lsr r6
-  bic     r5, r5, r2, lsl r6
-  adcs    r0, r5, r5
-  adc     r1, r1, #0      ; 0x0
-  movs    lr, r3, lsl r6
-  mov     r3, r4, lsr r6
-  bic     r4, r4, r3, lsl r6
-  adc     r1, r1, #0      ; 0x0
-  adds    r0, r0, lr
-  orr     r2, r2, r4, ror r6
-  adc     r1, r1, #0      ; 0x0
-  ldmia   sp!, {r4, r5, r6, pc}
-  
-_ll_udiv_ginormous
-  subs    r2, r5, lr
-  mov     r1, #0  ; 0x0
-  sbcs    r3, r4, ip
-  adc     r0, r1, r1
-  movcc   r2, r5
-  movcc   r3, r4
-  ldmia   sp!, {r4, r5, r6, pc}
-  
-_ll_div0
-  ldmia   sp!, {r4, r5, r6, lr}
-  mov     r0, #0  ; 0x0
-  mov     r1, #0  ; 0x0
-  b       __aeabi_ldiv0
-  
-__aeabi_ldiv0
-  BX        r14
-
-  END
-
+//------------------------------------------------------------------------------ \r
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+\r
+\r
+    EXPORT  __aeabi_uldivmod\r
+\r
+    AREA  Uldivmod, CODE, READONLY\r
+\r
+;        \r
+;UINT64\r
+;EFIAPI\r
+;__aeabi_uldivmod (\r
+;  IN  UINT64   Dividend  \r
+;  IN  UINT64   Divisor\r
+;  )\r
+;\r
+__aeabi_uldivmod\r
+  stmdb   sp!, {r4, r5, r6, lr}\r
+  mov     r4, r1\r
+  mov     r5, r0\r
+  mov     r6, #0  ; 0x0\r
+  orrs    ip, r3, r2, lsr #31\r
+  bne     __aeabi_uldivmod_label1\r
+  tst     r2, r2\r
+  beq     _ll_div0\r
+  movs    ip, r2, lsr #15\r
+  addeq   r6, r6, #16     ; 0x10\r
+  mov     ip, r2, lsl r6\r
+  movs    lr, ip, lsr #23\r
+  moveq   ip, ip, lsl #8\r
+  addeq   r6, r6, #8      ; 0x8\r
+  movs    lr, ip, lsr #27\r
+  moveq   ip, ip, lsl #4\r
+  addeq   r6, r6, #4      ; 0x4\r
+  movs    lr, ip, lsr #29\r
+  moveq   ip, ip, lsl #2\r
+  addeq   r6, r6, #2      ; 0x2\r
+  movs    lr, ip, lsr #30\r
+  moveq   ip, ip, lsl #1\r
+  addeq   r6, r6, #1      ; 0x1\r
+  b       _ll_udiv_small\r
+__aeabi_uldivmod_label1\r
+  tst     r3, #-2147483648        ; 0x80000000\r
+  bne     __aeabi_uldivmod_label2\r
+  movs    ip, r3, lsr #15\r
+  addeq   r6, r6, #16     ; 0x10\r
+  mov     ip, r3, lsl r6\r
+  movs    lr, ip, lsr #23\r
+  moveq   ip, ip, lsl #8\r
+  addeq   r6, r6, #8      ; 0x8\r
+  movs    lr, ip, lsr #27\r
+  moveq   ip, ip, lsl #4\r
+  addeq   r6, r6, #4      ; 0x4\r
+  movs    lr, ip, lsr #29\r
+  moveq   ip, ip, lsl #2\r
+  addeq   r6, r6, #2      ; 0x2\r
+  movs    lr, ip, lsr #30\r
+  addeq   r6, r6, #1      ; 0x1\r
+  rsb     r3, r6, #32     ; 0x20\r
+  moveq   ip, ip, lsl #1\r
+  orr     ip, ip, r2, lsr r3\r
+  mov     lr, r2, lsl r6\r
+  b       _ll_udiv_big\r
+__aeabi_uldivmod_label2\r
+  mov     ip, r3\r
+  mov     lr, r2\r
+  b       _ll_udiv_ginormous\r
+  \r
+_ll_udiv_small\r
+  cmp     r4, ip, lsl #1\r
+  mov     r3, #0  ; 0x0\r
+  subcs   r4, r4, ip, lsl #1\r
+  addcs   r3, r3, #2      ; 0x2\r
+  cmp     r4, ip\r
+  subcs   r4, r4, ip\r
+  adcs    r3, r3, #0      ; 0x0\r
+  add     r2, r6, #32     ; 0x20\r
+  cmp     r2, #32 ; 0x20\r
+  rsb     ip, ip, #0      ; 0x0\r
+  bcc     _ll_udiv_small_label1\r
+  orrs    r0, r4, r5, lsr #30\r
+  moveq   r4, r5\r
+  moveq   r5, #0  ; 0x0\r
+  subeq   r2, r2, #32     ; 0x20\r
+_ll_udiv_small_label1\r
+  mov     r1, #0  ; 0x0\r
+  cmp     r2, #16 ; 0x10\r
+  bcc     _ll_udiv_small_label2\r
+  movs    r0, r4, lsr #14\r
+  moveq   r4, r4, lsl #16\r
+  addeq   r1, r1, #16     ; 0x10\r
+_ll_udiv_small_label2\r
+  sub     lr, r2, r1\r
+  cmp     lr, #8  ; 0x8\r
+  bcc     _ll_udiv_small_label3\r
+  movs    r0, r4, lsr #22\r
+  moveq   r4, r4, lsl #8\r
+  addeq   r1, r1, #8      ; 0x8\r
+_ll_udiv_small_label3\r
+  rsb     r0, r1, #32     ; 0x20\r
+  sub     r2, r2, r1\r
+  orr     r4, r4, r5, lsr r0\r
+  mov     r5, r5, lsl r1\r
+  cmp     r2, #1  ; 0x1\r
+  bcc     _ll_udiv_small_label5\r
+  sub     r2, r2, #1      ; 0x1\r
+  and     r0, r2, #7      ; 0x7\r
+  eor     r0, r0, #7      ; 0x7\r
+  adds    r0, r0, r0, lsl #1\r
+  add     pc, pc, r0, lsl #2\r
+  nop                     ; (mov r0,r0)\r
+_ll_udiv_small_label4\r
+  adcs    r5, r5, r5\r
+  adcs    r4, ip, r4, lsl #1\r
+  rsbcc   r4, ip, r4\r
+  adcs    r5, r5, r5\r
+  adcs    r4, ip, r4, lsl #1\r
+  rsbcc   r4, ip, r4\r
+  adcs    r5, r5, r5\r
+  adcs    r4, ip, r4, lsl #1\r
+  rsbcc   r4, ip, r4\r
+  adcs    r5, r5, r5\r
+  adcs    r4, ip, r4, lsl #1\r
+  rsbcc   r4, ip, r4\r
+  adcs    r5, r5, r5\r
+  adcs    r4, ip, r4, lsl #1\r
+  rsbcc   r4, ip, r4\r
+  adcs    r5, r5, r5\r
+  adcs    r4, ip, r4, lsl #1\r
+  rsbcc   r4, ip, r4\r
+  adcs    r5, r5, r5\r
+  adcs    r4, ip, r4, lsl #1\r
+  rsbcc   r4, ip, r4\r
+  adcs    r5, r5, r5\r
+  adcs    r4, ip, r4, lsl #1\r
+  sub     r2, r2, #8      ; 0x8\r
+  tst     r2, r2\r
+  rsbcc   r4, ip, r4\r
+  bpl     _ll_udiv_small_label4\r
+_ll_udiv_small_label5\r
+  mov     r2, r4, lsr r6\r
+  bic     r4, r4, r2, lsl r6\r
+  adcs    r0, r5, r5\r
+  adc     r1, r4, r4\r
+  add     r1, r1, r3, lsl r6\r
+  mov     r3, #0  ; 0x0\r
+  ldmia   sp!, {r4, r5, r6, pc}\r
+  \r
+_ll_udiv_big\r
+  subs    r0, r5, lr\r
+  mov     r3, #0  ; 0x0\r
+  sbcs    r1, r4, ip\r
+  movcs   r5, r0\r
+  movcs   r4, r1\r
+  adcs    r3, r3, #0      ; 0x0\r
+  subs    r0, r5, lr\r
+  sbcs    r1, r4, ip\r
+  movcs   r5, r0\r
+  movcs   r4, r1\r
+  adcs    r3, r3, #0      ; 0x0\r
+  subs    r0, r5, lr\r
+  sbcs    r1, r4, ip\r
+  movcs   r5, r0\r
+  movcs   r4, r1\r
+  adcs    r3, r3, #0      ; 0x0\r
+  mov     r1, #0  ; 0x0\r
+  rsbs    lr, lr, #0      ; 0x0\r
+  rsc     ip, ip, #0      ; 0x0\r
+  cmp     r6, #16 ; 0x10\r
+  bcc     _ll_udiv_big_label1\r
+  movs    r0, r4, lsr #14\r
+  moveq   r4, r4, lsl #16\r
+  addeq   r1, r1, #16     ; 0x10\r
+_ll_udiv_big_label1\r
+  sub     r2, r6, r1\r
+  cmp     r2, #8  ; 0x8\r
+  bcc     _ll_udiv_big_label2\r
+  movs    r0, r4, lsr #22\r
+  moveq   r4, r4, lsl #8\r
+  addeq   r1, r1, #8      ; 0x8\r
+_ll_udiv_big_label2\r
+  rsb     r0, r1, #32     ; 0x20\r
+  sub     r2, r6, r1\r
+  orr     r4, r4, r5, lsr r0\r
+  mov     r5, r5, lsl r1\r
+  cmp     r2, #1  ; 0x1\r
+  bcc     _ll_udiv_big_label4\r
+  sub     r2, r2, #1      ; 0x1\r
+  and     r0, r2, #3      ; 0x3\r
+  rsb     r0, r0, #3      ; 0x3\r
+  adds    r0, r0, r0, lsl #1\r
+  add     pc, pc, r0, lsl #3\r
+  nop                     ; (mov r0,r0)\r
+_ll_udiv_big_label3\r
+  adcs    r5, r5, r5\r
+  adcs    r4, r4, r4\r
+  adcs    r0, lr, r5\r
+  adcs    r1, ip, r4\r
+  movcs   r5, r0\r
+  movcs   r4, r1\r
+  adcs    r5, r5, r5\r
+  adcs    r4, r4, r4\r
+  adcs    r0, lr, r5\r
+  adcs    r1, ip, r4\r
+  movcs   r5, r0\r
+  movcs   r4, r1\r
+  adcs    r5, r5, r5\r
+  adcs    r4, r4, r4\r
+  adcs    r0, lr, r5\r
+  adcs    r1, ip, r4\r
+  movcs   r5, r0\r
+  movcs   r4, r1\r
+  sub     r2, r2, #4      ; 0x4\r
+  adcs    r5, r5, r5\r
+  adcs    r4, r4, r4\r
+  adcs    r0, lr, r5\r
+  adcs    r1, ip, r4\r
+  tst     r2, r2\r
+  movcs   r5, r0\r
+  movcs   r4, r1\r
+  bpl     _ll_udiv_big_label3\r
+_ll_udiv_big_label4\r
+  mov     r1, #0  ; 0x0\r
+  mov     r2, r5, lsr r6\r
+  bic     r5, r5, r2, lsl r6\r
+  adcs    r0, r5, r5\r
+  adc     r1, r1, #0      ; 0x0\r
+  movs    lr, r3, lsl r6\r
+  mov     r3, r4, lsr r6\r
+  bic     r4, r4, r3, lsl r6\r
+  adc     r1, r1, #0      ; 0x0\r
+  adds    r0, r0, lr\r
+  orr     r2, r2, r4, ror r6\r
+  adc     r1, r1, #0      ; 0x0\r
+  ldmia   sp!, {r4, r5, r6, pc}\r
+  \r
+_ll_udiv_ginormous\r
+  subs    r2, r5, lr\r
+  mov     r1, #0  ; 0x0\r
+  sbcs    r3, r4, ip\r
+  adc     r0, r1, r1\r
+  movcc   r2, r5\r
+  movcc   r3, r4\r
+  ldmia   sp!, {r4, r5, r6, pc}\r
+  \r
+_ll_div0\r
+  ldmia   sp!, {r4, r5, r6, lr}\r
+  mov     r0, #0  ; 0x0\r
+  mov     r1, #0  ; 0x0\r
+  b       __aeabi_ldiv0\r
+  \r
+__aeabi_ldiv0\r
+  BX        r14\r
+\r
+  END\r
+\r
index 4876743339c83c4f67dfdb7e2a0485b2ffef97bf..feac60195dec5bbd10cd5324ba8341f37c3620a0 100755 (executable)
@@ -1,43 +1,43 @@
-/** @file
-
-  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-  
-  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 "Llvm_int_lib.h"
-#include <Library/BaseLib.h>
-
-
-UINT32 __udivsi3(UINT32 n, UINT32 d);
-UINT32 __umodsi3(UINT32 a, UINT32 b);
-
-
-UINT64 
-__aeabi_uidivmod(unsigned numerator, unsigned denominator)
-{
-  UINT64  Return;
-
-  Return = __udivsi3 (numerator, denominator);
-  Return |= LShiftU64 (__umodsi3 (numerator, denominator), 32);
-
-  return Return;
-}
-
-unsigned
-__aeabi_uidiv (unsigned n, unsigned d) 
-{
-  return __udivsi3 (n, d);
-}
-
-
-
-
-
+/** @file\r
+\r
+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "Llvm_int_lib.h"\r
+#include <Library/BaseLib.h>\r
+\r
+\r
+UINT32 __udivsi3(UINT32 n, UINT32 d);\r
+UINT32 __umodsi3(UINT32 a, UINT32 b);\r
+\r
+\r
+UINT64 \r
+__aeabi_uidivmod(unsigned numerator, unsigned denominator)\r
+{\r
+  UINT64  Return;\r
+\r
+  Return = __udivsi3 (numerator, denominator);\r
+  Return |= LShiftU64 (__umodsi3 (numerator, denominator), 32);\r
+\r
+  return Return;\r
+}\r
+\r
+unsigned\r
+__aeabi_uidiv (unsigned n, unsigned d) \r
+{\r
+  return __udivsi3 (n, d);\r
+}\r
+\r
+\r
+\r
+\r
+\r
index 75bb240888aa6f2f2497b77bd72f68580267cee5..6e23057c258b7f0ec839636c727c642a1c97667c 100644 (file)
@@ -1,29 +1,29 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__umoddi3)
-  
-ASM_PFX(__umoddi3):
-  stmfd  sp!, {r7, lr}
-  add  r7, sp, #0
-  sub  sp, sp, #16
-  add  ip, sp, #8
-  str  ip, [sp, #0]
-  bl  ASM_PFX(__udivmoddi4)
-  ldrd  r0, [sp, #8]
-  sub  sp, r7, #0
-  ldmfd  sp!, {r7, pc}
-
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__umoddi3)\r
+  \r
+ASM_PFX(__umoddi3):\r
+  stmfd  sp!, {r7, lr}\r
+  add  r7, sp, #0\r
+  sub  sp, sp, #16\r
+  add  ip, sp, #8\r
+  str  ip, [sp, #0]\r
+  bl  ASM_PFX(__udivmoddi4)\r
+  ldrd  r0, [sp, #8]\r
+  sub  sp, r7, #0\r
+  ldmfd  sp!, {r7, pc}\r
+\r
index 125af09b6465e72284dd39c7c97004eae1640027..ebd769755a4edb133245d034513506d5d01da38f 100644 (file)
@@ -1,72 +1,72 @@
-/** @file
-  Compiler intrinsic for 64-bit unsigned mod, ported from LLVM code.
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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.
-
-**/
-/**
-  University of Illinois/NCSA
-  Open Source License
-  
-  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
-  All rights reserved.
-  
-  Developed by:
-  
-      LLVM Team
-  
-      University of Illinois at Urbana-Champaign
-  
-      http://llvm.org
-  
-  Permission is hereby granted, free of charge, to any person obtaining a copy of
-  this software and associated documentation files (the "Software"), to deal with
-  the Software without restriction, including without limitation the rights to
-  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-  of the Software, and to permit persons to whom the Software is furnished to do
-  so, subject to the following conditions:
-  
-      * Redistributions of source code must retain the above copyright notice,
-        this list of conditions and the following disclaimers.
-  
-      * Redistributions in binary form must reproduce the above copyright notice,
-        this list of conditions and the following disclaimers in the
-        documentation and/or other materials provided with the distribution.
-  
-      * Neither the names of the LLVM Team, University of Illinois at
-        Urbana-Champaign, nor the names of its contributors may be used to
-        endorse or promote products derived from this Software without specific
-        prior written permission.
-  
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-  SOFTWARE.
-**/
-
-
-#include "Llvm_int_lib.h"
-
-UINT64 __udivmoddi4(UINT64 a, UINT64 b, UINT64* rem);
-
-// Returns: a % b
-
-UINT64
-__umoddi3(UINT64 a, UINT64 b)
-{
-    UINT64 r;
-    __udivmoddi4(a, b, &r);
-    return r;
-}
-
+/** @file\r
+  Compiler intrinsic for 64-bit unsigned mod, ported from LLVM code.\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+/**\r
+  University of Illinois/NCSA\r
+  Open Source License\r
+  \r
+  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.\r
+  All rights reserved.\r
+  \r
+  Developed by:\r
+  \r
+      LLVM Team\r
+  \r
+      University of Illinois at Urbana-Champaign\r
+  \r
+      http://llvm.org\r
+  \r
+  Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+  this software and associated documentation files (the "Software"), to deal with\r
+  the Software without restriction, including without limitation the rights to\r
+  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+  of the Software, and to permit persons to whom the Software is furnished to do\r
+  so, subject to the following conditions:\r
+  \r
+      * Redistributions of source code must retain the above copyright notice,\r
+        this list of conditions and the following disclaimers.\r
+  \r
+      * Redistributions in binary form must reproduce the above copyright notice,\r
+        this list of conditions and the following disclaimers in the\r
+        documentation and/or other materials provided with the distribution.\r
+  \r
+      * Neither the names of the LLVM Team, University of Illinois at\r
+        Urbana-Champaign, nor the names of its contributors may be used to\r
+        endorse or promote products derived from this Software without specific\r
+        prior written permission.\r
+  \r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE\r
+  SOFTWARE.\r
+**/\r
+\r
+\r
+#include "Llvm_int_lib.h"\r
+\r
+UINT64 __udivmoddi4(UINT64 a, UINT64 b, UINT64* rem);\r
+\r
+// Returns: a % b\r
+\r
+UINT64\r
+__umoddi3(UINT64 a, UINT64 b)\r
+{\r
+    UINT64 r;\r
+    __udivmoddi4(a, b, &r);\r
+    return r;\r
+}\r
+\r
index 9d0f17e6e9823bf39f19a1d29003b3b79c2e8e24..bd32fd12441acfabe18cecc279d0ca07a6e054db 100644 (file)
@@ -1,28 +1,28 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__umodsi3)
-  
-ASM_PFX(__umodsi3):
-  stmfd  sp!, {r4, r5, r7, lr}
-  add  r7, sp, #8
-  mov  r5, r0
-  mov  r4, r1
-  bl   ASM_PFX(__udivsi3)
-  mul  r0, r4, r0
-  rsb  r0, r0, r5
-  ldmfd  sp!, {r4, r5, r7, pc}
-
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+  .text\r
+  .align 2\r
+  GCC_ASM_EXPORT(__umodsi3)\r
+  \r
+ASM_PFX(__umodsi3):\r
+  stmfd  sp!, {r4, r5, r7, lr}\r
+  add  r7, sp, #8\r
+  mov  r5, r0\r
+  mov  r4, r1\r
+  bl   ASM_PFX(__udivsi3)\r
+  mul  r0, r4, r0\r
+  rsb  r0, r0, r5\r
+  ldmfd  sp!, {r4, r5, r7, pc}\r
+\r
index 5e302d6193b215e06400095c472c3273f7cbd40c..e3aa4da87c350d4e8d9b9a9dce67e24c44179b67 100644 (file)
@@ -1,68 +1,68 @@
-/** @file
-  Compiler intrinsic for 32-bit unsigned mod, ported from LLVM code.
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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.
-
-**/
-/**
-  University of Illinois/NCSA
-  Open Source License
-  
-  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
-  All rights reserved.
-  
-  Developed by:
-  
-      LLVM Team
-  
-      University of Illinois at Urbana-Champaign
-  
-      http://llvm.org
-  
-  Permission is hereby granted, free of charge, to any person obtaining a copy of
-  this software and associated documentation files (the "Software"), to deal with
-  the Software without restriction, including without limitation the rights to
-  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-  of the Software, and to permit persons to whom the Software is furnished to do
-  so, subject to the following conditions:
-  
-      * Redistributions of source code must retain the above copyright notice,
-        this list of conditions and the following disclaimers.
-  
-      * Redistributions in binary form must reproduce the above copyright notice,
-        this list of conditions and the following disclaimers in the
-        documentation and/or other materials provided with the distribution.
-  
-      * Neither the names of the LLVM Team, University of Illinois at
-        Urbana-Champaign, nor the names of its contributors may be used to
-        endorse or promote products derived from this Software without specific
-        prior written permission.
-  
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-  SOFTWARE.
-**/
-
-
-#include "Llvm_int_lib.h"
-
-
-// Returns: a % b
-
-UINT32
-__umodsi3(UINT32 a, UINT32 b)
-{
-    return a - (a / b) * b;
-}
+/** @file\r
+  Compiler intrinsic for 32-bit unsigned mod, ported from LLVM code.\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+/**\r
+  University of Illinois/NCSA\r
+  Open Source License\r
+  \r
+  Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.\r
+  All rights reserved.\r
+  \r
+  Developed by:\r
+  \r
+      LLVM Team\r
+  \r
+      University of Illinois at Urbana-Champaign\r
+  \r
+      http://llvm.org\r
+  \r
+  Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+  this software and associated documentation files (the "Software"), to deal with\r
+  the Software without restriction, including without limitation the rights to\r
+  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+  of the Software, and to permit persons to whom the Software is furnished to do\r
+  so, subject to the following conditions:\r
+  \r
+      * Redistributions of source code must retain the above copyright notice,\r
+        this list of conditions and the following disclaimers.\r
+  \r
+      * Redistributions in binary form must reproduce the above copyright notice,\r
+        this list of conditions and the following disclaimers in the\r
+        documentation and/or other materials provided with the distribution.\r
+  \r
+      * Neither the names of the LLVM Team, University of Illinois at\r
+        Urbana-Champaign, nor the names of its contributors may be used to\r
+        endorse or promote products derived from this Software without specific\r
+        prior written permission.\r
+  \r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE\r
+  SOFTWARE.\r
+**/\r
+\r
+\r
+#include "Llvm_int_lib.h"\r
+\r
+\r
+// Returns: a % b\r
+\r
+UINT32\r
+__umodsi3(UINT32 a, UINT32 b)\r
+{\r
+    return a - (a / b) * b;\r
+}\r
index a456ea25006ebe2940d9fbaf729cea6deed5b8ce..0b79e3416b399290b420a901f589605abcfc0336 100644 (file)
@@ -1,68 +1,68 @@
-//------------------------------------------------------------------------------ 
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-
-    EXPORT  __aeabi_uwrite4
-    EXPORT  __aeabi_uwrite8
-
-    AREA  Uwrite4, CODE, READONLY
-
-;
-;UINT32
-;EFIAPI
-;__aeabi_uwrite4 (
-;  IN UINT32 Data,
-;  IN VOID   *Pointer
-;  );
-;
-;
-__aeabi_uwrite4
-    mov     r2, r0, lsr #8
-    strb    r0, [r1]
-    strb    r2, [r1, #1]
-    mov     r2, r0, lsr #16
-    strb    r2, [r1, #2]
-    mov     r2, r0, lsr #24
-    strb    r2, [r1, #3]
-    bx      lr
-
-;
-;UINT64
-;EFIAPI
-;__aeabi_uwrite8 (
-;  IN UINT64 Data,    //r0-r1
-;  IN VOID   *Pointer //r2
-;  );
-;
-;
-__aeabi_uwrite8
-    mov     r3, r0, lsr #8
-    strb    r0, [r2]
-    strb    r3, [r2, #1]
-    mov     r3, r0, lsr #16
-    strb    r3, [r2, #2]
-    mov     r3, r0, lsr #24
-    strb    r3, [r2, #3]
-
-    mov     r3, r1, lsr #8
-    strb    r1, [r2, #4]
-    strb    r3, [r2, #5]
-    mov     r3, r1, lsr #16
-    strb    r3, [r2, #6]
-    mov     r3, r1, lsr #24
-    strb    r3, [r2, #7]
-    bx      lr
-
-    END
-
+//------------------------------------------------------------------------------ \r
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+\r
+    EXPORT  __aeabi_uwrite4\r
+    EXPORT  __aeabi_uwrite8\r
+\r
+    AREA  Uwrite4, CODE, READONLY\r
+\r
+;\r
+;UINT32\r
+;EFIAPI\r
+;__aeabi_uwrite4 (\r
+;  IN UINT32 Data,\r
+;  IN VOID   *Pointer\r
+;  );\r
+;\r
+;\r
+__aeabi_uwrite4\r
+    mov     r2, r0, lsr #8\r
+    strb    r0, [r1]\r
+    strb    r2, [r1, #1]\r
+    mov     r2, r0, lsr #16\r
+    strb    r2, [r1, #2]\r
+    mov     r2, r0, lsr #24\r
+    strb    r2, [r1, #3]\r
+    bx      lr\r
+\r
+;\r
+;UINT64\r
+;EFIAPI\r
+;__aeabi_uwrite8 (\r
+;  IN UINT64 Data,    //r0-r1\r
+;  IN VOID   *Pointer //r2\r
+;  );\r
+;\r
+;\r
+__aeabi_uwrite8\r
+    mov     r3, r0, lsr #8\r
+    strb    r0, [r2]\r
+    strb    r3, [r2, #1]\r
+    mov     r3, r0, lsr #16\r
+    strb    r3, [r2, #2]\r
+    mov     r3, r0, lsr #24\r
+    strb    r3, [r2, #3]\r
+\r
+    mov     r3, r1, lsr #8\r
+    strb    r1, [r2, #4]\r
+    strb    r3, [r2, #5]\r
+    mov     r3, r1, lsr #16\r
+    strb    r3, [r2, #6]\r
+    mov     r3, r1, lsr #24\r
+    strb    r3, [r2, #7]\r
+    bx      lr\r
+\r
+    END\r
+\r
index 9b116f8901543e110cc7ddbd82fa5b5e7b356295..e6e728af651d50e44991100bf3e53f8dc432ec24 100644 (file)
-#/** @file
-#  Base Library implementation.
-#
-#  Copyright (c) 2009, Apple Inc. All rights reserved.<BR>
-#  Copyright (c) 2011, ARM Limited. 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                      = CompilerIntrinsicsLib
-  FILE_GUID                      = 855274FA-3575-4C20-9709-C031DC5589FA
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = CompilerIntrinsicsLib 
-
-
-[Sources.common]
-
-
-[Sources.ARM]
-  Arm/mullu.asm        | RVCT
-  Arm/switch.asm       | RVCT
-  Arm/llsr.asm         | RVCT
-  Arm/memcpy.asm       | RVCT
-  Arm/memcpy4.asm      | RVCT
-  Arm/memset.asm       | RVCT
-  Arm/memmove.asm      | RVCT
-  Arm/uread.asm        | RVCT
-  Arm/uwrite.asm       | RVCT
-  Arm/lasr.asm         | RVCT
-  Arm/llsl.asm         | RVCT
-  Arm/div.asm          | RVCT
-  Arm/uldiv.asm        | RVCT
-  Arm/ldivmod.asm      | RVCT
-  
-
-#
-# Move .c to .s to work around LLVM issues
-#
-#  Arm/ashrdi3.c    | GCC
-#  Arm/ashldi3.c    | GCC
-#  Arm/divdi3.c     | GCC
-#  Arm/divsi3.c     | GCC
-#  Arm/lshrdi3.c    | GCC
-  Arm/ashrdi3.S    | GCC
-  Arm/ashldi3.S    | GCC
-  Arm/div.S        | GCC
-  Arm/divdi3.S     | GCC
-  Arm/divsi3.S     | GCC
-  Arm/lshrdi3.S    | GCC
-
-  Arm/memcpy.S     | GCC
-  Arm/memset.S     | GCC
-  
-#  Arm/modsi3.c     | GCC
-#  Arm/moddi3.c     | GCC
-#  Arm/muldi3.c     | GCC  
-  Arm/modsi3.S     | GCC
-  Arm/moddi3.S     | GCC
-  Arm/muldi3.S     | GCC
-  Arm/mullu.S      | GCC  
-
-#  Arm/udivsi3.c    | GCC
-#  Arm/umodsi3.c    | GCC
-#  Arm/udivdi3.c    | GCC
-#  Arm/umoddi3.c    | GCC
-#  Arm/udivmoddi4.c | GCC
-  Arm/udivsi3.S    | GCC
-  Arm/umodsi3.S    | GCC
-  Arm/udivdi3.S    | GCC
-  Arm/umoddi3.S    | GCC
-  Arm/udivmoddi4.S | GCC
-
-#  Arm/clzsi2.c     | GCC
-#  Arm/ctzsi2.c     | GCC
-#  Arm/ucmpdi2.c    | GCC
-  Arm/clzsi2.S     | GCC
-  Arm/ctzsi2.S     | GCC
-  Arm/ucmpdi2.S    | GCC
-  Arm/switch8.S    | GCC
-  Arm/switchu8.S   | GCC
-  Arm/switch16.S   | GCC
-  Arm/switch32.S   | GCC
-
-  Arm/sourcery.S   | GCC
-  Arm/uldiv.S      | GCC
-  Arm/ldivmod.S    | GCC
-
-[Packages]
-  MdePkg/MdePkg.dec
-
-[LibraryClasses]
-
+#/** @file\r
+#  Base Library implementation.\r
+#\r
+#  Copyright (c) 2009, Apple Inc. All rights reserved.<BR>\r
+#  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = CompilerIntrinsicsLib\r
+  FILE_GUID                      = 855274FA-3575-4C20-9709-C031DC5589FA\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = CompilerIntrinsicsLib \r
+\r
+\r
+[Sources.common]\r
+\r
+\r
+[Sources.ARM]\r
+  Arm/mullu.asm        | RVCT\r
+  Arm/switch.asm       | RVCT\r
+  Arm/llsr.asm         | RVCT\r
+  Arm/memcpy.asm       | RVCT\r
+  Arm/memcpy4.asm      | RVCT\r
+  Arm/memset.asm       | RVCT\r
+  Arm/memmove.asm      | RVCT\r
+  Arm/uread.asm        | RVCT\r
+  Arm/uwrite.asm       | RVCT\r
+  Arm/lasr.asm         | RVCT\r
+  Arm/llsl.asm         | RVCT\r
+  Arm/div.asm          | RVCT\r
+  Arm/uldiv.asm        | RVCT\r
+  Arm/ldivmod.asm      | RVCT\r
+  \r
+\r
+#\r
+# Move .c to .s to work around LLVM issues\r
+#\r
+#  Arm/ashrdi3.c    | GCC\r
+#  Arm/ashldi3.c    | GCC\r
+#  Arm/divdi3.c     | GCC\r
+#  Arm/divsi3.c     | GCC\r
+#  Arm/lshrdi3.c    | GCC\r
+  Arm/ashrdi3.S    | GCC\r
+  Arm/ashldi3.S    | GCC\r
+  Arm/div.S        | GCC\r
+  Arm/divdi3.S     | GCC\r
+  Arm/divsi3.S     | GCC\r
+  Arm/lshrdi3.S    | GCC\r
+\r
+  Arm/memcpy.S     | GCC\r
+  Arm/memset.S     | GCC\r
+  \r
+#  Arm/modsi3.c     | GCC\r
+#  Arm/moddi3.c     | GCC\r
+#  Arm/muldi3.c     | GCC  \r
+  Arm/modsi3.S     | GCC\r
+  Arm/moddi3.S     | GCC\r
+  Arm/muldi3.S     | GCC\r
+  Arm/mullu.S      | GCC  \r
+\r
+#  Arm/udivsi3.c    | GCC\r
+#  Arm/umodsi3.c    | GCC\r
+#  Arm/udivdi3.c    | GCC\r
+#  Arm/umoddi3.c    | GCC\r
+#  Arm/udivmoddi4.c | GCC\r
+  Arm/udivsi3.S    | GCC\r
+  Arm/umodsi3.S    | GCC\r
+  Arm/udivdi3.S    | GCC\r
+  Arm/umoddi3.S    | GCC\r
+  Arm/udivmoddi4.S | GCC\r
+\r
+#  Arm/clzsi2.c     | GCC\r
+#  Arm/ctzsi2.c     | GCC\r
+#  Arm/ucmpdi2.c    | GCC\r
+  Arm/clzsi2.S     | GCC\r
+  Arm/ctzsi2.S     | GCC\r
+  Arm/ucmpdi2.S    | GCC\r
+  Arm/switch8.S    | GCC\r
+  Arm/switchu8.S   | GCC\r
+  Arm/switch16.S   | GCC\r
+  Arm/switch32.S   | GCC\r
+\r
+  Arm/sourcery.S   | GCC\r
+  Arm/uldiv.S      | GCC\r
+  Arm/ldivmod.S    | GCC\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+\r
index 3c1738676671d15f6ce6e5e187a3396d9febd24e..d92acfeacbfd6cb1d07a6829492e18e7720dffb7 100644 (file)
-#------------------------------------------------------------------------------
-#
-# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-# Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
-#
-# 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 <Library/PcdLib.h>
-
-/*
-
-This is the stack constructed by the exception handler (low address to high address)
-                # R0 - IFAR is EFI_SYSTEM_CONTEXT for ARM
-  Reg   Offset
-  ===   ======
-  R0    0x00    # stmfd     SP!,{R0-R12}
-  R1    0x04
-  R2    0x08
-  R3    0x0c
-  R4    0x10
-  R5    0x14
-  R6    0x18
-  R7    0x1c
-  R8    0x20
-  R9    0x24
-  R10   0x28
-  R11   0x2c
-  R12   0x30
-  SP    0x34    # reserved via adding 0x20 (32) to the SP
-  LR    0x38
-  PC    0x3c
-  CPSR  0x40
-  DFSR  0x44
-  DFAR  0x48
-  IFSR  0x4c
-  IFAR  0x50
-
-  LR    0x54    # SVC Link register (we need to restore it)
-
-  LR    0x58    # pushed by srsfd
-  CPSR  0x5c
-
- */
-
-GCC_ASM_EXPORT(DebugAgentVectorTable)
-GCC_ASM_IMPORT(DefaultExceptionHandler)
-
-.text
-#if !defined(__APPLE__)
-.fpu neon    @ makes vpush/vpop assemble
-#endif
-.align 5
-
-
-//
-// This code gets copied to the ARM vector table
-// ExceptionHandlersStart - ExceptionHandlersEnd gets copied
-//
-ASM_PFX(DebugAgentVectorTable):
-  b ASM_PFX(ResetEntry)
-  b ASM_PFX(UndefinedInstructionEntry)
-  b ASM_PFX(SoftwareInterruptEntry)
-  b ASM_PFX(PrefetchAbortEntry)
-  b ASM_PFX(DataAbortEntry)
-  b ASM_PFX(ReservedExceptionEntry)
-  b ASM_PFX(IrqEntry)
-  b ASM_PFX(FiqEntry)
-
-ASM_PFX(ResetEntry):
-  srsdb     #0x13!                    @ Store return state on SVC stack
-                                      @ We are already in SVC mode
-
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-  
-  mov       R0,#0                     @ ExceptionType
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(UndefinedInstructionEntry):
-  sub       LR, LR, #4                @ Only -2 for Thumb, adjust in CommonExceptionEntry
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       R0,#1                     @ ExceptionType
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(SoftwareInterruptEntry):
-  sub       LR, LR, #4                @ Only -2 for Thumb, adjust in CommonExceptionEntry
-  srsdb     #0x13!                    @ Store return state on SVC stack
-                                      @ We are already in SVC mode
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       R0,#2                     @ ExceptionType
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(PrefetchAbortEntry):
-  sub       LR,LR,#4
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       R0,#3                     @ ExceptionType
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(DataAbortEntry):
-  sub       LR,LR,#8
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       R0,#4
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(ReservedExceptionEntry):
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       R0,#5
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(IrqEntry):
-  sub       LR,LR,#4
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       R0,#6                     @ ExceptionType
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(FiqEntry):
-  sub       LR,LR,#4
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-                                      @ Since we have already switch to SVC R8_fiq - R12_fiq
-                                      @ never get used or saved
-  mov       R0,#7                     @ ExceptionType
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-//
-// This gets patched by the C code that patches in the vector table
-//
-ASM_PFX(CommonExceptionEntry):
-  .word       ASM_PFX(AsmCommonExceptionEntry)
-
-ASM_PFX(ExceptionHandlersEnd):
-
-//
-// This code runs from CpuDxe driver loaded address. It is patched into
-// CommonExceptionEntry.
-//
-ASM_PFX(AsmCommonExceptionEntry):
-  mrc       p15, 0, R1, c6, c0, 2   @ Read IFAR
-  str       R1, [SP, #0x50]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFAR
-
-  mrc       p15, 0, R1, c5, c0, 1   @ Read IFSR
-  str       R1, [SP, #0x4c]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFSR
-
-  mrc       p15, 0, R1, c6, c0, 0   @ Read DFAR
-  str       R1, [SP, #0x48]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFAR
-
-  mrc       p15, 0, R1, c5, c0, 0   @ Read DFSR
-  str       R1, [SP, #0x44]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFSR
-
-  ldr       R1, [SP, #0x5c]         @ srsdb saved pre-exception CPSR on the stack
-  str       R1, [SP, #0x40]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.CPSR
-
-  add       R2, SP, #0x38           @ Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR
-  and       R3, R1, #0x1f           @ Check CPSR to see if User or System Mode
-  cmp       R3, #0x1f               @ if ((CPSR == 0x10) || (CPSR == 0x1df))
-  cmpne     R3, #0x10               @
-  stmeqed   R2, {lr}^               @   save unbanked lr
-                                    @ else
-  stmneed   R2, {lr}                @   save SVC lr
-
-
-  ldr       R5, [SP, #0x58]         @ PC is the LR pushed by srsfd
-                                    @ Check to see if we have to adjust for Thumb entry
-  sub       r4, r0, #1              @ if (ExceptionType == 1 || ExceptionType ==2)) {
-  cmp       r4, #1                  @   // UND & SVC have differnt LR adjust for Thumb
-  bhi       NoAdjustNeeded
-
-  tst       r1, #0x20               @   if ((CPSR & T)) == T) {  // Thumb Mode on entry
-  addne     R5, R5, #2              @     PC += 2@
-  str       R5,[SP,#0x58]           @ Update LR value pused by srsfd
-
-NoAdjustNeeded:
-
-  str       R5, [SP, #0x3c]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.PC
-
-  sub       R1, SP, #0x60           @ We pused 0x60 bytes on the stack
-  str       R1, [SP, #0x34]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.SP
-
-                                    @ R0 is ExceptionType
-  mov       R1,SP                   @ R1 is SystemContext
-
-#if (FixedPcdGet32(PcdVFPEnabled))
-  vpush     {d0-d15}                @ save vstm registers in case they are used in optimizations
-#endif
-
-/*
-VOID
-EFIAPI
-DefaultExceptionHandler (
-  IN     EFI_EXCEPTION_TYPE           ExceptionType,   R0
-  IN OUT EFI_SYSTEM_CONTEXT           SystemContext    R1
-  )
-
-*/
-  blx       ASM_PFX(DefaultExceptionHandler)  @ Call exception handler
-
-#if (FixedPcdGet32(PcdVFPEnabled))
-  vpop      {d0-d15}
-#endif
-
-  ldr       R1, [SP, #0x4c]         @ Restore EFI_SYSTEM_CONTEXT_ARM.IFSR
-  mcr       p15, 0, R1, c5, c0, 1   @ Write IFSR
-
-  ldr       R1, [SP, #0x44]         @ sRestore EFI_SYSTEM_CONTEXT_ARM.DFSR
-  mcr       p15, 0, R1, c5, c0, 0   @ Write DFSR
-
-  ldr       R1,[SP,#0x3c]           @ EFI_SYSTEM_CONTEXT_ARM.PC
-  str       R1,[SP,#0x58]           @ Store it back to srsfd stack slot so it can be restored
-
-  ldr       R1,[SP,#0x40]           @ EFI_SYSTEM_CONTEXT_ARM.CPSR
-  str       R1,[SP,#0x5c]           @ Store it back to srsfd stack slot so it can be restored
-
-  add       R3, SP, #0x54           @ Make R3 point to SVC LR saved on entry
-  add       R2, SP, #0x38           @ Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR
-  and       R1, R1, #0x1f           @ Check to see if User or System Mode
-  cmp       R1, #0x1f               @ if ((CPSR == 0x10) || (CPSR == 0x1f))
-  cmpne     R1, #0x10               @
-  ldmeqed   R2, {lr}^               @   restore unbanked lr
-                                    @ else
-  ldmneed   R3, {lr}                @   restore SVC lr, via ldmfd SP!, {LR}
-
-  ldmfd     SP!,{R0-R12}            @ Restore general purpose registers
-                                    @ Exception handler can not change SP
-
-  add       SP,SP,#0x20             @ Clear out the remaining stack space
-  ldmfd     SP!,{LR}                @ restore the link register for this context
-  rfefd     SP!                     @ return from exception via srsfd stack slot
-
+#------------------------------------------------------------------------------\r
+#\r
+# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+#include <Library/PcdLib.h>\r
+\r
+/*\r
+\r
+This is the stack constructed by the exception handler (low address to high address)\r
+                # R0 - IFAR is EFI_SYSTEM_CONTEXT for ARM\r
+  Reg   Offset\r
+  ===   ======\r
+  R0    0x00    # stmfd     SP!,{R0-R12}\r
+  R1    0x04\r
+  R2    0x08\r
+  R3    0x0c\r
+  R4    0x10\r
+  R5    0x14\r
+  R6    0x18\r
+  R7    0x1c\r
+  R8    0x20\r
+  R9    0x24\r
+  R10   0x28\r
+  R11   0x2c\r
+  R12   0x30\r
+  SP    0x34    # reserved via adding 0x20 (32) to the SP\r
+  LR    0x38\r
+  PC    0x3c\r
+  CPSR  0x40\r
+  DFSR  0x44\r
+  DFAR  0x48\r
+  IFSR  0x4c\r
+  IFAR  0x50\r
+\r
+  LR    0x54    # SVC Link register (we need to restore it)\r
+\r
+  LR    0x58    # pushed by srsfd\r
+  CPSR  0x5c\r
+\r
+ */\r
+\r
+GCC_ASM_EXPORT(DebugAgentVectorTable)\r
+GCC_ASM_IMPORT(DefaultExceptionHandler)\r
+\r
+.text\r
+#if !defined(__APPLE__)\r
+.fpu neon    @ makes vpush/vpop assemble\r
+#endif\r
+.align 5\r
+\r
+\r
+//\r
+// This code gets copied to the ARM vector table\r
+// ExceptionHandlersStart - ExceptionHandlersEnd gets copied\r
+//\r
+ASM_PFX(DebugAgentVectorTable):\r
+  b ASM_PFX(ResetEntry)\r
+  b ASM_PFX(UndefinedInstructionEntry)\r
+  b ASM_PFX(SoftwareInterruptEntry)\r
+  b ASM_PFX(PrefetchAbortEntry)\r
+  b ASM_PFX(DataAbortEntry)\r
+  b ASM_PFX(ReservedExceptionEntry)\r
+  b ASM_PFX(IrqEntry)\r
+  b ASM_PFX(FiqEntry)\r
+\r
+ASM_PFX(ResetEntry):\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+                                      @ We are already in SVC mode\r
+\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+  \r
+  mov       R0,#0                     @ ExceptionType\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(UndefinedInstructionEntry):\r
+  sub       LR, LR, #4                @ Only -2 for Thumb, adjust in CommonExceptionEntry\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       R0,#1                     @ ExceptionType\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(SoftwareInterruptEntry):\r
+  sub       LR, LR, #4                @ Only -2 for Thumb, adjust in CommonExceptionEntry\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+                                      @ We are already in SVC mode\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       R0,#2                     @ ExceptionType\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(PrefetchAbortEntry):\r
+  sub       LR,LR,#4\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       R0,#3                     @ ExceptionType\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(DataAbortEntry):\r
+  sub       LR,LR,#8\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       R0,#4\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(ReservedExceptionEntry):\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       R0,#5\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(IrqEntry):\r
+  sub       LR,LR,#4\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       R0,#6                     @ ExceptionType\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(FiqEntry):\r
+  sub       LR,LR,#4\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+                                      @ Since we have already switch to SVC R8_fiq - R12_fiq\r
+                                      @ never get used or saved\r
+  mov       R0,#7                     @ ExceptionType\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+//\r
+// This gets patched by the C code that patches in the vector table\r
+//\r
+ASM_PFX(CommonExceptionEntry):\r
+  .word       ASM_PFX(AsmCommonExceptionEntry)\r
+\r
+ASM_PFX(ExceptionHandlersEnd):\r
+\r
+//\r
+// This code runs from CpuDxe driver loaded address. It is patched into\r
+// CommonExceptionEntry.\r
+//\r
+ASM_PFX(AsmCommonExceptionEntry):\r
+  mrc       p15, 0, R1, c6, c0, 2   @ Read IFAR\r
+  str       R1, [SP, #0x50]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFAR\r
+\r
+  mrc       p15, 0, R1, c5, c0, 1   @ Read IFSR\r
+  str       R1, [SP, #0x4c]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFSR\r
+\r
+  mrc       p15, 0, R1, c6, c0, 0   @ Read DFAR\r
+  str       R1, [SP, #0x48]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFAR\r
+\r
+  mrc       p15, 0, R1, c5, c0, 0   @ Read DFSR\r
+  str       R1, [SP, #0x44]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFSR\r
+\r
+  ldr       R1, [SP, #0x5c]         @ srsdb saved pre-exception CPSR on the stack\r
+  str       R1, [SP, #0x40]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.CPSR\r
+\r
+  add       R2, SP, #0x38           @ Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR\r
+  and       R3, R1, #0x1f           @ Check CPSR to see if User or System Mode\r
+  cmp       R3, #0x1f               @ if ((CPSR == 0x10) || (CPSR == 0x1df))\r
+  cmpne     R3, #0x10               @\r
+  stmeqed   R2, {lr}^               @   save unbanked lr\r
+                                    @ else\r
+  stmneed   R2, {lr}                @   save SVC lr\r
+\r
+\r
+  ldr       R5, [SP, #0x58]         @ PC is the LR pushed by srsfd\r
+                                    @ Check to see if we have to adjust for Thumb entry\r
+  sub       r4, r0, #1              @ if (ExceptionType == 1 || ExceptionType ==2)) {\r
+  cmp       r4, #1                  @   // UND & SVC have differnt LR adjust for Thumb\r
+  bhi       NoAdjustNeeded\r
+\r
+  tst       r1, #0x20               @   if ((CPSR & T)) == T) {  // Thumb Mode on entry\r
+  addne     R5, R5, #2              @     PC += 2@\r
+  str       R5,[SP,#0x58]           @ Update LR value pused by srsfd\r
+\r
+NoAdjustNeeded:\r
+\r
+  str       R5, [SP, #0x3c]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.PC\r
+\r
+  sub       R1, SP, #0x60           @ We pused 0x60 bytes on the stack\r
+  str       R1, [SP, #0x34]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.SP\r
+\r
+                                    @ R0 is ExceptionType\r
+  mov       R1,SP                   @ R1 is SystemContext\r
+\r
+#if (FixedPcdGet32(PcdVFPEnabled))\r
+  vpush     {d0-d15}                @ save vstm registers in case they are used in optimizations\r
+#endif\r
+\r
+/*\r
+VOID\r
+EFIAPI\r
+DefaultExceptionHandler (\r
+  IN     EFI_EXCEPTION_TYPE           ExceptionType,   R0\r
+  IN OUT EFI_SYSTEM_CONTEXT           SystemContext    R1\r
+  )\r
+\r
+*/\r
+  blx       ASM_PFX(DefaultExceptionHandler)  @ Call exception handler\r
+\r
+#if (FixedPcdGet32(PcdVFPEnabled))\r
+  vpop      {d0-d15}\r
+#endif\r
+\r
+  ldr       R1, [SP, #0x4c]         @ Restore EFI_SYSTEM_CONTEXT_ARM.IFSR\r
+  mcr       p15, 0, R1, c5, c0, 1   @ Write IFSR\r
+\r
+  ldr       R1, [SP, #0x44]         @ sRestore EFI_SYSTEM_CONTEXT_ARM.DFSR\r
+  mcr       p15, 0, R1, c5, c0, 0   @ Write DFSR\r
+\r
+  ldr       R1,[SP,#0x3c]           @ EFI_SYSTEM_CONTEXT_ARM.PC\r
+  str       R1,[SP,#0x58]           @ Store it back to srsfd stack slot so it can be restored\r
+\r
+  ldr       R1,[SP,#0x40]           @ EFI_SYSTEM_CONTEXT_ARM.CPSR\r
+  str       R1,[SP,#0x5c]           @ Store it back to srsfd stack slot so it can be restored\r
+\r
+  add       R3, SP, #0x54           @ Make R3 point to SVC LR saved on entry\r
+  add       R2, SP, #0x38           @ Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR\r
+  and       R1, R1, #0x1f           @ Check to see if User or System Mode\r
+  cmp       R1, #0x1f               @ if ((CPSR == 0x10) || (CPSR == 0x1f))\r
+  cmpne     R1, #0x10               @\r
+  ldmeqed   R2, {lr}^               @   restore unbanked lr\r
+                                    @ else\r
+  ldmneed   R3, {lr}                @   restore SVC lr, via ldmfd SP!, {LR}\r
+\r
+  ldmfd     SP!,{R0-R12}            @ Restore general purpose registers\r
+                                    @ Exception handler can not change SP\r
+\r
+  add       SP,SP,#0x20             @ Clear out the remaining stack space\r
+  ldmfd     SP!,{LR}                @ restore the link register for this context\r
+  rfefd     SP!                     @ return from exception via srsfd stack slot\r
+\r
index ab57bbd5675ce539cd4a6115d1591a839542e12c..c1f717e5bda1b7dfe49f6924bd610429b92cf875 100755 (executable)
@@ -1,39 +1,39 @@
-#/** @file
-# PeCoff extra action libary for DXE phase that run Unix emulator.
-#
-# Lib to provide memory journal status code reporting Routines
-# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
-# Portions copyright (c) 2010, Apple Inc. All rights reserved.<BR>
-# 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                      = DebugUnixPeCoffExtraActionLib
-  FILE_GUID                      = C3E9448E-1726-42fb-9368-41F75B038C0C
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = PeCoffExtraActionLib
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-#  VALID_ARCHITECTURES           = ARM
-#
-
-[Sources.common]
-  DebugPeCoffExtraActionLib.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-
-[LibraryClasses]
-  DebugLib
+#/** @file\r
+# PeCoff extra action libary for DXE phase that run Unix emulator.\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2010, Apple Inc. All rights reserved.<BR>\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DebugUnixPeCoffExtraActionLib\r
+  FILE_GUID                      = C3E9448E-1726-42fb-9368-41F75B038C0C\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeCoffExtraActionLib\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = ARM\r
+#\r
+\r
+[Sources.common]\r
+  DebugPeCoffExtraActionLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
index d1f815828dbab1f9ac584ed2d5ccd1465f8d3a3a..b5e9fd8e90f2af3ebd0db0a838d932feb5f5a064 100644 (file)
@@ -44,4 +44,4 @@
   \r
   \r
 [Depex]\r
   \r
   \r
 [Depex]\r
-  gEfiCpuArchProtocolGuid AND gVirtualUncachedPagesProtocolGuid
\ No newline at end of file
+  gEfiCpuArchProtocolGuid AND gVirtualUncachedPagesProtocolGuid\r
\ No newline at end of file
index e634d39b9e457e635f53efd46baa68292890cf72..3be0237a3689eefc5723d605bdde1add05a92dd1 100644 (file)
@@ -1,41 +1,41 @@
-#/** @file
-# PeCoff extra action libary for DXE phase that run Unix emulator.
-#
-# Lib to provide memory journal status code reporting Routines
-# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
-# Portions copyright (c) 2010, Apple Inc. All rights reserved.<BR>
-# 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                      = RvdUnixPeCoffExtraActionLib
-  FILE_GUID                      = 5EDEB7E7-EA55-4E92-8216-335AC98A3B11
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = PeCoffExtraActionLib
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-#  VALID_ARCHITECTURES           = ARM
-#
-
-[Sources.common]
-  RvdPeCoffExtraActionLib.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  ArmPkg/ArmPkg.dec
-
-[LibraryClasses]
-  DebugLib
-  SemihostLib
+#/** @file\r
+# PeCoff extra action libary for DXE phase that run Unix emulator.\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2010, Apple Inc. All rights reserved.<BR>\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = RvdUnixPeCoffExtraActionLib\r
+  FILE_GUID                      = 5EDEB7E7-EA55-4E92-8216-335AC98A3B11\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeCoffExtraActionLib\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = ARM\r
+#\r
+\r
+[Sources.common]\r
+  RvdPeCoffExtraActionLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  SemihostLib\r
index 2d33664f7da00bec8a8235946623ea756b5db3b9..4aa886182fed7a41738bcd4dbeb2062ec65ccfa8 100755 (executable)
@@ -1,41 +1,41 @@
-#------------------------------------------------------------------------------ 
-#
-# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-.text
-.align 2
-
-.globl ASM_PFX(GccSemihostCall)
-INTERWORK_FUNC(GccSemihostCall)
-
-/*
-  Semihosting operation request mechanism
-  
-  SVC  0x123456  in ARM state (for all architectures)
-  SVC  0xAB in Thumb state (excluding ARMv7-M)
-  BKPT 0xAB for ARMv7-M (Thumb-2 only)
-  
-  R0 - operation type 
-  R1 - block containing all other parametes
-  
-  lr - must be saved as svc instruction will cause an svc exception and write 
-       the svc lr register. That happens to be the one we are using, so we must
-       save it or we will not be able to return. 
- */
-ASM_PFX(GccSemihostCall):
+#------------------------------------------------------------------------------ \r
+#\r
+# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+.text\r
+.align 2\r
+\r
+.globl ASM_PFX(GccSemihostCall)\r
+INTERWORK_FUNC(GccSemihostCall)\r
+\r
+/*\r
+  Semihosting operation request mechanism\r
+  \r
+  SVC  0x123456  in ARM state (for all architectures)\r
+  SVC  0xAB in Thumb state (excluding ARMv7-M)\r
+  BKPT 0xAB for ARMv7-M (Thumb-2 only)\r
+  \r
+  R0 - operation type \r
+  R1 - block containing all other parametes\r
+  \r
+  lr - must be saved as svc instruction will cause an svc exception and write \r
+       the svc lr register. That happens to be the one we are using, so we must\r
+       save it or we will not be able to return. \r
+ */\r
+ASM_PFX(GccSemihostCall):\r
   stmfd   sp!, {lr} \r
   stmfd   sp!, {lr} \r
-  svc     #0x123456  
+  svc     #0x123456  \r
   ldmfd   sp!, {lr}\r
   ldmfd   sp!, {lr}\r
-  bx      lr
-
-
+  bx      lr\r
+\r
+\r
index f8a76528f152f11d8d148294e88ca42d2451e852..02836ca281aff6027c5ac90a64a8a117cfb14ed5 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __SEMIHOST_PRIVATE_H__
-#define __SEMIHOST_PRIVATE_H__
-
-typedef struct {
-  CHAR8   *FileName;
-  UINT32  Mode;
-  UINT32  NameLength;
-} SEMIHOST_FILE_OPEN_BLOCK;
-
-typedef struct {
-  UINT32  Handle;
-  VOID    *Buffer;
-  UINT32  Length;
-} SEMIHOST_FILE_READ_WRITE_BLOCK;
-
-typedef struct {
-  UINT32  Handle;
-  UINT32  Location;
-} SEMIHOST_FILE_SEEK_BLOCK;
-
-typedef struct {
-  CHAR8   *FileName;
-  UINT32  NameLength;
-} SEMIHOST_FILE_REMOVE_BLOCK;
-
-typedef struct {
-  CHAR8   *CommandLine;
-  UINT32  CommandLength;
-} SEMIHOST_SYSTEM_BLOCK;
-
-#if defined(__CC_ARM) 
-
-#if defined(__thumb__)
-#define SWI 0xAB
-#else
-#define SWI 0x123456
-#endif
-
-#define SEMIHOST_SUPPORTED  TRUE
-
-__swi(SWI)
-INT32
-_Semihost_SYS_OPEN(
-  IN UINTN                    SWI_0x01,
-  IN SEMIHOST_FILE_OPEN_BLOCK *OpenBlock
-  );
-
-__swi(SWI)
-INT32
-_Semihost_SYS_CLOSE(
-  IN UINTN  SWI_0x02,
-  IN UINT32 *Handle
-  );
-
-__swi(SWI)
-VOID
-_Semihost_SYS_WRITEC(
-  IN UINTN    SWI_0x03,
-  IN CHAR8    *Character
-  );
-
-__swi(SWI)
-VOID
-_Semihost_SYS_WRITE0(
-  IN UINTN SWI_0x04,
-  IN CHAR8 *String
-  );
-
-__swi(SWI)
-UINT32
-_Semihost_SYS_WRITE(
-  IN     UINTN                          SWI_0x05,
-  IN OUT SEMIHOST_FILE_READ_WRITE_BLOCK *WriteBlock
-  );
-
-__swi(SWI)
-UINT32
-_Semihost_SYS_READ(
-  IN     UINTN                          SWI_0x06,
-  IN OUT SEMIHOST_FILE_READ_WRITE_BLOCK *ReadBlock
-  );
-
-__swi(SWI)
-CHAR8
-_Semihost_SYS_READC(
-  IN     UINTN SWI_0x07,
-  IN     UINTN Zero
-  );
-
-__swi(SWI)
-INT32
-_Semihost_SYS_SEEK(
-  IN UINTN                    SWI_0x0A,
-  IN SEMIHOST_FILE_SEEK_BLOCK *SeekBlock
-  );
-
-__swi(SWI)
-INT32
-_Semihost_SYS_FLEN(
-  IN UINTN  SWI_0x0C,
-  IN UINT32 *Handle
-  );
-
-__swi(SWI)
-UINT32
-_Semihost_SYS_REMOVE(
-  IN UINTN                      SWI_0x0E,
-  IN SEMIHOST_FILE_REMOVE_BLOCK *RemoveBlock
-  );
-
-__swi(SWI)
-UINT32
-_Semihost_SYS_SYSTEM(
-  IN UINTN                 SWI_0x12,
-  IN SEMIHOST_SYSTEM_BLOCK *SystemBlock
-  );
-
-#define Semihost_SYS_OPEN(OpenBlock)        _Semihost_SYS_OPEN(0x01, OpenBlock)
-#define Semihost_SYS_CLOSE(Handle)          _Semihost_SYS_CLOSE(0x02, Handle)
-#define Semihost_SYS_WRITE0(String)         _Semihost_SYS_WRITE0(0x04, String)
-#define Semihost_SYS_WRITEC(Character)      _Semihost_SYS_WRITEC(0x03, Character)
-#define Semihost_SYS_WRITE(WriteBlock)      _Semihost_SYS_WRITE(0x05, WriteBlock)
-#define Semihost_SYS_READ(ReadBlock)        _Semihost_SYS_READ(0x06, ReadBlock)
-#define Semihost_SYS_READC()                _Semihost_SYS_READC(0x07, 0)
-#define Semihost_SYS_SEEK(SeekBlock)        _Semihost_SYS_SEEK(0x0A, SeekBlock)
-#define Semihost_SYS_FLEN(Handle)           _Semihost_SYS_FLEN(0x0C, Handle)
-#define Semihost_SYS_REMOVE(RemoveBlock)    _Semihost_SYS_REMOVE(0x0E, RemoveBlock)
-#define Semihost_SYS_SYSTEM(SystemBlock)    _Semihost_SYS_SYSTEM(0x12, SystemBlock)
-
-#elif defined(__GNUC__) // __CC_ARM
-
-#define SEMIHOST_SUPPORTED  TRUE
-
-UINT32
-GccSemihostCall (
-  IN UINT32   Operation,
-  IN UINTN    SystemBlockAddress
-  ); // __attribute__ ((interrupt ("SVC")));
-
-#define Semihost_SYS_OPEN(OpenBlock)        GccSemihostCall(0x01, (UINTN)(OpenBlock))
-#define Semihost_SYS_CLOSE(Handle)          GccSemihostCall(0x02, (UINTN)(Handle))
-#define Semihost_SYS_WRITE0(String)         GccSemihostCall(0x04, (UINTN)(String))
-#define Semihost_SYS_WRITEC(Character)      GccSemihostCall(0x03, (UINTN)(Character))
-#define Semihost_SYS_WRITE(WriteBlock)      GccSemihostCall(0x05, (UINTN)(WriteBlock))
-#define Semihost_SYS_READ(ReadBlock)        GccSemihostCall(0x06, (UINTN)(ReadBlock))
-#define Semihost_SYS_READC()                GccSemihostCall(0x07, (UINTN)(0))
-#define Semihost_SYS_SEEK(SeekBlock)        GccSemihostCall(0x0A, (UINTN)(SeekBlock))
-#define Semihost_SYS_FLEN(Handle)           GccSemihostCall(0x0C, (UINTN)(Handle))
-#define Semihost_SYS_REMOVE(RemoveBlock)    GccSemihostCall(0x0E, (UINTN)(RemoveBlock))
-#define Semihost_SYS_SYSTEM(SystemBlock)    GccSemihostCall(0x12, (UINTN)(SystemBlock))
-
-#else // __CC_ARM
-
-#define SEMIHOST_SUPPORTED  FALSE
-
-#define Semihost_SYS_OPEN(OpenBlock)        (-1)
-#define Semihost_SYS_CLOSE(Handle)          (-1)
-#define Semihost_SYS_WRITE0(String)
-#define Semihost_SYS_WRITEC(Character)
-#define Semihost_SYS_WRITE(WriteBlock)      (0)
-#define Semihost_SYS_READ(ReadBlock)        ((ReadBlock)->Length)
-#define Semihost_SYS_READC()                ('x')
-#define Semihost_SYS_SEEK(SeekBlock)        (-1)
-#define Semihost_SYS_FLEN(Handle)           (-1)
-#define Semihost_SYS_REMOVE(RemoveBlock)    (-1)
-#define Semihost_SYS_SYSTEM(SystemBlock)    (-1)
-
-#endif // __CC_ARM
-
-#endif //__SEMIHOST_PRIVATE_H__
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __SEMIHOST_PRIVATE_H__\r
+#define __SEMIHOST_PRIVATE_H__\r
+\r
+typedef struct {\r
+  CHAR8   *FileName;\r
+  UINT32  Mode;\r
+  UINT32  NameLength;\r
+} SEMIHOST_FILE_OPEN_BLOCK;\r
+\r
+typedef struct {\r
+  UINT32  Handle;\r
+  VOID    *Buffer;\r
+  UINT32  Length;\r
+} SEMIHOST_FILE_READ_WRITE_BLOCK;\r
+\r
+typedef struct {\r
+  UINT32  Handle;\r
+  UINT32  Location;\r
+} SEMIHOST_FILE_SEEK_BLOCK;\r
+\r
+typedef struct {\r
+  CHAR8   *FileName;\r
+  UINT32  NameLength;\r
+} SEMIHOST_FILE_REMOVE_BLOCK;\r
+\r
+typedef struct {\r
+  CHAR8   *CommandLine;\r
+  UINT32  CommandLength;\r
+} SEMIHOST_SYSTEM_BLOCK;\r
+\r
+#if defined(__CC_ARM) \r
+\r
+#if defined(__thumb__)\r
+#define SWI 0xAB\r
+#else\r
+#define SWI 0x123456\r
+#endif\r
+\r
+#define SEMIHOST_SUPPORTED  TRUE\r
+\r
+__swi(SWI)\r
+INT32\r
+_Semihost_SYS_OPEN(\r
+  IN UINTN                    SWI_0x01,\r
+  IN SEMIHOST_FILE_OPEN_BLOCK *OpenBlock\r
+  );\r
+\r
+__swi(SWI)\r
+INT32\r
+_Semihost_SYS_CLOSE(\r
+  IN UINTN  SWI_0x02,\r
+  IN UINT32 *Handle\r
+  );\r
+\r
+__swi(SWI)\r
+VOID\r
+_Semihost_SYS_WRITEC(\r
+  IN UINTN    SWI_0x03,\r
+  IN CHAR8    *Character\r
+  );\r
+\r
+__swi(SWI)\r
+VOID\r
+_Semihost_SYS_WRITE0(\r
+  IN UINTN SWI_0x04,\r
+  IN CHAR8 *String\r
+  );\r
+\r
+__swi(SWI)\r
+UINT32\r
+_Semihost_SYS_WRITE(\r
+  IN     UINTN                          SWI_0x05,\r
+  IN OUT SEMIHOST_FILE_READ_WRITE_BLOCK *WriteBlock\r
+  );\r
+\r
+__swi(SWI)\r
+UINT32\r
+_Semihost_SYS_READ(\r
+  IN     UINTN                          SWI_0x06,\r
+  IN OUT SEMIHOST_FILE_READ_WRITE_BLOCK *ReadBlock\r
+  );\r
+\r
+__swi(SWI)\r
+CHAR8\r
+_Semihost_SYS_READC(\r
+  IN     UINTN SWI_0x07,\r
+  IN     UINTN Zero\r
+  );\r
+\r
+__swi(SWI)\r
+INT32\r
+_Semihost_SYS_SEEK(\r
+  IN UINTN                    SWI_0x0A,\r
+  IN SEMIHOST_FILE_SEEK_BLOCK *SeekBlock\r
+  );\r
+\r
+__swi(SWI)\r
+INT32\r
+_Semihost_SYS_FLEN(\r
+  IN UINTN  SWI_0x0C,\r
+  IN UINT32 *Handle\r
+  );\r
+\r
+__swi(SWI)\r
+UINT32\r
+_Semihost_SYS_REMOVE(\r
+  IN UINTN                      SWI_0x0E,\r
+  IN SEMIHOST_FILE_REMOVE_BLOCK *RemoveBlock\r
+  );\r
+\r
+__swi(SWI)\r
+UINT32\r
+_Semihost_SYS_SYSTEM(\r
+  IN UINTN                 SWI_0x12,\r
+  IN SEMIHOST_SYSTEM_BLOCK *SystemBlock\r
+  );\r
+\r
+#define Semihost_SYS_OPEN(OpenBlock)        _Semihost_SYS_OPEN(0x01, OpenBlock)\r
+#define Semihost_SYS_CLOSE(Handle)          _Semihost_SYS_CLOSE(0x02, Handle)\r
+#define Semihost_SYS_WRITE0(String)         _Semihost_SYS_WRITE0(0x04, String)\r
+#define Semihost_SYS_WRITEC(Character)      _Semihost_SYS_WRITEC(0x03, Character)\r
+#define Semihost_SYS_WRITE(WriteBlock)      _Semihost_SYS_WRITE(0x05, WriteBlock)\r
+#define Semihost_SYS_READ(ReadBlock)        _Semihost_SYS_READ(0x06, ReadBlock)\r
+#define Semihost_SYS_READC()                _Semihost_SYS_READC(0x07, 0)\r
+#define Semihost_SYS_SEEK(SeekBlock)        _Semihost_SYS_SEEK(0x0A, SeekBlock)\r
+#define Semihost_SYS_FLEN(Handle)           _Semihost_SYS_FLEN(0x0C, Handle)\r
+#define Semihost_SYS_REMOVE(RemoveBlock)    _Semihost_SYS_REMOVE(0x0E, RemoveBlock)\r
+#define Semihost_SYS_SYSTEM(SystemBlock)    _Semihost_SYS_SYSTEM(0x12, SystemBlock)\r
+\r
+#elif defined(__GNUC__) // __CC_ARM\r
+\r
+#define SEMIHOST_SUPPORTED  TRUE\r
+\r
+UINT32\r
+GccSemihostCall (\r
+  IN UINT32   Operation,\r
+  IN UINTN    SystemBlockAddress\r
+  ); // __attribute__ ((interrupt ("SVC")));\r
+\r
+#define Semihost_SYS_OPEN(OpenBlock)        GccSemihostCall(0x01, (UINTN)(OpenBlock))\r
+#define Semihost_SYS_CLOSE(Handle)          GccSemihostCall(0x02, (UINTN)(Handle))\r
+#define Semihost_SYS_WRITE0(String)         GccSemihostCall(0x04, (UINTN)(String))\r
+#define Semihost_SYS_WRITEC(Character)      GccSemihostCall(0x03, (UINTN)(Character))\r
+#define Semihost_SYS_WRITE(WriteBlock)      GccSemihostCall(0x05, (UINTN)(WriteBlock))\r
+#define Semihost_SYS_READ(ReadBlock)        GccSemihostCall(0x06, (UINTN)(ReadBlock))\r
+#define Semihost_SYS_READC()                GccSemihostCall(0x07, (UINTN)(0))\r
+#define Semihost_SYS_SEEK(SeekBlock)        GccSemihostCall(0x0A, (UINTN)(SeekBlock))\r
+#define Semihost_SYS_FLEN(Handle)           GccSemihostCall(0x0C, (UINTN)(Handle))\r
+#define Semihost_SYS_REMOVE(RemoveBlock)    GccSemihostCall(0x0E, (UINTN)(RemoveBlock))\r
+#define Semihost_SYS_SYSTEM(SystemBlock)    GccSemihostCall(0x12, (UINTN)(SystemBlock))\r
+\r
+#else // __CC_ARM\r
+\r
+#define SEMIHOST_SUPPORTED  FALSE\r
+\r
+#define Semihost_SYS_OPEN(OpenBlock)        (-1)\r
+#define Semihost_SYS_CLOSE(Handle)          (-1)\r
+#define Semihost_SYS_WRITE0(String)\r
+#define Semihost_SYS_WRITEC(Character)\r
+#define Semihost_SYS_WRITE(WriteBlock)      (0)\r
+#define Semihost_SYS_READ(ReadBlock)        ((ReadBlock)->Length)\r
+#define Semihost_SYS_READC()                ('x')\r
+#define Semihost_SYS_SEEK(SeekBlock)        (-1)\r
+#define Semihost_SYS_FLEN(Handle)           (-1)\r
+#define Semihost_SYS_REMOVE(RemoveBlock)    (-1)\r
+#define Semihost_SYS_SYSTEM(SystemBlock)    (-1)\r
+\r
+#endif // __CC_ARM\r
+\r
+#endif //__SEMIHOST_PRIVATE_H__\r
index f575a35f05426a6db10ad23bb6b050ce08bc4d60..5ec7fef3a6b0bc0b0fe755db86dfff912618ea89 100644 (file)
   Arm/SemihostLib.c\r
 \r
 \r
   Arm/SemihostLib.c\r
 \r
 \r
-[Packages]
+[Packages]\r
   MdePkg/MdePkg.dec\r
   ArmPkg/ArmPkg.dec\r
 \r
   MdePkg/MdePkg.dec\r
   ArmPkg/ArmPkg.dec\r
 \r
-[LibraryClasses]
+[LibraryClasses]\r
   BaseLib\r
   \r
 [Protocols]\r
   BaseLib\r
   \r
 [Protocols]\r
@@ -44,4 +44,4 @@
 [Guids]\r
  \r
 [Pcd]\r
 [Guids]\r
  \r
 [Pcd]\r
\ No newline at end of file
\r
\ No newline at end of file
index 4037b77941be6edb2291a0ddd4a635d6c88eaa30..a48d94eef4a227755a2f55567a284ac595e6185e 100644 (file)
@@ -39,4 +39,4 @@
   DxeServicesTableLib\r
 \r
 [Depex]\r
   DxeServicesTableLib\r
 \r
 [Depex]\r
-  gEfiCpuArchProtocolGuid    
\ No newline at end of file
+  gEfiCpuArchProtocolGuid    \r
\ No newline at end of file
index 02778a807fc37a3d4bee5975bb7689e3b50478f1..b6090431fda4801e96ee8a05ecb472e494f64565 100644 (file)
-#
-#  Copyright (c) 2011-2012, ARM Limited. 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                  = ArmPlatform
-  PLATFORM_GUID                  = 4fe82b83-9315-4ff3-8cc0-ab77ca93cb7f 
-  PLATFORM_VERSION               = 0.1
-  DSC_SPECIFICATION              = 0x00010005
-  OUTPUT_DIRECTORY               = Build/$(PLATFORM_NAME)
-  SUPPORTED_ARCHITECTURES        = ARM
-  BUILD_TARGETS                  = DEBUG|RELEASE
-  SKUID_IDENTIFIER               = DEFAULT
-  FLASH_DEFINITION               = ArmPlatformPkg/ArmPlatformPkg-2ndstage.fdf
-
-[LibraryClasses.common]
-  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf
-  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexA9Lib/ArmCortexA9Lib.inf
-  ArmPlatformLib|ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNull.inf
-
-!if $(TARGET) == RELEASE
-  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
-  UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf
-!else
-  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
-  UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf
-#  UncachedMemoryAllocationLib|ArmPkg/Library/DebugUncachedMemoryAllocationLib/DebugUncachedMemoryAllocationLib.inf
-!endif
-  DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
-  
-  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
-  SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
-  PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf
-  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
-  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
-  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
-  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
-  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf
-  CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
-
-  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
-  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
-  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
-  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
-  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
-  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
-  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
-  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
-  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
-  UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf  
-
-  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
-
-  #
-  # Assume everything is fixed at build
-  #
-  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
-  
-  # 1/123 faster than Stm or Vstm version
-  #BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
-  BaseMemoryLib|ArmPkg/Library/BaseMemoryLibStm/BaseMemoryLibStm.inf
-
-  # ARM Architectural Libraries
-  CacheMaintenanceLib|ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf
-  DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf
-  CpuExceptionHandlerLib|MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.inf
-  ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf
-  DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
-  ArmGicLib|ArmPkg/Drivers/PL390Gic/PL390GicLib.inf
-
-  SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf
-  TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
-  EfiResetSystemLib|EmbeddedPkg/Library/TemplateResetSystemLib/TemplateResetSystemLib.inf
-  RealTimeClockLib|EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf
-
-  # EBL Related Libraries  
-  EblCmdLib|ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf
-  EfiFileLib|EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf
-  EblAddExternalCommandLib|EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.inf
-  EblNetworkLib|EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.inf
-  
-  #
-  # Uncomment (and comment out the next line) For RealView Debugger. The Standard IO window 
-  # in the debugger will show load and unload commands for symbols. You can cut and paste this
-  # into the command window to load symbols. We should be able to use a script to do this, but
-  # the version of RVD I have does not support scripts accessing system memory.
-  #
-  #PeCoffExtraActionLib|ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.inf
-  PeCoffExtraActionLib|ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.inf
-  #PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf
-    
-  DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf
-  DebugAgentTimerLib|EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLibNull.inf
-
-  SemihostLib|ArmPkg/Library/SemihostLib/SemihostLib.inf  
-
-  # BDS Libraries
-  BdsLib|ArmPkg/Library/BdsLib/BdsLib.inf
-  FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf
-
-[LibraryClasses.common.SEC]
-  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf
-
-  ArmPlatformSecExtraActionLib|ArmPlatformPkg/Library/DebugSecExtraActionLib/DebugSecExtraActionLib.inf  
-  DebugAgentLib|ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.inf
-  
-  PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf
-  ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf
-  LzmaDecompressLib|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
-  MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf
-  HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf
-  PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf
-  PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf
-  PlatformPeiLib|ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf
-  MemoryInitPeiLib|ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf
-
-[LibraryClasses.common.DXE_CORE]
-  HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf
-  MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf
-  DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf
-  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
-  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
-  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf
-  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
-  PerformanceLib|MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.inf
-
-[LibraryClasses.common.DXE_DRIVER]
-  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
-  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
-  SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf
-  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf
-  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
-  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.inf
-
-[LibraryClasses.common.UEFI_APPLICATION]
-  UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf
-  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf
-  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
-  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
-
-[LibraryClasses.common.UEFI_DRIVER]
-  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
-  UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf
-  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
-  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf
-  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
-
-[LibraryClasses.common.DXE_RUNTIME_DRIVER]
-  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
-  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
-  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
-  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
-
-[LibraryClasses.ARM]
-  #
-  # It is not possible to prevent the ARM compiler for generic intrinsic functions.
-  # This library provides the instrinsic functions generate by a given compiler.
-  # [LibraryClasses.ARM] and NULL mean link this library into all ARM images.
-  #
-  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
-
-[BuildOptions]
-  XCODE:*_*_ARM_PLATFORM_FLAGS == -arch armv7
-
-  GCC:*_*_ARM_PLATFORM_FLAGS == -march=armv7-a
-
-  RVCT:*_*_ARM_PLATFORM_FLAGS == --cpu Cortex-A8
-
-################################################################################
-#
-# Pcd Section - list of all EDK II PCD Entries defined by this Platform
-#
-################################################################################
-
-[PcdsFeatureFlag.common]
-  gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|TRUE
-  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable|TRUE
-  gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable|TRUE
-  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable|TRUE
-  
-  #
-  # Control what commands are supported from the UI
-  # Turn these on and off to add features or save size
-  #  
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedMacBoot|TRUE
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedDirCmd|TRUE
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedHobCmd|TRUE
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedHwDebugCmd|TRUE
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedPciDebugCmd|TRUE
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedIoEnable|FALSE
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedScriptCmd|FALSE
-
-  gEmbeddedTokenSpaceGuid.PcdCacheEnable|TRUE
-  
-  # Use the Vector Table location in CpuDxe. We will not copy the Vector Table at PcdCpuVectorBaseAddress
-  gArmTokenSpaceGuid.PcdRelocateVectorTable|FALSE
-  
-  gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob|TRUE
-  
-  gEfiMdeModulePkgTokenSpaceGuid.PcdTurnOffUsbLegacySupport|TRUE
-
-[PcdsFixedAtBuild.common]
-  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM Platform"
-  
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"ArmPlatform"
-  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize|32
-  gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|0
-  gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000
-  gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|1000000
-  gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000
-  gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000
-  gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue|0xAF
-  gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|1
-  gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0
-  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320
-
-  # DEBUG_ASSERT_ENABLED       0x01
-  # DEBUG_PRINT_ENABLED        0x02
-  # DEBUG_CODE_ENABLED         0x04
-  # CLEAR_MEMORY_ENABLED       0x08
-  # ASSERT_BREAKPOINT_ENABLED  0x10
-  # ASSERT_DEADLOOP_ENABLED    0x20
-!if $(TARGET) == RELEASE
-  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x21
-!else
-  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2f
-!endif
-
-  #  DEBUG_INIT      0x00000001  // Initialization
-  #  DEBUG_WARN      0x00000002  // Warnings
-  #  DEBUG_LOAD      0x00000004  // Load events
-  #  DEBUG_FS        0x00000008  // EFI File system
-  #  DEBUG_POOL      0x00000010  // Alloc & Free's
-  #  DEBUG_PAGE      0x00000020  // Alloc & Free's
-  #  DEBUG_INFO      0x00000040  // Verbose
-  #  DEBUG_DISPATCH  0x00000080  // PEI/DXE Dispatchers
-  #  DEBUG_VARIABLE  0x00000100  // Variable
-  #  DEBUG_BM        0x00000400  // Boot Manager
-  #  DEBUG_BLKIO     0x00001000  // BlkIo Driver
-  #  DEBUG_NET       0x00004000  // SNI Driver
-  #  DEBUG_UNDI      0x00010000  // UNDI Driver
-  #  DEBUG_LOADFILE  0x00020000  // UNDI Driver
-  #  DEBUG_EVENT     0x00080000  // Event messages
-  #  DEBUG_ERROR     0x80000000  // Error
-  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000000F
-
-  gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07
-
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedAutomaticBootCommand|""
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedDefaultTextColor|0x07
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedMemVariableStoreSize|0x10000
-  
-  #
-  # Optional feature to help prevent EFI memory map fragments
-  # Turned on and off via: PcdPrePiProduceMemoryTypeInformationHob
-  # Values are in EFI Pages (4K). DXE Core will make sure that 
-  # at least this much of each type of memory can be allocated 
-  # from a single memory range. This way you only end up with
-  # maximum of two fragements for each type in the memory map
-  # (the memory used, and the free memory that was prereserved
-  # but not used).
-  #
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory|0
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS|0
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType|0
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData|50
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode|20
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode|400
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData|20000
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode|20
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData|0
-    
-  #
-  # ARM Pcds
-  #
-  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000000000000
-  
-  gArmTokenSpaceGuid.PcdSystemMemoryBase|0
-  gArmTokenSpaceGuid.PcdSystemMemorySize|0
-
-################################################################################
-#
-# Components Section - list of all EDK II Modules needed by this Platform
-#
-################################################################################
-[Components.common]
-  
-  #
-  # PEI Phase modules
-  #
-  ArmPlatformPkg/PrePi/PeiUniCore.inf
-
-  #
-  # DXE
-  #
-  MdeModulePkg/Core/Dxe/DxeMain.inf {
-    <LibraryClasses>
-      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
-      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf
-  }
-
-  #
-  # Architectural Protocols
-  #
-  ArmPkg/Drivers/CpuDxe/CpuDxe.inf  
-  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
-  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
-  MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
-  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
-  MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf
-  EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf  
-  
-  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf
-  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
-  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
-  
-  # Simple TextIn/TextOut for UEFI Terminal
-  EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf
-  
-  #
-  #
-  # Semi-hosting filesystem
-  #
-  ArmPkg/Filesystem/SemihostFs/SemihostFs.inf
-  
-  #
-  # FAT filesystem + GPT/MBR partitioning
-  #
-  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
-  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
-  FatPkg/EnhancedFatDxe/Fat.inf
-  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
-  
-  #
-  # Application
-  #  
-  EmbeddedPkg/Ebl/Ebl.inf
-
-  #
-  # Bds
-  #
-  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
-  ArmPlatformPkg/Bds/Bds.inf
-  
+#\r
+#  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+#\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  PLATFORM_NAME                  = ArmPlatform\r
+  PLATFORM_GUID                  = 4fe82b83-9315-4ff3-8cc0-ab77ca93cb7f \r
+  PLATFORM_VERSION               = 0.1\r
+  DSC_SPECIFICATION              = 0x00010005\r
+  OUTPUT_DIRECTORY               = Build/$(PLATFORM_NAME)\r
+  SUPPORTED_ARCHITECTURES        = ARM\r
+  BUILD_TARGETS                  = DEBUG|RELEASE\r
+  SKUID_IDENTIFIER               = DEFAULT\r
+  FLASH_DEFINITION               = ArmPlatformPkg/ArmPlatformPkg-2ndstage.fdf\r
+\r
+[LibraryClasses.common]\r
+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf\r
+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexA9Lib/ArmCortexA9Lib.inf\r
+  ArmPlatformLib|ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNull.inf\r
+\r
+!if $(TARGET) == RELEASE\r
+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
+  UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf\r
+!else\r
+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf\r
+  UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf\r
+#  UncachedMemoryAllocationLib|ArmPkg/Library/DebugUncachedMemoryAllocationLib/DebugUncachedMemoryAllocationLib.inf\r
+!endif\r
+  DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf\r
+  \r
+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf\r
+  SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf\r
+  PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf\r
+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf\r
+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf\r
+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf\r
+  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf\r
+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf\r
+  CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf\r
+\r
+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
+  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
+  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf\r
+  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf\r
+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf\r
+  UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf  \r
+\r
+  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf\r
+\r
+  #\r
+  # Assume everything is fixed at build\r
+  #\r
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  \r
+  # 1/123 faster than Stm or Vstm version\r
+  #BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf\r
+  BaseMemoryLib|ArmPkg/Library/BaseMemoryLibStm/BaseMemoryLibStm.inf\r
+\r
+  # ARM Architectural Libraries\r
+  CacheMaintenanceLib|ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf\r
+  DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf\r
+  CpuExceptionHandlerLib|MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.inf\r
+  ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf\r
+  DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf\r
+  ArmGicLib|ArmPkg/Drivers/PL390Gic/PL390GicLib.inf\r
+\r
+  SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf\r
+  TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf\r
+  EfiResetSystemLib|EmbeddedPkg/Library/TemplateResetSystemLib/TemplateResetSystemLib.inf\r
+  RealTimeClockLib|EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf\r
+\r
+  # EBL Related Libraries  \r
+  EblCmdLib|ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf\r
+  EfiFileLib|EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf\r
+  EblAddExternalCommandLib|EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.inf\r
+  EblNetworkLib|EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.inf\r
+  \r
+  #\r
+  # Uncomment (and comment out the next line) For RealView Debugger. The Standard IO window \r
+  # in the debugger will show load and unload commands for symbols. You can cut and paste this\r
+  # into the command window to load symbols. We should be able to use a script to do this, but\r
+  # the version of RVD I have does not support scripts accessing system memory.\r
+  #\r
+  #PeCoffExtraActionLib|ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.inf\r
+  PeCoffExtraActionLib|ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.inf\r
+  #PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf\r
+    \r
+  DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf\r
+  DebugAgentTimerLib|EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLibNull.inf\r
+\r
+  SemihostLib|ArmPkg/Library/SemihostLib/SemihostLib.inf  \r
+\r
+  # BDS Libraries\r
+  BdsLib|ArmPkg/Library/BdsLib/BdsLib.inf\r
+  FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf\r
+\r
+[LibraryClasses.common.SEC]\r
+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf\r
+\r
+  ArmPlatformSecExtraActionLib|ArmPlatformPkg/Library/DebugSecExtraActionLib/DebugSecExtraActionLib.inf  \r
+  DebugAgentLib|ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.inf\r
+  \r
+  PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf\r
+  ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf\r
+  LzmaDecompressLib|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf\r
+  MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf\r
+  HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf\r
+  PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf\r
+  PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf\r
+  PlatformPeiLib|ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf\r
+  MemoryInitPeiLib|ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf\r
+\r
+[LibraryClasses.common.DXE_CORE]\r
+  HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf\r
+  MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf\r
+  DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf\r
+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf\r
+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf\r
+  PerformanceLib|MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.inf\r
+\r
+[LibraryClasses.common.DXE_DRIVER]\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf\r
+  SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf\r
+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf\r
+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.inf\r
+\r
+[LibraryClasses.common.UEFI_APPLICATION]\r
+  UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf\r
+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf\r
+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf\r
+\r
+[LibraryClasses.common.UEFI_DRIVER]\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+  UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf\r
+  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf\r
+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf\r
+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
+\r
+[LibraryClasses.common.DXE_RUNTIME_DRIVER]\r
+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf\r
+\r
+[LibraryClasses.ARM]\r
+  #\r
+  # It is not possible to prevent the ARM compiler for generic intrinsic functions.\r
+  # This library provides the instrinsic functions generate by a given compiler.\r
+  # [LibraryClasses.ARM] and NULL mean link this library into all ARM images.\r
+  #\r
+  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf\r
+\r
+[BuildOptions]\r
+  XCODE:*_*_ARM_PLATFORM_FLAGS == -arch armv7\r
+\r
+  GCC:*_*_ARM_PLATFORM_FLAGS == -march=armv7-a\r
+\r
+  RVCT:*_*_ARM_PLATFORM_FLAGS == --cpu Cortex-A8\r
+\r
+################################################################################\r
+#\r
+# Pcd Section - list of all EDK II PCD Entries defined by this Platform\r
+#\r
+################################################################################\r
+\r
+[PcdsFeatureFlag.common]\r
+  gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|TRUE\r
+  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable|TRUE\r
+  gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable|TRUE\r
+  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable|TRUE\r
+  \r
+  #\r
+  # Control what commands are supported from the UI\r
+  # Turn these on and off to add features or save size\r
+  #  \r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedMacBoot|TRUE\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedDirCmd|TRUE\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedHobCmd|TRUE\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedHwDebugCmd|TRUE\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPciDebugCmd|TRUE\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedIoEnable|FALSE\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedScriptCmd|FALSE\r
+\r
+  gEmbeddedTokenSpaceGuid.PcdCacheEnable|TRUE\r
+  \r
+  # Use the Vector Table location in CpuDxe. We will not copy the Vector Table at PcdCpuVectorBaseAddress\r
+  gArmTokenSpaceGuid.PcdRelocateVectorTable|FALSE\r
+  \r
+  gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob|TRUE\r
+  \r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdTurnOffUsbLegacySupport|TRUE\r
+\r
+[PcdsFixedAtBuild.common]\r
+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM Platform"\r
+  \r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"ArmPlatform"\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize|32\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|0\r
+  gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|1000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue|0xAF\r
+  gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|1\r
+  gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0\r
+  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320\r
+\r
+  # DEBUG_ASSERT_ENABLED       0x01\r
+  # DEBUG_PRINT_ENABLED        0x02\r
+  # DEBUG_CODE_ENABLED         0x04\r
+  # CLEAR_MEMORY_ENABLED       0x08\r
+  # ASSERT_BREAKPOINT_ENABLED  0x10\r
+  # ASSERT_DEADLOOP_ENABLED    0x20\r
+!if $(TARGET) == RELEASE\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x21\r
+!else\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2f\r
+!endif\r
+\r
+  #  DEBUG_INIT      0x00000001  // Initialization\r
+  #  DEBUG_WARN      0x00000002  // Warnings\r
+  #  DEBUG_LOAD      0x00000004  // Load events\r
+  #  DEBUG_FS        0x00000008  // EFI File system\r
+  #  DEBUG_POOL      0x00000010  // Alloc & Free's\r
+  #  DEBUG_PAGE      0x00000020  // Alloc & Free's\r
+  #  DEBUG_INFO      0x00000040  // Verbose\r
+  #  DEBUG_DISPATCH  0x00000080  // PEI/DXE Dispatchers\r
+  #  DEBUG_VARIABLE  0x00000100  // Variable\r
+  #  DEBUG_BM        0x00000400  // Boot Manager\r
+  #  DEBUG_BLKIO     0x00001000  // BlkIo Driver\r
+  #  DEBUG_NET       0x00004000  // SNI Driver\r
+  #  DEBUG_UNDI      0x00010000  // UNDI Driver\r
+  #  DEBUG_LOADFILE  0x00020000  // UNDI Driver\r
+  #  DEBUG_EVENT     0x00080000  // Event messages\r
+  #  DEBUG_ERROR     0x80000000  // Error\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000000F\r
+\r
+  gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07\r
+\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedAutomaticBootCommand|""\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedDefaultTextColor|0x07\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedMemVariableStoreSize|0x10000\r
+  \r
+  #\r
+  # Optional feature to help prevent EFI memory map fragments\r
+  # Turned on and off via: PcdPrePiProduceMemoryTypeInformationHob\r
+  # Values are in EFI Pages (4K). DXE Core will make sure that \r
+  # at least this much of each type of memory can be allocated \r
+  # from a single memory range. This way you only end up with\r
+  # maximum of two fragements for each type in the memory map\r
+  # (the memory used, and the free memory that was prereserved\r
+  # but not used).\r
+  #\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory|0\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS|0\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType|0\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData|50\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode|20\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode|400\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData|20000\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode|20\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData|0\r
+    \r
+  #\r
+  # ARM Pcds\r
+  #\r
+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000000000000\r
+  \r
+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0\r
+  gArmTokenSpaceGuid.PcdSystemMemorySize|0\r
+\r
+################################################################################\r
+#\r
+# Components Section - list of all EDK II Modules needed by this Platform\r
+#\r
+################################################################################\r
+[Components.common]\r
+  \r
+  #\r
+  # PEI Phase modules\r
+  #\r
+  ArmPlatformPkg/PrePi/PeiUniCore.inf\r
+\r
+  #\r
+  # DXE\r
+  #\r
+  MdeModulePkg/Core/Dxe/DxeMain.inf {\r
+    <LibraryClasses>\r
+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf\r
+  }\r
+\r
+  #\r
+  # Architectural Protocols\r
+  #\r
+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf  \r
+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf\r
+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf\r
+  MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf\r
+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf\r
+  MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf\r
+  EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf  \r
+  \r
+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf\r
+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf\r
+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf\r
+  \r
+  # Simple TextIn/TextOut for UEFI Terminal\r
+  EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf\r
+  \r
+  #\r
+  #\r
+  # Semi-hosting filesystem\r
+  #\r
+  ArmPkg/Filesystem/SemihostFs/SemihostFs.inf\r
+  \r
+  #\r
+  # FAT filesystem + GPT/MBR partitioning\r
+  #\r
+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf\r
+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf\r
+  FatPkg/EnhancedFatDxe/Fat.inf\r
+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf\r
+  \r
+  #\r
+  # Application\r
+  #  \r
+  EmbeddedPkg/Ebl/Ebl.inf\r
+\r
+  #\r
+  # Bds\r
+  #\r
+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf\r
+  ArmPlatformPkg/Bds/Bds.inf\r
+  \r
index b669947125f758172acaf1cd0e807815954d0b1f..a88818ecbdf7b94a31e1d177e3d94fb3f364d9be 100644 (file)
-#
-#  Copyright (c) 2011, ARM Limited. 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.ArmPlatform_EFI]
-BaseAddress   = 0xEC200000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in NOR Flash.
-Size          = 0x00200000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device
-ErasePolarity = 1
-
-# This one is tricky, it must be: BlockSize * NumBlocks = Size
-BlockSize     = 0x00001000
-NumBlocks     = 0x200
-
-################################################################################
-#
-# 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|0x00200000
-gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize
-FV = FVMAIN_COMPACT
-
-
-################################################################################
-#
-# 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.FvMain]
-BlockSize          = 0x40
-NumBlocks          = 0         # This FV gets compressed so make it just big enough
-FvAlignment        = 8         # 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
-
-  INF MdeModulePkg/Core/Dxe/DxeMain.inf 
-
-  #
-  # PI DXE Drivers producing Architectural Protocols (EFI Services) 
-  #
-  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf
-  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
-  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
-  INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
-  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
-  INF MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf
-  INF EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf
-  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf
-  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
-  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
-
-  # Simple TextIn/TextOut for UEFI Terminal
-  INF EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf
-  
-  #
-  # Semi-hosting filesystem (Required the Hardware Debugger to be connected)
-  #
-  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf
-  
-  #
-  # FAT filesystem + GPT/MBR partitioning
-  #
-  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
-  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
-  INF FatPkg/EnhancedFatDxe/Fat.inf
-  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
-  
-  #
-  # UEFI application (Shell Embedded Boot Loader) 
-  #  
-  INF EmbeddedPkg/Ebl/Ebl.inf
-    
-  #
-  # Bds
-  #
-  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
-  INF ArmPlatformPkg/Bds/Bds.inf
-
-
-[FV.FVMAIN_COMPACT]
-FvAlignment        = 8
-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
-
-  INF ArmPlatformPkg/PrePi/PeiUniCore.inf
-  
-  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {
-    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {
-      SECTION FV_IMAGE = FVMAIN
-    }
-  }
-
-
-################################################################################
-#
-# 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 $(INF_OUTPUT)/$(MODULE_NAME).depex
-#    COMPRESS PI_STD {
-#      GUIDED {
-#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi
-#        UI       STRING="$(MODULE_NAME)" Optional
-#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
-#      }
-#    }
-#  }
-#
-############################################################################
-
-[Rule.Common.SEC]
-  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {
-    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi
-  }
-
-[Rule.Common.PEI_CORE]
-  FILE PEI_CORE = $(NAMED_GUID) {
-    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI     STRING ="$(MODULE_NAME)" Optional         
-  }
-
-[Rule.Common.PEIM]
-  FILE PEIM = $(NAMED_GUID) {
-     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex
-     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi
-     UI       STRING="$(MODULE_NAME)" Optional         
-  }
-
-[Rule.Common.PEIM.TIANOCOMPRESSED]
-  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {
-    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex
-    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {
-      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi
-      UI        STRING="$(MODULE_NAME)" Optional
-    }
-  }
-
-[Rule.Common.DXE_CORE]
-  FILE DXE_CORE = $(NAMED_GUID) {
-    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI       STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.UEFI_DRIVER]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
-    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI           STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.DXE_DRIVER]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
-    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI           STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.DXE_RUNTIME_DRIVER]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
-    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI           STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.UEFI_APPLICATION]
-  FILE APPLICATION = $(NAMED_GUID) {
-    UI     STRING ="$(MODULE_NAME)" Optional         
-    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi
-  }
+#\r
+#  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+\r
+################################################################################\r
+#\r
+# FD Section\r
+# The [FD] Section is made up of the definition statements and a\r
+# description of what goes into  the Flash Device Image.  Each FD section\r
+# defines one flash "device" image.  A flash device image may be one of\r
+# the following: Removable media bootable image (like a boot floppy\r
+# image,) an Option ROM image (that would be "flashed" into an add-in\r
+# card,) a System "Flash"  image (that would be burned into a system's\r
+# flash) or an Update ("Capsule") image that will be used to update and\r
+# existing system flash.\r
+#\r
+################################################################################\r
+\r
+[FD.ArmPlatform_EFI]\r
+BaseAddress   = 0xEC200000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in NOR Flash.\r
+Size          = 0x00200000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device\r
+ErasePolarity = 1\r
+\r
+# This one is tricky, it must be: BlockSize * NumBlocks = Size\r
+BlockSize     = 0x00001000\r
+NumBlocks     = 0x200\r
+\r
+################################################################################\r
+#\r
+# Following are lists of FD Region layout which correspond to the locations of different\r
+# images within the flash device.\r
+#\r
+# Regions must be defined in ascending order and may not overlap.\r
+#\r
+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by\r
+# the pipe "|" character, followed by the size of the region, also in hex with the leading\r
+# "0x" characters. Like:\r
+# Offset|Size\r
+# PcdOffsetCName|PcdSizeCName\r
+# RegionType <FV, DATA, or FILE>\r
+#\r
+################################################################################\r
+\r
+0x00000000|0x00200000\r
+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize\r
+FV = FVMAIN_COMPACT\r
+\r
+\r
+################################################################################\r
+#\r
+# FV Section\r
+#\r
+# [FV] section is used to define what components or modules are placed within a flash\r
+# device file.  This section also defines order the components and modules are positioned\r
+# within the image.  The [FV] section consists of define statements, set statements and\r
+# module statements.\r
+#\r
+################################################################################\r
+\r
+[FV.FvMain]\r
+BlockSize          = 0x40\r
+NumBlocks          = 0         # This FV gets compressed so make it just big enough\r
+FvAlignment        = 8         # FV alignment and FV attributes setting.\r
+ERASE_POLARITY     = 1\r
+MEMORY_MAPPED      = TRUE\r
+STICKY_WRITE       = TRUE\r
+LOCK_CAP           = TRUE\r
+LOCK_STATUS        = TRUE\r
+WRITE_DISABLED_CAP = TRUE\r
+WRITE_ENABLED_CAP  = TRUE\r
+WRITE_STATUS       = TRUE\r
+WRITE_LOCK_CAP     = TRUE\r
+WRITE_LOCK_STATUS  = TRUE\r
+READ_DISABLED_CAP  = TRUE\r
+READ_ENABLED_CAP   = TRUE\r
+READ_STATUS        = TRUE\r
+READ_LOCK_CAP      = TRUE\r
+READ_LOCK_STATUS   = TRUE\r
+\r
+  INF MdeModulePkg/Core/Dxe/DxeMain.inf \r
+\r
+  #\r
+  # PI DXE Drivers producing Architectural Protocols (EFI Services) \r
+  #\r
+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf\r
+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf\r
+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf\r
+  INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf\r
+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf\r
+  INF MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf\r
+  INF EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf\r
+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf\r
+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf\r
+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf\r
+\r
+  # Simple TextIn/TextOut for UEFI Terminal\r
+  INF EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf\r
+  \r
+  #\r
+  # Semi-hosting filesystem (Required the Hardware Debugger to be connected)\r
+  #\r
+  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf\r
+  \r
+  #\r
+  # FAT filesystem + GPT/MBR partitioning\r
+  #\r
+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf\r
+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf\r
+  INF FatPkg/EnhancedFatDxe/Fat.inf\r
+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf\r
+  \r
+  #\r
+  # UEFI application (Shell Embedded Boot Loader) \r
+  #  \r
+  INF EmbeddedPkg/Ebl/Ebl.inf\r
+    \r
+  #\r
+  # Bds\r
+  #\r
+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf\r
+  INF ArmPlatformPkg/Bds/Bds.inf\r
+\r
+\r
+[FV.FVMAIN_COMPACT]\r
+FvAlignment        = 8\r
+ERASE_POLARITY     = 1\r
+MEMORY_MAPPED      = TRUE\r
+STICKY_WRITE       = TRUE\r
+LOCK_CAP           = TRUE\r
+LOCK_STATUS        = TRUE\r
+WRITE_DISABLED_CAP = TRUE\r
+WRITE_ENABLED_CAP  = TRUE\r
+WRITE_STATUS       = TRUE\r
+WRITE_LOCK_CAP     = TRUE\r
+WRITE_LOCK_STATUS  = TRUE\r
+READ_DISABLED_CAP  = TRUE\r
+READ_ENABLED_CAP   = TRUE\r
+READ_STATUS        = TRUE\r
+READ_LOCK_CAP      = TRUE\r
+READ_LOCK_STATUS   = TRUE\r
+\r
+  INF ArmPlatformPkg/PrePi/PeiUniCore.inf\r
+  \r
+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {\r
+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {\r
+      SECTION FV_IMAGE = FVMAIN\r
+    }\r
+  }\r
+\r
+\r
+################################################################################\r
+#\r
+# Rules are use with the [FV] section's module INF type to define\r
+# how an FFS file is created for a given INF file. The following Rule are the default\r
+# rules for the different module type. User can add the customized rules to define the\r
+# content of the FFS file.\r
+#\r
+################################################################################\r
+\r
+\r
+############################################################################\r
+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   # \r
+############################################################################\r
+#\r
+#[Rule.Common.DXE_DRIVER]\r
+#  FILE DRIVER = $(NAMED_GUID) {\r
+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+#    COMPRESS PI_STD {\r
+#      GUIDED {\r
+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+#        UI       STRING="$(MODULE_NAME)" Optional\r
+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+#      }\r
+#    }\r
+#  }\r
+#\r
+############################################################################\r
+\r
+[Rule.Common.SEC]\r
+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {\r
+    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+  }\r
+\r
+[Rule.Common.PEI_CORE]\r
+  FILE PEI_CORE = $(NAMED_GUID) {\r
+    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI     STRING ="$(MODULE_NAME)" Optional         \r
+  }\r
+\r
+[Rule.Common.PEIM]\r
+  FILE PEIM = $(NAMED_GUID) {\r
+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+     UI       STRING="$(MODULE_NAME)" Optional         \r
+  }\r
+\r
+[Rule.Common.PEIM.TIANOCOMPRESSED]\r
+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {\r
+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {\r
+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+      UI        STRING="$(MODULE_NAME)" Optional\r
+    }\r
+  }\r
+\r
+[Rule.Common.DXE_CORE]\r
+  FILE DXE_CORE = $(NAMED_GUID) {\r
+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI       STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.UEFI_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI           STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.DXE_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI           STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.DXE_RUNTIME_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI           STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.UEFI_APPLICATION]\r
+  FILE APPLICATION = $(NAMED_GUID) {\r
+    UI     STRING ="$(MODULE_NAME)" Optional         \r
+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+  }\r
index d829d4043ef29f34ba0f170fa41bd888e58f2da6..be7dfa1879e0759fc12fed1f4db603b734896a7f 100644 (file)
-#
-#  Copyright (c) 2011, ARM Limited. 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.Sec_ArmPlatform_EFI]
-BaseAddress   = 0xEC000000|gArmTokenSpaceGuid.PcdSecureFdBaseAddress  #The base address of the Secure FLASH Device.
-Size          = 0x00010000|gArmTokenSpaceGuid.PcdSecureFdSize         #The size in bytes of the Secure FLASH Device
-ErasePolarity = 1
-BlockSize     = 0x00001000
-NumBlocks     = 0x10
-
-################################################################################
-#
-# 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|0x00010000
-gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize
-FV = FVMAIN_SEC
-
-
-[FD.ArmPlatform_EFI]
-BaseAddress   = 0xEC200000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in NOR Flash.
-Size          = 0x00200000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device
-ErasePolarity = 1
-
-# This one is tricky, it must be: BlockSize * NumBlocks = Size
-BlockSize     = 0x00001000
-NumBlocks     = 0x200
-
-################################################################################
-#
-# 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|0x00200000
-gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize
-FV = FVMAIN_COMPACT
-
-
-################################################################################
-#
-# 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.FVMAIN_SEC]
-FvAlignment        = 8
-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
-
-  INF ArmPlatformPkg/Sec/Sec.inf
-
-
-[FV.FvMain]
-BlockSize          = 0x40
-NumBlocks          = 0         # This FV gets compressed so make it just big enough
-FvAlignment        = 8         # 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
-
-  INF MdeModulePkg/Core/Dxe/DxeMain.inf 
-
-  #
-  # PI DXE Drivers producing Architectural Protocols (EFI Services) 
-  #
-  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf
-  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
-  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
-  INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
-  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
-  INF MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf
-  INF EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf
-  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf
-  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
-  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
-
-  # Simple TextIn/TextOut for UEFI Terminal
-  INF EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf
-  
-  #
-  # Semi-hosting filesystem (Required the Hardware Debugger to be connected)
-  #
-  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf
-  
-  #
-  # FAT filesystem + GPT/MBR partitioning
-  #
-  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
-  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
-  INF FatPkg/EnhancedFatDxe/Fat.inf
-  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
-  
-  #
-  # UEFI application (Shell Embedded Boot Loader) 
-  #  
-  INF EmbeddedPkg/Ebl/Ebl.inf
-    
-  #
-  # Bds
-  #
-  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
-  INF ArmPlatformPkg/Bds/Bds.inf
-
-
-[FV.FVMAIN_COMPACT]
-FvAlignment        = 8
-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
-
-  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf
-  INF MdeModulePkg/Core/Pei/PeiMain.inf
-  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf
-  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf
-  INF ArmPkg/Drivers/CpuPei/CpuPei.inf
-  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf
-  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf
-  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
-  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
-  
-  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {
-    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {
-      SECTION FV_IMAGE = FVMAIN
-    }
-  }
-
-
-################################################################################
-#
-# 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 $(INF_OUTPUT)/$(MODULE_NAME).depex
-#    COMPRESS PI_STD {
-#      GUIDED {
-#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi
-#        UI       STRING="$(MODULE_NAME)" Optional
-#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
-#      }
-#    }
-#  }
-#
-############################################################################
-
-[Rule.Common.SEC]
-  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {
-    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi
-  }
-
-[Rule.Common.PEI_CORE]
-  FILE PEI_CORE = $(NAMED_GUID) {
-    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI     STRING ="$(MODULE_NAME)" Optional         
-  }
-
-[Rule.Common.PEIM]
-  FILE PEIM = $(NAMED_GUID) {
-     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex
-     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi
-     UI       STRING="$(MODULE_NAME)" Optional         
-  }
-
-[Rule.Common.PEIM.TIANOCOMPRESSED]
-  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {
-    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex
-    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {
-      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi
-      UI        STRING="$(MODULE_NAME)" Optional
-    }
-  }
-
-[Rule.Common.DXE_CORE]
-  FILE DXE_CORE = $(NAMED_GUID) {
-    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI       STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.UEFI_DRIVER]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
-    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI           STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.DXE_DRIVER]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
-    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI           STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.DXE_RUNTIME_DRIVER]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
-    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI           STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.UEFI_APPLICATION]
-  FILE APPLICATION = $(NAMED_GUID) {
-    UI     STRING ="$(MODULE_NAME)" Optional         
-    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi
-  }
+#\r
+#  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+\r
+################################################################################\r
+#\r
+# FD Section\r
+# The [FD] Section is made up of the definition statements and a\r
+# description of what goes into  the Flash Device Image.  Each FD section\r
+# defines one flash "device" image.  A flash device image may be one of\r
+# the following: Removable media bootable image (like a boot floppy\r
+# image,) an Option ROM image (that would be "flashed" into an add-in\r
+# card,) a System "Flash"  image (that would be burned into a system's\r
+# flash) or an Update ("Capsule") image that will be used to update and\r
+# existing system flash.\r
+#\r
+################################################################################\r
+\r
+[FD.Sec_ArmPlatform_EFI]\r
+BaseAddress   = 0xEC000000|gArmTokenSpaceGuid.PcdSecureFdBaseAddress  #The base address of the Secure FLASH Device.\r
+Size          = 0x00010000|gArmTokenSpaceGuid.PcdSecureFdSize         #The size in bytes of the Secure FLASH Device\r
+ErasePolarity = 1\r
+BlockSize     = 0x00001000\r
+NumBlocks     = 0x10\r
+\r
+################################################################################\r
+#\r
+# Following are lists of FD Region layout which correspond to the locations of different\r
+# images within the flash device.\r
+#\r
+# Regions must be defined in ascending order and may not overlap.\r
+#\r
+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by\r
+# the pipe "|" character, followed by the size of the region, also in hex with the leading\r
+# "0x" characters. Like:\r
+# Offset|Size\r
+# PcdOffsetCName|PcdSizeCName\r
+# RegionType <FV, DATA, or FILE>\r
+#\r
+################################################################################\r
+\r
+0x00000000|0x00010000\r
+gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize\r
+FV = FVMAIN_SEC\r
+\r
+\r
+[FD.ArmPlatform_EFI]\r
+BaseAddress   = 0xEC200000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in NOR Flash.\r
+Size          = 0x00200000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device\r
+ErasePolarity = 1\r
+\r
+# This one is tricky, it must be: BlockSize * NumBlocks = Size\r
+BlockSize     = 0x00001000\r
+NumBlocks     = 0x200\r
+\r
+################################################################################\r
+#\r
+# Following are lists of FD Region layout which correspond to the locations of different\r
+# images within the flash device.\r
+#\r
+# Regions must be defined in ascending order and may not overlap.\r
+#\r
+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by\r
+# the pipe "|" character, followed by the size of the region, also in hex with the leading\r
+# "0x" characters. Like:\r
+# Offset|Size\r
+# PcdOffsetCName|PcdSizeCName\r
+# RegionType <FV, DATA, or FILE>\r
+#\r
+################################################################################\r
+\r
+0x00000000|0x00200000\r
+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize\r
+FV = FVMAIN_COMPACT\r
+\r
+\r
+################################################################################\r
+#\r
+# FV Section\r
+#\r
+# [FV] section is used to define what components or modules are placed within a flash\r
+# device file.  This section also defines order the components and modules are positioned\r
+# within the image.  The [FV] section consists of define statements, set statements and\r
+# module statements.\r
+#\r
+################################################################################\r
+\r
+[FV.FVMAIN_SEC]\r
+FvAlignment        = 8\r
+ERASE_POLARITY     = 1\r
+MEMORY_MAPPED      = TRUE\r
+STICKY_WRITE       = TRUE\r
+LOCK_CAP           = TRUE\r
+LOCK_STATUS        = TRUE\r
+WRITE_DISABLED_CAP = TRUE\r
+WRITE_ENABLED_CAP  = TRUE\r
+WRITE_STATUS       = TRUE\r
+WRITE_LOCK_CAP     = TRUE\r
+WRITE_LOCK_STATUS  = TRUE\r
+READ_DISABLED_CAP  = TRUE\r
+READ_ENABLED_CAP   = TRUE\r
+READ_STATUS        = TRUE\r
+READ_LOCK_CAP      = TRUE\r
+READ_LOCK_STATUS   = TRUE\r
+\r
+  INF ArmPlatformPkg/Sec/Sec.inf\r
+\r
+\r
+[FV.FvMain]\r
+BlockSize          = 0x40\r
+NumBlocks          = 0         # This FV gets compressed so make it just big enough\r
+FvAlignment        = 8         # FV alignment and FV attributes setting.\r
+ERASE_POLARITY     = 1\r
+MEMORY_MAPPED      = TRUE\r
+STICKY_WRITE       = TRUE\r
+LOCK_CAP           = TRUE\r
+LOCK_STATUS        = TRUE\r
+WRITE_DISABLED_CAP = TRUE\r
+WRITE_ENABLED_CAP  = TRUE\r
+WRITE_STATUS       = TRUE\r
+WRITE_LOCK_CAP     = TRUE\r
+WRITE_LOCK_STATUS  = TRUE\r
+READ_DISABLED_CAP  = TRUE\r
+READ_ENABLED_CAP   = TRUE\r
+READ_STATUS        = TRUE\r
+READ_LOCK_CAP      = TRUE\r
+READ_LOCK_STATUS   = TRUE\r
+\r
+  INF MdeModulePkg/Core/Dxe/DxeMain.inf \r
+\r
+  #\r
+  # PI DXE Drivers producing Architectural Protocols (EFI Services) \r
+  #\r
+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf\r
+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf\r
+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf\r
+  INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf\r
+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf\r
+  INF MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf\r
+  INF EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf\r
+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf\r
+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf\r
+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf\r
+\r
+  # Simple TextIn/TextOut for UEFI Terminal\r
+  INF EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf\r
+  \r
+  #\r
+  # Semi-hosting filesystem (Required the Hardware Debugger to be connected)\r
+  #\r
+  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf\r
+  \r
+  #\r
+  # FAT filesystem + GPT/MBR partitioning\r
+  #\r
+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf\r
+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf\r
+  INF FatPkg/EnhancedFatDxe/Fat.inf\r
+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf\r
+  \r
+  #\r
+  # UEFI application (Shell Embedded Boot Loader) \r
+  #  \r
+  INF EmbeddedPkg/Ebl/Ebl.inf\r
+    \r
+  #\r
+  # Bds\r
+  #\r
+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf\r
+  INF ArmPlatformPkg/Bds/Bds.inf\r
+\r
+\r
+[FV.FVMAIN_COMPACT]\r
+FvAlignment        = 8\r
+ERASE_POLARITY     = 1\r
+MEMORY_MAPPED      = TRUE\r
+STICKY_WRITE       = TRUE\r
+LOCK_CAP           = TRUE\r
+LOCK_STATUS        = TRUE\r
+WRITE_DISABLED_CAP = TRUE\r
+WRITE_ENABLED_CAP  = TRUE\r
+WRITE_STATUS       = TRUE\r
+WRITE_LOCK_CAP     = TRUE\r
+WRITE_LOCK_STATUS  = TRUE\r
+READ_DISABLED_CAP  = TRUE\r
+READ_ENABLED_CAP   = TRUE\r
+READ_STATUS        = TRUE\r
+READ_LOCK_CAP      = TRUE\r
+READ_LOCK_STATUS   = TRUE\r
+\r
+  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf\r
+  INF MdeModulePkg/Core/Pei/PeiMain.inf\r
+  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf\r
+  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf\r
+  INF ArmPkg/Drivers/CpuPei/CpuPei.inf\r
+  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf\r
+  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf\r
+  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf\r
+  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf\r
+  \r
+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {\r
+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {\r
+      SECTION FV_IMAGE = FVMAIN\r
+    }\r
+  }\r
+\r
+\r
+################################################################################\r
+#\r
+# Rules are use with the [FV] section's module INF type to define\r
+# how an FFS file is created for a given INF file. The following Rule are the default\r
+# rules for the different module type. User can add the customized rules to define the\r
+# content of the FFS file.\r
+#\r
+################################################################################\r
+\r
+\r
+############################################################################\r
+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   # \r
+############################################################################\r
+#\r
+#[Rule.Common.DXE_DRIVER]\r
+#  FILE DRIVER = $(NAMED_GUID) {\r
+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+#    COMPRESS PI_STD {\r
+#      GUIDED {\r
+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+#        UI       STRING="$(MODULE_NAME)" Optional\r
+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+#      }\r
+#    }\r
+#  }\r
+#\r
+############################################################################\r
+\r
+[Rule.Common.SEC]\r
+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {\r
+    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+  }\r
+\r
+[Rule.Common.PEI_CORE]\r
+  FILE PEI_CORE = $(NAMED_GUID) {\r
+    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI     STRING ="$(MODULE_NAME)" Optional         \r
+  }\r
+\r
+[Rule.Common.PEIM]\r
+  FILE PEIM = $(NAMED_GUID) {\r
+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+     UI       STRING="$(MODULE_NAME)" Optional         \r
+  }\r
+\r
+[Rule.Common.PEIM.TIANOCOMPRESSED]\r
+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {\r
+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {\r
+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+      UI        STRING="$(MODULE_NAME)" Optional\r
+    }\r
+  }\r
+\r
+[Rule.Common.DXE_CORE]\r
+  FILE DXE_CORE = $(NAMED_GUID) {\r
+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI       STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.UEFI_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI           STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.DXE_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI           STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.DXE_RUNTIME_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI           STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.UEFI_APPLICATION]\r
+  FILE APPLICATION = $(NAMED_GUID) {\r
+    UI     STRING ="$(MODULE_NAME)" Optional         \r
+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+  }\r
index 558e304f524c12c7a7547c9884d40413862b9db6..70fc87bcf53c2e55d80c34cf37ed9c75d8959ebe 100644 (file)
-# FLASH layout file for ARM VE.
-#
-#  Copyright (c) 2011, ARM Limited. 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.ArmRealViewEb_EFI]
-BaseAddress   = 0x40000000|gArmTokenSpaceGuid.PcdFdBaseAddress
-Size          = 0x00200000|gArmTokenSpaceGuid.PcdFdSize
-ErasePolarity = 1
-BlockSize     = 0x00010000
-NumBlocks     = 0x20
-
-################################################################################
-#
-# 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|0x00050000
-gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize
-FV = FVMAIN_SEC
-
-0x00050000|0x00100000
-gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize
-FV = FVMAIN_COMPACT
-
-################################################################################
-#
-# 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.FVMAIN_SEC]
-FvAlignment        = 8
-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
-
-  INF ArmPlatformPkg/Sec/Sec.inf
-
-
-[FV.FvMain]
-BlockSize          = 0x40
-NumBlocks          = 0         # This FV gets compressed so make it just big enough
-FvAlignment        = 8         # 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
-
-  INF MdeModulePkg/Core/Dxe/DxeMain.inf 
-
-  #
-  # PI DXE Drivers producing Architectural Protocols (EFI Services) 
-  #
-  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf
-  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
-  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
-  INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
-  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
-  INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
-  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
-  INF EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf
-  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf
-  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
-  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
-
-  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
-  INF ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf
-
-  #
-  # Multiple Console IO support
-  #
-  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 EmbeddedPkg/SerialDxe/SerialDxe.inf
-  
-  INF ArmPkg/Drivers/PL390Gic/PL390GicDxe.inf
-  INF ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf
-  
-  INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf
-
-  #
-  # Semi-hosting filesystem
-  #
-  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf
-  
-  #
-  # FAT filesystem + GPT/MBR partitioning
-  #
-  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
-  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
-  INF FatBinPkg/EnhancedFatDxe/Fat.inf
-  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
-
-  #
-  # UEFI application (Shell Embedded Boot Loader) 
-  #  
-  INF ShellBinPkg/UefiShell/UefiShell.inf 
-
-  #
-  # Bds
-  #
-  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
-  INF ArmPlatformPkg/Bds/Bds.inf
-
-
-[FV.FVMAIN_COMPACT]
-FvAlignment        = 8
-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
-
-!if $(EDK2_SKIP_PEICORE) == 1
-  INF ArmPlatformPkg/PrePi/PeiMPCore.inf
-!else
-  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf
-  INF MdeModulePkg/Core/Pei/PeiMain.inf
-  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf
-  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf
-  INF ArmPkg/Drivers/CpuPei/CpuPei.inf
-  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf
-  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf
-  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
-  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
-!endif
-
-  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {
-    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {
-      SECTION FV_IMAGE = FVMAIN
-    }
-  }
-
-################################################################################
-#
-# 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 $(INF_OUTPUT)/$(MODULE_NAME).depex
-#    COMPRESS PI_STD {
-#      GUIDED {
-#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi
-#        UI       STRING="$(MODULE_NAME)" Optional
-#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
-#      }
-#    }
-#  }
-#
-############################################################################
-
-[Rule.Common.SEC]
-  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {
-    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi
-  }
-
-[Rule.Common.PEI_CORE]
-  FILE PEI_CORE = $(NAMED_GUID) {
-    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI     STRING ="$(MODULE_NAME)" Optional         
-  }
-
-[Rule.Common.PEIM]
-  FILE PEIM = $(NAMED_GUID) {
-     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex
-     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi
-     UI       STRING="$(MODULE_NAME)" Optional         
-  }
-
-[Rule.Common.PEIM.TIANOCOMPRESSED]
-  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {
-    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex
-    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {
-      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi
-      UI        STRING="$(MODULE_NAME)" Optional
-    }
-  }
-
-[Rule.Common.DXE_CORE]
-  FILE DXE_CORE = $(NAMED_GUID) {
-    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI       STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.UEFI_DRIVER]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
-    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI           STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.DXE_DRIVER]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
-    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI           STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.DXE_RUNTIME_DRIVER]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
-    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI           STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.UEFI_APPLICATION]
-  FILE APPLICATION = $(NAMED_GUID) {
-    UI     STRING ="$(MODULE_NAME)" Optional         
-    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi
-  }
-
-[Rule.Common.UEFI_DRIVER.BINARY]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX DXE_DEPEX Optional      |.depex
-    PE32      PE32                    |.efi
-    UI        STRING="$(MODULE_NAME)" Optional
-    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
-  }
-
-[Rule.Common.UEFI_APPLICATION.BINARY]
-  FILE APPLICATION = $(NAMED_GUID) {
-    PE32      PE32                    |.efi
-    UI        STRING="$(MODULE_NAME)" Optional
-    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
-  }
+# FLASH layout file for ARM VE.\r
+#\r
+#  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+\r
+################################################################################\r
+#\r
+# FD Section\r
+# The [FD] Section is made up of the definition statements and a\r
+# description of what goes into  the Flash Device Image.  Each FD section\r
+# defines one flash "device" image.  A flash device image may be one of\r
+# the following: Removable media bootable image (like a boot floppy\r
+# image,) an Option ROM image (that would be "flashed" into an add-in\r
+# card,) a System "Flash"  image (that would be burned into a system's\r
+# flash) or an Update ("Capsule") image that will be used to update and\r
+# existing system flash.\r
+#\r
+################################################################################\r
+\r
+\r
+[FD.ArmRealViewEb_EFI]\r
+BaseAddress   = 0x40000000|gArmTokenSpaceGuid.PcdFdBaseAddress\r
+Size          = 0x00200000|gArmTokenSpaceGuid.PcdFdSize\r
+ErasePolarity = 1\r
+BlockSize     = 0x00010000\r
+NumBlocks     = 0x20\r
+\r
+################################################################################\r
+#\r
+# Following are lists of FD Region layout which correspond to the locations of different\r
+# images within the flash device.\r
+#\r
+# Regions must be defined in ascending order and may not overlap.\r
+#\r
+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by\r
+# the pipe "|" character, followed by the size of the region, also in hex with the leading\r
+# "0x" characters. Like:\r
+# Offset|Size\r
+# PcdOffsetCName|PcdSizeCName\r
+# RegionType <FV, DATA, or FILE>\r
+#\r
+################################################################################\r
+\r
+0x00000000|0x00050000\r
+gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize\r
+FV = FVMAIN_SEC\r
+\r
+0x00050000|0x00100000\r
+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize\r
+FV = FVMAIN_COMPACT\r
+\r
+################################################################################\r
+#\r
+# FV Section\r
+#\r
+# [FV] section is used to define what components or modules are placed within a flash\r
+# device file.  This section also defines order the components and modules are positioned\r
+# within the image.  The [FV] section consists of define statements, set statements and\r
+# module statements.\r
+#\r
+################################################################################\r
+\r
+[FV.FVMAIN_SEC]\r
+FvAlignment        = 8\r
+ERASE_POLARITY     = 1\r
+MEMORY_MAPPED      = TRUE\r
+STICKY_WRITE       = TRUE\r
+LOCK_CAP           = TRUE\r
+LOCK_STATUS        = TRUE\r
+WRITE_DISABLED_CAP = TRUE\r
+WRITE_ENABLED_CAP  = TRUE\r
+WRITE_STATUS       = TRUE\r
+WRITE_LOCK_CAP     = TRUE\r
+WRITE_LOCK_STATUS  = TRUE\r
+READ_DISABLED_CAP  = TRUE\r
+READ_ENABLED_CAP   = TRUE\r
+READ_STATUS        = TRUE\r
+READ_LOCK_CAP      = TRUE\r
+READ_LOCK_STATUS   = TRUE\r
+\r
+  INF ArmPlatformPkg/Sec/Sec.inf\r
+\r
+\r
+[FV.FvMain]\r
+BlockSize          = 0x40\r
+NumBlocks          = 0         # This FV gets compressed so make it just big enough\r
+FvAlignment        = 8         # FV alignment and FV attributes setting.\r
+ERASE_POLARITY     = 1\r
+MEMORY_MAPPED      = TRUE\r
+STICKY_WRITE       = TRUE\r
+LOCK_CAP           = TRUE\r
+LOCK_STATUS        = TRUE\r
+WRITE_DISABLED_CAP = TRUE\r
+WRITE_ENABLED_CAP  = TRUE\r
+WRITE_STATUS       = TRUE\r
+WRITE_LOCK_CAP     = TRUE\r
+WRITE_LOCK_STATUS  = TRUE\r
+READ_DISABLED_CAP  = TRUE\r
+READ_ENABLED_CAP   = TRUE\r
+READ_STATUS        = TRUE\r
+READ_LOCK_CAP      = TRUE\r
+READ_LOCK_STATUS   = TRUE\r
+\r
+  INF MdeModulePkg/Core/Dxe/DxeMain.inf \r
+\r
+  #\r
+  # PI DXE Drivers producing Architectural Protocols (EFI Services) \r
+  #\r
+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf\r
+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf\r
+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf\r
+  INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf\r
+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf\r
+  INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf\r
+  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf\r
+  INF EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf\r
+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf\r
+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf\r
+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf\r
+\r
+  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf\r
+  INF ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf\r
+\r
+  #\r
+  # Multiple Console IO support\r
+  #\r
+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf\r
+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf\r
+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf\r
+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf\r
+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf\r
+  \r
+  INF ArmPkg/Drivers/PL390Gic/PL390GicDxe.inf\r
+  INF ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf\r
+  \r
+  INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf\r
+\r
+  #\r
+  # Semi-hosting filesystem\r
+  #\r
+  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf\r
+  \r
+  #\r
+  # FAT filesystem + GPT/MBR partitioning\r
+  #\r
+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf\r
+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf\r
+  INF FatBinPkg/EnhancedFatDxe/Fat.inf\r
+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf\r
+\r
+  #\r
+  # UEFI application (Shell Embedded Boot Loader) \r
+  #  \r
+  INF ShellBinPkg/UefiShell/UefiShell.inf \r
+\r
+  #\r
+  # Bds\r
+  #\r
+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf\r
+  INF ArmPlatformPkg/Bds/Bds.inf\r
+\r
+\r
+[FV.FVMAIN_COMPACT]\r
+FvAlignment        = 8\r
+ERASE_POLARITY     = 1\r
+MEMORY_MAPPED      = TRUE\r
+STICKY_WRITE       = TRUE\r
+LOCK_CAP           = TRUE\r
+LOCK_STATUS        = TRUE\r
+WRITE_DISABLED_CAP = TRUE\r
+WRITE_ENABLED_CAP  = TRUE\r
+WRITE_STATUS       = TRUE\r
+WRITE_LOCK_CAP     = TRUE\r
+WRITE_LOCK_STATUS  = TRUE\r
+READ_DISABLED_CAP  = TRUE\r
+READ_ENABLED_CAP   = TRUE\r
+READ_STATUS        = TRUE\r
+READ_LOCK_CAP      = TRUE\r
+READ_LOCK_STATUS   = TRUE\r
+\r
+!if $(EDK2_SKIP_PEICORE) == 1\r
+  INF ArmPlatformPkg/PrePi/PeiMPCore.inf\r
+!else\r
+  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf\r
+  INF MdeModulePkg/Core/Pei/PeiMain.inf\r
+  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf\r
+  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf\r
+  INF ArmPkg/Drivers/CpuPei/CpuPei.inf\r
+  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf\r
+  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf\r
+  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf\r
+  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf\r
+!endif\r
+\r
+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {\r
+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {\r
+      SECTION FV_IMAGE = FVMAIN\r
+    }\r
+  }\r
+\r
+################################################################################\r
+#\r
+# Rules are use with the [FV] section's module INF type to define\r
+# how an FFS file is created for a given INF file. The following Rule are the default\r
+# rules for the different module type. User can add the customized rules to define the\r
+# content of the FFS file.\r
+#\r
+################################################################################\r
+\r
+\r
+############################################################################\r
+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   # \r
+############################################################################\r
+#\r
+#[Rule.Common.DXE_DRIVER]\r
+#  FILE DRIVER = $(NAMED_GUID) {\r
+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+#    COMPRESS PI_STD {\r
+#      GUIDED {\r
+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+#        UI       STRING="$(MODULE_NAME)" Optional\r
+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+#      }\r
+#    }\r
+#  }\r
+#\r
+############################################################################\r
+\r
+[Rule.Common.SEC]\r
+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {\r
+    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+  }\r
+\r
+[Rule.Common.PEI_CORE]\r
+  FILE PEI_CORE = $(NAMED_GUID) {\r
+    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI     STRING ="$(MODULE_NAME)" Optional         \r
+  }\r
+\r
+[Rule.Common.PEIM]\r
+  FILE PEIM = $(NAMED_GUID) {\r
+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+     UI       STRING="$(MODULE_NAME)" Optional         \r
+  }\r
+\r
+[Rule.Common.PEIM.TIANOCOMPRESSED]\r
+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {\r
+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {\r
+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+      UI        STRING="$(MODULE_NAME)" Optional\r
+    }\r
+  }\r
+\r
+[Rule.Common.DXE_CORE]\r
+  FILE DXE_CORE = $(NAMED_GUID) {\r
+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI       STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.UEFI_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI           STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.DXE_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI           STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.DXE_RUNTIME_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI           STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.UEFI_APPLICATION]\r
+  FILE APPLICATION = $(NAMED_GUID) {\r
+    UI     STRING ="$(MODULE_NAME)" Optional         \r
+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+  }\r
+\r
+[Rule.Common.UEFI_DRIVER.BINARY]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX DXE_DEPEX Optional      |.depex\r
+    PE32      PE32                    |.efi\r
+    UI        STRING="$(MODULE_NAME)" Optional\r
+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+  }\r
+\r
+[Rule.Common.UEFI_APPLICATION.BINARY]\r
+  FILE APPLICATION = $(NAMED_GUID) {\r
+    PE32      PE32                    |.efi\r
+    UI        STRING="$(MODULE_NAME)" Optional\r
+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+  }\r
index a5fb26a327afcff4cba0ba5866ec8a80a6205655..77d48acce1c2cac7e747b28fb08fd5d99277e916 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 <Library/IoLib.h>
-#include <Library/ArmLib.h>
-#include <Library/ArmPlatformLib.h>
-#include <Library/DebugLib.h>
-#include <Library/PcdLib.h>
-
-#include <Drivers/PL341Dmc.h>
-#include <Drivers/SP804Timer.h>
-
-#include <Ppi/ArmMpCoreInfo.h>
-
-#include <ArmPlatform.h>
-
-ARM_CORE_INFO mRealViewEbMpCoreInfoTable[] = {
-  {
-    // Cluster 0, Core 0
-    0x0, 0x0,
-
-    // MP Core MailBox Set/Get/Clear Addresses and Clear Value
-    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_SET_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_CLR_REG,
-    (UINT64)0xFFFFFFFF
-  },
-  {
-    // Cluster 0, Core 1
-    0x0, 0x1,
-
-    // MP Core MailBox Set/Get/Clear Addresses and Clear Value
-    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_SET_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_CLR_REG,
-    (UINT64)0xFFFFFFFF
-  }
-};
-
-/**
-  Return the current Boot Mode
-
-  This function returns the boot reason on the platform
-
-**/
-EFI_BOOT_MODE
-ArmPlatformGetBootMode (
-  VOID
-  )
-{
-  return BOOT_WITH_FULL_CONFIGURATION;
-}
-
-/**
-  Initialize controllers that must setup in the normal world
-
-  This function is called by the ArmPlatformPkg/PrePi or ArmPlatformPkg/PlatformPei
-  in the PEI phase.
-
-**/
-RETURN_STATUS
-ArmPlatformInitialize (
-  IN  UINTN                     MpId
-  )
-{
-  if (!IS_PRIMARY_CORE(MpId)) {
-    return RETURN_SUCCESS;
-  }
-
-  // Disable memory remapping and return to normal mapping
-  MmioOr32 (ARM_EB_SYSCTRL, BIT8); //EB_SP810_CTRL_BASE
-
-  // Configure periodic timer (TIMER0) for 1MHz operation
-  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER0_TIMCLK);
-  // Configure 1MHz clock
-  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER1_TIMCLK);
-  // configure SP810 to use 1MHz clock and disable
-  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER2_EN, SP810_SYS_CTRL_TIMER2_TIMCLK);
-  // Configure SP810 to use 1MHz clock and disable
-  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER3_EN, SP810_SYS_CTRL_TIMER3_TIMCLK);
-
-  return RETURN_SUCCESS;
-}
-
-/**
-  Initialize the system (or sometimes called permanent) memory
-
-  This memory is generally represented by the DRAM.
-
-**/
-VOID
-ArmPlatformInitializeSystemMemory (
-  VOID
-  )
-{
-  // We do not need to initialize the System Memory on RTSM
-}
-
-EFI_STATUS
-PrePeiCoreGetMpCoreInfo (
-  OUT UINTN                   *CoreCount,
-  OUT ARM_CORE_INFO           **ArmCoreTable
-  )
-{
-  if ((MmioRead32 (ARM_EB_SYS_PROCID0_REG) & ARM_EB_SYS_PROC_ID_MASK) == ARM_EB_SYS_PROC_ID_CORTEX_A9) {
-    *CoreCount    = sizeof(mRealViewEbMpCoreInfoTable) / sizeof(ARM_CORE_INFO);
-    *ArmCoreTable = mRealViewEbMpCoreInfoTable;
-    return EFI_SUCCESS;
-  } else {
-    return EFI_UNSUPPORTED;
-  }
-}
-
-// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore
-EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;
-ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };
-
-EFI_PEI_PPI_DESCRIPTOR      gPlatformPpiTable[] = {
-  {
-    EFI_PEI_PPI_DESCRIPTOR_PPI,
-    &mArmMpCoreInfoPpiGuid,
-    &mMpCoreInfoPpi
-  }
-};
-
-VOID
-ArmPlatformGetPlatformPpiList (
-  OUT UINTN                   *PpiListSize,
-  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList
-  )
-{
-  *PpiListSize = sizeof(gPlatformPpiTable);
-  *PpiList = gPlatformPpiTable;
-}
-
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include <Library/IoLib.h>\r
+#include <Library/ArmLib.h>\r
+#include <Library/ArmPlatformLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+#include <Drivers/PL341Dmc.h>\r
+#include <Drivers/SP804Timer.h>\r
+\r
+#include <Ppi/ArmMpCoreInfo.h>\r
+\r
+#include <ArmPlatform.h>\r
+\r
+ARM_CORE_INFO mRealViewEbMpCoreInfoTable[] = {\r
+  {\r
+    // Cluster 0, Core 0\r
+    0x0, 0x0,\r
+\r
+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value\r
+    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_SET_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_CLR_REG,\r
+    (UINT64)0xFFFFFFFF\r
+  },\r
+  {\r
+    // Cluster 0, Core 1\r
+    0x0, 0x1,\r
+\r
+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value\r
+    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_SET_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_CLR_REG,\r
+    (UINT64)0xFFFFFFFF\r
+  }\r
+};\r
+\r
+/**\r
+  Return the current Boot Mode\r
+\r
+  This function returns the boot reason on the platform\r
+\r
+**/\r
+EFI_BOOT_MODE\r
+ArmPlatformGetBootMode (\r
+  VOID\r
+  )\r
+{\r
+  return BOOT_WITH_FULL_CONFIGURATION;\r
+}\r
+\r
+/**\r
+  Initialize controllers that must setup in the normal world\r
+\r
+  This function is called by the ArmPlatformPkg/PrePi or ArmPlatformPkg/PlatformPei\r
+  in the PEI phase.\r
+\r
+**/\r
+RETURN_STATUS\r
+ArmPlatformInitialize (\r
+  IN  UINTN                     MpId\r
+  )\r
+{\r
+  if (!IS_PRIMARY_CORE(MpId)) {\r
+    return RETURN_SUCCESS;\r
+  }\r
+\r
+  // Disable memory remapping and return to normal mapping\r
+  MmioOr32 (ARM_EB_SYSCTRL, BIT8); //EB_SP810_CTRL_BASE\r
+\r
+  // Configure periodic timer (TIMER0) for 1MHz operation\r
+  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER0_TIMCLK);\r
+  // Configure 1MHz clock\r
+  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER1_TIMCLK);\r
+  // configure SP810 to use 1MHz clock and disable\r
+  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER2_EN, SP810_SYS_CTRL_TIMER2_TIMCLK);\r
+  // Configure SP810 to use 1MHz clock and disable\r
+  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER3_EN, SP810_SYS_CTRL_TIMER3_TIMCLK);\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Initialize the system (or sometimes called permanent) memory\r
+\r
+  This memory is generally represented by the DRAM.\r
+\r
+**/\r
+VOID\r
+ArmPlatformInitializeSystemMemory (\r
+  VOID\r
+  )\r
+{\r
+  // We do not need to initialize the System Memory on RTSM\r
+}\r
+\r
+EFI_STATUS\r
+PrePeiCoreGetMpCoreInfo (\r
+  OUT UINTN                   *CoreCount,\r
+  OUT ARM_CORE_INFO           **ArmCoreTable\r
+  )\r
+{\r
+  if ((MmioRead32 (ARM_EB_SYS_PROCID0_REG) & ARM_EB_SYS_PROC_ID_MASK) == ARM_EB_SYS_PROC_ID_CORTEX_A9) {\r
+    *CoreCount    = sizeof(mRealViewEbMpCoreInfoTable) / sizeof(ARM_CORE_INFO);\r
+    *ArmCoreTable = mRealViewEbMpCoreInfoTable;\r
+    return EFI_SUCCESS;\r
+  } else {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+}\r
+\r
+// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore\r
+EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;\r
+ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };\r
+\r
+EFI_PEI_PPI_DESCRIPTOR      gPlatformPpiTable[] = {\r
+  {\r
+    EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+    &mArmMpCoreInfoPpiGuid,\r
+    &mMpCoreInfoPpi\r
+  }\r
+};\r
+\r
+VOID\r
+ArmPlatformGetPlatformPpiList (\r
+  OUT UINTN                   *PpiListSize,\r
+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList\r
+  )\r
+{\r
+  *PpiListSize = sizeof(gPlatformPpiTable);\r
+  *PpiList = gPlatformPpiTable;\r
+}\r
+\r
index 10dcef92add53722f51d90552f770c8b13938b32..033c9d7ea082376e144a8c9dfb2b30d25ab0a574 100644 (file)
@@ -1,76 +1,76 @@
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 <Library/IoLib.h>
-#include <Library/ArmLib.h>
-#include <Library/ArmPlatformSecLib.h>
-#include <Library/DebugLib.h>
-#include <Library/PcdLib.h>
-
-#include <Drivers/PL341Dmc.h>
-#include <Drivers/SP804Timer.h>
-
-#include <ArmPlatform.h>
-
-/**
-  Initialize the Secure peripherals and memory regions
-
-  If Trustzone is supported by your platform then this function makes the required initialization
-  of the secure peripherals and memory regions.
-
-**/
-VOID
-ArmPlatformSecTrustzoneInit (
-  IN  UINTN                     MpId
-  )
-{
-  ASSERT(FALSE);
-}
-
-/**
-  Initialize controllers that must setup at the early stage
-
-  Some peripherals must be initialized in Secure World.
-  For example, some L2x0 requires to be initialized in Secure World
-
-**/
-RETURN_STATUS
-ArmPlatformSecInitialize (
-  IN  UINTN                     MpId
-  )
-{
-  // If it is not the primary core then there is nothing to do
-  if (!IS_PRIMARY_CORE(MpId)) {
-    return RETURN_SUCCESS;
-  }
-
-  // Do nothing yet
-  return RETURN_SUCCESS;
-}
-
-/**
-  Call before jumping to Normal World
-
-  This function allows the firmware platform to do extra actions before
-  jumping to the Normal World
-
-**/
-VOID
-ArmPlatformSecExtraAction (
-  IN  UINTN         MpId,
-  OUT UINTN*        JumpAddress
-  )
-{
-  *JumpAddress = PcdGet32(PcdFvBaseAddress);
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include <Library/IoLib.h>\r
+#include <Library/ArmLib.h>\r
+#include <Library/ArmPlatformSecLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+#include <Drivers/PL341Dmc.h>\r
+#include <Drivers/SP804Timer.h>\r
+\r
+#include <ArmPlatform.h>\r
+\r
+/**\r
+  Initialize the Secure peripherals and memory regions\r
+\r
+  If Trustzone is supported by your platform then this function makes the required initialization\r
+  of the secure peripherals and memory regions.\r
+\r
+**/\r
+VOID\r
+ArmPlatformSecTrustzoneInit (\r
+  IN  UINTN                     MpId\r
+  )\r
+{\r
+  ASSERT(FALSE);\r
+}\r
+\r
+/**\r
+  Initialize controllers that must setup at the early stage\r
+\r
+  Some peripherals must be initialized in Secure World.\r
+  For example, some L2x0 requires to be initialized in Secure World\r
+\r
+**/\r
+RETURN_STATUS\r
+ArmPlatformSecInitialize (\r
+  IN  UINTN                     MpId\r
+  )\r
+{\r
+  // If it is not the primary core then there is nothing to do\r
+  if (!IS_PRIMARY_CORE(MpId)) {\r
+    return RETURN_SUCCESS;\r
+  }\r
+\r
+  // Do nothing yet\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Call before jumping to Normal World\r
+\r
+  This function allows the firmware platform to do extra actions before\r
+  jumping to the Normal World\r
+\r
+**/\r
+VOID\r
+ArmPlatformSecExtraAction (\r
+  IN  UINTN         MpId,\r
+  OUT UINTN*        JumpAddress\r
+  )\r
+{\r
+  *JumpAddress = PcdGet32(PcdFvBaseAddress);\r
+}\r
index 9a68da96ac7f090624cb01096c6fff689aeb92a4..48dd960cf60781ab4bdde12a6a35442cdf9901f8 100644 (file)
@@ -1,35 +1,35 @@
-#/** @file
-#  
-#  Component description file for NorFlashArmRealViewEbLib module
-#  
-#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
-#
-#  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                      = NorFlashArmRealViewEbLib
-  FILE_GUID                      = a3a49a60-7597-11e0-b07c-0002a5d5c51b
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = NorFlashPlatformLib
-  
-[Sources.common]
-  NorFlashArmRealViewEb.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  BaseLib
-  DebugLib
-  IoLib
+#/** @file\r
+#  \r
+#  Component description file for NorFlashArmRealViewEbLib module\r
+#  \r
+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = NorFlashArmRealViewEbLib\r
+  FILE_GUID                      = a3a49a60-7597-11e0-b07c-0002a5d5c51b\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = NorFlashPlatformLib\r
+  \r
+[Sources.common]\r
+  NorFlashArmRealViewEb.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  IoLib\r
index fda59de7fd894f2dc5998f0236603f4dd1c507b6..b44e868c04958d3973d00b51d2b4e0f2e13190ac 100644 (file)
@@ -1,65 +1,65 @@
-#/** @file
-#  
-#  Component description file for ArmRealViewGraphicsDxe module
-#  
-#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
-#  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                      = PL111LcdArmRealViewEbLib
-  FILE_GUID                      = 51396ee0-4973-11e0-868a-0002a5d5c51b
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = PL111LcdPlatformLib
-  
-[Sources.common]
-  PL111LcdArmRealViewEb.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  BaseLib
-  DebugLib
-  IoLib
-
-[Guids]
-
-[Protocols]
-  gEfiEdidDiscoveredProtocolGuid                # Produced
-  gEfiEdidActiveProtocolGuid                    # Produced
-
-[FixedPcd.common]
-
-  #
-  # The following modes are supported by PL111
-  #
-  #    0 :  640 x 480 x 24 bpp
-  #    1 :  800 x 600 x 24 bpp
-  #    2 : 1024 x 768 x 24 bpp
-  #    3 :  640 x 480 x 16 bpp (565 RGB Mode)
-  #    4 :  800 x 600 x 16 bpp (565 RGB Mode) 
-  #    5 : 1024 x 768 x 16 bpp (565 RGB Mode)
-  #    6 :  640 x 480 x 15 bpp (555 RGB Mode)
-  #    7 :  800 x 600 x 15 bpp (555 RGB Mode) 
-  #    8 : 1024 x 768 x 15 bpp (555 RGB Mode)
-  #    9 : 1024 x 768 x 15 bpp (555 RGB Mode) - Linux driver settings
-  #   10 :  640 x 480 x 12 bpp (444 RGB Mode)
-  #   11 :  800 x 600 x 12 bpp (444 RGB Mode) 
-  #   12 : 1024 x 768 x 12 bpp (444 RGB Mode)
-  #
-
-[Pcd.common]
-
-[Depex]
- # gEfiCpuArchProtocolGuid
+#/** @file\r
+#  \r
+#  Component description file for ArmRealViewGraphicsDxe module\r
+#  \r
+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PL111LcdArmRealViewEbLib\r
+  FILE_GUID                      = 51396ee0-4973-11e0-868a-0002a5d5c51b\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PL111LcdPlatformLib\r
+  \r
+[Sources.common]\r
+  PL111LcdArmRealViewEb.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  IoLib\r
+\r
+[Guids]\r
+\r
+[Protocols]\r
+  gEfiEdidDiscoveredProtocolGuid                # Produced\r
+  gEfiEdidActiveProtocolGuid                    # Produced\r
+\r
+[FixedPcd.common]\r
+\r
+  #\r
+  # The following modes are supported by PL111\r
+  #\r
+  #    0 :  640 x 480 x 24 bpp\r
+  #    1 :  800 x 600 x 24 bpp\r
+  #    2 : 1024 x 768 x 24 bpp\r
+  #    3 :  640 x 480 x 16 bpp (565 RGB Mode)\r
+  #    4 :  800 x 600 x 16 bpp (565 RGB Mode) \r
+  #    5 : 1024 x 768 x 16 bpp (565 RGB Mode)\r
+  #    6 :  640 x 480 x 15 bpp (555 RGB Mode)\r
+  #    7 :  800 x 600 x 15 bpp (555 RGB Mode) \r
+  #    8 : 1024 x 768 x 15 bpp (555 RGB Mode)\r
+  #    9 : 1024 x 768 x 15 bpp (555 RGB Mode) - Linux driver settings\r
+  #   10 :  640 x 480 x 12 bpp (444 RGB Mode)\r
+  #   11 :  800 x 600 x 12 bpp (444 RGB Mode) \r
+  #   12 : 1024 x 768 x 12 bpp (444 RGB Mode)\r
+  #\r
+\r
+[Pcd.common]\r
+\r
+[Depex]\r
+ # gEfiCpuArchProtocolGuid\r
index b45c20b5b02364f4ca5b21bfbe6ffcd15a5bd832..e1a735345edb035c81b2a4b741ebec5ab625989a 100644 (file)
@@ -1,34 +1,34 @@
-#/** @file
-#  
-#  Component description file for SysConfigArmRealViewEbLib module
-#  
-#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
-#
-#  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                      = SysConfigArmRealViewEbLib
-  FILE_GUID                      = 46eddfa0-8de0-11e0-944b-0002a5d5c51b
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = ArmPlatformSysConfigLib
-  
-[Sources.common]
-  SysConfigArmRealViewEb.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  BaseLib
+#/** @file\r
+#  \r
+#  Component description file for SysConfigArmRealViewEbLib module\r
+#  \r
+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = SysConfigArmRealViewEbLib\r
+  FILE_GUID                      = 46eddfa0-8de0-11e0-944b-0002a5d5c51b\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ArmPlatformSysConfigLib\r
+  \r
+[Sources.common]\r
+  SysConfigArmRealViewEb.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
index 4be620c3f320a068fa13aa85aa10552722957f42..c961897d007066b639a1951d3d68473d1b7657bf 100644 (file)
-# FLASH layout file for ARM VE.
-#
-#  Copyright (c) 2011, ARM Limited. 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.RTSM_VE_Cortex-A15_EFI]
-BaseAddress   = 0x08000000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in NOR Flash.
-Size          = 0x00280000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device
-ErasePolarity = 1
-
-# This one is tricky, it must be: BlockSize * NumBlocks = Size
-BlockSize     = 0x00001000
-NumBlocks     = 0x280
-
-################################################################################
-#
-# 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|0x00080000
-gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize
-FV = FVMAIN_SEC
-
-0x00080000|0x00280000
-gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize
-FV = FVMAIN_COMPACT
-
-
-################################################################################
-#
-# 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.FVMAIN_SEC]
-FvAlignment        = 8
-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
-
-  INF ArmPlatformPkg/Sec/Sec.inf
-
-
-[FV.FvMain]
-BlockSize          = 0x40
-NumBlocks          = 0         # This FV gets compressed so make it just big enough
-FvAlignment        = 8         # 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
-
-  INF MdeModulePkg/Core/Dxe/DxeMain.inf 
-
-  #
-  # PI DXE Drivers producing Architectural Protocols (EFI Services) 
-  #
-  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf
-  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
-  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
-  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
-  INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
-  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
-  INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
-  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf
-  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
-  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
-
-  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
-  
-  #
-  # Multiple Console IO support
-  #
-  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 EmbeddedPkg/SerialDxe/SerialDxe.inf
-
-  INF ArmPkg/Drivers/PL390Gic/PL390GicDxe.inf
-  INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf
-  INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf
-  INF ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf
-  INF ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf
-
-  #
-  # Semi-hosting filesystem
-  #
-  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf
-  
-  #
-  # FAT filesystem + GPT/MBR partitioning
-  #
-  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
-  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
-  INF FatBinPkg/EnhancedFatDxe/Fat.inf
-  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
-
-  #
-  # Multimedia Card Interface
-  #
-  INF EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf
-  INF ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf
-
-  #
-  # UEFI application (Shell Embedded Boot Loader) 
-  #  
-  INF ShellBinPkg/UefiShell/UefiShell.inf 
-  
-  #
-  # Bds
-  #
-  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
-  INF ArmPlatformPkg/Bds/Bds.inf
-
-
-[FV.FVMAIN_COMPACT]
-FvAlignment        = 8
-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
-
-!if $(EDK2_SKIP_PEICORE) == 1
-  INF ArmPlatformPkg/PrePi/PeiUniCore.inf
-!else
-  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf
-  INF MdeModulePkg/Core/Pei/PeiMain.inf
-  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf
-  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf
-  INF ArmPkg/Drivers/CpuPei/CpuPei.inf
-  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf
-  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf
-  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
-  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
-!endif
-  
-  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {
-    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {
-      SECTION FV_IMAGE = FVMAIN
-    }
-  }
-
-
-################################################################################
-#
-# 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 $(INF_OUTPUT)/$(MODULE_NAME).depex
-#    COMPRESS PI_STD {
-#      GUIDED {
-#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi
-#        UI       STRING="$(MODULE_NAME)" Optional
-#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
-#      }
-#    }
-#  }
-#
-############################################################################
-
-[Rule.Common.SEC]
-  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {
-    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi
-  }
-
-[Rule.Common.PEI_CORE]
-  FILE PEI_CORE = $(NAMED_GUID) {
-    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI     STRING ="$(MODULE_NAME)" Optional         
-  }
-
-[Rule.Common.PEIM]
-  FILE PEIM = $(NAMED_GUID) {
-     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex
-     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi
-     UI       STRING="$(MODULE_NAME)" Optional         
-  }
-
-[Rule.Common.PEIM.TIANOCOMPRESSED]
-  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {
-    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex
-    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {
-      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi
-      UI        STRING="$(MODULE_NAME)" Optional
-    }
-  }
-
-[Rule.Common.DXE_CORE]
-  FILE DXE_CORE = $(NAMED_GUID) {
-    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI       STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.UEFI_DRIVER]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
-    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI           STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.DXE_DRIVER]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
-    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI           STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.DXE_RUNTIME_DRIVER]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
-    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI           STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.UEFI_APPLICATION]
-  FILE APPLICATION = $(NAMED_GUID) {
-    UI     STRING ="$(MODULE_NAME)" Optional         
-    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi
-  }
-
-[Rule.Common.UEFI_DRIVER.BINARY]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX DXE_DEPEX Optional      |.depex
-    PE32      PE32                    |.efi
-    UI        STRING="$(MODULE_NAME)" Optional
-    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
-  }
-
-[Rule.Common.UEFI_APPLICATION.BINARY]
-  FILE APPLICATION = $(NAMED_GUID) {
-    PE32      PE32                    |.efi
-    UI        STRING="$(MODULE_NAME)" Optional
-    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
-  }
+# FLASH layout file for ARM VE.\r
+#\r
+#  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+\r
+################################################################################\r
+#\r
+# FD Section\r
+# The [FD] Section is made up of the definition statements and a\r
+# description of what goes into  the Flash Device Image.  Each FD section\r
+# defines one flash "device" image.  A flash device image may be one of\r
+# the following: Removable media bootable image (like a boot floppy\r
+# image,) an Option ROM image (that would be "flashed" into an add-in\r
+# card,) a System "Flash"  image (that would be burned into a system's\r
+# flash) or an Update ("Capsule") image that will be used to update and\r
+# existing system flash.\r
+#\r
+################################################################################\r
+\r
+[FD.RTSM_VE_Cortex-A15_EFI]\r
+BaseAddress   = 0x08000000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in NOR Flash.\r
+Size          = 0x00280000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device\r
+ErasePolarity = 1\r
+\r
+# This one is tricky, it must be: BlockSize * NumBlocks = Size\r
+BlockSize     = 0x00001000\r
+NumBlocks     = 0x280\r
+\r
+################################################################################\r
+#\r
+# Following are lists of FD Region layout which correspond to the locations of different\r
+# images within the flash device.\r
+#\r
+# Regions must be defined in ascending order and may not overlap.\r
+#\r
+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by\r
+# the pipe "|" character, followed by the size of the region, also in hex with the leading\r
+# "0x" characters. Like:\r
+# Offset|Size\r
+# PcdOffsetCName|PcdSizeCName\r
+# RegionType <FV, DATA, or FILE>\r
+#\r
+################################################################################\r
+\r
+0x00000000|0x00080000\r
+gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize\r
+FV = FVMAIN_SEC\r
+\r
+0x00080000|0x00280000\r
+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize\r
+FV = FVMAIN_COMPACT\r
+\r
+\r
+################################################################################\r
+#\r
+# FV Section\r
+#\r
+# [FV] section is used to define what components or modules are placed within a flash\r
+# device file.  This section also defines order the components and modules are positioned\r
+# within the image.  The [FV] section consists of define statements, set statements and\r
+# module statements.\r
+#\r
+################################################################################\r
+\r
+[FV.FVMAIN_SEC]\r
+FvAlignment        = 8\r
+ERASE_POLARITY     = 1\r
+MEMORY_MAPPED      = TRUE\r
+STICKY_WRITE       = TRUE\r
+LOCK_CAP           = TRUE\r
+LOCK_STATUS        = TRUE\r
+WRITE_DISABLED_CAP = TRUE\r
+WRITE_ENABLED_CAP  = TRUE\r
+WRITE_STATUS       = TRUE\r
+WRITE_LOCK_CAP     = TRUE\r
+WRITE_LOCK_STATUS  = TRUE\r
+READ_DISABLED_CAP  = TRUE\r
+READ_ENABLED_CAP   = TRUE\r
+READ_STATUS        = TRUE\r
+READ_LOCK_CAP      = TRUE\r
+READ_LOCK_STATUS   = TRUE\r
+\r
+  INF ArmPlatformPkg/Sec/Sec.inf\r
+\r
+\r
+[FV.FvMain]\r
+BlockSize          = 0x40\r
+NumBlocks          = 0         # This FV gets compressed so make it just big enough\r
+FvAlignment        = 8         # FV alignment and FV attributes setting.\r
+ERASE_POLARITY     = 1\r
+MEMORY_MAPPED      = TRUE\r
+STICKY_WRITE       = TRUE\r
+LOCK_CAP           = TRUE\r
+LOCK_STATUS        = TRUE\r
+WRITE_DISABLED_CAP = TRUE\r
+WRITE_ENABLED_CAP  = TRUE\r
+WRITE_STATUS       = TRUE\r
+WRITE_LOCK_CAP     = TRUE\r
+WRITE_LOCK_STATUS  = TRUE\r
+READ_DISABLED_CAP  = TRUE\r
+READ_ENABLED_CAP   = TRUE\r
+READ_STATUS        = TRUE\r
+READ_LOCK_CAP      = TRUE\r
+READ_LOCK_STATUS   = TRUE\r
+\r
+  INF MdeModulePkg/Core/Dxe/DxeMain.inf \r
+\r
+  #\r
+  # PI DXE Drivers producing Architectural Protocols (EFI Services) \r
+  #\r
+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf\r
+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf\r
+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf\r
+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf\r
+  INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf\r
+  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf\r
+  INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf\r
+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf\r
+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf\r
+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf\r
+\r
+  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf\r
+  \r
+  #\r
+  # Multiple Console IO support\r
+  #\r
+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf\r
+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf\r
+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf\r
+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf\r
+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf\r
+\r
+  INF ArmPkg/Drivers/PL390Gic/PL390GicDxe.inf\r
+  INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf\r
+  INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf\r
+  INF ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf\r
+  INF ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf\r
+\r
+  #\r
+  # Semi-hosting filesystem\r
+  #\r
+  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf\r
+  \r
+  #\r
+  # FAT filesystem + GPT/MBR partitioning\r
+  #\r
+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf\r
+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf\r
+  INF FatBinPkg/EnhancedFatDxe/Fat.inf\r
+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf\r
+\r
+  #\r
+  # Multimedia Card Interface\r
+  #\r
+  INF EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf\r
+  INF ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf\r
+\r
+  #\r
+  # UEFI application (Shell Embedded Boot Loader) \r
+  #  \r
+  INF ShellBinPkg/UefiShell/UefiShell.inf \r
+  \r
+  #\r
+  # Bds\r
+  #\r
+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf\r
+  INF ArmPlatformPkg/Bds/Bds.inf\r
+\r
+\r
+[FV.FVMAIN_COMPACT]\r
+FvAlignment        = 8\r
+ERASE_POLARITY     = 1\r
+MEMORY_MAPPED      = TRUE\r
+STICKY_WRITE       = TRUE\r
+LOCK_CAP           = TRUE\r
+LOCK_STATUS        = TRUE\r
+WRITE_DISABLED_CAP = TRUE\r
+WRITE_ENABLED_CAP  = TRUE\r
+WRITE_STATUS       = TRUE\r
+WRITE_LOCK_CAP     = TRUE\r
+WRITE_LOCK_STATUS  = TRUE\r
+READ_DISABLED_CAP  = TRUE\r
+READ_ENABLED_CAP   = TRUE\r
+READ_STATUS        = TRUE\r
+READ_LOCK_CAP      = TRUE\r
+READ_LOCK_STATUS   = TRUE\r
+\r
+!if $(EDK2_SKIP_PEICORE) == 1\r
+  INF ArmPlatformPkg/PrePi/PeiUniCore.inf\r
+!else\r
+  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf\r
+  INF MdeModulePkg/Core/Pei/PeiMain.inf\r
+  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf\r
+  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf\r
+  INF ArmPkg/Drivers/CpuPei/CpuPei.inf\r
+  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf\r
+  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf\r
+  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf\r
+  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf\r
+!endif\r
+  \r
+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {\r
+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {\r
+      SECTION FV_IMAGE = FVMAIN\r
+    }\r
+  }\r
+\r
+\r
+################################################################################\r
+#\r
+# Rules are use with the [FV] section's module INF type to define\r
+# how an FFS file is created for a given INF file. The following Rule are the default\r
+# rules for the different module type. User can add the customized rules to define the\r
+# content of the FFS file.\r
+#\r
+################################################################################\r
+\r
+\r
+############################################################################\r
+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   # \r
+############################################################################\r
+#\r
+#[Rule.Common.DXE_DRIVER]\r
+#  FILE DRIVER = $(NAMED_GUID) {\r
+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+#    COMPRESS PI_STD {\r
+#      GUIDED {\r
+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+#        UI       STRING="$(MODULE_NAME)" Optional\r
+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+#      }\r
+#    }\r
+#  }\r
+#\r
+############################################################################\r
+\r
+[Rule.Common.SEC]\r
+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {\r
+    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+  }\r
+\r
+[Rule.Common.PEI_CORE]\r
+  FILE PEI_CORE = $(NAMED_GUID) {\r
+    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI     STRING ="$(MODULE_NAME)" Optional         \r
+  }\r
+\r
+[Rule.Common.PEIM]\r
+  FILE PEIM = $(NAMED_GUID) {\r
+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+     UI       STRING="$(MODULE_NAME)" Optional         \r
+  }\r
+\r
+[Rule.Common.PEIM.TIANOCOMPRESSED]\r
+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {\r
+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {\r
+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+      UI        STRING="$(MODULE_NAME)" Optional\r
+    }\r
+  }\r
+\r
+[Rule.Common.DXE_CORE]\r
+  FILE DXE_CORE = $(NAMED_GUID) {\r
+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI       STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.UEFI_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI           STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.DXE_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI           STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.DXE_RUNTIME_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI           STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.UEFI_APPLICATION]\r
+  FILE APPLICATION = $(NAMED_GUID) {\r
+    UI     STRING ="$(MODULE_NAME)" Optional         \r
+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+  }\r
+\r
+[Rule.Common.UEFI_DRIVER.BINARY]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX DXE_DEPEX Optional      |.depex\r
+    PE32      PE32                    |.efi\r
+    UI        STRING="$(MODULE_NAME)" Optional\r
+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+  }\r
+\r
+[Rule.Common.UEFI_APPLICATION.BINARY]\r
+  FILE APPLICATION = $(NAMED_GUID) {\r
+    PE32      PE32                    |.efi\r
+    UI        STRING="$(MODULE_NAME)" Optional\r
+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+  }\r
index 4718c18595b6a83e9aa2e3579329cc1418e3685b..58170490ac4928c8d30d1ec61f29110baa58536e 100644 (file)
-# FLASH layout file for ARM VE.
-#
-#  Copyright (c) 2011, ARM Limited. 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.RTSM_VE_Cortex-A15_MPCore_EFI]
-BaseAddress   = 0x08000000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in NOR Flash.
-Size          = 0x00280000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device
-ErasePolarity = 1
-
-# This one is tricky, it must be: BlockSize * NumBlocks = Size
-BlockSize     = 0x00001000
-NumBlocks     = 0x280
-
-################################################################################
-#
-# 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|0x00080000
-gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize
-FV = FVMAIN_SEC
-
-0x00080000|0x00280000
-gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize
-FV = FVMAIN_COMPACT
-
-
-################################################################################
-#
-# 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.FVMAIN_SEC]
-FvAlignment        = 8
-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
-
-  INF ArmPlatformPkg/Sec/Sec.inf
-
-
-[FV.FvMain]
-BlockSize          = 0x40
-NumBlocks          = 0         # This FV gets compressed so make it just big enough
-FvAlignment        = 8         # 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
-
-  INF MdeModulePkg/Core/Dxe/DxeMain.inf 
-
-  #
-  # PI DXE Drivers producing Architectural Protocols (EFI Services) 
-  #
-  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf
-  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
-  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
-  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
-  INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
-  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
-  INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
-  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf
-  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
-  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
-
-  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
-  
-  #
-  # Multiple Console IO support
-  #
-  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 EmbeddedPkg/SerialDxe/SerialDxe.inf
-
-  INF ArmPkg/Drivers/PL390Gic/PL390GicDxe.inf
-  INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf
-  INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf
-  INF ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf
-  INF ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf
-
-  #
-  # Semi-hosting filesystem
-  #
-  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf
-  
-  #
-  # FAT filesystem + GPT/MBR partitioning
-  #
-  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
-  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
-  INF FatBinPkg/EnhancedFatDxe/Fat.inf
-  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
-
-  #
-  # Multimedia Card Interface
-  #
-  INF EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf
-  INF ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf
-
-  #
-  # UEFI application (Shell Embedded Boot Loader) 
-  #  
-  INF ShellBinPkg/UefiShell/UefiShell.inf 
-  
-  #
-  # Bds
-  #
-  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
-  INF ArmPlatformPkg/Bds/Bds.inf
-
-
-[FV.FVMAIN_COMPACT]
-FvAlignment        = 8
-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
-
-!if $(EDK2_SKIP_PEICORE) == 1
-  INF ArmPlatformPkg/PrePi/PeiMPCore.inf
-!else
-  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf
-  INF MdeModulePkg/Core/Pei/PeiMain.inf
-  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf
-  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf
-  INF ArmPkg/Drivers/CpuPei/CpuPei.inf
-  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf
-  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf
-  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
-  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
-!endif
-  
-  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {
-    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {
-      SECTION FV_IMAGE = FVMAIN
-    }
-  }
-
-
-################################################################################
-#
-# 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 $(INF_OUTPUT)/$(MODULE_NAME).depex
-#    COMPRESS PI_STD {
-#      GUIDED {
-#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi
-#        UI       STRING="$(MODULE_NAME)" Optional
-#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
-#      }
-#    }
-#  }
-#
-############################################################################
-
-[Rule.Common.SEC]
-  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {
-    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi
-  }
-
-[Rule.Common.PEI_CORE]
-  FILE PEI_CORE = $(NAMED_GUID) {
-    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI     STRING ="$(MODULE_NAME)" Optional         
-  }
-
-[Rule.Common.PEIM]
-  FILE PEIM = $(NAMED_GUID) {
-     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex
-     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi
-     UI       STRING="$(MODULE_NAME)" Optional         
-  }
-
-[Rule.Common.PEIM.TIANOCOMPRESSED]
-  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {
-    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex
-    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {
-      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi
-      UI        STRING="$(MODULE_NAME)" Optional
-    }
-  }
-
-[Rule.Common.DXE_CORE]
-  FILE DXE_CORE = $(NAMED_GUID) {
-    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI       STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.UEFI_DRIVER]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
-    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI           STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.DXE_DRIVER]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
-    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI           STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.DXE_RUNTIME_DRIVER]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
-    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
-    UI           STRING="$(MODULE_NAME)" Optional
-  }
-
-[Rule.Common.UEFI_APPLICATION]
-  FILE APPLICATION = $(NAMED_GUID) {
-    UI     STRING ="$(MODULE_NAME)" Optional         
-    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi
-  }
-
-[Rule.Common.UEFI_DRIVER.BINARY]
-  FILE DRIVER = $(NAMED_GUID) {
-    DXE_DEPEX DXE_DEPEX Optional      |.depex
-    PE32      PE32                    |.efi
-    UI        STRING="$(MODULE_NAME)" Optional
-    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
-  }
-
-[Rule.Common.UEFI_APPLICATION.BINARY]
-  FILE APPLICATION = $(NAMED_GUID) {
-    PE32      PE32                    |.efi
-    UI        STRING="$(MODULE_NAME)" Optional
-    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
-  }
+# FLASH layout file for ARM VE.\r
+#\r
+#  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+\r
+################################################################################\r
+#\r
+# FD Section\r
+# The [FD] Section is made up of the definition statements and a\r
+# description of what goes into  the Flash Device Image.  Each FD section\r
+# defines one flash "device" image.  A flash device image may be one of\r
+# the following: Removable media bootable image (like a boot floppy\r
+# image,) an Option ROM image (that would be "flashed" into an add-in\r
+# card,) a System "Flash"  image (that would be burned into a system's\r
+# flash) or an Update ("Capsule") image that will be used to update and\r
+# existing system flash.\r
+#\r
+################################################################################\r
+\r
+[FD.RTSM_VE_Cortex-A15_MPCore_EFI]\r
+BaseAddress   = 0x08000000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in NOR Flash.\r
+Size          = 0x00280000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device\r
+ErasePolarity = 1\r
+\r
+# This one is tricky, it must be: BlockSize * NumBlocks = Size\r
+BlockSize     = 0x00001000\r
+NumBlocks     = 0x280\r
+\r
+################################################################################\r
+#\r
+# Following are lists of FD Region layout which correspond to the locations of different\r
+# images within the flash device.\r
+#\r
+# Regions must be defined in ascending order and may not overlap.\r
+#\r
+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by\r
+# the pipe "|" character, followed by the size of the region, also in hex with the leading\r
+# "0x" characters. Like:\r
+# Offset|Size\r
+# PcdOffsetCName|PcdSizeCName\r
+# RegionType <FV, DATA, or FILE>\r
+#\r
+################################################################################\r
+\r
+0x00000000|0x00080000\r
+gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize\r
+FV = FVMAIN_SEC\r
+\r
+0x00080000|0x00280000\r
+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize\r
+FV = FVMAIN_COMPACT\r
+\r
+\r
+################################################################################\r
+#\r
+# FV Section\r
+#\r
+# [FV] section is used to define what components or modules are placed within a flash\r
+# device file.  This section also defines order the components and modules are positioned\r
+# within the image.  The [FV] section consists of define statements, set statements and\r
+# module statements.\r
+#\r
+################################################################################\r
+\r
+[FV.FVMAIN_SEC]\r
+FvAlignment        = 8\r
+ERASE_POLARITY     = 1\r
+MEMORY_MAPPED      = TRUE\r
+STICKY_WRITE       = TRUE\r
+LOCK_CAP           = TRUE\r
+LOCK_STATUS        = TRUE\r
+WRITE_DISABLED_CAP = TRUE\r
+WRITE_ENABLED_CAP  = TRUE\r
+WRITE_STATUS       = TRUE\r
+WRITE_LOCK_CAP     = TRUE\r
+WRITE_LOCK_STATUS  = TRUE\r
+READ_DISABLED_CAP  = TRUE\r
+READ_ENABLED_CAP   = TRUE\r
+READ_STATUS        = TRUE\r
+READ_LOCK_CAP      = TRUE\r
+READ_LOCK_STATUS   = TRUE\r
+\r
+  INF ArmPlatformPkg/Sec/Sec.inf\r
+\r
+\r
+[FV.FvMain]\r
+BlockSize          = 0x40\r
+NumBlocks          = 0         # This FV gets compressed so make it just big enough\r
+FvAlignment        = 8         # FV alignment and FV attributes setting.\r
+ERASE_POLARITY     = 1\r
+MEMORY_MAPPED      = TRUE\r
+STICKY_WRITE       = TRUE\r
+LOCK_CAP           = TRUE\r
+LOCK_STATUS        = TRUE\r
+WRITE_DISABLED_CAP = TRUE\r
+WRITE_ENABLED_CAP  = TRUE\r
+WRITE_STATUS       = TRUE\r
+WRITE_LOCK_CAP     = TRUE\r
+WRITE_LOCK_STATUS  = TRUE\r
+READ_DISABLED_CAP  = TRUE\r
+READ_ENABLED_CAP   = TRUE\r
+READ_STATUS        = TRUE\r
+READ_LOCK_CAP      = TRUE\r
+READ_LOCK_STATUS   = TRUE\r
+\r
+  INF MdeModulePkg/Core/Dxe/DxeMain.inf \r
+\r
+  #\r
+  # PI DXE Drivers producing Architectural Protocols (EFI Services) \r
+  #\r
+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf\r
+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf\r
+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf\r
+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf\r
+  INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf\r
+  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf\r
+  INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf\r
+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf\r
+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf\r
+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf\r
+\r
+  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf\r
+  \r
+  #\r
+  # Multiple Console IO support\r
+  #\r
+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf\r
+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf\r
+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf\r
+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf\r
+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf\r
+\r
+  INF ArmPkg/Drivers/PL390Gic/PL390GicDxe.inf\r
+  INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf\r
+  INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf\r
+  INF ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf\r
+  INF ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf\r
+\r
+  #\r
+  # Semi-hosting filesystem\r
+  #\r
+  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf\r
+  \r
+  #\r
+  # FAT filesystem + GPT/MBR partitioning\r
+  #\r
+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf\r
+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf\r
+  INF FatBinPkg/EnhancedFatDxe/Fat.inf\r
+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf\r
+\r
+  #\r
+  # Multimedia Card Interface\r
+  #\r
+  INF EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf\r
+  INF ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf\r
+\r
+  #\r
+  # UEFI application (Shell Embedded Boot Loader) \r
+  #  \r
+  INF ShellBinPkg/UefiShell/UefiShell.inf \r
+  \r
+  #\r
+  # Bds\r
+  #\r
+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf\r
+  INF ArmPlatformPkg/Bds/Bds.inf\r
+\r
+\r
+[FV.FVMAIN_COMPACT]\r
+FvAlignment        = 8\r
+ERASE_POLARITY     = 1\r
+MEMORY_MAPPED      = TRUE\r
+STICKY_WRITE       = TRUE\r
+LOCK_CAP           = TRUE\r
+LOCK_STATUS        = TRUE\r
+WRITE_DISABLED_CAP = TRUE\r
+WRITE_ENABLED_CAP  = TRUE\r
+WRITE_STATUS       = TRUE\r
+WRITE_LOCK_CAP     = TRUE\r
+WRITE_LOCK_STATUS  = TRUE\r
+READ_DISABLED_CAP  = TRUE\r
+READ_ENABLED_CAP   = TRUE\r
+READ_STATUS        = TRUE\r
+READ_LOCK_CAP      = TRUE\r
+READ_LOCK_STATUS   = TRUE\r
+\r
+!if $(EDK2_SKIP_PEICORE) == 1\r
+  INF ArmPlatformPkg/PrePi/PeiMPCore.inf\r
+!else\r
+  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf\r
+  INF MdeModulePkg/Core/Pei/PeiMain.inf\r
+  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf\r
+  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf\r
+  INF ArmPkg/Drivers/CpuPei/CpuPei.inf\r
+  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf\r
+  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf\r
+  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf\r
+  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf\r
+!endif\r
+  \r
+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {\r
+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {\r
+      SECTION FV_IMAGE = FVMAIN\r
+    }\r
+  }\r
+\r
+\r
+################################################################################\r
+#\r
+# Rules are use with the [FV] section's module INF type to define\r
+# how an FFS file is created for a given INF file. The following Rule are the default\r
+# rules for the different module type. User can add the customized rules to define the\r
+# content of the FFS file.\r
+#\r
+################################################################################\r
+\r
+\r
+############################################################################\r
+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   # \r
+############################################################################\r
+#\r
+#[Rule.Common.DXE_DRIVER]\r
+#  FILE DRIVER = $(NAMED_GUID) {\r
+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+#    COMPRESS PI_STD {\r
+#      GUIDED {\r
+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+#        UI       STRING="$(MODULE_NAME)" Optional\r
+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+#      }\r
+#    }\r
+#  }\r
+#\r
+############################################################################\r
+\r
+[Rule.Common.SEC]\r
+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {\r
+    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+  }\r
+\r
+[Rule.Common.PEI_CORE]\r
+  FILE PEI_CORE = $(NAMED_GUID) {\r
+    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI     STRING ="$(MODULE_NAME)" Optional         \r
+  }\r
+\r
+[Rule.Common.PEIM]\r
+  FILE PEIM = $(NAMED_GUID) {\r
+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+     UI       STRING="$(MODULE_NAME)" Optional         \r
+  }\r
+\r
+[Rule.Common.PEIM.TIANOCOMPRESSED]\r
+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {\r
+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {\r
+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+      UI        STRING="$(MODULE_NAME)" Optional\r
+    }\r
+  }\r
+\r
+[Rule.Common.DXE_CORE]\r
+  FILE DXE_CORE = $(NAMED_GUID) {\r
+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI       STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.UEFI_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI           STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.DXE_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI           STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.DXE_RUNTIME_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex\r
+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+    UI           STRING="$(MODULE_NAME)" Optional\r
+  }\r
+\r
+[Rule.Common.UEFI_APPLICATION]\r
+  FILE APPLICATION = $(NAMED_GUID) {\r
+    UI     STRING ="$(MODULE_NAME)" Optional         \r
+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi\r
+  }\r
+\r
+[Rule.Common.UEFI_DRIVER.BINARY]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX DXE_DEPEX Optional      |.depex\r
+    PE32      PE32                    |.efi\r
+    UI        STRING="$(MODULE_NAME)" Optional\r
+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+  }\r
+\r
+[Rule.Common.UEFI_APPLICATION.BINARY]\r
+  FILE APPLICATION = $(NAMED_GUID) {\r
+    PE32      PE32                    |.efi\r
+    UI        STRING="$(MODULE_NAME)" Optional\r
+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+  }\r
index f20db58d6a7b1f7bb868696d8336b1956751e4b5..a255c40b3e255a607e799a892749a95c54885021 100644 (file)
@@ -1,55 +1,55 @@
-#/* @file
-#  Copyright (c) 2011-2012, ARM Limited. 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                      = CTA9x4ArmVExpressLib
-  FILE_GUID                      = b16c63a0-f417-11df-b3af-0002a5d5c51b
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = ArmPlatformLib
-
-[Packages]
-  MdePkg/MdePkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  ArmPkg/ArmPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  IoLib
-  ArmLib
-  ArmTrustZoneLib
-  MemoryAllocationLib
-  PL341DmcLib
-  PL301AxiLib
-  L2X0CacheLib
-  SerialPortLib
-
-[Sources.common]
-  CTA9x4.c
-  CTA9x4Mem.c
-
-[FeaturePcd]
-  gEmbeddedTokenSpaceGuid.PcdCacheEnable
-  gArmPlatformTokenSpaceGuid.PcdNorFlashRemapping
-
-[FixedPcd]
-  gArmTokenSpaceGuid.PcdTrustzoneSupport
-  gArmTokenSpaceGuid.PcdSystemMemoryBase
-  gArmTokenSpaceGuid.PcdSystemMemorySize
-
-  gArmTokenSpaceGuid.PcdL2x0ControllerBase
-
-  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask
-  gArmTokenSpaceGuid.PcdArmPrimaryCore
+#/* @file\r
+#  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+#*/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = CTA9x4ArmVExpressLib\r
+  FILE_GUID                      = b16c63a0-f417-11df-b3af-0002a5d5c51b\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ArmPlatformLib\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  IoLib\r
+  ArmLib\r
+  ArmTrustZoneLib\r
+  MemoryAllocationLib\r
+  PL341DmcLib\r
+  PL301AxiLib\r
+  L2X0CacheLib\r
+  SerialPortLib\r
+\r
+[Sources.common]\r
+  CTA9x4.c\r
+  CTA9x4Mem.c\r
+\r
+[FeaturePcd]\r
+  gEmbeddedTokenSpaceGuid.PcdCacheEnable\r
+  gArmPlatformTokenSpaceGuid.PcdNorFlashRemapping\r
+\r
+[FixedPcd]\r
+  gArmTokenSpaceGuid.PcdTrustzoneSupport\r
+  gArmTokenSpaceGuid.PcdSystemMemoryBase\r
+  gArmTokenSpaceGuid.PcdSystemMemorySize\r
+\r
+  gArmTokenSpaceGuid.PcdL2x0ControllerBase\r
+\r
+  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask\r
+  gArmTokenSpaceGuid.PcdArmPrimaryCore\r
index b7e7b37000e4b492e11dcc321e2588d4e7d3129d..862a51aaf10f928e98c99f90184ef6f9ccde2d0b 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 <Library/IoLib.h>
-#include <Library/ArmPlatformLib.h>
-#include <Library/DebugLib.h>
-#include <Library/PcdLib.h>
-#include <Library/SerialPortLib.h>
-
-#include <Drivers/PL341Dmc.h>
-#include <Drivers/PL301Axi.h>
-#include <Drivers/SP804Timer.h>
-
-#include <Ppi/ArmMpCoreInfo.h>
-
-#include <ArmPlatform.h>
-
-#define SerialPrint(txt)  SerialPortWrite ((UINT8*)(txt), AsciiStrLen(txt)+1);
-
-ARM_CORE_INFO mVersatileExpressMpCoreInfoCTA9x4[] = {
-  {
-    // Cluster 0, Core 0
-    0x0, 0x0,
-
-    // MP Core MailBox Set/Get/Clear Addresses and Clear Value
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,
-    (UINT64)0xFFFFFFFF
-  },
-  {
-    // Cluster 0, Core 1
-    0x0, 0x1,
-
-    // MP Core MailBox Set/Get/Clear Addresses and Clear Value
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,
-    (UINT64)0xFFFFFFFF
-  },
-  {
-    // Cluster 0, Core 2
-    0x0, 0x2,
-
-    // MP Core MailBox Set/Get/Clear Addresses and Clear Value
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,
-    (UINT64)0xFFFFFFFF
-  },
-  {
-    // Cluster 0, Core 3
-    0x0, 0x3,
-
-    // MP Core MailBox Set/Get/Clear Addresses and Clear Value
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,
-    (UINT64)0xFFFFFFFF
-  }
-};
-
-// DDR2 timings
-PL341_DMC_CONFIG DDRTimings = {
-  .MaxChip   = 1,
-  .IsUserCfg = TRUE,
-  .User0Cfg = 0x7C924924,
-  .User2Cfg = (TC_UIOLHXC_VALUE << TC_UIOLHNC_SHIFT) | (TC_UIOLHXC_VALUE << TC_UIOLHPC_SHIFT) | (0x1 << TC_UIOHOCT_SHIFT) | (0x1 << TC_UIOHSTOP_SHIFT),
-  .HasQos    = TRUE,
-  .RefreshPeriod  = 0x3D0,
-  .CasLatency  = 0x8,
-  .WriteLatency  = 0x3,
-  .t_mrd    = 0x2,
-  .t_ras    = 0xA,
-  .t_rc   = 0xE,
-  .t_rcd    = 0x104,
-  .t_rfc    = 0x2f32,
-  .t_rp   = 0x14,
-  .t_rrd    = 0x2,
-  .t_wr   = 0x4,
-  .t_wtr    = 0x2,
-  .t_xp   = 0x2,
-  .t_xsr    = 0xC8,
-  .t_esr    = 0x14,
-  .MemoryCfg   = DMC_MEMORY_CONFIG_ACTIVE_CHIP_1 | DMC_MEMORY_CONFIG_BURST_4 |
-                        DMC_MEMORY_CONFIG_ROW_ADDRESS_15 | DMC_MEMORY_CONFIG_COLUMN_ADDRESS_10,
-  .MemoryCfg2  = DMC_MEMORY_CFG2_DQM_INIT | DMC_MEMORY_CFG2_CKE_INIT |
-            DMC_MEMORY_CFG2_BANK_BITS_3 | DMC_MEMORY_CFG2_MEM_WIDTH_32,
-  .MemoryCfg3  = 0x00000001,
-  .ChipCfg0    = 0x00010000,
-  .t_faw    = 0x00000A0D,
-  .ModeReg = DDR2_MR_BURST_LENGTH_4 | DDR2_MR_CAS_LATENCY_4 | DDR2_MR_WR_CYCLES_4,
-  .ExtModeReg = DDR_EMR_RTT_50R | (DDR_EMR_ODS_VAL << DDR_EMR_ODS_MASK),
-};
-
-/**
-  Return the current Boot Mode
-
-  This function returns the boot reason on the platform
-
-  @return   Return the current Boot Mode of the platform
-
-**/
-EFI_BOOT_MODE
-ArmPlatformGetBootMode (
-  VOID
-  )
-{
-  if (MmioRead32(ARM_VE_SYS_FLAGS_NV_REG) == 0) {
-    return BOOT_WITH_FULL_CONFIGURATION;
-  } else {
-    return BOOT_ON_S2_RESUME;
-  }
-}
-
-/**
-  Initialize controllers that must setup in the normal world
-
-  This function is called by the ArmPlatformPkg/PrePi or ArmPlatformPkg/PlatformPei
-  in the PEI phase.
-
-**/
-RETURN_STATUS
-ArmPlatformInitialize (
-  IN  UINTN                     MpId
-  )
-{
-  if (!IS_PRIMARY_CORE(MpId)) {
-    return RETURN_SUCCESS;
-  }
-
-  // Configure periodic timer (TIMER0) for 1MHz operation
-  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER0_TIMCLK);
-  // Configure 1MHz clock
-  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER1_TIMCLK);
-  // configure SP810 to use 1MHz clock and disable
-  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER2_EN, SP810_SYS_CTRL_TIMER2_TIMCLK);
-  // Configure SP810 to use 1MHz clock and disable
-  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER3_EN, SP810_SYS_CTRL_TIMER3_TIMCLK);
-
-  return RETURN_SUCCESS;
-}
-
-/**
-  Initialize the system (or sometimes called permanent) memory
-
-  This memory is generally represented by the DRAM.
-
-**/
-VOID
-ArmPlatformInitializeSystemMemory (
-  VOID
-  )
-{
-  UINT32 Value;
-
-  // Memory Map remapping
-  if (FeaturePcdGet(PcdNorFlashRemapping)) {
-    SerialPrint ("Secure ROM at 0x0\n\r");
-  } else {
-    Value = MmioRead32(ARM_VE_SYS_CFGRW1_REG); //Scc - CFGRW1
-    // Remap the DRAM to 0x0
-    MmioWrite32(ARM_VE_SYS_CFGRW1_REG, (Value & 0x0FFFFFFF) | ARM_VE_CFGRW1_REMAP_DRAM);
-  }
-
-  PL341DmcInit(ARM_VE_DMC_BASE, &DDRTimings);
-  PL301AxiInit(ARM_VE_FAXI_BASE);
-}
-
-EFI_STATUS
-PrePeiCoreGetMpCoreInfo (
-  OUT UINTN                   *CoreCount,
-  OUT ARM_CORE_INFO           **ArmCoreTable
-  )
-{
-  *CoreCount    = sizeof(mVersatileExpressMpCoreInfoCTA9x4) / sizeof(ARM_CORE_INFO);
-  *ArmCoreTable = mVersatileExpressMpCoreInfoCTA9x4;
-
-  return EFI_SUCCESS;
-}
-
-// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore
-EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;
-ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };
-
-EFI_PEI_PPI_DESCRIPTOR      gPlatformPpiTable[] = {
-  {
-    EFI_PEI_PPI_DESCRIPTOR_PPI,
-    &mArmMpCoreInfoPpiGuid,
-    &mMpCoreInfoPpi
-  }
-};
-
-VOID
-ArmPlatformGetPlatformPpiList (
-  OUT UINTN                   *PpiListSize,
-  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList
-  )
-{
-  *PpiListSize = sizeof(gPlatformPpiTable);
-  *PpiList = gPlatformPpiTable;
-}
-
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include <Library/IoLib.h>\r
+#include <Library/ArmPlatformLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/SerialPortLib.h>\r
+\r
+#include <Drivers/PL341Dmc.h>\r
+#include <Drivers/PL301Axi.h>\r
+#include <Drivers/SP804Timer.h>\r
+\r
+#include <Ppi/ArmMpCoreInfo.h>\r
+\r
+#include <ArmPlatform.h>\r
+\r
+#define SerialPrint(txt)  SerialPortWrite ((UINT8*)(txt), AsciiStrLen(txt)+1);\r
+\r
+ARM_CORE_INFO mVersatileExpressMpCoreInfoCTA9x4[] = {\r
+  {\r
+    // Cluster 0, Core 0\r
+    0x0, 0x0,\r
+\r
+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,\r
+    (UINT64)0xFFFFFFFF\r
+  },\r
+  {\r
+    // Cluster 0, Core 1\r
+    0x0, 0x1,\r
+\r
+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,\r
+    (UINT64)0xFFFFFFFF\r
+  },\r
+  {\r
+    // Cluster 0, Core 2\r
+    0x0, 0x2,\r
+\r
+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,\r
+    (UINT64)0xFFFFFFFF\r
+  },\r
+  {\r
+    // Cluster 0, Core 3\r
+    0x0, 0x3,\r
+\r
+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,\r
+    (UINT64)0xFFFFFFFF\r
+  }\r
+};\r
+\r
+// DDR2 timings\r
+PL341_DMC_CONFIG DDRTimings = {\r
+  .MaxChip   = 1,\r
+  .IsUserCfg = TRUE,\r
+  .User0Cfg = 0x7C924924,\r
+  .User2Cfg = (TC_UIOLHXC_VALUE << TC_UIOLHNC_SHIFT) | (TC_UIOLHXC_VALUE << TC_UIOLHPC_SHIFT) | (0x1 << TC_UIOHOCT_SHIFT) | (0x1 << TC_UIOHSTOP_SHIFT),\r
+  .HasQos    = TRUE,\r
+  .RefreshPeriod  = 0x3D0,\r
+  .CasLatency  = 0x8,\r
+  .WriteLatency  = 0x3,\r
+  .t_mrd    = 0x2,\r
+  .t_ras    = 0xA,\r
+  .t_rc   = 0xE,\r
+  .t_rcd    = 0x104,\r
+  .t_rfc    = 0x2f32,\r
+  .t_rp   = 0x14,\r
+  .t_rrd    = 0x2,\r
+  .t_wr   = 0x4,\r
+  .t_wtr    = 0x2,\r
+  .t_xp   = 0x2,\r
+  .t_xsr    = 0xC8,\r
+  .t_esr    = 0x14,\r
+  .MemoryCfg   = DMC_MEMORY_CONFIG_ACTIVE_CHIP_1 | DMC_MEMORY_CONFIG_BURST_4 |\r
+                        DMC_MEMORY_CONFIG_ROW_ADDRESS_15 | DMC_MEMORY_CONFIG_COLUMN_ADDRESS_10,\r
+  .MemoryCfg2  = DMC_MEMORY_CFG2_DQM_INIT | DMC_MEMORY_CFG2_CKE_INIT |\r
+            DMC_MEMORY_CFG2_BANK_BITS_3 | DMC_MEMORY_CFG2_MEM_WIDTH_32,\r
+  .MemoryCfg3  = 0x00000001,\r
+  .ChipCfg0    = 0x00010000,\r
+  .t_faw    = 0x00000A0D,\r
+  .ModeReg = DDR2_MR_BURST_LENGTH_4 | DDR2_MR_CAS_LATENCY_4 | DDR2_MR_WR_CYCLES_4,\r
+  .ExtModeReg = DDR_EMR_RTT_50R | (DDR_EMR_ODS_VAL << DDR_EMR_ODS_MASK),\r
+};\r
+\r
+/**\r
+  Return the current Boot Mode\r
+\r
+  This function returns the boot reason on the platform\r
+\r
+  @return   Return the current Boot Mode of the platform\r
+\r
+**/\r
+EFI_BOOT_MODE\r
+ArmPlatformGetBootMode (\r
+  VOID\r
+  )\r
+{\r
+  if (MmioRead32(ARM_VE_SYS_FLAGS_NV_REG) == 0) {\r
+    return BOOT_WITH_FULL_CONFIGURATION;\r
+  } else {\r
+    return BOOT_ON_S2_RESUME;\r
+  }\r
+}\r
+\r
+/**\r
+  Initialize controllers that must setup in the normal world\r
+\r
+  This function is called by the ArmPlatformPkg/PrePi or ArmPlatformPkg/PlatformPei\r
+  in the PEI phase.\r
+\r
+**/\r
+RETURN_STATUS\r
+ArmPlatformInitialize (\r
+  IN  UINTN                     MpId\r
+  )\r
+{\r
+  if (!IS_PRIMARY_CORE(MpId)) {\r
+    return RETURN_SUCCESS;\r
+  }\r
+\r
+  // Configure periodic timer (TIMER0) for 1MHz operation\r
+  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER0_TIMCLK);\r
+  // Configure 1MHz clock\r
+  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER1_TIMCLK);\r
+  // configure SP810 to use 1MHz clock and disable\r
+  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER2_EN, SP810_SYS_CTRL_TIMER2_TIMCLK);\r
+  // Configure SP810 to use 1MHz clock and disable\r
+  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER3_EN, SP810_SYS_CTRL_TIMER3_TIMCLK);\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Initialize the system (or sometimes called permanent) memory\r
+\r
+  This memory is generally represented by the DRAM.\r
+\r
+**/\r
+VOID\r
+ArmPlatformInitializeSystemMemory (\r
+  VOID\r
+  )\r
+{\r
+  UINT32 Value;\r
+\r
+  // Memory Map remapping\r
+  if (FeaturePcdGet(PcdNorFlashRemapping)) {\r
+    SerialPrint ("Secure ROM at 0x0\n\r");\r
+  } else {\r
+    Value = MmioRead32(ARM_VE_SYS_CFGRW1_REG); //Scc - CFGRW1\r
+    // Remap the DRAM to 0x0\r
+    MmioWrite32(ARM_VE_SYS_CFGRW1_REG, (Value & 0x0FFFFFFF) | ARM_VE_CFGRW1_REMAP_DRAM);\r
+  }\r
+\r
+  PL341DmcInit(ARM_VE_DMC_BASE, &DDRTimings);\r
+  PL301AxiInit(ARM_VE_FAXI_BASE);\r
+}\r
+\r
+EFI_STATUS\r
+PrePeiCoreGetMpCoreInfo (\r
+  OUT UINTN                   *CoreCount,\r
+  OUT ARM_CORE_INFO           **ArmCoreTable\r
+  )\r
+{\r
+  *CoreCount    = sizeof(mVersatileExpressMpCoreInfoCTA9x4) / sizeof(ARM_CORE_INFO);\r
+  *ArmCoreTable = mVersatileExpressMpCoreInfoCTA9x4;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore\r
+EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;\r
+ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };\r
+\r
+EFI_PEI_PPI_DESCRIPTOR      gPlatformPpiTable[] = {\r
+  {\r
+    EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+    &mArmMpCoreInfoPpiGuid,\r
+    &mMpCoreInfoPpi\r
+  }\r
+};\r
+\r
+VOID\r
+ArmPlatformGetPlatformPpiList (\r
+  OUT UINTN                   *PpiListSize,\r
+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList\r
+  )\r
+{\r
+  *PpiListSize = sizeof(gPlatformPpiTable);\r
+  *PpiList = gPlatformPpiTable;\r
+}\r
+\r
index 69ffd45fdf772a7fb969d3db068a72f68b9845b4..f055608abc90173f2e32e9c196fb19330cb98726 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 <Library/IoLib.h>
-#include <Library/ArmPlatformLib.h>
-#include <Library/DebugLib.h>
-#include <Library/PcdLib.h>
-
-#include <Ppi/ArmMpCoreInfo.h>
-
-#include <ArmPlatform.h>
-
-UINTN
-ArmGetCpuCountPerCluster (
-  VOID
-  );
-
-ARM_CORE_INFO mVersatileExpressMpCoreInfoTable[] = {
-  {
-    // Cluster 0, Core 0
-    0x0, 0x0,
-
-    // MP Core MailBox Set/Get/Clear Addresses and Clear Value
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,
-    (UINT64)0xFFFFFFFF
-  },
-  {
-    // Cluster 0, Core 1
-    0x0, 0x1,
-
-    // MP Core MailBox Set/Get/Clear Addresses and Clear Value
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,
-    (UINT64)0xFFFFFFFF
-  },
-  {
-    // Cluster 0, Core 2
-    0x0, 0x2,
-
-    // MP Core MailBox Set/Get/Clear Addresses and Clear Value
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,
-    (UINT64)0xFFFFFFFF
-  },
-  {
-    // Cluster 0, Core 3
-    0x0, 0x3,
-
-    // MP Core MailBox Set/Get/Clear Addresses and Clear Value
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,
-    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,
-    (UINT64)0xFFFFFFFF
-  }
-};
-
-/**
-  Return the current Boot Mode
-
-  This function returns the boot reason on the platform
-
-  @return   Return the current Boot Mode of the platform
-
-**/
-EFI_BOOT_MODE
-ArmPlatformGetBootMode (
-  VOID
-  )
-{
-  return BOOT_WITH_FULL_CONFIGURATION;
-}
-
-/**
-  Initialize controllers that must setup in the normal world
-
-  This function is called by the ArmPlatformPkg/Pei or ArmPlatformPkg/Pei/PlatformPeim
-  in the PEI phase.
-
-**/
-RETURN_STATUS
-ArmPlatformInitialize (
-  IN  UINTN                     MpId
-  )
-{
-  if (!IS_PRIMARY_CORE(MpId)) {
-    return RETURN_SUCCESS;
-  }
-
-  // Disable memory remapping and return to normal mapping
-  MmioOr32 (SP810_CTRL_BASE, BIT8);
-
-  return RETURN_SUCCESS;
-}
-
-/**
-  Initialize the system (or sometimes called permanent) memory
-
-  This memory is generally represented by the DRAM.
-
-**/
-VOID
-ArmPlatformInitializeSystemMemory (
-  VOID
-  )
-{
-  // Nothing to do here
-}
-
-EFI_STATUS
-PrePeiCoreGetMpCoreInfo (
-  OUT UINTN                   *CoreCount,
-  OUT ARM_CORE_INFO           **ArmCoreTable
-  )
-{
-  UINT32   ProcType;
-
-  ProcType = MmioRead32 (ARM_VE_SYS_PROCID0_REG) & ARM_VE_SYS_PROC_ID_MASK;
-  if ((ProcType == ARM_VE_SYS_PROC_ID_CORTEX_A9) || (ProcType == ARM_VE_SYS_PROC_ID_CORTEX_A15)) {
-    // Only support one cluster
-    *CoreCount    = ArmGetCpuCountPerCluster ();
-    *ArmCoreTable = mVersatileExpressMpCoreInfoTable;
-    return EFI_SUCCESS;
-  } else {
-    return EFI_UNSUPPORTED;
-  }
-}
-
-// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore
-EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;
-ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };
-
-EFI_PEI_PPI_DESCRIPTOR      gPlatformPpiTable[] = {
-  {
-    EFI_PEI_PPI_DESCRIPTOR_PPI,
-    &mArmMpCoreInfoPpiGuid,
-    &mMpCoreInfoPpi
-  }
-};
-
-VOID
-ArmPlatformGetPlatformPpiList (
-  OUT UINTN                   *PpiListSize,
-  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList
-  )
-{
-  *PpiListSize = sizeof(gPlatformPpiTable);
-  *PpiList = gPlatformPpiTable;
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include <Library/IoLib.h>\r
+#include <Library/ArmPlatformLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+#include <Ppi/ArmMpCoreInfo.h>\r
+\r
+#include <ArmPlatform.h>\r
+\r
+UINTN\r
+ArmGetCpuCountPerCluster (\r
+  VOID\r
+  );\r
+\r
+ARM_CORE_INFO mVersatileExpressMpCoreInfoTable[] = {\r
+  {\r
+    // Cluster 0, Core 0\r
+    0x0, 0x0,\r
+\r
+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,\r
+    (UINT64)0xFFFFFFFF\r
+  },\r
+  {\r
+    // Cluster 0, Core 1\r
+    0x0, 0x1,\r
+\r
+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,\r
+    (UINT64)0xFFFFFFFF\r
+  },\r
+  {\r
+    // Cluster 0, Core 2\r
+    0x0, 0x2,\r
+\r
+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,\r
+    (UINT64)0xFFFFFFFF\r
+  },\r
+  {\r
+    // Cluster 0, Core 3\r
+    0x0, 0x3,\r
+\r
+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,\r
+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,\r
+    (UINT64)0xFFFFFFFF\r
+  }\r
+};\r
+\r
+/**\r
+  Return the current Boot Mode\r
+\r
+  This function returns the boot reason on the platform\r
+\r
+  @return   Return the current Boot Mode of the platform\r
+\r
+**/\r
+EFI_BOOT_MODE\r
+ArmPlatformGetBootMode (\r
+  VOID\r
+  )\r
+{\r
+  return BOOT_WITH_FULL_CONFIGURATION;\r
+}\r
+\r
+/**\r
+  Initialize controllers that must setup in the normal world\r
+\r
+  This function is called by the ArmPlatformPkg/Pei or ArmPlatformPkg/Pei/PlatformPeim\r
+  in the PEI phase.\r
+\r
+**/\r
+RETURN_STATUS\r
+ArmPlatformInitialize (\r
+  IN  UINTN                     MpId\r
+  )\r
+{\r
+  if (!IS_PRIMARY_CORE(MpId)) {\r
+    return RETURN_SUCCESS;\r
+  }\r
+\r
+  // Disable memory remapping and return to normal mapping\r
+  MmioOr32 (SP810_CTRL_BASE, BIT8);\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Initialize the system (or sometimes called permanent) memory\r
+\r
+  This memory is generally represented by the DRAM.\r
+\r
+**/\r
+VOID\r
+ArmPlatformInitializeSystemMemory (\r
+  VOID\r
+  )\r
+{\r
+  // Nothing to do here\r
+}\r
+\r
+EFI_STATUS\r
+PrePeiCoreGetMpCoreInfo (\r
+  OUT UINTN                   *CoreCount,\r
+  OUT ARM_CORE_INFO           **ArmCoreTable\r
+  )\r
+{\r
+  UINT32   ProcType;\r
+\r
+  ProcType = MmioRead32 (ARM_VE_SYS_PROCID0_REG) & ARM_VE_SYS_PROC_ID_MASK;\r
+  if ((ProcType == ARM_VE_SYS_PROC_ID_CORTEX_A9) || (ProcType == ARM_VE_SYS_PROC_ID_CORTEX_A15)) {\r
+    // Only support one cluster\r
+    *CoreCount    = ArmGetCpuCountPerCluster ();\r
+    *ArmCoreTable = mVersatileExpressMpCoreInfoTable;\r
+    return EFI_SUCCESS;\r
+  } else {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+}\r
+\r
+// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore\r
+EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;\r
+ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };\r
+\r
+EFI_PEI_PPI_DESCRIPTOR      gPlatformPpiTable[] = {\r
+  {\r
+    EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+    &mArmMpCoreInfoPpiGuid,\r
+    &mMpCoreInfoPpi\r
+  }\r
+};\r
+\r
+VOID\r
+ArmPlatformGetPlatformPpiList (\r
+  OUT UINTN                   *PpiListSize,\r
+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList\r
+  )\r
+{\r
+  *PpiListSize = sizeof(gPlatformPpiTable);\r
+  *PpiList = gPlatformPpiTable;\r
+}\r
index f3e8cafc0f9efed671fce835b2ed2befb8b92d35..cb6376f65e41e212adf6c414ff140e99f248af57 100644 (file)
@@ -103,7 +103,7 @@ ArmPlatformGetVirtualMemoryMap (
   VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_PERIPH_BASE;\r
   VirtualMemoryTable[Index].VirtualBase  = ARM_VE_SMB_PERIPH_BASE;\r
   VirtualMemoryTable[Index].Length       = 2 * ARM_VE_SMB_PERIPH_SZ;\r
   VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_PERIPH_BASE;\r
   VirtualMemoryTable[Index].VirtualBase  = ARM_VE_SMB_PERIPH_BASE;\r
   VirtualMemoryTable[Index].Length       = 2 * ARM_VE_SMB_PERIPH_SZ;\r
-  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r
 \r
 //TODO:This should be enabled for final release. Right now, ARM VE RTSM crashes.\r
 //  // If a Logic Tile is connected to The ARM Versatile Express Motherboard\r
 \r
 //TODO:This should be enabled for final release. Right now, ARM VE RTSM crashes.\r
 //  // If a Logic Tile is connected to The ARM Versatile Express Motherboard\r
index ce9bc8b271109470db1c6bb92d0755d3d9d94aac..228a0fb0f830c2a06d34a3dc90fe63787d37dcaf 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 <Library/ArmPlatformLib.h>
-#include <Library/ArmPlatformSysConfigLib.h>
-#include <Library/DebugLib.h>
-#include <Library/IoLib.h>
-#include <Library/PcdLib.h>
-
-#include <Drivers/ArmTrustzone.h>
-#include <Drivers/PL310L2Cache.h>
-
-#include <ArmPlatform.h>
-
-/**
-  Initialize the Secure peripherals and memory regions
-
-  If Trustzone is supported by your platform then this function makes the required initialization
-  of the secure peripherals and memory regions.
-
-**/
-VOID
-ArmPlatformSecTrustzoneInit (
-  IN  UINTN                     MpId
-  )
-{
-  // Nothing to do
-  if (!IS_PRIMARY_CORE(MpId)) {
-    return;
-  }
-
-  //
-  // Setup TZ Protection Controller
-  //
-
-  if (MmioRead32(ARM_VE_SYS_CFGRW1_REG) & ARM_VE_CFGRW1_TZASC_EN_BIT_MASK) {
-    ASSERT (PcdGetBool (PcdTrustzoneSupport) == TRUE);
-  } else {
-    ASSERT (PcdGetBool (PcdTrustzoneSupport) == FALSE);
-  }
-
-  // Set Non Secure access for all devices
-  TZPCSetDecProtBits(ARM_VE_TZPC_BASE, TZPC_DECPROT_0, 0xFFFFFFFF);
-  TZPCSetDecProtBits(ARM_VE_TZPC_BASE, TZPC_DECPROT_1, 0xFFFFFFFF);
-  TZPCSetDecProtBits(ARM_VE_TZPC_BASE, TZPC_DECPROT_2, 0xFFFFFFFF);
-
-  // Remove Non secure access to secure devices
-  TZPCClearDecProtBits(ARM_VE_TZPC_BASE, TZPC_DECPROT_0,
-       ARM_VE_DECPROT_BIT_TZPC | ARM_VE_DECPROT_BIT_DMC_TZASC | ARM_VE_DECPROT_BIT_NMC_TZASC | ARM_VE_DECPROT_BIT_SMC_TZASC);
-
-  TZPCClearDecProtBits(ARM_VE_TZPC_BASE, TZPC_DECPROT_2,
-       ARM_VE_DECPROT_BIT_EXT_MAST_TZ | ARM_VE_DECPROT_BIT_DMC_TZASC_LOCK | ARM_VE_DECPROT_BIT_NMC_TZASC_LOCK | ARM_VE_DECPROT_BIT_SMC_TZASC_LOCK);
-
-  //
-  // Setup TZ Address Space Controller for the SMC. Create 5 Non Secure regions (NOR0, NOR1, SRAM, SMC Peripheral regions)
-  //
-
-  // NOR Flash 0 non secure (BootMon)
-  TZASCSetRegion(ARM_VE_TZASC_BASE,1,TZASC_REGION_ENABLED,
-      ARM_VE_SMB_NOR0_BASE,0,
-      TZASC_REGION_SIZE_64MB, TZASC_REGION_SECURITY_NSRW);
-
-  // NOR Flash 1. The first half of the NOR Flash1 must be secure for the secure firmware (sec_uefi.bin)
-  if (PcdGetBool (PcdTrustzoneSupport) == TRUE) {
-    //Note: Your OS Kernel must be aware of the secure regions before to enable this region
-    TZASCSetRegion(ARM_VE_TZASC_BASE,2,TZASC_REGION_ENABLED,
-        ARM_VE_SMB_NOR1_BASE + SIZE_32MB,0,
-        TZASC_REGION_SIZE_32MB, TZASC_REGION_SECURITY_NSRW);
-  } else {
-    TZASCSetRegion(ARM_VE_TZASC_BASE,2,TZASC_REGION_ENABLED,
-        ARM_VE_SMB_NOR1_BASE,0,
-        TZASC_REGION_SIZE_64MB, TZASC_REGION_SECURITY_NSRW);
-  }
-
-  // Base of SRAM. Only half of SRAM in Non Secure world
-  // First half non secure (16MB) + Second Half secure (16MB) = 32MB of SRAM
-  if (PcdGetBool (PcdTrustzoneSupport) == TRUE) {
-    //Note: Your OS Kernel must be aware of the secure regions before to enable this region
-    TZASCSetRegion(ARM_VE_TZASC_BASE,3,TZASC_REGION_ENABLED,
-        ARM_VE_SMB_SRAM_BASE,0,
-        TZASC_REGION_SIZE_16MB, TZASC_REGION_SECURITY_NSRW);
-  } else {
-    TZASCSetRegion(ARM_VE_TZASC_BASE,3,TZASC_REGION_ENABLED,
-        ARM_VE_SMB_SRAM_BASE,0,
-        TZASC_REGION_SIZE_32MB, TZASC_REGION_SECURITY_NSRW);
-  }
-
-  // Memory Mapped Peripherals. All in non secure world
-  TZASCSetRegion(ARM_VE_TZASC_BASE,4,TZASC_REGION_ENABLED,
-      ARM_VE_SMB_PERIPH_BASE,0,
-      TZASC_REGION_SIZE_64MB, TZASC_REGION_SECURITY_NSRW);
-
-  // MotherBoard Peripherals and On-chip peripherals.
-  TZASCSetRegion(ARM_VE_TZASC_BASE,5,TZASC_REGION_ENABLED,
-      ARM_VE_SMB_MB_ON_CHIP_PERIPH_BASE,0,
-      TZASC_REGION_SIZE_256MB, TZASC_REGION_SECURITY_NSRW);
-}
-
-/**
-  Initialize controllers that must setup at the early stage
-
-  Some peripherals must be initialized in Secure World.
-  For example, some L2x0 requires to be initialized in Secure World
-
-**/
-RETURN_STATUS
-ArmPlatformSecInitialize (
-  IN  UINTN                     MpId
-  )
-{
-  // If it is not the primary core then there is nothing to do
-  if (!IS_PRIMARY_CORE(MpId)) {
-    return RETURN_SUCCESS;
-  }
-
-  // The L2x0 controller must be intialize in Secure World
-  L2x0CacheInit(PcdGet32(PcdL2x0ControllerBase),
-      PL310_TAG_LATENCIES(L2x0_LATENCY_8_CYCLES,L2x0_LATENCY_8_CYCLES,L2x0_LATENCY_8_CYCLES),
-      PL310_DATA_LATENCIES(L2x0_LATENCY_8_CYCLES,L2x0_LATENCY_8_CYCLES,L2x0_LATENCY_8_CYCLES),
-      0,~0, // Use default setting for the Auxiliary Control Register
-      FALSE);
-
-  // Initialize the System Configuration
-  ArmPlatformSysConfigInitialize ();
-
-  // If we skip the PEI Core we could want to initialize the DRAM in the SEC phase.
-  // If we are in standalone, we need the initialization to copy the UEFI firmware into DRAM
-  if ((FeaturePcdGet (PcdSystemMemoryInitializeInSec)) || (FeaturePcdGet (PcdStandalone) == FALSE)) {
-    // If it is not a standalone build ensure the PcdSystemMemoryInitializeInSec has been set
-    ASSERT(FeaturePcdGet (PcdSystemMemoryInitializeInSec) == TRUE);
-
-    // Initialize system memory (DRAM)
-    ArmPlatformInitializeSystemMemory ();
-  }
-
-  return RETURN_SUCCESS;
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include <Library/ArmPlatformLib.h>\r
+#include <Library/ArmPlatformSysConfigLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+#include <Drivers/ArmTrustzone.h>\r
+#include <Drivers/PL310L2Cache.h>\r
+\r
+#include <ArmPlatform.h>\r
+\r
+/**\r
+  Initialize the Secure peripherals and memory regions\r
+\r
+  If Trustzone is supported by your platform then this function makes the required initialization\r
+  of the secure peripherals and memory regions.\r
+\r
+**/\r
+VOID\r
+ArmPlatformSecTrustzoneInit (\r
+  IN  UINTN                     MpId\r
+  )\r
+{\r
+  // Nothing to do\r
+  if (!IS_PRIMARY_CORE(MpId)) {\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Setup TZ Protection Controller\r
+  //\r
+\r
+  if (MmioRead32(ARM_VE_SYS_CFGRW1_REG) & ARM_VE_CFGRW1_TZASC_EN_BIT_MASK) {\r
+    ASSERT (PcdGetBool (PcdTrustzoneSupport) == TRUE);\r
+  } else {\r
+    ASSERT (PcdGetBool (PcdTrustzoneSupport) == FALSE);\r
+  }\r
+\r
+  // Set Non Secure access for all devices\r
+  TZPCSetDecProtBits(ARM_VE_TZPC_BASE, TZPC_DECPROT_0, 0xFFFFFFFF);\r
+  TZPCSetDecProtBits(ARM_VE_TZPC_BASE, TZPC_DECPROT_1, 0xFFFFFFFF);\r
+  TZPCSetDecProtBits(ARM_VE_TZPC_BASE, TZPC_DECPROT_2, 0xFFFFFFFF);\r
+\r
+  // Remove Non secure access to secure devices\r
+  TZPCClearDecProtBits(ARM_VE_TZPC_BASE, TZPC_DECPROT_0,\r
+       ARM_VE_DECPROT_BIT_TZPC | ARM_VE_DECPROT_BIT_DMC_TZASC | ARM_VE_DECPROT_BIT_NMC_TZASC | ARM_VE_DECPROT_BIT_SMC_TZASC);\r
+\r
+  TZPCClearDecProtBits(ARM_VE_TZPC_BASE, TZPC_DECPROT_2,\r
+       ARM_VE_DECPROT_BIT_EXT_MAST_TZ | ARM_VE_DECPROT_BIT_DMC_TZASC_LOCK | ARM_VE_DECPROT_BIT_NMC_TZASC_LOCK | ARM_VE_DECPROT_BIT_SMC_TZASC_LOCK);\r
+\r
+  //\r
+  // Setup TZ Address Space Controller for the SMC. Create 5 Non Secure regions (NOR0, NOR1, SRAM, SMC Peripheral regions)\r
+  //\r
+\r
+  // NOR Flash 0 non secure (BootMon)\r
+  TZASCSetRegion(ARM_VE_TZASC_BASE,1,TZASC_REGION_ENABLED,\r
+      ARM_VE_SMB_NOR0_BASE,0,\r
+      TZASC_REGION_SIZE_64MB, TZASC_REGION_SECURITY_NSRW);\r
+\r
+  // NOR Flash 1. The first half of the NOR Flash1 must be secure for the secure firmware (sec_uefi.bin)\r
+  if (PcdGetBool (PcdTrustzoneSupport) == TRUE) {\r
+    //Note: Your OS Kernel must be aware of the secure regions before to enable this region\r
+    TZASCSetRegion(ARM_VE_TZASC_BASE,2,TZASC_REGION_ENABLED,\r
+        ARM_VE_SMB_NOR1_BASE + SIZE_32MB,0,\r
+        TZASC_REGION_SIZE_32MB, TZASC_REGION_SECURITY_NSRW);\r
+  } else {\r
+    TZASCSetRegion(ARM_VE_TZASC_BASE,2,TZASC_REGION_ENABLED,\r
+        ARM_VE_SMB_NOR1_BASE,0,\r
+        TZASC_REGION_SIZE_64MB, TZASC_REGION_SECURITY_NSRW);\r
+  }\r
+\r
+  // Base of SRAM. Only half of SRAM in Non Secure world\r
+  // First half non secure (16MB) + Second Half secure (16MB) = 32MB of SRAM\r
+  if (PcdGetBool (PcdTrustzoneSupport) == TRUE) {\r
+    //Note: Your OS Kernel must be aware of the secure regions before to enable this region\r
+    TZASCSetRegion(ARM_VE_TZASC_BASE,3,TZASC_REGION_ENABLED,\r
+        ARM_VE_SMB_SRAM_BASE,0,\r
+        TZASC_REGION_SIZE_16MB, TZASC_REGION_SECURITY_NSRW);\r
+  } else {\r
+    TZASCSetRegion(ARM_VE_TZASC_BASE,3,TZASC_REGION_ENABLED,\r
+        ARM_VE_SMB_SRAM_BASE,0,\r
+        TZASC_REGION_SIZE_32MB, TZASC_REGION_SECURITY_NSRW);\r
+  }\r
+\r
+  // Memory Mapped Peripherals. All in non secure world\r
+  TZASCSetRegion(ARM_VE_TZASC_BASE,4,TZASC_REGION_ENABLED,\r
+      ARM_VE_SMB_PERIPH_BASE,0,\r
+      TZASC_REGION_SIZE_64MB, TZASC_REGION_SECURITY_NSRW);\r
+\r
+  // MotherBoard Peripherals and On-chip peripherals.\r
+  TZASCSetRegion(ARM_VE_TZASC_BASE,5,TZASC_REGION_ENABLED,\r
+      ARM_VE_SMB_MB_ON_CHIP_PERIPH_BASE,0,\r
+      TZASC_REGION_SIZE_256MB, TZASC_REGION_SECURITY_NSRW);\r
+}\r
+\r
+/**\r
+  Initialize controllers that must setup at the early stage\r
+\r
+  Some peripherals must be initialized in Secure World.\r
+  For example, some L2x0 requires to be initialized in Secure World\r
+\r
+**/\r
+RETURN_STATUS\r
+ArmPlatformSecInitialize (\r
+  IN  UINTN                     MpId\r
+  )\r
+{\r
+  // If it is not the primary core then there is nothing to do\r
+  if (!IS_PRIMARY_CORE(MpId)) {\r
+    return RETURN_SUCCESS;\r
+  }\r
+\r
+  // The L2x0 controller must be intialize in Secure World\r
+  L2x0CacheInit(PcdGet32(PcdL2x0ControllerBase),\r
+      PL310_TAG_LATENCIES(L2x0_LATENCY_8_CYCLES,L2x0_LATENCY_8_CYCLES,L2x0_LATENCY_8_CYCLES),\r
+      PL310_DATA_LATENCIES(L2x0_LATENCY_8_CYCLES,L2x0_LATENCY_8_CYCLES,L2x0_LATENCY_8_CYCLES),\r
+      0,~0, // Use default setting for the Auxiliary Control Register\r
+      FALSE);\r
+\r
+  // Initialize the System Configuration\r
+  ArmPlatformSysConfigInitialize ();\r
+\r
+  // If we skip the PEI Core we could want to initialize the DRAM in the SEC phase.\r
+  // If we are in standalone, we need the initialization to copy the UEFI firmware into DRAM\r
+  if ((FeaturePcdGet (PcdSystemMemoryInitializeInSec)) || (FeaturePcdGet (PcdStandalone) == FALSE)) {\r
+    // If it is not a standalone build ensure the PcdSystemMemoryInitializeInSec has been set\r
+    ASSERT(FeaturePcdGet (PcdSystemMemoryInitializeInSec) == TRUE);\r
+\r
+    // Initialize system memory (DRAM)\r
+    ArmPlatformInitializeSystemMemory ();\r
+  }\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
index 4a1e056af0ee723449a94106bfe7ff6d9b3cc13d..ff8476718f3b24fc1d1226b3ca8d6b3ec7b1956e 100644 (file)
@@ -1,52 +1,52 @@
-#/* @file
-#  Copyright (c) 2011-2012, ARM Limited. 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                      = RTSMArmVExpressSecLib
-  FILE_GUID                      = 1fdaabb0-ab7d-480c-91ff-428dc1546f3a
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = ArmPlatformSecLib
-
-[Packages]
-  MdePkg/MdePkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  ArmPkg/ArmPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  IoLib
-  ArmLib
-  SerialPortLib
-
-[Sources.common]
-  RTSMSec.c
-
-[Sources.ARM]
-  Arm/RTSMBoot.asm     | RVCT
-  Arm/RTSMBoot.S       | GCC
-  Arm/RTSMHelper.asm   | RVCT
-  Arm/RTSMHelper.S     | GCC
-
-[FeaturePcd]
-  gEmbeddedTokenSpaceGuid.PcdCacheEnable
-  gArmPlatformTokenSpaceGuid.PcdNorFlashRemapping
-  gArmPlatformTokenSpaceGuid.PcdStandalone
-
-[FixedPcd]
-  gArmTokenSpaceGuid.PcdFvBaseAddress
-
-  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask
-  gArmTokenSpaceGuid.PcdArmPrimaryCore
+#/* @file\r
+#  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+#*/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = RTSMArmVExpressSecLib\r
+  FILE_GUID                      = 1fdaabb0-ab7d-480c-91ff-428dc1546f3a\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ArmPlatformSecLib\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  IoLib\r
+  ArmLib\r
+  SerialPortLib\r
+\r
+[Sources.common]\r
+  RTSMSec.c\r
+\r
+[Sources.ARM]\r
+  Arm/RTSMBoot.asm     | RVCT\r
+  Arm/RTSMBoot.S       | GCC\r
+  Arm/RTSMHelper.asm   | RVCT\r
+  Arm/RTSMHelper.S     | GCC\r
+\r
+[FeaturePcd]\r
+  gEmbeddedTokenSpaceGuid.PcdCacheEnable\r
+  gArmPlatformTokenSpaceGuid.PcdNorFlashRemapping\r
+  gArmPlatformTokenSpaceGuid.PcdStandalone\r
+\r
+[FixedPcd]\r
+  gArmTokenSpaceGuid.PcdFvBaseAddress\r
+\r
+  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask\r
+  gArmTokenSpaceGuid.PcdArmPrimaryCore\r
index 4ae6301603407e1a7cca040c4443110677d29208..92df56cd575040874faf116864df694d71a2174b 100644 (file)
@@ -1,83 +1,83 @@
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 <Library/IoLib.h>
-#include <Library/ArmPlatformLib.h>
-#include <Library/DebugLib.h>
-#include <Library/PcdLib.h>
-
-#include <Drivers/PL310L2Cache.h>
-#include <Drivers/SP804Timer.h>
-
-#include <ArmPlatform.h>
-
-/**
-  Initialize the Secure peripherals and memory regions
-
-  If Trustzone is supported by your platform then this function makes the required initialization
-  of the secure peripherals and memory regions.
-
-**/
-VOID
-ArmPlatformSecTrustzoneInit (
-  IN  UINTN                     MpId
-  )
-{
-  // No TZPC or TZASC on RTSM to initialize
-}
-
-/**
-  Initialize controllers that must setup at the early stage
-
-  Some peripherals must be initialized in Secure World.
-  For example, some L2x0 requires to be initialized in Secure World
-
-**/
-RETURN_STATUS
-ArmPlatformSecInitialize (
-  IN  UINTN                     MpId
-  )
-{
-  // If it is not the primary core then there is nothing to do
-  if (!IS_PRIMARY_CORE(MpId)) {
-    return RETURN_SUCCESS;
-  }
-
-  // Configure periodic timer (TIMER0) for 1MHz operation
-  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER0_TIMCLK);
-  // Configure 1MHz clock
-  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER1_TIMCLK);
-  // Configure SP810 to use 1MHz clock and disable
-  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER2_EN, SP810_SYS_CTRL_TIMER2_TIMCLK);
-  // Configure SP810 to use 1MHz clock and disable
-  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER3_EN, SP810_SYS_CTRL_TIMER3_TIMCLK);
-
-  return RETURN_SUCCESS;
-}
-
-/**
-  Call before jumping to Normal World
-
-  This function allows the firmware platform to do extra actions before
-  jumping to the Normal World
-
-**/
-VOID
-ArmPlatformSecExtraAction (
-  IN  UINTN         MpId,
-  OUT UINTN*        JumpAddress
-  )
-{
-  *JumpAddress = PcdGet32(PcdFvBaseAddress);
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include <Library/IoLib.h>\r
+#include <Library/ArmPlatformLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+#include <Drivers/PL310L2Cache.h>\r
+#include <Drivers/SP804Timer.h>\r
+\r
+#include <ArmPlatform.h>\r
+\r
+/**\r
+  Initialize the Secure peripherals and memory regions\r
+\r
+  If Trustzone is supported by your platform then this function makes the required initialization\r
+  of the secure peripherals and memory regions.\r
+\r
+**/\r
+VOID\r
+ArmPlatformSecTrustzoneInit (\r
+  IN  UINTN                     MpId\r
+  )\r
+{\r
+  // No TZPC or TZASC on RTSM to initialize\r
+}\r
+\r
+/**\r
+  Initialize controllers that must setup at the early stage\r
+\r
+  Some peripherals must be initialized in Secure World.\r
+  For example, some L2x0 requires to be initialized in Secure World\r
+\r
+**/\r
+RETURN_STATUS\r
+ArmPlatformSecInitialize (\r
+  IN  UINTN                     MpId\r
+  )\r
+{\r
+  // If it is not the primary core then there is nothing to do\r
+  if (!IS_PRIMARY_CORE(MpId)) {\r
+    return RETURN_SUCCESS;\r
+  }\r
+\r
+  // Configure periodic timer (TIMER0) for 1MHz operation\r
+  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER0_TIMCLK);\r
+  // Configure 1MHz clock\r
+  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER1_TIMCLK);\r
+  // Configure SP810 to use 1MHz clock and disable\r
+  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER2_EN, SP810_SYS_CTRL_TIMER2_TIMCLK);\r
+  // Configure SP810 to use 1MHz clock and disable\r
+  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER3_EN, SP810_SYS_CTRL_TIMER3_TIMCLK);\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Call before jumping to Normal World\r
+\r
+  This function allows the firmware platform to do extra actions before\r
+  jumping to the Normal World\r
+\r
+**/\r
+VOID\r
+ArmPlatformSecExtraAction (\r
+  IN  UINTN         MpId,\r
+  OUT UINTN*        JumpAddress\r
+  )\r
+{\r
+  *JumpAddress = PcdGet32(PcdFvBaseAddress);\r
+}\r
index 3dfa756ddb74014baad6d635700987877c42250a..8d4f52c52e2dc62ca65515ff5de96e74c9cbf9f7 100644 (file)
@@ -1,35 +1,35 @@
-#/** @file
-#  
-#  Component description file for ArmVExpressSysConfigLib module
-#  
-#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
-#
-#  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                      = ArmVExpressSysConfigLib
-  FILE_GUID                      = a05b5cc0-82d2-11e0-82cb-0002a5d5c51b
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = ArmPlatformSysConfigLib
-  
-[Sources.common]
-  ArmVExpressSysConfig.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  BaseLib
-  IoLib
+#/** @file\r
+#  \r
+#  Component description file for ArmVExpressSysConfigLib module\r
+#  \r
+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = ArmVExpressSysConfigLib\r
+  FILE_GUID                      = a05b5cc0-82d2-11e0-82cb-0002a5d5c51b\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ArmPlatformSysConfigLib\r
+  \r
+[Sources.common]\r
+  ArmVExpressSysConfig.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  IoLib\r
index 73a17fb818dd9a16cedac3f761b3fe7f58244f0f..6a1814e095048354cc2f872f244d2eb1f0b0a489 100644 (file)
@@ -41,4 +41,4 @@ HdLcdArmVExpress.c
 \r
 [Pcd]\r
   gArmVExpressTokenSpaceGuid.PcdPL111LcdMaxMode\r
 \r
 [Pcd]\r
   gArmVExpressTokenSpaceGuid.PcdPL111LcdMaxMode\r
-  gArmVExpressTokenSpaceGuid.PcdHdLcdVideoModeOscId
\ No newline at end of file
+  gArmVExpressTokenSpaceGuid.PcdHdLcdVideoModeOscId\r
\ No newline at end of file
index 45af92126b86a90bc249adecc821f7dcf7ea517b..af227d5e659c23a99f54d880e3b730e048436b87 100644 (file)
@@ -1,32 +1,32 @@
-#/** @file
-#  
-#  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>
-#  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                      = NorFlashArmVExpressLib
-  FILE_GUID                      = c0f5dfa0-7599-11e0-9665-0002a5d5c51b
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = NorFlashPlatformLib
-  
-[Sources.common]
-  NorFlashArmVExpress.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  BaseLib
-  DebugLib
-  IoLib
+#/** @file\r
+#  \r
+#  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = NorFlashArmVExpressLib\r
+  FILE_GUID                      = c0f5dfa0-7599-11e0-9665-0002a5d5c51b\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = NorFlashPlatformLib\r
+  \r
+[Sources.common]\r
+  NorFlashArmVExpress.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  IoLib\r
index c9b6a98c2c6168396815bedd90f7ee4696272b8f..2440ea99cfc8339d5128cb53b973047444a44203 100644 (file)
@@ -1,43 +1,43 @@
-#/** @file
-#  
-#  Component description file for ArmVeGraphicsDxe module
-#  
-#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
-#
-#  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                      = PL111LcdArmVExpressLib
-  FILE_GUID                      = b7f06f20-496f-11e0-a8e8-0002a5d5c51b
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = LcdPlatformLib
-  
-[Sources.common]
-  PL111LcdArmVExpress.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  BaseLib
-  ArmPlatformSysConfigLib
-
-[Protocols]
-  gEfiEdidDiscoveredProtocolGuid                # Produced
-  gEfiEdidActiveProtocolGuid                    # Produced
-
-[Pcd]
-  gArmVExpressTokenSpaceGuid.PcdPL111LcdMaxMode
-  gArmVExpressTokenSpaceGuid.PcdPL111LcdVideoModeOscId
+#/** @file\r
+#  \r
+#  Component description file for ArmVeGraphicsDxe module\r
+#  \r
+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PL111LcdArmVExpressLib\r
+  FILE_GUID                      = b7f06f20-496f-11e0-a8e8-0002a5d5c51b\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = LcdPlatformLib\r
+  \r
+[Sources.common]\r
+  PL111LcdArmVExpress.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  ArmPlatformSysConfigLib\r
+\r
+[Protocols]\r
+  gEfiEdidDiscoveredProtocolGuid                # Produced\r
+  gEfiEdidActiveProtocolGuid                    # Produced\r
+\r
+[Pcd]\r
+  gArmVExpressTokenSpaceGuid.PcdPL111LcdMaxMode\r
+  gArmVExpressTokenSpaceGuid.PcdPL111LcdVideoModeOscId\r
index a471eb260252483cbd0c7046ea67efe7404fe6e3..f858317550835a66a807e5a8ed499ac92b1dc500 100644 (file)
@@ -1,81 +1,81 @@
-/** @file
-  Template library implementation to support ResetSystem Runtime call.
-  
-  Fill in the templates with what ever makes you system reset.
-
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <PiDxe.h>
-
-#include <Library/BaseLib.h>
-#include <Library/DebugLib.h>
-#include <Library/EfiResetSystemLib.h>
-#include <Library/ArmPlatformSysConfigLib.h>
-
-#include <ArmPlatform.h>
-
-/**
-  Resets the entire platform.
-
-  @param  ResetType             The type of reset to perform.
-  @param  ResetStatus           The status code for the reset.
-  @param  DataSize              The size, in bytes, of WatchdogData.
-  @param  ResetData             For a ResetType of EfiResetCold, EfiResetWarm, or
-                                EfiResetShutdown the data buffer starts with a Null-terminated
-                                Unicode string, optionally followed by additional binary data.
-
-**/
-EFI_STATUS
-EFIAPI
-LibResetSystem (
-  IN EFI_RESET_TYPE   ResetType,
-  IN EFI_STATUS       ResetStatus,
-  IN UINTN            DataSize,
-  IN CHAR16           *ResetData OPTIONAL
-  )
-{
-  switch (ResetType) {
-  case EfiResetWarm:
-    // Map a warm reset into a cold reset
-  case EfiResetCold:
-  case EfiResetShutdown:
-    // Send the REBOOT function to the platform microcontroller
-    ArmPlatformSysConfigSet (SYS_CFG_REBOOT, 0);
-
-    // We should never be here
-    while(1);
-  }
-
-  ASSERT(FALSE);
-  return EFI_UNSUPPORTED;
-}
-
-/**
-  Initialize any infrastructure required for LibResetSystem () to function.
-
-  @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
-LibInitializeResetSystem (
-  IN EFI_HANDLE        ImageHandle,
-  IN EFI_SYSTEM_TABLE  *SystemTable
-  )
-{
-  return EFI_SUCCESS;
-}
+/** @file\r
+  Template library implementation to support ResetSystem Runtime call.\r
+  \r
+  Fill in the templates with what ever makes you system reset.\r
+\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/EfiResetSystemLib.h>\r
+#include <Library/ArmPlatformSysConfigLib.h>\r
+\r
+#include <ArmPlatform.h>\r
+\r
+/**\r
+  Resets the entire platform.\r
+\r
+  @param  ResetType             The type of reset to perform.\r
+  @param  ResetStatus           The status code for the reset.\r
+  @param  DataSize              The size, in bytes, of WatchdogData.\r
+  @param  ResetData             For a ResetType of EfiResetCold, EfiResetWarm, or\r
+                                EfiResetShutdown the data buffer starts with a Null-terminated\r
+                                Unicode string, optionally followed by additional binary data.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LibResetSystem (\r
+  IN EFI_RESET_TYPE   ResetType,\r
+  IN EFI_STATUS       ResetStatus,\r
+  IN UINTN            DataSize,\r
+  IN CHAR16           *ResetData OPTIONAL\r
+  )\r
+{\r
+  switch (ResetType) {\r
+  case EfiResetWarm:\r
+    // Map a warm reset into a cold reset\r
+  case EfiResetCold:\r
+  case EfiResetShutdown:\r
+    // Send the REBOOT function to the platform microcontroller\r
+    ArmPlatformSysConfigSet (SYS_CFG_REBOOT, 0);\r
+\r
+    // We should never be here\r
+    while(1);\r
+  }\r
+\r
+  ASSERT(FALSE);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Initialize any infrastructure required for LibResetSystem () to function.\r
+\r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LibInitializeResetSystem (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
index 3965e211ec6de6ff8286796916d9d56ba929e920..8dbd1c869ba7088210ee09630b0d74bee584f6c7 100644 (file)
@@ -1,35 +1,35 @@
-#/** @file
-# Reset System lib to make it easy to port new platforms
-#
-# Copyright (c) 2008, Apple Inc. All rights reserved.<BR>
-#
-#  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                      = ArmVeResetSystemLib
-  FILE_GUID                      = 36885202-0854-4373-bfd2-95d229b44d44 
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = EfiResetSystemLib
-
-[Sources.common]
-  ResetSystemLib.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  DebugLib
-  BaseLib
-  ArmPlatformSysConfigLib
+#/** @file\r
+# Reset System lib to make it easy to port new platforms\r
+#\r
+# Copyright (c) 2008, Apple Inc. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = ArmVeResetSystemLib\r
+  FILE_GUID                      = 36885202-0854-4373-bfd2-95d229b44d44 \r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = EfiResetSystemLib\r
+\r
+[Sources.common]\r
+  ResetSystemLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  BaseLib\r
+  ArmPlatformSysConfigLib\r
index 164e2ae526fd5c03c1d8384ff30320abc71cbc2e..502704121120b2080770ca1307ac5158cb67c8e8 100644 (file)
@@ -1,75 +1,75 @@
-#/** @file
-#  
-#  Component description file for Bds module
-#  
-#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
-#
-#  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                      = ArmPlatformBds
-  FILE_GUID                      = 5a50aa81-c3ae-4608-a0e3-41a2e69baf94 
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-
-  ENTRY_POINT                    = BdsInitialize
-
-[Sources.common]
-  Bds.c
-  BdsHelper.c
-  BootMenu.c
-  BootOption.c
-  BootOptionSupport.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-  ArmPkg/ArmPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  BdsLib
-  TimerLib
-  PerformanceLib
-  UefiBootServicesTableLib
-  DxeServicesTableLib
-  UefiDriverEntryPoint
-  DebugLib
-  PrintLib
-  BaseLib
-  
-[Guids]
-  gEfiFileSystemInfoGuid
-  
-[Protocols]
-  gEfiBdsArchProtocolGuid
-  gEfiBlockIoProtocolGuid
-  gEfiSimpleTextInProtocolGuid
-  gEfiPxeBaseCodeProtocolGuid
-  gEfiSimpleNetworkProtocolGuid
-  gEfiDevicePathToTextProtocolGuid
-
-[Pcd]
-  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor
-  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription
-  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath
-  gArmPlatformTokenSpaceGuid.PcdDefaultBootInitrdPath
-  gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument
-  gArmPlatformTokenSpaceGuid.PcdDefaultBootType
-  gArmPlatformTokenSpaceGuid.PcdFdtDevicePath
-  gArmPlatformTokenSpaceGuid.PcdPlatformBootTimeOut
-  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths
-  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths
-  
-[Depex]
-  TRUE
+#/** @file\r
+#  \r
+#  Component description file for Bds module\r
+#  \r
+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = ArmPlatformBds\r
+  FILE_GUID                      = 5a50aa81-c3ae-4608-a0e3-41a2e69baf94 \r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = BdsInitialize\r
+\r
+[Sources.common]\r
+  Bds.c\r
+  BdsHelper.c\r
+  BootMenu.c\r
+  BootOption.c\r
+  BootOptionSupport.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  BdsLib\r
+  TimerLib\r
+  PerformanceLib\r
+  UefiBootServicesTableLib\r
+  DxeServicesTableLib\r
+  UefiDriverEntryPoint\r
+  DebugLib\r
+  PrintLib\r
+  BaseLib\r
+  \r
+[Guids]\r
+  gEfiFileSystemInfoGuid\r
+  \r
+[Protocols]\r
+  gEfiBdsArchProtocolGuid\r
+  gEfiBlockIoProtocolGuid\r
+  gEfiSimpleTextInProtocolGuid\r
+  gEfiPxeBaseCodeProtocolGuid\r
+  gEfiSimpleNetworkProtocolGuid\r
+  gEfiDevicePathToTextProtocolGuid\r
+\r
+[Pcd]\r
+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor\r
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription\r
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath\r
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootInitrdPath\r
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument\r
+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType\r
+  gArmPlatformTokenSpaceGuid.PcdFdtDevicePath\r
+  gArmPlatformTokenSpaceGuid.PcdPlatformBootTimeOut\r
+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths\r
+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths\r
+  \r
+[Depex]\r
+  TRUE\r
index 28d02c6620d6ea23521d237c64202f06b791e02f..459ebc39fcbdd5afc266d1675336d0d885138aa2 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 "BdsInternal.h"
-
-EFI_STATUS
-EditHIInputStr (
-  IN OUT CHAR16  *CmdLine,
-  IN     UINTN   MaxCmdLine
-  )
-{
-  UINTN           CmdLineIndex;
-  UINTN           WaitIndex;
-  CHAR8           Char;
-  EFI_INPUT_KEY   Key;
-  EFI_STATUS      Status;
-
-  Print (CmdLine);
-
-  for (CmdLineIndex = StrLen (CmdLine); CmdLineIndex < MaxCmdLine; ) {
-    Status = gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &WaitIndex);
-    ASSERT_EFI_ERROR (Status);
-
-    Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
-    ASSERT_EFI_ERROR (Status);
-
-    // Unicode character is valid when Scancode is NUll
-    if (Key.ScanCode == SCAN_NULL) {
-      // Scan code is NUll, hence read Unicode character
-      Char = (CHAR8)Key.UnicodeChar;
-    } else {
-      Char = CHAR_NULL;
-    }
-
-    if ((Char == CHAR_LINEFEED) || (Char == CHAR_CARRIAGE_RETURN) || (Char == 0x7f)) {
-      CmdLine[CmdLineIndex] = '\0';
-      Print (L"\n\r");
-
-      return EFI_SUCCESS;
-    } else if ((Key.UnicodeChar == L'\b') || (Key.ScanCode == SCAN_LEFT) || (Key.ScanCode == SCAN_DELETE)){
-      if (CmdLineIndex != 0) {
-        CmdLineIndex--;
-        Print (L"\b \b");
-      }
-    } else if ((Key.ScanCode == SCAN_ESC) || (Char == 0x1B) || (Char == 0x0)) {
-      return EFI_INVALID_PARAMETER;
-    } else {
-      CmdLine[CmdLineIndex++] = Key.UnicodeChar;
-      Print (L"%c", Key.UnicodeChar);
-    }
-  }
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-GetHIInputStr (
-  IN OUT CHAR16  *CmdLine,
-  IN     UINTN   MaxCmdLine
-  )
-{
-  EFI_STATUS  Status;
-
-  // For a new input just passed an empty string
-  CmdLine[0] = L'\0';
-
-  Status = EditHIInputStr (CmdLine, MaxCmdLine);
-
-  return Status;
-}
-
-EFI_STATUS
-EditHIInputAscii (
-  IN OUT CHAR8   *CmdLine,
-  IN     UINTN   MaxCmdLine
-  )
-{
-  CHAR16*     Str;
-  EFI_STATUS  Status;
-
-  Str = (CHAR16*)AllocatePool (MaxCmdLine * sizeof(CHAR16));
-  AsciiStrToUnicodeStr (CmdLine, Str);
-
-  Status = EditHIInputStr (Str, MaxCmdLine);
-  if (!EFI_ERROR(Status)) {
-    UnicodeStrToAsciiStr (Str, CmdLine);
-  }
-  FreePool (Str);
-
-  return Status;
-}
-
-EFI_STATUS
-GetHIInputAscii (
-  IN OUT CHAR8   *CmdLine,
-  IN     UINTN   MaxCmdLine
-  )
-{
-  // For a new input just passed an empty string
-  CmdLine[0] = '\0';
-
-  return EditHIInputAscii (CmdLine,MaxCmdLine);
-}
-
-EFI_STATUS
-GetHIInputInteger (
-  OUT UINTN   *Integer
-  )
-{
-  CHAR16      CmdLine[255];
-  EFI_STATUS  Status;
-
-  CmdLine[0] = '\0';
-  Status = EditHIInputStr (CmdLine, 255);
-  if (!EFI_ERROR(Status)) {
-    *Integer = StrDecimalToUintn (CmdLine);
-  }
-
-  return Status;
-}
-
-EFI_STATUS
-GetHIInputIP (
-  OUT EFI_IP_ADDRESS   *Ip
-  )
-{
-  CHAR16  CmdLine[255];
-  CHAR16  *Str;
-  EFI_STATUS  Status;
-
-  CmdLine[0] = '\0';
-  Status = EditHIInputStr (CmdLine,255);
-  if (!EFI_ERROR(Status)) {
-    Str = CmdLine;
-    Ip->v4.Addr[0] = (UINT8)StrDecimalToUintn (Str);
-
-    Str = StrStr (Str, L".");
-    if (Str == NULL) {
-      return EFI_INVALID_PARAMETER;
-    }
-
-    Ip->v4.Addr[1] = (UINT8)StrDecimalToUintn (++Str);
-
-    Str = StrStr (Str, L".");
-    if (Str == NULL) {
-      return EFI_INVALID_PARAMETER;
-    }
-
-    Ip->v4.Addr[2] = (UINT8)StrDecimalToUintn (++Str);
-
-    Str = StrStr (Str, L".");
-    if (Str == NULL) {
-      return EFI_INVALID_PARAMETER;
-    }
-
-    Ip->v4.Addr[3] = (UINT8)StrDecimalToUintn (++Str);
-  }
-
-  return Status;
-}
-
-EFI_STATUS
-GetHIInputBoolean (
-  OUT BOOLEAN *Value
-  )
-{
-  CHAR16      CmdBoolean[2];
-  EFI_STATUS  Status;
-
-  while(1) {
-    Print (L"[y/n] ");
-    Status = GetHIInputStr (CmdBoolean, 2);
-    if (EFI_ERROR(Status)) {
-      return Status;
-    } else if ((CmdBoolean[0] == L'y') || (CmdBoolean[0] == L'Y')) {
-      if (Value) *Value = TRUE;
-      return EFI_SUCCESS;
-    } else if ((CmdBoolean[0] == L'n') || (CmdBoolean[0] == L'N')) {
-      if (Value) *Value = FALSE;
-      return EFI_SUCCESS;
-    }
-  }
-}
-
-BOOLEAN
-HasFilePathEfiExtension (
-  IN CHAR16* FilePath
-  )
-{
-  return (StrCmp (FilePath + (StrSize(FilePath)/sizeof(CHAR16)) - 5, L".efi") == 0);
-}
-
-// Return the last non end-type Device Path Node from a Device Path
-EFI_DEVICE_PATH*
-GetLastDevicePathNode (
-  IN EFI_DEVICE_PATH*  DevicePath
-  )
-{
-  EFI_DEVICE_PATH*     PrevDevicePathNode;
-
-  PrevDevicePathNode = DevicePath;
-  while (!IsDevicePathEndType (DevicePath)) {
-    PrevDevicePathNode = DevicePath;
-    DevicePath = NextDevicePathNode (DevicePath);
-  }
-
-  return PrevDevicePathNode;
-}
-
-EFI_STATUS
-GenerateDeviceDescriptionName (
-  IN  EFI_HANDLE  Handle,
-  IN OUT CHAR16*  Description
-  )
-{
-  EFI_STATUS                        Status;
-  EFI_COMPONENT_NAME_PROTOCOL*      ComponentName2Protocol;
-  EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;
-  EFI_DEVICE_PATH_PROTOCOL*         DevicePathProtocol;
-  CHAR16*                           DriverName;
-  CHAR16*                           DevicePathTxt;
-  EFI_DEVICE_PATH*                  DevicePathNode;
-
-  ComponentName2Protocol = NULL;
-  Status = gBS->HandleProtocol (Handle, &gEfiComponentName2ProtocolGuid, (VOID **)&ComponentName2Protocol);
-  if (!EFI_ERROR(Status)) {
-    //TODO: Fixme. we must find the best langague
-    Status = ComponentName2Protocol->GetDriverName (ComponentName2Protocol,"en",&DriverName);
-    if (!EFI_ERROR(Status)) {
-      StrnCpy (Description, DriverName, BOOT_DEVICE_DESCRIPTION_MAX);
-    }
-  }
-
-  if (EFI_ERROR(Status)) {
-    // Use the lastest non null entry of the Device path as a description
-    Status = gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **)&DevicePathProtocol);
-    if (EFI_ERROR(Status)) {
-      return Status;
-    }
-
-    // Convert the last non end-type Device Path Node in text for the description
-    DevicePathNode = GetLastDevicePathNode (DevicePathProtocol);
-    Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
-    ASSERT_EFI_ERROR(Status);
-    DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePathNode, TRUE, TRUE);
-    StrnCpy (Description, DevicePathTxt, BOOT_DEVICE_DESCRIPTION_MAX);
-    FreePool (DevicePathTxt);
-  }
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-BdsStartBootOption (
-  IN CHAR16* BootOption
-  )
-{
-  EFI_STATUS          Status;
-  BDS_LOAD_OPTION     *BdsLoadOption;
-
-  Status = BootOptionFromLoadOptionVariable (BootOption, &BdsLoadOption);
-  if (!EFI_ERROR(Status)) {
-    Status = BootOptionStart (BdsLoadOption);
-    FreePool (BdsLoadOption);
-
-    if (!EFI_ERROR(Status)) {
-      Status = EFI_SUCCESS;
-    } else {
-      Status = EFI_NOT_STARTED;
-    }
-  } else {
-    Status = EFI_NOT_FOUND;
-  }
-  return Status;
-}
-
-UINTN
-GetUnalignedDevicePathSize (
-  IN EFI_DEVICE_PATH* DevicePath
-  )
-{
-  UINTN Size;
-  EFI_DEVICE_PATH* AlignedDevicePath;
-
-  if ((UINTN)DevicePath & 0x1) {
-    AlignedDevicePath = DuplicateDevicePath (DevicePath);
-    Size = GetDevicePathSize (AlignedDevicePath);
-    FreePool (AlignedDevicePath);
-  } else {
-    Size = GetDevicePathSize (DevicePath);
-  }
-  return Size;
-}
-
-EFI_DEVICE_PATH*
-GetAlignedDevicePath (
-  IN EFI_DEVICE_PATH* DevicePath
-  )
-{
-  if ((UINTN)DevicePath & 0x1) {
-    return DuplicateDevicePath (DevicePath);
-  } else {
-    return DevicePath;
-  }
-}
-
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include "BdsInternal.h"\r
+\r
+EFI_STATUS\r
+EditHIInputStr (\r
+  IN OUT CHAR16  *CmdLine,\r
+  IN     UINTN   MaxCmdLine\r
+  )\r
+{\r
+  UINTN           CmdLineIndex;\r
+  UINTN           WaitIndex;\r
+  CHAR8           Char;\r
+  EFI_INPUT_KEY   Key;\r
+  EFI_STATUS      Status;\r
+\r
+  Print (CmdLine);\r
+\r
+  for (CmdLineIndex = StrLen (CmdLine); CmdLineIndex < MaxCmdLine; ) {\r
+    Status = gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &WaitIndex);\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    // Unicode character is valid when Scancode is NUll\r
+    if (Key.ScanCode == SCAN_NULL) {\r
+      // Scan code is NUll, hence read Unicode character\r
+      Char = (CHAR8)Key.UnicodeChar;\r
+    } else {\r
+      Char = CHAR_NULL;\r
+    }\r
+\r
+    if ((Char == CHAR_LINEFEED) || (Char == CHAR_CARRIAGE_RETURN) || (Char == 0x7f)) {\r
+      CmdLine[CmdLineIndex] = '\0';\r
+      Print (L"\n\r");\r
+\r
+      return EFI_SUCCESS;\r
+    } else if ((Key.UnicodeChar == L'\b') || (Key.ScanCode == SCAN_LEFT) || (Key.ScanCode == SCAN_DELETE)){\r
+      if (CmdLineIndex != 0) {\r
+        CmdLineIndex--;\r
+        Print (L"\b \b");\r
+      }\r
+    } else if ((Key.ScanCode == SCAN_ESC) || (Char == 0x1B) || (Char == 0x0)) {\r
+      return EFI_INVALID_PARAMETER;\r
+    } else {\r
+      CmdLine[CmdLineIndex++] = Key.UnicodeChar;\r
+      Print (L"%c", Key.UnicodeChar);\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+GetHIInputStr (\r
+  IN OUT CHAR16  *CmdLine,\r
+  IN     UINTN   MaxCmdLine\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  // For a new input just passed an empty string\r
+  CmdLine[0] = L'\0';\r
+\r
+  Status = EditHIInputStr (CmdLine, MaxCmdLine);\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EditHIInputAscii (\r
+  IN OUT CHAR8   *CmdLine,\r
+  IN     UINTN   MaxCmdLine\r
+  )\r
+{\r
+  CHAR16*     Str;\r
+  EFI_STATUS  Status;\r
+\r
+  Str = (CHAR16*)AllocatePool (MaxCmdLine * sizeof(CHAR16));\r
+  AsciiStrToUnicodeStr (CmdLine, Str);\r
+\r
+  Status = EditHIInputStr (Str, MaxCmdLine);\r
+  if (!EFI_ERROR(Status)) {\r
+    UnicodeStrToAsciiStr (Str, CmdLine);\r
+  }\r
+  FreePool (Str);\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+GetHIInputAscii (\r
+  IN OUT CHAR8   *CmdLine,\r
+  IN     UINTN   MaxCmdLine\r
+  )\r
+{\r
+  // For a new input just passed an empty string\r
+  CmdLine[0] = '\0';\r
+\r
+  return EditHIInputAscii (CmdLine,MaxCmdLine);\r
+}\r
+\r
+EFI_STATUS\r
+GetHIInputInteger (\r
+  OUT UINTN   *Integer\r
+  )\r
+{\r
+  CHAR16      CmdLine[255];\r
+  EFI_STATUS  Status;\r
+\r
+  CmdLine[0] = '\0';\r
+  Status = EditHIInputStr (CmdLine, 255);\r
+  if (!EFI_ERROR(Status)) {\r
+    *Integer = StrDecimalToUintn (CmdLine);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+GetHIInputIP (\r
+  OUT EFI_IP_ADDRESS   *Ip\r
+  )\r
+{\r
+  CHAR16  CmdLine[255];\r
+  CHAR16  *Str;\r
+  EFI_STATUS  Status;\r
+\r
+  CmdLine[0] = '\0';\r
+  Status = EditHIInputStr (CmdLine,255);\r
+  if (!EFI_ERROR(Status)) {\r
+    Str = CmdLine;\r
+    Ip->v4.Addr[0] = (UINT8)StrDecimalToUintn (Str);\r
+\r
+    Str = StrStr (Str, L".");\r
+    if (Str == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    Ip->v4.Addr[1] = (UINT8)StrDecimalToUintn (++Str);\r
+\r
+    Str = StrStr (Str, L".");\r
+    if (Str == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    Ip->v4.Addr[2] = (UINT8)StrDecimalToUintn (++Str);\r
+\r
+    Str = StrStr (Str, L".");\r
+    if (Str == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    Ip->v4.Addr[3] = (UINT8)StrDecimalToUintn (++Str);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+GetHIInputBoolean (\r
+  OUT BOOLEAN *Value\r
+  )\r
+{\r
+  CHAR16      CmdBoolean[2];\r
+  EFI_STATUS  Status;\r
+\r
+  while(1) {\r
+    Print (L"[y/n] ");\r
+    Status = GetHIInputStr (CmdBoolean, 2);\r
+    if (EFI_ERROR(Status)) {\r
+      return Status;\r
+    } else if ((CmdBoolean[0] == L'y') || (CmdBoolean[0] == L'Y')) {\r
+      if (Value) *Value = TRUE;\r
+      return EFI_SUCCESS;\r
+    } else if ((CmdBoolean[0] == L'n') || (CmdBoolean[0] == L'N')) {\r
+      if (Value) *Value = FALSE;\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+}\r
+\r
+BOOLEAN\r
+HasFilePathEfiExtension (\r
+  IN CHAR16* FilePath\r
+  )\r
+{\r
+  return (StrCmp (FilePath + (StrSize(FilePath)/sizeof(CHAR16)) - 5, L".efi") == 0);\r
+}\r
+\r
+// Return the last non end-type Device Path Node from a Device Path\r
+EFI_DEVICE_PATH*\r
+GetLastDevicePathNode (\r
+  IN EFI_DEVICE_PATH*  DevicePath\r
+  )\r
+{\r
+  EFI_DEVICE_PATH*     PrevDevicePathNode;\r
+\r
+  PrevDevicePathNode = DevicePath;\r
+  while (!IsDevicePathEndType (DevicePath)) {\r
+    PrevDevicePathNode = DevicePath;\r
+    DevicePath = NextDevicePathNode (DevicePath);\r
+  }\r
+\r
+  return PrevDevicePathNode;\r
+}\r
+\r
+EFI_STATUS\r
+GenerateDeviceDescriptionName (\r
+  IN  EFI_HANDLE  Handle,\r
+  IN OUT CHAR16*  Description\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  EFI_COMPONENT_NAME_PROTOCOL*      ComponentName2Protocol;\r
+  EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
+  EFI_DEVICE_PATH_PROTOCOL*         DevicePathProtocol;\r
+  CHAR16*                           DriverName;\r
+  CHAR16*                           DevicePathTxt;\r
+  EFI_DEVICE_PATH*                  DevicePathNode;\r
+\r
+  ComponentName2Protocol = NULL;\r
+  Status = gBS->HandleProtocol (Handle, &gEfiComponentName2ProtocolGuid, (VOID **)&ComponentName2Protocol);\r
+  if (!EFI_ERROR(Status)) {\r
+    //TODO: Fixme. we must find the best langague\r
+    Status = ComponentName2Protocol->GetDriverName (ComponentName2Protocol,"en",&DriverName);\r
+    if (!EFI_ERROR(Status)) {\r
+      StrnCpy (Description, DriverName, BOOT_DEVICE_DESCRIPTION_MAX);\r
+    }\r
+  }\r
+\r
+  if (EFI_ERROR(Status)) {\r
+    // Use the lastest non null entry of the Device path as a description\r
+    Status = gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **)&DevicePathProtocol);\r
+    if (EFI_ERROR(Status)) {\r
+      return Status;\r
+    }\r
+\r
+    // Convert the last non end-type Device Path Node in text for the description\r
+    DevicePathNode = GetLastDevicePathNode (DevicePathProtocol);\r
+    Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
+    ASSERT_EFI_ERROR(Status);\r
+    DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePathNode, TRUE, TRUE);\r
+    StrnCpy (Description, DevicePathTxt, BOOT_DEVICE_DESCRIPTION_MAX);\r
+    FreePool (DevicePathTxt);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+BdsStartBootOption (\r
+  IN CHAR16* BootOption\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  BDS_LOAD_OPTION     *BdsLoadOption;\r
+\r
+  Status = BootOptionFromLoadOptionVariable (BootOption, &BdsLoadOption);\r
+  if (!EFI_ERROR(Status)) {\r
+    Status = BootOptionStart (BdsLoadOption);\r
+    FreePool (BdsLoadOption);\r
+\r
+    if (!EFI_ERROR(Status)) {\r
+      Status = EFI_SUCCESS;\r
+    } else {\r
+      Status = EFI_NOT_STARTED;\r
+    }\r
+  } else {\r
+    Status = EFI_NOT_FOUND;\r
+  }\r
+  return Status;\r
+}\r
+\r
+UINTN\r
+GetUnalignedDevicePathSize (\r
+  IN EFI_DEVICE_PATH* DevicePath\r
+  )\r
+{\r
+  UINTN Size;\r
+  EFI_DEVICE_PATH* AlignedDevicePath;\r
+\r
+  if ((UINTN)DevicePath & 0x1) {\r
+    AlignedDevicePath = DuplicateDevicePath (DevicePath);\r
+    Size = GetDevicePathSize (AlignedDevicePath);\r
+    FreePool (AlignedDevicePath);\r
+  } else {\r
+    Size = GetDevicePathSize (DevicePath);\r
+  }\r
+  return Size;\r
+}\r
+\r
+EFI_DEVICE_PATH*\r
+GetAlignedDevicePath (\r
+  IN EFI_DEVICE_PATH* DevicePath\r
+  )\r
+{\r
+  if ((UINTN)DevicePath & 0x1) {\r
+    return DuplicateDevicePath (DevicePath);\r
+  } else {\r
+    return DevicePath;\r
+  }\r
+}\r
+\r
index 3c267df4dad4294806b4a419b9f4e18747c3b070..e998a195ff6e72c4a64f7676864544e5d9f533ac 100644 (file)
-/** @file
-
- Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>
- 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 <PiDxe.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/DevicePathLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/MemoryAllocationLib.h>
-
-#include <Guid/GlobalVariable.h>
-
-#include "LcdGraphicsOutputDxe.h"
-
-extern BOOLEAN mDisplayInitialized;
-
-//
-// Function Definitions
-//
-
-STATIC
-EFI_STATUS
-VideoCopyNoHorizontalOverlap (
-  IN UINTN          BitsPerPixel,
-  IN volatile VOID  *FrameBufferBase,
-  IN UINT32         HorizontalResolution,
-  IN UINTN          SourceX,
-  IN UINTN          SourceY,
-  IN UINTN          DestinationX,
-  IN UINTN          DestinationY,
-  IN UINTN          Width,
-  IN UINTN          Height
-)
-{
-  EFI_STATUS    Status = EFI_SUCCESS;
-  UINTN         SourceLine;
-  UINTN         DestinationLine;
-  UINTN         WidthInBytes;
-  UINTN         LineCount;
-  INTN          Step;
-  VOID          *SourceAddr;
-  VOID          *DestinationAddr;
-
-  if( DestinationY <= SourceY ) {
-    // scrolling up (or horizontally but without overlap)
-    SourceLine       = SourceY;
-    DestinationLine  = DestinationY;
-    Step             = 1;
-  } else {
-    // scrolling down
-    SourceLine       = SourceY + Height;
-    DestinationLine  = DestinationY + Height;
-    Step             = -1;
-  }
-
-  switch (BitsPerPixel) {
-
-  case LCD_BITS_PER_PIXEL_24:
-
-    WidthInBytes = Width * 4;
-
-    for( LineCount = 0; LineCount < Height; LineCount++ ) {
-      // Update the start addresses of source & destination using 32bit pointer arithmetic
-      SourceAddr      = (VOID *)((UINT32 *)FrameBufferBase + SourceLine      * HorizontalResolution + SourceX     );
-      DestinationAddr = (VOID *)((UINT32 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationX);
-
-      // Copy the entire line Y from video ram to the temp buffer
-      CopyMem( DestinationAddr, SourceAddr, WidthInBytes);
-
-      // Update the line numbers
-      SourceLine      += Step;
-      DestinationLine += Step;
-    }
-    break;
-
-  case LCD_BITS_PER_PIXEL_16_555:
-  case LCD_BITS_PER_PIXEL_16_565:
-  case LCD_BITS_PER_PIXEL_12_444:
-
-    WidthInBytes = Width * 2;
-
-    for( LineCount = 0; LineCount < Height; LineCount++ ) {
-      // Update the start addresses of source & destination using 16bit pointer arithmetic
-      SourceAddr      = (VOID *)((UINT16 *)FrameBufferBase + SourceLine      * HorizontalResolution + SourceX     );
-      DestinationAddr = (VOID *)((UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationX);
-
-      // Copy the entire line Y from video ram to the temp buffer
-      CopyMem( DestinationAddr, SourceAddr, WidthInBytes);
-
-      // Update the line numbers
-      SourceLine      += Step;
-      DestinationLine += Step;
-    }
-    break;
-
-  case LCD_BITS_PER_PIXEL_8:
-  case LCD_BITS_PER_PIXEL_4:
-  case LCD_BITS_PER_PIXEL_2:
-  case LCD_BITS_PER_PIXEL_1:
-  default:
-    // Can't handle this case
-    DEBUG((DEBUG_ERROR, "ArmVeGraphics_Blt: EfiBltVideoToVideo: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));
-    Status = EFI_INVALID_PARAMETER;
-    goto EXIT;
-    // break;
-
-  }
-
-  EXIT:
-  return Status;
-}
-
-STATIC
-EFI_STATUS
-VideoCopyHorizontalOverlap (
-  IN UINTN          BitsPerPixel,
-  IN volatile VOID  *FrameBufferBase,
-  UINT32            HorizontalResolution,
-  IN UINTN          SourceX,
-  IN UINTN          SourceY,
-  IN UINTN          DestinationX,
-  IN UINTN          DestinationY,
-  IN UINTN          Width,
-  IN UINTN          Height
-)
-{
-  EFI_STATUS      Status = EFI_SUCCESS;
-
-  UINT32 *PixelBuffer32bit;
-  UINT32 *SourcePixel32bit;
-  UINT32 *DestinationPixel32bit;
-
-  UINT16 *PixelBuffer16bit;
-  UINT16 *SourcePixel16bit;
-  UINT16 *DestinationPixel16bit;
-
-  UINT32          SourcePixelY;
-  UINT32          DestinationPixelY;
-  UINTN           SizeIn32Bits;
-  UINTN           SizeIn16Bits;
-
-  switch (BitsPerPixel) {
-
-  case LCD_BITS_PER_PIXEL_24:
-    // Allocate a temporary buffer
-
-    PixelBuffer32bit = (UINT32 *) AllocatePool((Height * Width) * sizeof(UINT32));
-
-    if (PixelBuffer32bit == NULL) {
-      Status = EFI_OUT_OF_RESOURCES;
-      goto EXIT;
-    }
-
-    SizeIn32Bits = Width * 4;
-
-    // Copy from the video ram (source region) to a temp buffer
-    for (SourcePixelY = SourceY, DestinationPixel32bit = PixelBuffer32bit;
-         SourcePixelY < SourceY + Height;
-         SourcePixelY++, DestinationPixel32bit += Width)
-    {
-      // Update the start address of line Y (source)
-      SourcePixel32bit = (UINT32 *)FrameBufferBase + SourcePixelY * HorizontalResolution + SourceX;
-
-      // Copy the entire line Y from video ram to the temp buffer
-      CopyMem( (VOID *)DestinationPixel32bit, (CONST VOID *)SourcePixel32bit, SizeIn32Bits);
-    }
-
-    // Copy from the temp buffer to the video ram (destination region)
-    for (DestinationPixelY = DestinationY, SourcePixel32bit = PixelBuffer32bit;
-         DestinationPixelY < DestinationY + Height;
-         DestinationPixelY++, SourcePixel32bit += Width)
-    {
-      // Update the start address of line Y (target)
-      DestinationPixel32bit = (UINT32 *)FrameBufferBase + DestinationPixelY * HorizontalResolution + DestinationX;
-
-      // Copy the entire line Y from the temp buffer to video ram
-      CopyMem( (VOID *)DestinationPixel32bit, (CONST VOID *)SourcePixel32bit, SizeIn32Bits);
-    }
-
-    // Free up the allocated memory
-    FreePool((VOID *) PixelBuffer32bit);
-
-    break;
-
-
-  case LCD_BITS_PER_PIXEL_16_555:
-  case LCD_BITS_PER_PIXEL_16_565:
-  case LCD_BITS_PER_PIXEL_12_444:
-    // Allocate a temporary buffer
-    PixelBuffer16bit = (UINT16 *) AllocatePool((Height * Width) * sizeof(UINT16));
-
-    if (PixelBuffer16bit == NULL) {
-      Status = EFI_OUT_OF_RESOURCES;
-      goto EXIT;
-    }
-
-    // Access each pixel inside the source area of the Video Memory and copy it to the temp buffer
-
-    SizeIn16Bits = Width * 2;
-
-    for (SourcePixelY = SourceY, DestinationPixel16bit = PixelBuffer16bit;
-         SourcePixelY < SourceY + Height;
-         SourcePixelY++, DestinationPixel16bit += Width)
-    {
-      // Calculate the source address:
-      SourcePixel16bit = (UINT16 *)FrameBufferBase + SourcePixelY * HorizontalResolution + SourceX;
-
-      // Copy the entire line Y from Video to the temp buffer
-      CopyMem( (VOID *)DestinationPixel16bit, (CONST VOID *)SourcePixel16bit, SizeIn16Bits);
-    }
-
-    // Copy from the temp buffer into the destination area of the Video Memory
-
-    for (DestinationPixelY = DestinationY, SourcePixel16bit = PixelBuffer16bit;
-         DestinationPixelY < DestinationY + Height;
-         DestinationPixelY++, SourcePixel16bit += Width)
-    {
-      // Calculate the target address:
-      DestinationPixel16bit = (UINT16 *)FrameBufferBase + (DestinationPixelY * HorizontalResolution + DestinationX);
-
-      // Copy the entire line Y from the temp buffer to Video
-      CopyMem( (VOID *)DestinationPixel16bit, (CONST VOID *)SourcePixel16bit, SizeIn16Bits);
-    }
-
-    // Free the allocated memory
-    FreePool((VOID *) PixelBuffer16bit);
-
-    break;
-
-
-  case LCD_BITS_PER_PIXEL_8:
-  case LCD_BITS_PER_PIXEL_4:
-  case LCD_BITS_PER_PIXEL_2:
-  case LCD_BITS_PER_PIXEL_1:
-  default:
-    // Can't handle this case
-    DEBUG((DEBUG_ERROR, "ArmVeGraphics_Blt: EfiBltVideoToVideo: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));
-    Status = EFI_INVALID_PARAMETER;
-    goto EXIT;
-    // break;
-
-  }
-
-EXIT:
-  return Status;
-}
-
-STATIC
-EFI_STATUS
-BltVideoFill (
-  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,
-  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *EfiSourcePixel,     OPTIONAL
-  IN UINTN                               SourceX,
-  IN UINTN                               SourceY,
-  IN UINTN                               DestinationX,
-  IN UINTN                               DestinationY,
-  IN UINTN                               Width,
-  IN UINTN                               Height,
-  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer
-  )
-{
-  EFI_PIXEL_BITMASK*  PixelInformation;
-  EFI_STATUS         Status;
-  UINT32             HorizontalResolution;
-  LCD_BPP            BitsPerPixel;
-  VOID            *FrameBufferBase;
-  VOID            *DestinationAddr;
-  UINT16          *DestinationPixel16bit;
-  UINT16          Pixel16bit;
-  UINT32          DestinationPixelX;
-  UINT32          DestinationLine;
-  UINTN           WidthInBytes;
-
-  Status           = EFI_SUCCESS;
-  PixelInformation = &This->Mode->Info->PixelInformation;
-  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));
-  HorizontalResolution = This->Mode->Info->HorizontalResolution;
-
-  LcdPlatformGetBpp (This->Mode->Mode,&BitsPerPixel);
-
-  switch (BitsPerPixel) {
-  case LCD_BITS_PER_PIXEL_24:
-    WidthInBytes = Width * 4;
-
-    // Copy the SourcePixel into every pixel inside the target rectangle
-    for (DestinationLine = DestinationY;
-         DestinationLine < DestinationY + Height;
-         DestinationLine++)
-    {
-      // Calculate the target address using 32bit pointer arithmetic:
-      DestinationAddr = (VOID *)((UINT32 *)FrameBufferBase + DestinationLine * HorizontalResolution  + DestinationX);
-
-      // Fill the entire line
-      SetMemN( DestinationAddr, WidthInBytes, *((UINTN *)EfiSourcePixel));
-    }
-    break;
-
-  case LCD_BITS_PER_PIXEL_16_555:
-    // Convert the EFI pixel at the start of the BltBuffer(0,0) into a video display pixel
-    Pixel16bit = (UINT16) (
-        ( (EfiSourcePixel->Red      <<  7) & PixelInformation->RedMask      )
-      | ( (EfiSourcePixel->Green    <<  2) & PixelInformation->GreenMask    )
-      | ( (EfiSourcePixel->Blue     >>  3) & PixelInformation->BlueMask     )
-//      | ( 0                           & PixelInformation->ReservedMask )
-     );
-
-    // Copy the SourcePixel into every pixel inside the target rectangle
-    for (DestinationLine = DestinationY;
-         DestinationLine < DestinationY + Height;
-         DestinationLine++)
-    {
-      for (DestinationPixelX = DestinationX;
-           DestinationPixelX < DestinationX + Width;
-           DestinationPixelX++)
-      {
-        // Calculate the target address:
-        DestinationPixel16bit =  (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationPixelX;
-
-        // Copy the pixel into the new target
-        *DestinationPixel16bit = Pixel16bit;
-      }
-    }
-    break;
-
-  case LCD_BITS_PER_PIXEL_16_565:
-    // Convert the EFI pixel at the start of the BltBuffer(0,0) into a video display pixel
-    Pixel16bit = (UINT16) (
-        ( (EfiSourcePixel->Red      <<  8) & PixelInformation->RedMask      )
-      | ( (EfiSourcePixel->Green    <<  3) & PixelInformation->GreenMask    )
-      | ( (EfiSourcePixel->Blue     >>  3) & PixelInformation->BlueMask     )
-     );
-
-    // Copy the SourcePixel into every pixel inside the target rectangle
-    for (DestinationLine = DestinationY;
-         DestinationLine < DestinationY + Height;
-         DestinationLine++)
-    {
-      for (DestinationPixelX = DestinationX;
-           DestinationPixelX < DestinationX + Width;
-           DestinationPixelX++)
-      {
-        // Calculate the target address:
-        DestinationPixel16bit =  (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution  + DestinationPixelX;
-
-        // Copy the pixel into the new target
-        *DestinationPixel16bit = Pixel16bit;
-      }
-    }
-    break;
-
-  case LCD_BITS_PER_PIXEL_12_444:
-    // Convert the EFI pixel at the start of the BltBuffer(0,0) into a video display pixel
-    Pixel16bit = (UINT16) (
-        ( (EfiSourcePixel->Red      >> 4) & PixelInformation->RedMask      )
-      | ( (EfiSourcePixel->Green        ) & PixelInformation->GreenMask    )
-      | ( (EfiSourcePixel->Blue     << 4) & PixelInformation->BlueMask     )
-     );
-
-    // Copy the SourcePixel into every pixel inside the target rectangle
-    for (DestinationLine = DestinationY;
-         DestinationLine < DestinationY + Height;
-         DestinationLine++)
-    {
-      for (DestinationPixelX = DestinationX;
-           DestinationPixelX < DestinationX + Width;
-           DestinationPixelX++)
-      {
-        // Calculate the target address:
-        DestinationPixel16bit =  (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution  + DestinationPixelX;
-
-        // Copy the pixel into the new target
-        *DestinationPixel16bit = Pixel16bit;
-      }
-    }
-    break;
-
-  case LCD_BITS_PER_PIXEL_8:
-  case LCD_BITS_PER_PIXEL_4:
-  case LCD_BITS_PER_PIXEL_2:
-  case LCD_BITS_PER_PIXEL_1:
-  default:
-    // Can't handle this case
-    DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: EfiBltVideoFill: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));
-    Status = EFI_INVALID_PARAMETER;
-    break;
-  }
-
-  return Status;
-}
-
-STATIC
-EFI_STATUS
-BltVideoToBltBuffer (
-  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,
-  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL
-  IN UINTN                               SourceX,
-  IN UINTN                               SourceY,
-  IN UINTN                               DestinationX,
-  IN UINTN                               DestinationY,
-  IN UINTN                               Width,
-  IN UINTN                               Height,
-  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer
-  )
-{
-  EFI_STATUS         Status;
-  UINT32             HorizontalResolution;
-  LCD_BPP            BitsPerPixel;
-  EFI_PIXEL_BITMASK  *PixelInformation;
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *EfiDestinationPixel;
-  VOID   *FrameBufferBase;
-  VOID            *SourceAddr;
-  VOID            *DestinationAddr;
-  UINT16 *SourcePixel16bit;
-  UINT16          Pixel16bit;
-  UINT32          SourcePixelX;
-  UINT32          SourceLine;
-  UINT32          DestinationPixelX;
-  UINT32          DestinationLine;
-  UINT32          BltBufferHorizontalResolution;
-  UINTN           WidthInBytes;
-
-  Status = EFI_SUCCESS;
-  PixelInformation = &This->Mode->Info->PixelInformation;
-  HorizontalResolution = This->Mode->Info->HorizontalResolution;
-  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));
-
-  if(( Delta != 0 ) && ( Delta != Width * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {
-    // Delta is not zero and it is different from the width.
-    // Divide it by the size of a pixel to find out the buffer's horizontal resolution.
-    BltBufferHorizontalResolution = (UINT32) (Delta / sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
-  } else {
-    BltBufferHorizontalResolution = Width;
-  }
-
-  LcdPlatformGetBpp (This->Mode->Mode,&BitsPerPixel);
-
-  switch (BitsPerPixel) {
-  case LCD_BITS_PER_PIXEL_24:
-    WidthInBytes = Width * 4;
-
-    // Access each line inside the Video Memory
-    for (SourceLine = SourceY, DestinationLine = DestinationY;
-         SourceLine < SourceY + Height;
-         SourceLine++, DestinationLine++)
-    {
-      // Calculate the source and target addresses using 32bit pointer arithmetic:
-      SourceAddr      = (VOID *)((UINT32 *)FrameBufferBase + SourceLine      * HorizontalResolution          + SourceX     );
-      DestinationAddr = (VOID *)((UINT32 *)BltBuffer       + DestinationLine * BltBufferHorizontalResolution + DestinationX);
-
-      // Copy the entire line
-      CopyMem( DestinationAddr, SourceAddr, WidthInBytes);
-    }
-    break;
-
-  case LCD_BITS_PER_PIXEL_16_555:
-    // Access each pixel inside the Video Memory
-    for (SourceLine = SourceY, DestinationLine = DestinationY;
-         SourceLine < SourceY + Height;
-         SourceLine++, DestinationLine++)
-    {
-      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;
-           SourcePixelX < SourceX + Width;
-           SourcePixelX++, DestinationPixelX++)
-      {
-        // Calculate the source and target addresses:
-        SourcePixel16bit = (UINT16 *)FrameBufferBase + SourceLine * HorizontalResolution + SourcePixelX;
-        EfiDestinationPixel = BltBuffer + DestinationLine * BltBufferHorizontalResolution + DestinationPixelX;
-
-        // Snapshot the pixel from the video buffer once, to speed up the operation.
-        // If we were dereferencing the pointer, as it is volatile, we would perform 3 memory read operations.
-        Pixel16bit = *SourcePixel16bit;
-
-        // Copy the pixel into the new target
-        EfiDestinationPixel->Red      = (UINT8) ( (Pixel16bit & PixelInformation->RedMask     ) >>  7 );
-        EfiDestinationPixel->Green    = (UINT8) ( (Pixel16bit & PixelInformation->GreenMask   ) >>  2);
-        EfiDestinationPixel->Blue     = (UINT8) ( (Pixel16bit & PixelInformation->BlueMask    ) <<  3 );
-        // EfiDestinationPixel->Reserved = (UINT8) 0;
-      }
-    }
-    break;
-
-  case LCD_BITS_PER_PIXEL_16_565:
-    // Access each pixel inside the Video Memory
-    for (SourceLine = SourceY, DestinationLine = DestinationY;
-         SourceLine < SourceY + Height;
-         SourceLine++, DestinationLine++)
-    {
-      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;
-           SourcePixelX < SourceX + Width;
-           SourcePixelX++, DestinationPixelX++)
-      {
-        // Calculate the source and target addresses:
-        SourcePixel16bit = (UINT16 *)FrameBufferBase + SourceLine * HorizontalResolution + SourcePixelX;
-        EfiDestinationPixel = BltBuffer + DestinationLine * BltBufferHorizontalResolution + DestinationPixelX;
-
-        // Snapshot the pixel from the video buffer once, to speed up the operation.
-        // If we were dereferencing the pointer, as it is volatile, we would perform 3 memory read operations.
-        Pixel16bit = *SourcePixel16bit;
-
-        // Copy the pixel into the new target
-        // There is no info for the Reserved byte, so we set it to zero
-        EfiDestinationPixel->Red      = (UINT8) ( (Pixel16bit & PixelInformation->RedMask     ) >> 8 );
-        EfiDestinationPixel->Green    = (UINT8) ( (Pixel16bit & PixelInformation->GreenMask   ) >> 3);
-        EfiDestinationPixel->Blue     = (UINT8) ( (Pixel16bit & PixelInformation->BlueMask    ) << 3 );
-        // EfiDestinationPixel->Reserved = (UINT8) 0;
-      }
-    }
-    break;
-
-  case LCD_BITS_PER_PIXEL_12_444:
-    // Access each pixel inside the Video Memory
-    for (SourceLine = SourceY, DestinationLine = DestinationY;
-         SourceLine < SourceY + Height;
-         SourceLine++, DestinationLine++)
-    {
-      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;
-           SourcePixelX < SourceX + Width;
-           SourcePixelX++, DestinationPixelX++)
-      {
-        // Calculate the source and target addresses:
-        SourcePixel16bit = (UINT16 *)FrameBufferBase + SourceLine * HorizontalResolution + SourcePixelX;
-        EfiDestinationPixel = BltBuffer + DestinationLine * BltBufferHorizontalResolution + DestinationPixelX;
-
-        // Snapshot the pixel from the video buffer once, to speed up the operation.
-        // If we were dereferencing the pointer, as it is volatile, we would perform 3 memory read operations.
-        Pixel16bit = *SourcePixel16bit;
-
-        // Copy the pixel into the new target
-        EfiDestinationPixel->Red      = (UINT8) ( (Pixel16bit & PixelInformation->RedMask     ) >> 4 );
-        EfiDestinationPixel->Green    = (UINT8) ( (Pixel16bit & PixelInformation->GreenMask   )     );
-        EfiDestinationPixel->Blue     = (UINT8) ( (Pixel16bit & PixelInformation->BlueMask    ) << 4 );
-        // EfiDestinationPixel->Reserved = (UINT8) 0;
-      }
-    }
-    break;
-
-  case LCD_BITS_PER_PIXEL_8:
-  case LCD_BITS_PER_PIXEL_4:
-  case LCD_BITS_PER_PIXEL_2:
-  case LCD_BITS_PER_PIXEL_1:
-  default:
-    // Can't handle this case
-    DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: EfiBltVideoToBltBuffer: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));
-    Status = EFI_INVALID_PARAMETER;
-    break;
-  }
-  return Status;
-}
-
-STATIC
-EFI_STATUS
-BltBufferToVideo (
-  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,
-  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL
-  IN UINTN                               SourceX,
-  IN UINTN                               SourceY,
-  IN UINTN                               DestinationX,
-  IN UINTN                               DestinationY,
-  IN UINTN                               Width,
-  IN UINTN                               Height,
-  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer
-  )
-{
-  EFI_STATUS         Status;
-  UINT32             HorizontalResolution;
-  LCD_BPP            BitsPerPixel;
-  EFI_PIXEL_BITMASK  *PixelInformation;
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *EfiSourcePixel;
-  VOID   *FrameBufferBase;
-  VOID            *SourceAddr;
-  VOID            *DestinationAddr;
-  UINT16 *DestinationPixel16bit;
-  UINT32          SourcePixelX;
-  UINT32          SourceLine;
-  UINT32          DestinationPixelX;
-  UINT32          DestinationLine;
-  UINT32          BltBufferHorizontalResolution;
-  UINTN           WidthInBytes;
-
-  Status = EFI_SUCCESS;
-  PixelInformation = &This->Mode->Info->PixelInformation;
-  HorizontalResolution = This->Mode->Info->HorizontalResolution;
-  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));
-
-  if(( Delta != 0 ) && ( Delta != Width * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {
-    // Delta is not zero and it is different from the width.
-    // Divide it by the size of a pixel to find out the buffer's horizontal resolution.
-    BltBufferHorizontalResolution = (UINT32) (Delta / sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
-  } else {
-    BltBufferHorizontalResolution = Width;
-  }
-
-  LcdPlatformGetBpp (This->Mode->Mode,&BitsPerPixel);
-
-  switch (BitsPerPixel) {
-  case LCD_BITS_PER_PIXEL_24:
-    WidthInBytes = Width * 4;
-
-    // Access each pixel inside the BltBuffer Memory
-    for (SourceLine = SourceY, DestinationLine = DestinationY;
-       SourceLine < SourceY + Height;
-       SourceLine++, DestinationLine++)
-    {
-      // Calculate the source and target addresses using 32bit pointer arithmetic:
-      SourceAddr      = (VOID *)((UINT32 *)BltBuffer       + SourceLine      * BltBufferHorizontalResolution + SourceX     );
-      DestinationAddr = (VOID *)((UINT32 *)FrameBufferBase + DestinationLine * HorizontalResolution          + DestinationX);
-
-      // Copy the entire row Y
-      CopyMem( DestinationAddr, SourceAddr, WidthInBytes);
-    }
-    break;
-
-  case LCD_BITS_PER_PIXEL_16_555:
-    // Access each pixel inside the BltBuffer Memory
-    for (SourceLine = SourceY, DestinationLine = DestinationY;
-       SourceLine < SourceY + Height;
-       SourceLine++, DestinationLine++) {
-
-      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;
-           SourcePixelX < SourceX + Width;
-           SourcePixelX++, DestinationPixelX++)
-      {
-        // Calculate the source and target addresses:
-        EfiSourcePixel  = BltBuffer + SourceLine * BltBufferHorizontalResolution + SourcePixelX;
-        DestinationPixel16bit = (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationPixelX;
-
-        // Copy the pixel into the new target
-        // Only the most significant bits will be copied across:
-        // To convert from 8 bits to 5 bits per pixel we throw away the 3 least significant bits
-        *DestinationPixel16bit = (UINT16) (
-              ( (EfiSourcePixel->Red      <<  7) & PixelInformation->RedMask      )
-            | ( (EfiSourcePixel->Green    <<  2) & PixelInformation->GreenMask    )
-            | ( (EfiSourcePixel->Blue     >>  3) & PixelInformation->BlueMask     )
-      //            | ( 0                                & PixelInformation->ReservedMask )
-            );
-      }
-    }
-    break;
-
-  case LCD_BITS_PER_PIXEL_16_565:
-    // Access each pixel inside the BltBuffer Memory
-    for (SourceLine = SourceY, DestinationLine = DestinationY;
-         SourceLine < SourceY + Height;
-         SourceLine++, DestinationLine++) {
-
-      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;
-           SourcePixelX < SourceX + Width;
-           SourcePixelX++, DestinationPixelX++)
-      {
-        // Calculate the source and target addresses:
-        EfiSourcePixel = BltBuffer + SourceLine * BltBufferHorizontalResolution + SourcePixelX;
-        DestinationPixel16bit = (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationPixelX;
-
-        // Copy the pixel into the new target
-        // Only the most significant bits will be copied across:
-        // To convert from 8 bits to 5 or 6 bits per pixel we throw away the 3 or 2  least significant bits
-        // There is no room for the Reserved byte so we ignore that completely
-        *DestinationPixel16bit = (UINT16) (
-              ( (EfiSourcePixel->Red      <<  8) & PixelInformation->RedMask      )
-            | ( (EfiSourcePixel->Green    <<  3) & PixelInformation->GreenMask    )
-            | ( (EfiSourcePixel->Blue     >>  3) & PixelInformation->BlueMask     )
-           );
-      }
-    }
-    break;
-
-  case LCD_BITS_PER_PIXEL_12_444:
-    // Access each pixel inside the BltBuffer Memory
-    for (SourceLine = SourceY, DestinationLine = DestinationY;
-         SourceLine < SourceY + Height;
-         SourceLine++, DestinationLine++) {
-
-      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;
-           SourcePixelX < SourceX + Width;
-           SourcePixelX++, DestinationPixelX++)
-      {
-        // Calculate the source and target addresses:
-        EfiSourcePixel = BltBuffer + SourceLine * BltBufferHorizontalResolution + SourcePixelX;
-        DestinationPixel16bit = (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationPixelX;
-
-        // Copy the pixel into the new target
-        // Only the most significant bits will be copied across:
-        // To convert from 8 bits to 5 bits per pixel we throw away the 3 least significant bits
-        *DestinationPixel16bit = (UINT16) (
-              ( (EfiSourcePixel->Red      << 4) & PixelInformation->RedMask      )
-            | ( (EfiSourcePixel->Green        ) & PixelInformation->GreenMask    )
-            | ( (EfiSourcePixel->Blue     >> 4) & PixelInformation->BlueMask     )
-  //            | ( 0                               & PixelInformation->ReservedMask )
-           );
-      }
-    }
-    break;
-
-  case LCD_BITS_PER_PIXEL_8:
-  case LCD_BITS_PER_PIXEL_4:
-  case LCD_BITS_PER_PIXEL_2:
-  case LCD_BITS_PER_PIXEL_1:
-  default:
-    // Can't handle this case
-    DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: EfiBltBufferToVideo: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));
-    Status = EFI_INVALID_PARAMETER;
-    break;
-  }
-  return Status;
-}
-
-STATIC
-EFI_STATUS
-BltVideoToVideo (
-  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,
-  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL
-  IN UINTN                               SourceX,
-  IN UINTN                               SourceY,
-  IN UINTN                               DestinationX,
-  IN UINTN                               DestinationY,
-  IN UINTN                               Width,
-  IN UINTN                               Height,
-  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer
-  )
-{
-  EFI_STATUS         Status;
-  UINT32             HorizontalResolution;
-  LCD_BPP            BitsPerPixel;
-  VOID   *FrameBufferBase;
-
-  HorizontalResolution = This->Mode->Info->HorizontalResolution;
-  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));
-
-  //
-  // BltVideo to BltVideo:
-  //
-  //  Source is the Video Memory,
-  //  Destination is the Video Memory
-
-  LcdPlatformGetBpp (This->Mode->Mode,&BitsPerPixel);
-  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));
-
-  // The UEFI spec currently states:
-  // "There is no limitation on the overlapping of the source and destination rectangles"
-  // Therefore, we must be careful to avoid overwriting the source data
-  if( SourceY == DestinationY ) {
-    // Copying within the same height, e.g. horizontal shift
-    if( SourceX == DestinationX ) {
-      // Nothing to do
-      Status = EFI_SUCCESS;
-    } else if( ((SourceX>DestinationX)?(SourceX - DestinationX):(DestinationX - SourceX)) < Width ) {
-      // There is overlap
-      Status = VideoCopyHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height );
-    } else {
-      // No overlap
-      Status = VideoCopyNoHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height );
-    }
-  } else {
-    // Copying from different heights
-    Status = VideoCopyNoHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height );
-  }
-
-  return Status;
-}
-
-/***************************************
- * GraphicsOutput Protocol function, mapping to
- * EFI_GRAPHICS_OUTPUT_PROTOCOL.Blt
- *
- * PRESUMES: 1 pixel = 4 bytes (32bits)
- *  ***************************************/
-EFI_STATUS
-EFIAPI
-LcdGraphicsBlt (
-  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,
-       IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL
-       IN EFI_GRAPHICS_OUTPUT_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   // Number of BYTES in a row of the BltBuffer
-  )
-{
-       EFI_STATUS         Status;
-       UINT32             HorizontalResolution;
-  UINT32             VerticalResolution;
-       LCD_INSTANCE*      Instance;
-
-  Instance = LCD_INSTANCE_FROM_GOP_THIS(This);
-
-  // Setup the hardware if not already done
-  if (!mDisplayInitialized) {
-    Status = InitializeDisplay (Instance);
-    if (EFI_ERROR(Status)) {
-      goto EXIT;
-    }
-  }
-
-  HorizontalResolution = This->Mode->Info->HorizontalResolution;
-  VerticalResolution   = This->Mode->Info->VerticalResolution;
-
-  DEBUG((DEBUG_INFO, "LcdGraphicsBlt (BltOperation:%d,DestX:%d,DestY:%d,Width:%d,Height:%d) res(%d,%d)\n",
-      BltOperation,DestinationX,DestinationY,Width,Height,HorizontalResolution,VerticalResolution));
-
-  // Check we have reasonable parameters
-       if (Width == 0 || Height == 0) {
-    DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: ERROR - Invalid dimension: Zero size area.\n" ));
-               Status = EFI_INVALID_PARAMETER;
-               goto EXIT;
-       }
-
-       if ((BltOperation == EfiBltVideoFill) || (BltOperation == EfiBltBufferToVideo) || (BltOperation == EfiBltVideoToBltBuffer)) {
-         ASSERT( BltBuffer != NULL);
-       }
-
-       /*if ((DestinationX >= HorizontalResolution) || (DestinationY >= VerticalResolution)) {
-         DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: ERROR - Invalid destination.\n" ));
-         Status = EFI_INVALID_PARAMETER;
-         goto EXIT;
-       }*/
-
-       // If we are reading data out of the video buffer, check that the source area is within the display limits
-       if ((BltOperation == EfiBltVideoToBltBuffer) || (BltOperation == EfiBltVideoToVideo)) {
-    if ((SourceY + Height > VerticalResolution) || (SourceX + Width > HorizontalResolution)) {
-      DEBUG((DEBUG_INFO, "LcdGraphicsBlt: ERROR - Invalid source resolution.\n" ));
-      DEBUG((DEBUG_INFO, "                      - SourceY=%d + Height=%d > VerticalResolution=%d.\n", SourceY, Height, VerticalResolution ));
-      DEBUG((DEBUG_INFO, "                      - SourceX=%d + Width=%d > HorizontalResolution=%d.\n", SourceX, Width, HorizontalResolution ));
-      Status = EFI_INVALID_PARAMETER;
-      goto EXIT;
-    }
-       }
-
-       // If we are writing data into the video buffer, that the destination area is within the display limits
-       if ((BltOperation == EfiBltVideoFill) || (BltOperation == EfiBltBufferToVideo) || (BltOperation == EfiBltVideoToVideo)) {
-    if ((DestinationY + Height > VerticalResolution) || (DestinationX + Width > HorizontalResolution)) {
-      DEBUG((DEBUG_INFO, "LcdGraphicsBlt: ERROR - Invalid destination resolution.\n" ));
-      DEBUG((DEBUG_INFO, "                      - DestinationY=%d + Height=%d > VerticalResolution=%d.\n", DestinationY, Height, VerticalResolution ));
-      DEBUG((DEBUG_INFO, "                      - DestinationX=%d + Width=%d > HorizontalResolution=%d.\n", DestinationX, Width, HorizontalResolution ));
-      Status = EFI_INVALID_PARAMETER;
-      goto EXIT;
-    }
-       }
-
-  //
-  // Perform the Block Transfer Operation
-  //
-
-       switch (BltOperation) {
-       case EfiBltVideoFill:
-         Status = BltVideoFill (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);
-               break;
-
-       case EfiBltVideoToBltBuffer:
-         Status = BltVideoToBltBuffer (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);
-    break;
-
-  case EfiBltBufferToVideo:
-    Status = BltBufferToVideo (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);
-               break;
-
-       case EfiBltVideoToVideo:
-         Status = BltVideoToVideo (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);
-               break;
-
-       case EfiGraphicsOutputBltOperationMax:
-       default:
-               DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: Invalid Operation\n"));
-               Status = EFI_INVALID_PARAMETER;
-               break;
-       }
-
-EXIT:
-       return Status;
-}
+/** @file\r
+\r
+ Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution.  The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ **/\r
+\r
+#include <PiDxe.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+#include <Guid/GlobalVariable.h>\r
+\r
+#include "LcdGraphicsOutputDxe.h"\r
+\r
+extern BOOLEAN mDisplayInitialized;\r
+\r
+//\r
+// Function Definitions\r
+//\r
+\r
+STATIC\r
+EFI_STATUS\r
+VideoCopyNoHorizontalOverlap (\r
+  IN UINTN          BitsPerPixel,\r
+  IN volatile VOID  *FrameBufferBase,\r
+  IN UINT32         HorizontalResolution,\r
+  IN UINTN          SourceX,\r
+  IN UINTN          SourceY,\r
+  IN UINTN          DestinationX,\r
+  IN UINTN          DestinationY,\r
+  IN UINTN          Width,\r
+  IN UINTN          Height\r
+)\r
+{\r
+  EFI_STATUS    Status = EFI_SUCCESS;\r
+  UINTN         SourceLine;\r
+  UINTN         DestinationLine;\r
+  UINTN         WidthInBytes;\r
+  UINTN         LineCount;\r
+  INTN          Step;\r
+  VOID          *SourceAddr;\r
+  VOID          *DestinationAddr;\r
+\r
+  if( DestinationY <= SourceY ) {\r
+    // scrolling up (or horizontally but without overlap)\r
+    SourceLine       = SourceY;\r
+    DestinationLine  = DestinationY;\r
+    Step             = 1;\r
+  } else {\r
+    // scrolling down\r
+    SourceLine       = SourceY + Height;\r
+    DestinationLine  = DestinationY + Height;\r
+    Step             = -1;\r
+  }\r
+\r
+  switch (BitsPerPixel) {\r
+\r
+  case LCD_BITS_PER_PIXEL_24:\r
+\r
+    WidthInBytes = Width * 4;\r
+\r
+    for( LineCount = 0; LineCount < Height; LineCount++ ) {\r
+      // Update the start addresses of source & destination using 32bit pointer arithmetic\r
+      SourceAddr      = (VOID *)((UINT32 *)FrameBufferBase + SourceLine      * HorizontalResolution + SourceX     );\r
+      DestinationAddr = (VOID *)((UINT32 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationX);\r
+\r
+      // Copy the entire line Y from video ram to the temp buffer\r
+      CopyMem( DestinationAddr, SourceAddr, WidthInBytes);\r
+\r
+      // Update the line numbers\r
+      SourceLine      += Step;\r
+      DestinationLine += Step;\r
+    }\r
+    break;\r
+\r
+  case LCD_BITS_PER_PIXEL_16_555:\r
+  case LCD_BITS_PER_PIXEL_16_565:\r
+  case LCD_BITS_PER_PIXEL_12_444:\r
+\r
+    WidthInBytes = Width * 2;\r
+\r
+    for( LineCount = 0; LineCount < Height; LineCount++ ) {\r
+      // Update the start addresses of source & destination using 16bit pointer arithmetic\r
+      SourceAddr      = (VOID *)((UINT16 *)FrameBufferBase + SourceLine      * HorizontalResolution + SourceX     );\r
+      DestinationAddr = (VOID *)((UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationX);\r
+\r
+      // Copy the entire line Y from video ram to the temp buffer\r
+      CopyMem( DestinationAddr, SourceAddr, WidthInBytes);\r
+\r
+      // Update the line numbers\r
+      SourceLine      += Step;\r
+      DestinationLine += Step;\r
+    }\r
+    break;\r
+\r
+  case LCD_BITS_PER_PIXEL_8:\r
+  case LCD_BITS_PER_PIXEL_4:\r
+  case LCD_BITS_PER_PIXEL_2:\r
+  case LCD_BITS_PER_PIXEL_1:\r
+  default:\r
+    // Can't handle this case\r
+    DEBUG((DEBUG_ERROR, "ArmVeGraphics_Blt: EfiBltVideoToVideo: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto EXIT;\r
+    // break;\r
+\r
+  }\r
+\r
+  EXIT:\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+VideoCopyHorizontalOverlap (\r
+  IN UINTN          BitsPerPixel,\r
+  IN volatile VOID  *FrameBufferBase,\r
+  UINT32            HorizontalResolution,\r
+  IN UINTN          SourceX,\r
+  IN UINTN          SourceY,\r
+  IN UINTN          DestinationX,\r
+  IN UINTN          DestinationY,\r
+  IN UINTN          Width,\r
+  IN UINTN          Height\r
+)\r
+{\r
+  EFI_STATUS      Status = EFI_SUCCESS;\r
+\r
+  UINT32 *PixelBuffer32bit;\r
+  UINT32 *SourcePixel32bit;\r
+  UINT32 *DestinationPixel32bit;\r
+\r
+  UINT16 *PixelBuffer16bit;\r
+  UINT16 *SourcePixel16bit;\r
+  UINT16 *DestinationPixel16bit;\r
+\r
+  UINT32          SourcePixelY;\r
+  UINT32          DestinationPixelY;\r
+  UINTN           SizeIn32Bits;\r
+  UINTN           SizeIn16Bits;\r
+\r
+  switch (BitsPerPixel) {\r
+\r
+  case LCD_BITS_PER_PIXEL_24:\r
+    // Allocate a temporary buffer\r
+\r
+    PixelBuffer32bit = (UINT32 *) AllocatePool((Height * Width) * sizeof(UINT32));\r
+\r
+    if (PixelBuffer32bit == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto EXIT;\r
+    }\r
+\r
+    SizeIn32Bits = Width * 4;\r
+\r
+    // Copy from the video ram (source region) to a temp buffer\r
+    for (SourcePixelY = SourceY, DestinationPixel32bit = PixelBuffer32bit;\r
+         SourcePixelY < SourceY + Height;\r
+         SourcePixelY++, DestinationPixel32bit += Width)\r
+    {\r
+      // Update the start address of line Y (source)\r
+      SourcePixel32bit = (UINT32 *)FrameBufferBase + SourcePixelY * HorizontalResolution + SourceX;\r
+\r
+      // Copy the entire line Y from video ram to the temp buffer\r
+      CopyMem( (VOID *)DestinationPixel32bit, (CONST VOID *)SourcePixel32bit, SizeIn32Bits);\r
+    }\r
+\r
+    // Copy from the temp buffer to the video ram (destination region)\r
+    for (DestinationPixelY = DestinationY, SourcePixel32bit = PixelBuffer32bit;\r
+         DestinationPixelY < DestinationY + Height;\r
+         DestinationPixelY++, SourcePixel32bit += Width)\r
+    {\r
+      // Update the start address of line Y (target)\r
+      DestinationPixel32bit = (UINT32 *)FrameBufferBase + DestinationPixelY * HorizontalResolution + DestinationX;\r
+\r
+      // Copy the entire line Y from the temp buffer to video ram\r
+      CopyMem( (VOID *)DestinationPixel32bit, (CONST VOID *)SourcePixel32bit, SizeIn32Bits);\r
+    }\r
+\r
+    // Free up the allocated memory\r
+    FreePool((VOID *) PixelBuffer32bit);\r
+\r
+    break;\r
+\r
+\r
+  case LCD_BITS_PER_PIXEL_16_555:\r
+  case LCD_BITS_PER_PIXEL_16_565:\r
+  case LCD_BITS_PER_PIXEL_12_444:\r
+    // Allocate a temporary buffer\r
+    PixelBuffer16bit = (UINT16 *) AllocatePool((Height * Width) * sizeof(UINT16));\r
+\r
+    if (PixelBuffer16bit == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto EXIT;\r
+    }\r
+\r
+    // Access each pixel inside the source area of the Video Memory and copy it to the temp buffer\r
+\r
+    SizeIn16Bits = Width * 2;\r
+\r
+    for (SourcePixelY = SourceY, DestinationPixel16bit = PixelBuffer16bit;\r
+         SourcePixelY < SourceY + Height;\r
+         SourcePixelY++, DestinationPixel16bit += Width)\r
+    {\r
+      // Calculate the source address:\r
+      SourcePixel16bit = (UINT16 *)FrameBufferBase + SourcePixelY * HorizontalResolution + SourceX;\r
+\r
+      // Copy the entire line Y from Video to the temp buffer\r
+      CopyMem( (VOID *)DestinationPixel16bit, (CONST VOID *)SourcePixel16bit, SizeIn16Bits);\r
+    }\r
+\r
+    // Copy from the temp buffer into the destination area of the Video Memory\r
+\r
+    for (DestinationPixelY = DestinationY, SourcePixel16bit = PixelBuffer16bit;\r
+         DestinationPixelY < DestinationY + Height;\r
+         DestinationPixelY++, SourcePixel16bit += Width)\r
+    {\r
+      // Calculate the target address:\r
+      DestinationPixel16bit = (UINT16 *)FrameBufferBase + (DestinationPixelY * HorizontalResolution + DestinationX);\r
+\r
+      // Copy the entire line Y from the temp buffer to Video\r
+      CopyMem( (VOID *)DestinationPixel16bit, (CONST VOID *)SourcePixel16bit, SizeIn16Bits);\r
+    }\r
+\r
+    // Free the allocated memory\r
+    FreePool((VOID *) PixelBuffer16bit);\r
+\r
+    break;\r
+\r
+\r
+  case LCD_BITS_PER_PIXEL_8:\r
+  case LCD_BITS_PER_PIXEL_4:\r
+  case LCD_BITS_PER_PIXEL_2:\r
+  case LCD_BITS_PER_PIXEL_1:\r
+  default:\r
+    // Can't handle this case\r
+    DEBUG((DEBUG_ERROR, "ArmVeGraphics_Blt: EfiBltVideoToVideo: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto EXIT;\r
+    // break;\r
+\r
+  }\r
+\r
+EXIT:\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+BltVideoFill (\r
+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,\r
+  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *EfiSourcePixel,     OPTIONAL\r
+  IN UINTN                               SourceX,\r
+  IN UINTN                               SourceY,\r
+  IN UINTN                               DestinationX,\r
+  IN UINTN                               DestinationY,\r
+  IN UINTN                               Width,\r
+  IN UINTN                               Height,\r
+  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer\r
+  )\r
+{\r
+  EFI_PIXEL_BITMASK*  PixelInformation;\r
+  EFI_STATUS         Status;\r
+  UINT32             HorizontalResolution;\r
+  LCD_BPP            BitsPerPixel;\r
+  VOID            *FrameBufferBase;\r
+  VOID            *DestinationAddr;\r
+  UINT16          *DestinationPixel16bit;\r
+  UINT16          Pixel16bit;\r
+  UINT32          DestinationPixelX;\r
+  UINT32          DestinationLine;\r
+  UINTN           WidthInBytes;\r
+\r
+  Status           = EFI_SUCCESS;\r
+  PixelInformation = &This->Mode->Info->PixelInformation;\r
+  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));\r
+  HorizontalResolution = This->Mode->Info->HorizontalResolution;\r
+\r
+  LcdPlatformGetBpp (This->Mode->Mode,&BitsPerPixel);\r
+\r
+  switch (BitsPerPixel) {\r
+  case LCD_BITS_PER_PIXEL_24:\r
+    WidthInBytes = Width * 4;\r
+\r
+    // Copy the SourcePixel into every pixel inside the target rectangle\r
+    for (DestinationLine = DestinationY;\r
+         DestinationLine < DestinationY + Height;\r
+         DestinationLine++)\r
+    {\r
+      // Calculate the target address using 32bit pointer arithmetic:\r
+      DestinationAddr = (VOID *)((UINT32 *)FrameBufferBase + DestinationLine * HorizontalResolution  + DestinationX);\r
+\r
+      // Fill the entire line\r
+      SetMemN( DestinationAddr, WidthInBytes, *((UINTN *)EfiSourcePixel));\r
+    }\r
+    break;\r
+\r
+  case LCD_BITS_PER_PIXEL_16_555:\r
+    // Convert the EFI pixel at the start of the BltBuffer(0,0) into a video display pixel\r
+    Pixel16bit = (UINT16) (\r
+        ( (EfiSourcePixel->Red      <<  7) & PixelInformation->RedMask      )\r
+      | ( (EfiSourcePixel->Green    <<  2) & PixelInformation->GreenMask    )\r
+      | ( (EfiSourcePixel->Blue     >>  3) & PixelInformation->BlueMask     )\r
+//      | ( 0                           & PixelInformation->ReservedMask )\r
+     );\r
+\r
+    // Copy the SourcePixel into every pixel inside the target rectangle\r
+    for (DestinationLine = DestinationY;\r
+         DestinationLine < DestinationY + Height;\r
+         DestinationLine++)\r
+    {\r
+      for (DestinationPixelX = DestinationX;\r
+           DestinationPixelX < DestinationX + Width;\r
+           DestinationPixelX++)\r
+      {\r
+        // Calculate the target address:\r
+        DestinationPixel16bit =  (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationPixelX;\r
+\r
+        // Copy the pixel into the new target\r
+        *DestinationPixel16bit = Pixel16bit;\r
+      }\r
+    }\r
+    break;\r
+\r
+  case LCD_BITS_PER_PIXEL_16_565:\r
+    // Convert the EFI pixel at the start of the BltBuffer(0,0) into a video display pixel\r
+    Pixel16bit = (UINT16) (\r
+        ( (EfiSourcePixel->Red      <<  8) & PixelInformation->RedMask      )\r
+      | ( (EfiSourcePixel->Green    <<  3) & PixelInformation->GreenMask    )\r
+      | ( (EfiSourcePixel->Blue     >>  3) & PixelInformation->BlueMask     )\r
+     );\r
+\r
+    // Copy the SourcePixel into every pixel inside the target rectangle\r
+    for (DestinationLine = DestinationY;\r
+         DestinationLine < DestinationY + Height;\r
+         DestinationLine++)\r
+    {\r
+      for (DestinationPixelX = DestinationX;\r
+           DestinationPixelX < DestinationX + Width;\r
+           DestinationPixelX++)\r
+      {\r
+        // Calculate the target address:\r
+        DestinationPixel16bit =  (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution  + DestinationPixelX;\r
+\r
+        // Copy the pixel into the new target\r
+        *DestinationPixel16bit = Pixel16bit;\r
+      }\r
+    }\r
+    break;\r
+\r
+  case LCD_BITS_PER_PIXEL_12_444:\r
+    // Convert the EFI pixel at the start of the BltBuffer(0,0) into a video display pixel\r
+    Pixel16bit = (UINT16) (\r
+        ( (EfiSourcePixel->Red      >> 4) & PixelInformation->RedMask      )\r
+      | ( (EfiSourcePixel->Green        ) & PixelInformation->GreenMask    )\r
+      | ( (EfiSourcePixel->Blue     << 4) & PixelInformation->BlueMask     )\r
+     );\r
+\r
+    // Copy the SourcePixel into every pixel inside the target rectangle\r
+    for (DestinationLine = DestinationY;\r
+         DestinationLine < DestinationY + Height;\r
+         DestinationLine++)\r
+    {\r
+      for (DestinationPixelX = DestinationX;\r
+           DestinationPixelX < DestinationX + Width;\r
+           DestinationPixelX++)\r
+      {\r
+        // Calculate the target address:\r
+        DestinationPixel16bit =  (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution  + DestinationPixelX;\r
+\r
+        // Copy the pixel into the new target\r
+        *DestinationPixel16bit = Pixel16bit;\r
+      }\r
+    }\r
+    break;\r
+\r
+  case LCD_BITS_PER_PIXEL_8:\r
+  case LCD_BITS_PER_PIXEL_4:\r
+  case LCD_BITS_PER_PIXEL_2:\r
+  case LCD_BITS_PER_PIXEL_1:\r
+  default:\r
+    // Can't handle this case\r
+    DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: EfiBltVideoFill: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));\r
+    Status = EFI_INVALID_PARAMETER;\r
+    break;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+BltVideoToBltBuffer (\r
+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,\r
+  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL\r
+  IN UINTN                               SourceX,\r
+  IN UINTN                               SourceY,\r
+  IN UINTN                               DestinationX,\r
+  IN UINTN                               DestinationY,\r
+  IN UINTN                               Width,\r
+  IN UINTN                               Height,\r
+  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer\r
+  )\r
+{\r
+  EFI_STATUS         Status;\r
+  UINT32             HorizontalResolution;\r
+  LCD_BPP            BitsPerPixel;\r
+  EFI_PIXEL_BITMASK  *PixelInformation;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *EfiDestinationPixel;\r
+  VOID   *FrameBufferBase;\r
+  VOID            *SourceAddr;\r
+  VOID            *DestinationAddr;\r
+  UINT16 *SourcePixel16bit;\r
+  UINT16          Pixel16bit;\r
+  UINT32          SourcePixelX;\r
+  UINT32          SourceLine;\r
+  UINT32          DestinationPixelX;\r
+  UINT32          DestinationLine;\r
+  UINT32          BltBufferHorizontalResolution;\r
+  UINTN           WidthInBytes;\r
+\r
+  Status = EFI_SUCCESS;\r
+  PixelInformation = &This->Mode->Info->PixelInformation;\r
+  HorizontalResolution = This->Mode->Info->HorizontalResolution;\r
+  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));\r
+\r
+  if(( Delta != 0 ) && ( Delta != Width * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {\r
+    // Delta is not zero and it is different from the width.\r
+    // Divide it by the size of a pixel to find out the buffer's horizontal resolution.\r
+    BltBufferHorizontalResolution = (UINT32) (Delta / sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
+  } else {\r
+    BltBufferHorizontalResolution = Width;\r
+  }\r
+\r
+  LcdPlatformGetBpp (This->Mode->Mode,&BitsPerPixel);\r
+\r
+  switch (BitsPerPixel) {\r
+  case LCD_BITS_PER_PIXEL_24:\r
+    WidthInBytes = Width * 4;\r
+\r
+    // Access each line inside the Video Memory\r
+    for (SourceLine = SourceY, DestinationLine = DestinationY;\r
+         SourceLine < SourceY + Height;\r
+         SourceLine++, DestinationLine++)\r
+    {\r
+      // Calculate the source and target addresses using 32bit pointer arithmetic:\r
+      SourceAddr      = (VOID *)((UINT32 *)FrameBufferBase + SourceLine      * HorizontalResolution          + SourceX     );\r
+      DestinationAddr = (VOID *)((UINT32 *)BltBuffer       + DestinationLine * BltBufferHorizontalResolution + DestinationX);\r
+\r
+      // Copy the entire line\r
+      CopyMem( DestinationAddr, SourceAddr, WidthInBytes);\r
+    }\r
+    break;\r
+\r
+  case LCD_BITS_PER_PIXEL_16_555:\r
+    // Access each pixel inside the Video Memory\r
+    for (SourceLine = SourceY, DestinationLine = DestinationY;\r
+         SourceLine < SourceY + Height;\r
+         SourceLine++, DestinationLine++)\r
+    {\r
+      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;\r
+           SourcePixelX < SourceX + Width;\r
+           SourcePixelX++, DestinationPixelX++)\r
+      {\r
+        // Calculate the source and target addresses:\r
+        SourcePixel16bit = (UINT16 *)FrameBufferBase + SourceLine * HorizontalResolution + SourcePixelX;\r
+        EfiDestinationPixel = BltBuffer + DestinationLine * BltBufferHorizontalResolution + DestinationPixelX;\r
+\r
+        // Snapshot the pixel from the video buffer once, to speed up the operation.\r
+        // If we were dereferencing the pointer, as it is volatile, we would perform 3 memory read operations.\r
+        Pixel16bit = *SourcePixel16bit;\r
+\r
+        // Copy the pixel into the new target\r
+        EfiDestinationPixel->Red      = (UINT8) ( (Pixel16bit & PixelInformation->RedMask     ) >>  7 );\r
+        EfiDestinationPixel->Green    = (UINT8) ( (Pixel16bit & PixelInformation->GreenMask   ) >>  2);\r
+        EfiDestinationPixel->Blue     = (UINT8) ( (Pixel16bit & PixelInformation->BlueMask    ) <<  3 );\r
+        // EfiDestinationPixel->Reserved = (UINT8) 0;\r
+      }\r
+    }\r
+    break;\r
+\r
+  case LCD_BITS_PER_PIXEL_16_565:\r
+    // Access each pixel inside the Video Memory\r
+    for (SourceLine = SourceY, DestinationLine = DestinationY;\r
+         SourceLine < SourceY + Height;\r
+         SourceLine++, DestinationLine++)\r
+    {\r
+      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;\r
+           SourcePixelX < SourceX + Width;\r
+           SourcePixelX++, DestinationPixelX++)\r
+      {\r
+        // Calculate the source and target addresses:\r
+        SourcePixel16bit = (UINT16 *)FrameBufferBase + SourceLine * HorizontalResolution + SourcePixelX;\r
+        EfiDestinationPixel = BltBuffer + DestinationLine * BltBufferHorizontalResolution + DestinationPixelX;\r
+\r
+        // Snapshot the pixel from the video buffer once, to speed up the operation.\r
+        // If we were dereferencing the pointer, as it is volatile, we would perform 3 memory read operations.\r
+        Pixel16bit = *SourcePixel16bit;\r
+\r
+        // Copy the pixel into the new target\r
+        // There is no info for the Reserved byte, so we set it to zero\r
+        EfiDestinationPixel->Red      = (UINT8) ( (Pixel16bit & PixelInformation->RedMask     ) >> 8 );\r
+        EfiDestinationPixel->Green    = (UINT8) ( (Pixel16bit & PixelInformation->GreenMask   ) >> 3);\r
+        EfiDestinationPixel->Blue     = (UINT8) ( (Pixel16bit & PixelInformation->BlueMask    ) << 3 );\r
+        // EfiDestinationPixel->Reserved = (UINT8) 0;\r
+      }\r
+    }\r
+    break;\r
+\r
+  case LCD_BITS_PER_PIXEL_12_444:\r
+    // Access each pixel inside the Video Memory\r
+    for (SourceLine = SourceY, DestinationLine = DestinationY;\r
+         SourceLine < SourceY + Height;\r
+         SourceLine++, DestinationLine++)\r
+    {\r
+      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;\r
+           SourcePixelX < SourceX + Width;\r
+           SourcePixelX++, DestinationPixelX++)\r
+      {\r
+        // Calculate the source and target addresses:\r
+        SourcePixel16bit = (UINT16 *)FrameBufferBase + SourceLine * HorizontalResolution + SourcePixelX;\r
+        EfiDestinationPixel = BltBuffer + DestinationLine * BltBufferHorizontalResolution + DestinationPixelX;\r
+\r
+        // Snapshot the pixel from the video buffer once, to speed up the operation.\r
+        // If we were dereferencing the pointer, as it is volatile, we would perform 3 memory read operations.\r
+        Pixel16bit = *SourcePixel16bit;\r
+\r
+        // Copy the pixel into the new target\r
+        EfiDestinationPixel->Red      = (UINT8) ( (Pixel16bit & PixelInformation->RedMask     ) >> 4 );\r
+        EfiDestinationPixel->Green    = (UINT8) ( (Pixel16bit & PixelInformation->GreenMask   )     );\r
+        EfiDestinationPixel->Blue     = (UINT8) ( (Pixel16bit & PixelInformation->BlueMask    ) << 4 );\r
+        // EfiDestinationPixel->Reserved = (UINT8) 0;\r
+      }\r
+    }\r
+    break;\r
+\r
+  case LCD_BITS_PER_PIXEL_8:\r
+  case LCD_BITS_PER_PIXEL_4:\r
+  case LCD_BITS_PER_PIXEL_2:\r
+  case LCD_BITS_PER_PIXEL_1:\r
+  default:\r
+    // Can't handle this case\r
+    DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: EfiBltVideoToBltBuffer: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));\r
+    Status = EFI_INVALID_PARAMETER;\r
+    break;\r
+  }\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+BltBufferToVideo (\r
+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,\r
+  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL\r
+  IN UINTN                               SourceX,\r
+  IN UINTN                               SourceY,\r
+  IN UINTN                               DestinationX,\r
+  IN UINTN                               DestinationY,\r
+  IN UINTN                               Width,\r
+  IN UINTN                               Height,\r
+  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer\r
+  )\r
+{\r
+  EFI_STATUS         Status;\r
+  UINT32             HorizontalResolution;\r
+  LCD_BPP            BitsPerPixel;\r
+  EFI_PIXEL_BITMASK  *PixelInformation;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *EfiSourcePixel;\r
+  VOID   *FrameBufferBase;\r
+  VOID            *SourceAddr;\r
+  VOID            *DestinationAddr;\r
+  UINT16 *DestinationPixel16bit;\r
+  UINT32          SourcePixelX;\r
+  UINT32          SourceLine;\r
+  UINT32          DestinationPixelX;\r
+  UINT32          DestinationLine;\r
+  UINT32          BltBufferHorizontalResolution;\r
+  UINTN           WidthInBytes;\r
+\r
+  Status = EFI_SUCCESS;\r
+  PixelInformation = &This->Mode->Info->PixelInformation;\r
+  HorizontalResolution = This->Mode->Info->HorizontalResolution;\r
+  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));\r
+\r
+  if(( Delta != 0 ) && ( Delta != Width * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {\r
+    // Delta is not zero and it is different from the width.\r
+    // Divide it by the size of a pixel to find out the buffer's horizontal resolution.\r
+    BltBufferHorizontalResolution = (UINT32) (Delta / sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
+  } else {\r
+    BltBufferHorizontalResolution = Width;\r
+  }\r
+\r
+  LcdPlatformGetBpp (This->Mode->Mode,&BitsPerPixel);\r
+\r
+  switch (BitsPerPixel) {\r
+  case LCD_BITS_PER_PIXEL_24:\r
+    WidthInBytes = Width * 4;\r
+\r
+    // Access each pixel inside the BltBuffer Memory\r
+    for (SourceLine = SourceY, DestinationLine = DestinationY;\r
+       SourceLine < SourceY + Height;\r
+       SourceLine++, DestinationLine++)\r
+    {\r
+      // Calculate the source and target addresses using 32bit pointer arithmetic:\r
+      SourceAddr      = (VOID *)((UINT32 *)BltBuffer       + SourceLine      * BltBufferHorizontalResolution + SourceX     );\r
+      DestinationAddr = (VOID *)((UINT32 *)FrameBufferBase + DestinationLine * HorizontalResolution          + DestinationX);\r
+\r
+      // Copy the entire row Y\r
+      CopyMem( DestinationAddr, SourceAddr, WidthInBytes);\r
+    }\r
+    break;\r
+\r
+  case LCD_BITS_PER_PIXEL_16_555:\r
+    // Access each pixel inside the BltBuffer Memory\r
+    for (SourceLine = SourceY, DestinationLine = DestinationY;\r
+       SourceLine < SourceY + Height;\r
+       SourceLine++, DestinationLine++) {\r
+\r
+      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;\r
+           SourcePixelX < SourceX + Width;\r
+           SourcePixelX++, DestinationPixelX++)\r
+      {\r
+        // Calculate the source and target addresses:\r
+        EfiSourcePixel  = BltBuffer + SourceLine * BltBufferHorizontalResolution + SourcePixelX;\r
+        DestinationPixel16bit = (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationPixelX;\r
+\r
+        // Copy the pixel into the new target\r
+        // Only the most significant bits will be copied across:\r
+        // To convert from 8 bits to 5 bits per pixel we throw away the 3 least significant bits\r
+        *DestinationPixel16bit = (UINT16) (\r
+              ( (EfiSourcePixel->Red      <<  7) & PixelInformation->RedMask      )\r
+            | ( (EfiSourcePixel->Green    <<  2) & PixelInformation->GreenMask    )\r
+            | ( (EfiSourcePixel->Blue     >>  3) & PixelInformation->BlueMask     )\r
+      //            | ( 0                                & PixelInformation->ReservedMask )\r
+            );\r
+      }\r
+    }\r
+    break;\r
+\r
+  case LCD_BITS_PER_PIXEL_16_565:\r
+    // Access each pixel inside the BltBuffer Memory\r
+    for (SourceLine = SourceY, DestinationLine = DestinationY;\r
+         SourceLine < SourceY + Height;\r
+         SourceLine++, DestinationLine++) {\r
+\r
+      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;\r
+           SourcePixelX < SourceX + Width;\r
+           SourcePixelX++, DestinationPixelX++)\r
+      {\r
+        // Calculate the source and target addresses:\r
+        EfiSourcePixel = BltBuffer + SourceLine * BltBufferHorizontalResolution + SourcePixelX;\r
+        DestinationPixel16bit = (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationPixelX;\r
+\r
+        // Copy the pixel into the new target\r
+        // Only the most significant bits will be copied across:\r
+        // To convert from 8 bits to 5 or 6 bits per pixel we throw away the 3 or 2  least significant bits\r
+        // There is no room for the Reserved byte so we ignore that completely\r
+        *DestinationPixel16bit = (UINT16) (\r
+              ( (EfiSourcePixel->Red      <<  8) & PixelInformation->RedMask      )\r
+            | ( (EfiSourcePixel->Green    <<  3) & PixelInformation->GreenMask    )\r
+            | ( (EfiSourcePixel->Blue     >>  3) & PixelInformation->BlueMask     )\r
+           );\r
+      }\r
+    }\r
+    break;\r
+\r
+  case LCD_BITS_PER_PIXEL_12_444:\r
+    // Access each pixel inside the BltBuffer Memory\r
+    for (SourceLine = SourceY, DestinationLine = DestinationY;\r
+         SourceLine < SourceY + Height;\r
+         SourceLine++, DestinationLine++) {\r
+\r
+      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;\r
+           SourcePixelX < SourceX + Width;\r
+           SourcePixelX++, DestinationPixelX++)\r
+      {\r
+        // Calculate the source and target addresses:\r
+        EfiSourcePixel = BltBuffer + SourceLine * BltBufferHorizontalResolution + SourcePixelX;\r
+        DestinationPixel16bit = (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationPixelX;\r
+\r
+        // Copy the pixel into the new target\r
+        // Only the most significant bits will be copied across:\r
+        // To convert from 8 bits to 5 bits per pixel we throw away the 3 least significant bits\r
+        *DestinationPixel16bit = (UINT16) (\r
+              ( (EfiSourcePixel->Red      << 4) & PixelInformation->RedMask      )\r
+            | ( (EfiSourcePixel->Green        ) & PixelInformation->GreenMask    )\r
+            | ( (EfiSourcePixel->Blue     >> 4) & PixelInformation->BlueMask     )\r
+  //            | ( 0                               & PixelInformation->ReservedMask )\r
+           );\r
+      }\r
+    }\r
+    break;\r
+\r
+  case LCD_BITS_PER_PIXEL_8:\r
+  case LCD_BITS_PER_PIXEL_4:\r
+  case LCD_BITS_PER_PIXEL_2:\r
+  case LCD_BITS_PER_PIXEL_1:\r
+  default:\r
+    // Can't handle this case\r
+    DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: EfiBltBufferToVideo: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));\r
+    Status = EFI_INVALID_PARAMETER;\r
+    break;\r
+  }\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+BltVideoToVideo (\r
+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,\r
+  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL\r
+  IN UINTN                               SourceX,\r
+  IN UINTN                               SourceY,\r
+  IN UINTN                               DestinationX,\r
+  IN UINTN                               DestinationY,\r
+  IN UINTN                               Width,\r
+  IN UINTN                               Height,\r
+  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer\r
+  )\r
+{\r
+  EFI_STATUS         Status;\r
+  UINT32             HorizontalResolution;\r
+  LCD_BPP            BitsPerPixel;\r
+  VOID   *FrameBufferBase;\r
+\r
+  HorizontalResolution = This->Mode->Info->HorizontalResolution;\r
+  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));\r
+\r
+  //\r
+  // BltVideo to BltVideo:\r
+  //\r
+  //  Source is the Video Memory,\r
+  //  Destination is the Video Memory\r
+\r
+  LcdPlatformGetBpp (This->Mode->Mode,&BitsPerPixel);\r
+  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));\r
+\r
+  // The UEFI spec currently states:\r
+  // "There is no limitation on the overlapping of the source and destination rectangles"\r
+  // Therefore, we must be careful to avoid overwriting the source data\r
+  if( SourceY == DestinationY ) {\r
+    // Copying within the same height, e.g. horizontal shift\r
+    if( SourceX == DestinationX ) {\r
+      // Nothing to do\r
+      Status = EFI_SUCCESS;\r
+    } else if( ((SourceX>DestinationX)?(SourceX - DestinationX):(DestinationX - SourceX)) < Width ) {\r
+      // There is overlap\r
+      Status = VideoCopyHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height );\r
+    } else {\r
+      // No overlap\r
+      Status = VideoCopyNoHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height );\r
+    }\r
+  } else {\r
+    // Copying from different heights\r
+    Status = VideoCopyNoHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/***************************************\r
+ * GraphicsOutput Protocol function, mapping to\r
+ * EFI_GRAPHICS_OUTPUT_PROTOCOL.Blt\r
+ *\r
+ * PRESUMES: 1 pixel = 4 bytes (32bits)\r
+ *  ***************************************/\r
+EFI_STATUS\r
+EFIAPI\r
+LcdGraphicsBlt (\r
+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,\r
+       IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL\r
+       IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION   BltOperation,\r
+       IN UINTN                               SourceX,\r
+       IN UINTN                               SourceY,\r
+       IN UINTN                               DestinationX,\r
+       IN UINTN                               DestinationY,\r
+       IN UINTN                               Width,\r
+       IN UINTN                               Height,\r
+       IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer\r
+  )\r
+{\r
+       EFI_STATUS         Status;\r
+       UINT32             HorizontalResolution;\r
+  UINT32             VerticalResolution;\r
+       LCD_INSTANCE*      Instance;\r
+\r
+  Instance = LCD_INSTANCE_FROM_GOP_THIS(This);\r
+\r
+  // Setup the hardware if not already done\r
+  if (!mDisplayInitialized) {\r
+    Status = InitializeDisplay (Instance);\r
+    if (EFI_ERROR(Status)) {\r
+      goto EXIT;\r
+    }\r
+  }\r
+\r
+  HorizontalResolution = This->Mode->Info->HorizontalResolution;\r
+  VerticalResolution   = This->Mode->Info->VerticalResolution;\r
+\r
+  DEBUG((DEBUG_INFO, "LcdGraphicsBlt (BltOperation:%d,DestX:%d,DestY:%d,Width:%d,Height:%d) res(%d,%d)\n",\r
+      BltOperation,DestinationX,DestinationY,Width,Height,HorizontalResolution,VerticalResolution));\r
+\r
+  // Check we have reasonable parameters\r
+       if (Width == 0 || Height == 0) {\r
+    DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: ERROR - Invalid dimension: Zero size area.\n" ));\r
+               Status = EFI_INVALID_PARAMETER;\r
+               goto EXIT;\r
+       }\r
+\r
+       if ((BltOperation == EfiBltVideoFill) || (BltOperation == EfiBltBufferToVideo) || (BltOperation == EfiBltVideoToBltBuffer)) {\r
+         ASSERT( BltBuffer != NULL);\r
+       }\r
+\r
+       /*if ((DestinationX >= HorizontalResolution) || (DestinationY >= VerticalResolution)) {\r
+         DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: ERROR - Invalid destination.\n" ));\r
+         Status = EFI_INVALID_PARAMETER;\r
+         goto EXIT;\r
+       }*/\r
+\r
+       // If we are reading data out of the video buffer, check that the source area is within the display limits\r
+       if ((BltOperation == EfiBltVideoToBltBuffer) || (BltOperation == EfiBltVideoToVideo)) {\r
+    if ((SourceY + Height > VerticalResolution) || (SourceX + Width > HorizontalResolution)) {\r
+      DEBUG((DEBUG_INFO, "LcdGraphicsBlt: ERROR - Invalid source resolution.\n" ));\r
+      DEBUG((DEBUG_INFO, "                      - SourceY=%d + Height=%d > VerticalResolution=%d.\n", SourceY, Height, VerticalResolution ));\r
+      DEBUG((DEBUG_INFO, "                      - SourceX=%d + Width=%d > HorizontalResolution=%d.\n", SourceX, Width, HorizontalResolution ));\r
+      Status = EFI_INVALID_PARAMETER;\r
+      goto EXIT;\r
+    }\r
+       }\r
+\r
+       // If we are writing data into the video buffer, that the destination area is within the display limits\r
+       if ((BltOperation == EfiBltVideoFill) || (BltOperation == EfiBltBufferToVideo) || (BltOperation == EfiBltVideoToVideo)) {\r
+    if ((DestinationY + Height > VerticalResolution) || (DestinationX + Width > HorizontalResolution)) {\r
+      DEBUG((DEBUG_INFO, "LcdGraphicsBlt: ERROR - Invalid destination resolution.\n" ));\r
+      DEBUG((DEBUG_INFO, "                      - DestinationY=%d + Height=%d > VerticalResolution=%d.\n", DestinationY, Height, VerticalResolution ));\r
+      DEBUG((DEBUG_INFO, "                      - DestinationX=%d + Width=%d > HorizontalResolution=%d.\n", DestinationX, Width, HorizontalResolution ));\r
+      Status = EFI_INVALID_PARAMETER;\r
+      goto EXIT;\r
+    }\r
+       }\r
+\r
+  //\r
+  // Perform the Block Transfer Operation\r
+  //\r
+\r
+       switch (BltOperation) {\r
+       case EfiBltVideoFill:\r
+         Status = BltVideoFill (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);\r
+               break;\r
+\r
+       case EfiBltVideoToBltBuffer:\r
+         Status = BltVideoToBltBuffer (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);\r
+    break;\r
+\r
+  case EfiBltBufferToVideo:\r
+    Status = BltBufferToVideo (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);\r
+               break;\r
+\r
+       case EfiBltVideoToVideo:\r
+         Status = BltVideoToVideo (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);\r
+               break;\r
+\r
+       case EfiGraphicsOutputBltOperationMax:\r
+       default:\r
+               DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: Invalid Operation\n"));\r
+               Status = EFI_INVALID_PARAMETER;\r
+               break;\r
+       }\r
+\r
+EXIT:\r
+       return Status;\r
+}\r
index 229d2a6aa24627b2dd0f0d2c922778cabe6bb72e..34a56b3d8dc6d4a9216d1850a0935b1bded228b6 100644 (file)
-/** @file
-
- Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>
- 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 <PiDxe.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/DevicePathLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/MemoryAllocationLib.h>
-
-#include <Guid/GlobalVariable.h>
-
-#include "LcdGraphicsOutputDxe.h"
-
-/**********************************************************************
- *
- *  This file implements the Graphics Output protocol on ArmVersatileExpress
- *  using the Lcd controller
- *
- **********************************************************************/
-
-//
-// Global variables
-//
-
-BOOLEAN mDisplayInitialized = FALSE;
-
-LCD_INSTANCE mLcdTemplate = {
-  LCD_INSTANCE_SIGNATURE,
-  NULL, // Handle
-  { // ModeInfo
-    0, // Version
-    0, // HorizontalResolution
-    0, // VerticalResolution
-    PixelBltOnly, // PixelFormat
-    0, // PixelInformation
-    0, // PixelsPerScanLine
-  },
-  {
-    0, // MaxMode;
-    0, // Mode;
-    NULL, // Info;
-    0, // SizeOfInfo;
-    0, // FrameBufferBase;
-    0 // FrameBufferSize;
-  },
-  { // Gop
-    LcdGraphicsQueryMode,  // QueryMode
-    LcdGraphicsSetMode,    // SetMode
-    LcdGraphicsBlt,        // Blt
-    NULL                     // *Mode
-  },
-  { // DevicePath
-    {
-      {
-        HARDWARE_DEVICE_PATH, HW_VENDOR_DP,
-        (UINT8) (sizeof(VENDOR_DEVICE_PATH)),
-        (UINT8) ((sizeof(VENDOR_DEVICE_PATH)) >> 8),
-      },
-      // Hardware Device Path for Lcd
-      EFI_CALLER_ID_GUID // Use the driver's GUID
-    },
-
-    {
-      END_DEVICE_PATH_TYPE,
-      END_ENTIRE_DEVICE_PATH_SUBTYPE,
-      sizeof(EFI_DEVICE_PATH_PROTOCOL),
-      0
-    }
-  },
-  (EFI_EVENT) NULL // ExitBootServicesEvent
-};
-
-EFI_STATUS
-LcdInstanceContructor (
-  OUT LCD_INSTANCE** NewInstance
-  )
-{
-  LCD_INSTANCE* Instance;
-
-  Instance = AllocateCopyPool (sizeof(LCD_INSTANCE), &mLcdTemplate);
-  if (Instance == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  Instance->Gop.Mode          = &Instance->Mode;
-  Instance->Gop.Mode->MaxMode = LcdPlatformGetMaxMode ();
-  Instance->Mode.Info         = &Instance->ModeInfo;
-
-  *NewInstance = Instance;
-  return EFI_SUCCESS;
-}
-
-//
-// Function Definitions
-//
-
-EFI_STATUS
-InitializeDisplay (
-  IN LCD_INSTANCE* Instance
-  )
-{
-  EFI_STATUS             Status = EFI_SUCCESS;
-  EFI_PHYSICAL_ADDRESS   VramBaseAddress;
-  UINTN                  VramSize;
-
-  Status = LcdPlatformGetVram (&VramBaseAddress, &VramSize);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  // Setup the LCD
-  Status = LcdInitialize (VramBaseAddress);
-  if (EFI_ERROR(Status)) {
-    goto EXIT_ERROR_LCD_SHUTDOWN;
-  }
-
-  Status = LcdPlatformInitializeDisplay (Instance->Handle);
-  if (EFI_ERROR(Status)) {
-    goto EXIT_ERROR_LCD_SHUTDOWN;
-  }
-
-  // Setup all the relevant mode information
-  Instance->Gop.Mode->SizeOfInfo      = sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
-  Instance->Gop.Mode->FrameBufferBase = VramBaseAddress;
-  Instance->Gop.Mode->FrameBufferSize = VramSize;
-
-  // Set the flag before changing the mode, to avoid infinite loops
-  mDisplayInitialized = TRUE;
-
-  // All is ok, so don't deal with any errors
-  goto EXIT;
-
-EXIT_ERROR_LCD_SHUTDOWN:
-  DEBUG((DEBUG_ERROR, "InitializeDisplay: ERROR - Can not initialise the display. Exit Status=%r\n", Status));
-  LcdShutdown ();
-
-EXIT:
-  return Status;
-}
-
-EFI_STATUS
-EFIAPI
-LcdGraphicsOutputDxeInitialize (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
-  )
-{
-  EFI_STATUS  Status = EFI_SUCCESS;
-  LCD_INSTANCE* Instance;
-
-  Status = LcdInstanceContructor (&Instance);
-  if (EFI_ERROR(Status)) {
-    goto EXIT;
-  }
-
-       // Install the Graphics Output Protocol and the Device Path
-       Status = gBS->InstallMultipleProtocolInterfaces(
-                       &Instance->Handle,
-                       &gEfiGraphicsOutputProtocolGuid, &Instance->Gop,
-                       &gEfiDevicePathProtocolGuid,     &Instance->DevicePath,
-                       NULL
-          );
-
-       if (EFI_ERROR(Status)) {
-         DEBUG((DEBUG_ERROR, "GraphicsOutputDxeInitialize: Can not install the protocol. Exit Status=%r\n", Status));
-               goto EXIT;
-       }
-
-       // Register for an ExitBootServicesEvent
-       // When ExitBootServices starts, this function here will make sure that the graphics driver will shut down properly,
-       // i.e. it will free up all allocated memory and perform any necessary hardware re-configuration.
-       Status = gBS->CreateEvent (
-           EVT_SIGNAL_EXIT_BOOT_SERVICES,
-           TPL_NOTIFY,
-           LcdGraphicsExitBootServicesEvent, NULL,
-                       &Instance->ExitBootServicesEvent
-                       );
-
-       if (EFI_ERROR(Status)) {
-         DEBUG((DEBUG_ERROR, "GraphicsOutputDxeInitialize: Can not install the ExitBootServicesEvent handler. Exit Status=%r\n", Status));
-               goto EXIT_ERROR_UNINSTALL_PROTOCOL;
-       }
-
-       // To get here, everything must be fine, so just exit
-       goto EXIT;
-
-EXIT_ERROR_UNINSTALL_PROTOCOL:
-       /* The following function could return an error message,
-        * however, to get here something must have gone wrong already,
-        * so preserve the original error, i.e. don't change
-        * the Status variable, even it fails to uninstall the protocol.
-        */
-       gBS->UninstallMultipleProtocolInterfaces (
-           Instance->Handle,
-           &gEfiGraphicsOutputProtocolGuid, &Instance->Gop, // Uninstall Graphics Output protocol
-           &gEfiDevicePathProtocolGuid,     &Instance->DevicePath,     // Uninstall device path
-           NULL
-           );
-
-EXIT:
-       return Status;
-
-}
-
-/***************************************
- * This function should be called
- * on Event: ExitBootServices
- * to free up memory, stop the driver
- * and uninstall the protocols
- ***************************************/
-VOID
-LcdGraphicsExitBootServicesEvent (
-  IN EFI_EVENT  Event,
-  IN VOID       *Context
-  )
-{
-       //TODO: Implement me
-}
-
-/***************************************
- * GraphicsOutput Protocol function, mapping to
- * EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode
- ***************************************/
-EFI_STATUS
-EFIAPI
-LcdGraphicsQueryMode (
-  IN EFI_GRAPHICS_OUTPUT_PROTOCOL            *This,
-       IN UINT32                                  ModeNumber,
-       OUT UINTN                                  *SizeOfInfo,
-       OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION   **Info
-       )
-{
-       EFI_STATUS Status = EFI_SUCCESS;
-       LCD_INSTANCE *Instance;
-
-       Instance = LCD_INSTANCE_FROM_GOP_THIS(This);
-
-  // Setup the hardware if not already done
-  if( !mDisplayInitialized ) {
-    Status = InitializeDisplay(Instance);
-    if (EFI_ERROR(Status)) {
-      goto EXIT;
-    }
-  }
-
-       // Error checking
-       if ( (This == NULL) || (Info == NULL) || (SizeOfInfo == NULL) || (ModeNumber >= This->Mode->MaxMode) ) {
-         DEBUG((DEBUG_ERROR, "LcdGraphicsQueryMode: ERROR - For mode number %d : Invalid Parameter.\n", ModeNumber ));
-               Status = EFI_INVALID_PARAMETER;
-               goto EXIT;
-       }
-
-       *Info = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
-  if (*Info == NULL) {
-    Status = EFI_OUT_OF_RESOURCES;
-    goto EXIT;
-  }
-
-  *SizeOfInfo = sizeof( EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
-
-  Status = LcdPlatformQueryMode (ModeNumber,*Info);
-  if (EFI_ERROR(Status)) {
-    FreePool(*Info);
-  }
-
-EXIT:
-       return Status;
-}
-
-/***************************************
- * GraphicsOutput Protocol function, mapping to
- * EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode
- ***************************************/
-EFI_STATUS
-EFIAPI
-LcdGraphicsSetMode (
-  IN EFI_GRAPHICS_OUTPUT_PROTOCOL   *This,
-       IN UINT32                         ModeNumber
-       )
-{
-       EFI_STATUS                      Status               = EFI_SUCCESS;
-       EFI_GRAPHICS_OUTPUT_BLT_PIXEL   FillColour;
-       LCD_INSTANCE* Instance;
-
-       Instance = LCD_INSTANCE_FROM_GOP_THIS (This);
-
-  // Setup the hardware if not already done
-  if(!mDisplayInitialized) {
-    Status = InitializeDisplay (Instance);
-    if (EFI_ERROR(Status)) {
-      goto EXIT;
-    }
-  }
-
-  // Check if this mode is supported
-  if( ModeNumber >= This->Mode->MaxMode ) {
-    DEBUG((DEBUG_ERROR, "LcdGraphicsSetMode: ERROR - Unsupported mode number %d .\n", ModeNumber ));
-    Status = EFI_UNSUPPORTED;
-    goto EXIT;
-  }
-
-       // Set the oscillator frequency to support the new mode
-  Status = LcdPlatformSetMode (ModeNumber);
-  if (EFI_ERROR(Status)) {
-    Status = EFI_DEVICE_ERROR;
-    goto EXIT;
-  }
-
-       // Update the UEFI mode information
-       This->Mode->Mode = ModeNumber;
-       LcdPlatformQueryMode (ModeNumber,&Instance->ModeInfo);
-
-  // Set the hardware to the new mode
-       Status = LcdSetMode (ModeNumber);
-  if (EFI_ERROR(Status)) {
-    Status = EFI_DEVICE_ERROR;
-    goto EXIT;
-  }
-
-       // The UEFI spec requires that we now clear the visible portions of the output display to black.
-
-  // Set the fill colour to black
-  SetMem (&FillColour, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);
-
-  // Fill the entire visible area with the same colour.
-  Status = This->Blt (
-      This,
-      &FillColour,
-      EfiBltVideoFill,
-      0,
-      0,
-      0,
-      0,
-      This->Mode->Info->HorizontalResolution,
-      This->Mode->Info->VerticalResolution,
-      0);
-
-EXIT:
-       return Status;
-}
-
-UINTN
-GetBytesPerPixel (
-  IN  LCD_BPP       Bpp
-  )
-{
-  switch(Bpp) {
-  case LCD_BITS_PER_PIXEL_24:
-    return 4;
-
-  case LCD_BITS_PER_PIXEL_16_565:
-  case LCD_BITS_PER_PIXEL_16_555:
-  case LCD_BITS_PER_PIXEL_12_444:
-    return 2;
-
-  case LCD_BITS_PER_PIXEL_8:
-  case LCD_BITS_PER_PIXEL_4:
-  case LCD_BITS_PER_PIXEL_2:
-  case LCD_BITS_PER_PIXEL_1:
-    return 1;
-
-  default:
-    return 0;
-  }
-}
+/** @file\r
+\r
+ Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution.  The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ **/\r
+\r
+#include <PiDxe.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+#include <Guid/GlobalVariable.h>\r
+\r
+#include "LcdGraphicsOutputDxe.h"\r
+\r
+/**********************************************************************\r
+ *\r
+ *  This file implements the Graphics Output protocol on ArmVersatileExpress\r
+ *  using the Lcd controller\r
+ *\r
+ **********************************************************************/\r
+\r
+//\r
+// Global variables\r
+//\r
+\r
+BOOLEAN mDisplayInitialized = FALSE;\r
+\r
+LCD_INSTANCE mLcdTemplate = {\r
+  LCD_INSTANCE_SIGNATURE,\r
+  NULL, // Handle\r
+  { // ModeInfo\r
+    0, // Version\r
+    0, // HorizontalResolution\r
+    0, // VerticalResolution\r
+    PixelBltOnly, // PixelFormat\r
+    0, // PixelInformation\r
+    0, // PixelsPerScanLine\r
+  },\r
+  {\r
+    0, // MaxMode;\r
+    0, // Mode;\r
+    NULL, // Info;\r
+    0, // SizeOfInfo;\r
+    0, // FrameBufferBase;\r
+    0 // FrameBufferSize;\r
+  },\r
+  { // Gop\r
+    LcdGraphicsQueryMode,  // QueryMode\r
+    LcdGraphicsSetMode,    // SetMode\r
+    LcdGraphicsBlt,        // Blt\r
+    NULL                     // *Mode\r
+  },\r
+  { // DevicePath\r
+    {\r
+      {\r
+        HARDWARE_DEVICE_PATH, HW_VENDOR_DP,\r
+        (UINT8) (sizeof(VENDOR_DEVICE_PATH)),\r
+        (UINT8) ((sizeof(VENDOR_DEVICE_PATH)) >> 8),\r
+      },\r
+      // Hardware Device Path for Lcd\r
+      EFI_CALLER_ID_GUID // Use the driver's GUID\r
+    },\r
+\r
+    {\r
+      END_DEVICE_PATH_TYPE,\r
+      END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+      sizeof(EFI_DEVICE_PATH_PROTOCOL),\r
+      0\r
+    }\r
+  },\r
+  (EFI_EVENT) NULL // ExitBootServicesEvent\r
+};\r
+\r
+EFI_STATUS\r
+LcdInstanceContructor (\r
+  OUT LCD_INSTANCE** NewInstance\r
+  )\r
+{\r
+  LCD_INSTANCE* Instance;\r
+\r
+  Instance = AllocateCopyPool (sizeof(LCD_INSTANCE), &mLcdTemplate);\r
+  if (Instance == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Instance->Gop.Mode          = &Instance->Mode;\r
+  Instance->Gop.Mode->MaxMode = LcdPlatformGetMaxMode ();\r
+  Instance->Mode.Info         = &Instance->ModeInfo;\r
+\r
+  *NewInstance = Instance;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+//\r
+// Function Definitions\r
+//\r
+\r
+EFI_STATUS\r
+InitializeDisplay (\r
+  IN LCD_INSTANCE* Instance\r
+  )\r
+{\r
+  EFI_STATUS             Status = EFI_SUCCESS;\r
+  EFI_PHYSICAL_ADDRESS   VramBaseAddress;\r
+  UINTN                  VramSize;\r
+\r
+  Status = LcdPlatformGetVram (&VramBaseAddress, &VramSize);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  // Setup the LCD\r
+  Status = LcdInitialize (VramBaseAddress);\r
+  if (EFI_ERROR(Status)) {\r
+    goto EXIT_ERROR_LCD_SHUTDOWN;\r
+  }\r
+\r
+  Status = LcdPlatformInitializeDisplay (Instance->Handle);\r
+  if (EFI_ERROR(Status)) {\r
+    goto EXIT_ERROR_LCD_SHUTDOWN;\r
+  }\r
+\r
+  // Setup all the relevant mode information\r
+  Instance->Gop.Mode->SizeOfInfo      = sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
+  Instance->Gop.Mode->FrameBufferBase = VramBaseAddress;\r
+  Instance->Gop.Mode->FrameBufferSize = VramSize;\r
+\r
+  // Set the flag before changing the mode, to avoid infinite loops\r
+  mDisplayInitialized = TRUE;\r
+\r
+  // All is ok, so don't deal with any errors\r
+  goto EXIT;\r
+\r
+EXIT_ERROR_LCD_SHUTDOWN:\r
+  DEBUG((DEBUG_ERROR, "InitializeDisplay: ERROR - Can not initialise the display. Exit Status=%r\n", Status));\r
+  LcdShutdown ();\r
+\r
+EXIT:\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+LcdGraphicsOutputDxeInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS  Status = EFI_SUCCESS;\r
+  LCD_INSTANCE* Instance;\r
+\r
+  Status = LcdInstanceContructor (&Instance);\r
+  if (EFI_ERROR(Status)) {\r
+    goto EXIT;\r
+  }\r
+\r
+       // Install the Graphics Output Protocol and the Device Path\r
+       Status = gBS->InstallMultipleProtocolInterfaces(\r
+                       &Instance->Handle,\r
+                       &gEfiGraphicsOutputProtocolGuid, &Instance->Gop,\r
+                       &gEfiDevicePathProtocolGuid,     &Instance->DevicePath,\r
+                       NULL\r
+          );\r
+\r
+       if (EFI_ERROR(Status)) {\r
+         DEBUG((DEBUG_ERROR, "GraphicsOutputDxeInitialize: Can not install the protocol. Exit Status=%r\n", Status));\r
+               goto EXIT;\r
+       }\r
+\r
+       // Register for an ExitBootServicesEvent\r
+       // When ExitBootServices starts, this function here will make sure that the graphics driver will shut down properly,\r
+       // i.e. it will free up all allocated memory and perform any necessary hardware re-configuration.\r
+       Status = gBS->CreateEvent (\r
+           EVT_SIGNAL_EXIT_BOOT_SERVICES,\r
+           TPL_NOTIFY,\r
+           LcdGraphicsExitBootServicesEvent, NULL,\r
+                       &Instance->ExitBootServicesEvent\r
+                       );\r
+\r
+       if (EFI_ERROR(Status)) {\r
+         DEBUG((DEBUG_ERROR, "GraphicsOutputDxeInitialize: Can not install the ExitBootServicesEvent handler. Exit Status=%r\n", Status));\r
+               goto EXIT_ERROR_UNINSTALL_PROTOCOL;\r
+       }\r
+\r
+       // To get here, everything must be fine, so just exit\r
+       goto EXIT;\r
+\r
+EXIT_ERROR_UNINSTALL_PROTOCOL:\r
+       /* The following function could return an error message,\r
+        * however, to get here something must have gone wrong already,\r
+        * so preserve the original error, i.e. don't change\r
+        * the Status variable, even it fails to uninstall the protocol.\r
+        */\r
+       gBS->UninstallMultipleProtocolInterfaces (\r
+           Instance->Handle,\r
+           &gEfiGraphicsOutputProtocolGuid, &Instance->Gop, // Uninstall Graphics Output protocol\r
+           &gEfiDevicePathProtocolGuid,     &Instance->DevicePath,     // Uninstall device path\r
+           NULL\r
+           );\r
+\r
+EXIT:\r
+       return Status;\r
+\r
+}\r
+\r
+/***************************************\r
+ * This function should be called\r
+ * on Event: ExitBootServices\r
+ * to free up memory, stop the driver\r
+ * and uninstall the protocols\r
+ ***************************************/\r
+VOID\r
+LcdGraphicsExitBootServicesEvent (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+       //TODO: Implement me\r
+}\r
+\r
+/***************************************\r
+ * GraphicsOutput Protocol function, mapping to\r
+ * EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode\r
+ ***************************************/\r
+EFI_STATUS\r
+EFIAPI\r
+LcdGraphicsQueryMode (\r
+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL            *This,\r
+       IN UINT32                                  ModeNumber,\r
+       OUT UINTN                                  *SizeOfInfo,\r
+       OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION   **Info\r
+       )\r
+{\r
+       EFI_STATUS Status = EFI_SUCCESS;\r
+       LCD_INSTANCE *Instance;\r
+\r
+       Instance = LCD_INSTANCE_FROM_GOP_THIS(This);\r
+\r
+  // Setup the hardware if not already done\r
+  if( !mDisplayInitialized ) {\r
+    Status = InitializeDisplay(Instance);\r
+    if (EFI_ERROR(Status)) {\r
+      goto EXIT;\r
+    }\r
+  }\r
+\r
+       // Error checking\r
+       if ( (This == NULL) || (Info == NULL) || (SizeOfInfo == NULL) || (ModeNumber >= This->Mode->MaxMode) ) {\r
+         DEBUG((DEBUG_ERROR, "LcdGraphicsQueryMode: ERROR - For mode number %d : Invalid Parameter.\n", ModeNumber ));\r
+               Status = EFI_INVALID_PARAMETER;\r
+               goto EXIT;\r
+       }\r
+\r
+       *Info = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));\r
+  if (*Info == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto EXIT;\r
+  }\r
+\r
+  *SizeOfInfo = sizeof( EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
+\r
+  Status = LcdPlatformQueryMode (ModeNumber,*Info);\r
+  if (EFI_ERROR(Status)) {\r
+    FreePool(*Info);\r
+  }\r
+\r
+EXIT:\r
+       return Status;\r
+}\r
+\r
+/***************************************\r
+ * GraphicsOutput Protocol function, mapping to\r
+ * EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode\r
+ ***************************************/\r
+EFI_STATUS\r
+EFIAPI\r
+LcdGraphicsSetMode (\r
+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL   *This,\r
+       IN UINT32                         ModeNumber\r
+       )\r
+{\r
+       EFI_STATUS                      Status               = EFI_SUCCESS;\r
+       EFI_GRAPHICS_OUTPUT_BLT_PIXEL   FillColour;\r
+       LCD_INSTANCE* Instance;\r
+\r
+       Instance = LCD_INSTANCE_FROM_GOP_THIS (This);\r
+\r
+  // Setup the hardware if not already done\r
+  if(!mDisplayInitialized) {\r
+    Status = InitializeDisplay (Instance);\r
+    if (EFI_ERROR(Status)) {\r
+      goto EXIT;\r
+    }\r
+  }\r
+\r
+  // Check if this mode is supported\r
+  if( ModeNumber >= This->Mode->MaxMode ) {\r
+    DEBUG((DEBUG_ERROR, "LcdGraphicsSetMode: ERROR - Unsupported mode number %d .\n", ModeNumber ));\r
+    Status = EFI_UNSUPPORTED;\r
+    goto EXIT;\r
+  }\r
+\r
+       // Set the oscillator frequency to support the new mode\r
+  Status = LcdPlatformSetMode (ModeNumber);\r
+  if (EFI_ERROR(Status)) {\r
+    Status = EFI_DEVICE_ERROR;\r
+    goto EXIT;\r
+  }\r
+\r
+       // Update the UEFI mode information\r
+       This->Mode->Mode = ModeNumber;\r
+       LcdPlatformQueryMode (ModeNumber,&Instance->ModeInfo);\r
+\r
+  // Set the hardware to the new mode\r
+       Status = LcdSetMode (ModeNumber);\r
+  if (EFI_ERROR(Status)) {\r
+    Status = EFI_DEVICE_ERROR;\r
+    goto EXIT;\r
+  }\r
+\r
+       // The UEFI spec requires that we now clear the visible portions of the output display to black.\r
+\r
+  // Set the fill colour to black\r
+  SetMem (&FillColour, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);\r
+\r
+  // Fill the entire visible area with the same colour.\r
+  Status = This->Blt (\r
+      This,\r
+      &FillColour,\r
+      EfiBltVideoFill,\r
+      0,\r
+      0,\r
+      0,\r
+      0,\r
+      This->Mode->Info->HorizontalResolution,\r
+      This->Mode->Info->VerticalResolution,\r
+      0);\r
+\r
+EXIT:\r
+       return Status;\r
+}\r
+\r
+UINTN\r
+GetBytesPerPixel (\r
+  IN  LCD_BPP       Bpp\r
+  )\r
+{\r
+  switch(Bpp) {\r
+  case LCD_BITS_PER_PIXEL_24:\r
+    return 4;\r
+\r
+  case LCD_BITS_PER_PIXEL_16_565:\r
+  case LCD_BITS_PER_PIXEL_16_555:\r
+  case LCD_BITS_PER_PIXEL_12_444:\r
+    return 2;\r
+\r
+  case LCD_BITS_PER_PIXEL_8:\r
+  case LCD_BITS_PER_PIXEL_4:\r
+  case LCD_BITS_PER_PIXEL_2:\r
+  case LCD_BITS_PER_PIXEL_1:\r
+    return 1;\r
+\r
+  default:\r
+    return 0;\r
+  }\r
+}\r
index a267a538cd9c28d670bafcb443215d2fd1750dba..5387e53c4ac3b4b0d50c122342d30d9a0b4a8559 100644 (file)
@@ -1,56 +1,56 @@
-#/** @file
-#  
-#  Component description file for PL111LcdGraphicsOutputDxe module
-#  
-#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
-#  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                      = PL111LcdGraphicsDxe
-  FILE_GUID                      = 407B4008-BF5B-11DF-9547-CF16E0D72085
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-  ENTRY_POINT                    = LcdGraphicsOutputDxeInitialize
-
-[Sources.common]
-  LcdGraphicsOutputDxe.c
-  LcdGraphicsOutputBlt.c
-  PL111Lcd.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-  ArmPkg/ArmPkg.dec
-  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  ArmLib
-  UefiLib
-  BaseLib
-  DebugLib
-  TimerLib
-  UefiDriverEntryPoint
-  UefiBootServicesTableLib
-  IoLib
-  BaseMemoryLib
-  LcdPlatformLib
-
-[Protocols]
-  gEfiDevicePathProtocolGuid
-  gEfiGraphicsOutputProtocolGuid
-
-[FixedPcd]
-  gArmPlatformTokenSpaceGuid.PcdPL111LcdBase
-
-[Depex]
-  gEfiCpuArchProtocolGuid
+#/** @file\r
+#  \r
+#  Component description file for PL111LcdGraphicsOutputDxe module\r
+#  \r
+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PL111LcdGraphicsDxe\r
+  FILE_GUID                      = 407B4008-BF5B-11DF-9547-CF16E0D72085\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = LcdGraphicsOutputDxeInitialize\r
+\r
+[Sources.common]\r
+  LcdGraphicsOutputDxe.c\r
+  LcdGraphicsOutputBlt.c\r
+  PL111Lcd.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  ArmLib\r
+  UefiLib\r
+  BaseLib\r
+  DebugLib\r
+  TimerLib\r
+  UefiDriverEntryPoint\r
+  UefiBootServicesTableLib\r
+  IoLib\r
+  BaseMemoryLib\r
+  LcdPlatformLib\r
+\r
+[Protocols]\r
+  gEfiDevicePathProtocolGuid\r
+  gEfiGraphicsOutputProtocolGuid\r
+\r
+[FixedPcd]\r
+  gArmPlatformTokenSpaceGuid.PcdPL111LcdBase\r
+\r
+[Depex]\r
+  gEfiCpuArchProtocolGuid\r
index d4dabeaefec112e6958dfd713edd81cd50de798c..21fceac1dc79979cce7ee0e4f1174b97caeec9f7 100644 (file)
-/** @file  NorFlashBlockIoDxe.c
-
-  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
-
-  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 <Library/BaseMemoryLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-
-#include "NorFlashDxe.h"
-
-//
-// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset
-//
-EFI_STATUS
-EFIAPI
-NorFlashBlockIoReset (
-  IN EFI_BLOCK_IO_PROTOCOL  *This,
-  IN BOOLEAN                ExtendedVerification
-  )
-{
-  NOR_FLASH_INSTANCE *Instance;
-
-  Instance = INSTANCE_FROM_BLKIO_THIS(This);
-
-  DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReset(MediaId=0x%x)\n", This->Media->MediaId));
-
-  return NorFlashReset (Instance);
-}
-
-//
-// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks
-//
-EFI_STATUS
-EFIAPI
-NorFlashBlockIoReadBlocks (
-  IN  EFI_BLOCK_IO_PROTOCOL   *This,
-  IN  UINT32                  MediaId,
-  IN  EFI_LBA                 Lba,
-  IN  UINTN                   BufferSizeInBytes,
-  OUT VOID                    *Buffer
-  )
-{
-  NOR_FLASH_INSTANCE  *Instance;
-  EFI_STATUS          Status;
-
-  Instance = INSTANCE_FROM_BLKIO_THIS(This);
-
-  DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
-
-  if( !This->Media->MediaPresent ) {
-    Status = EFI_NO_MEDIA;
-  } else if( This->Media->MediaId != MediaId ) {
-    Status = EFI_MEDIA_CHANGED;
-  } else {
-    Status = NorFlashReadBlocks (Instance,Lba,BufferSizeInBytes,Buffer);
-  }
-
-  return Status;
-}
-
-//
-// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
-//
-EFI_STATUS
-EFIAPI
-NorFlashBlockIoWriteBlocks (
-  IN  EFI_BLOCK_IO_PROTOCOL   *This,
-  IN  UINT32                  MediaId,
-  IN  EFI_LBA                 Lba,
-  IN  UINTN                   BufferSizeInBytes,
-  IN  VOID                    *Buffer
-  )
-{
-  NOR_FLASH_INSTANCE  *Instance;
-  EFI_STATUS          Status;
-
-  Instance = INSTANCE_FROM_BLKIO_THIS(This);
-
-  DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
-
-  if( !This->Media->MediaPresent ) {
-    Status = EFI_NO_MEDIA;
-  } else if( This->Media->MediaId != MediaId ) {
-    Status = EFI_MEDIA_CHANGED;
-  } else if( This->Media->ReadOnly ) {
-    Status = EFI_WRITE_PROTECTED;
-  } else {
-    Status = NorFlashWriteBlocks (Instance,Lba,BufferSizeInBytes,Buffer);
-  }
-
-  return Status;
-}
-
-//
-// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
-//
-EFI_STATUS
-EFIAPI
-NorFlashBlockIoFlushBlocks (
-  IN EFI_BLOCK_IO_PROTOCOL  *This
-  )
-{
-  // No Flush required for the NOR Flash driver
-  // because cache operations are not permitted.
-
-  DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoFlushBlocks: Function NOT IMPLEMENTED (not required).\n"));
-
-  // Nothing to do so just return without error
-  return EFI_SUCCESS;
-}
+/** @file  NorFlashBlockIoDxe.c\r
+\r
+  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#include "NorFlashDxe.h"\r
+\r
+//\r
+// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+NorFlashBlockIoReset (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN BOOLEAN                ExtendedVerification\r
+  )\r
+{\r
+  NOR_FLASH_INSTANCE *Instance;\r
+\r
+  Instance = INSTANCE_FROM_BLKIO_THIS(This);\r
+\r
+  DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReset(MediaId=0x%x)\n", This->Media->MediaId));\r
+\r
+  return NorFlashReset (Instance);\r
+}\r
+\r
+//\r
+// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+NorFlashBlockIoReadBlocks (\r
+  IN  EFI_BLOCK_IO_PROTOCOL   *This,\r
+  IN  UINT32                  MediaId,\r
+  IN  EFI_LBA                 Lba,\r
+  IN  UINTN                   BufferSizeInBytes,\r
+  OUT VOID                    *Buffer\r
+  )\r
+{\r
+  NOR_FLASH_INSTANCE  *Instance;\r
+  EFI_STATUS          Status;\r
+\r
+  Instance = INSTANCE_FROM_BLKIO_THIS(This);\r
+\r
+  DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));\r
+\r
+  if( !This->Media->MediaPresent ) {\r
+    Status = EFI_NO_MEDIA;\r
+  } else if( This->Media->MediaId != MediaId ) {\r
+    Status = EFI_MEDIA_CHANGED;\r
+  } else {\r
+    Status = NorFlashReadBlocks (Instance,Lba,BufferSizeInBytes,Buffer);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+//\r
+// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+NorFlashBlockIoWriteBlocks (\r
+  IN  EFI_BLOCK_IO_PROTOCOL   *This,\r
+  IN  UINT32                  MediaId,\r
+  IN  EFI_LBA                 Lba,\r
+  IN  UINTN                   BufferSizeInBytes,\r
+  IN  VOID                    *Buffer\r
+  )\r
+{\r
+  NOR_FLASH_INSTANCE  *Instance;\r
+  EFI_STATUS          Status;\r
+\r
+  Instance = INSTANCE_FROM_BLKIO_THIS(This);\r
+\r
+  DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));\r
+\r
+  if( !This->Media->MediaPresent ) {\r
+    Status = EFI_NO_MEDIA;\r
+  } else if( This->Media->MediaId != MediaId ) {\r
+    Status = EFI_MEDIA_CHANGED;\r
+  } else if( This->Media->ReadOnly ) {\r
+    Status = EFI_WRITE_PROTECTED;\r
+  } else {\r
+    Status = NorFlashWriteBlocks (Instance,Lba,BufferSizeInBytes,Buffer);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+//\r
+// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+NorFlashBlockIoFlushBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This\r
+  )\r
+{\r
+  // No Flush required for the NOR Flash driver\r
+  // because cache operations are not permitted.\r
+\r
+  DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoFlushBlocks: Function NOT IMPLEMENTED (not required).\n"));\r
+\r
+  // Nothing to do so just return without error\r
+  return EFI_SUCCESS;\r
+}\r
index 8464a98fd1bf1d32b9de2f2b9faeed1bdc70314c..d1506c721725a982f5a47f278c0cda8f883c8028 100644 (file)
@@ -1,52 +1,52 @@
-/** @file  NorFlashDxe.c
-
-  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
-
-  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 <Library/UefiLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/PcdLib.h>
-
-#include "NorFlashDxe.h"
-
-
-//
-// Global variable declarations
-//
-NOR_FLASH_INSTANCE **mNorFlashInstances;
-
-NOR_FLASH_INSTANCE  mNorFlashInstanceTemplate = {
-  NOR_FLASH_SIGNATURE, // Signature
-  NULL, // Handle ... NEED TO BE FILLED
-
-  FALSE, // Initialized
-  NULL, // Initialize
-
-  0, // DeviceBaseAddress ... NEED TO BE FILLED
-  0, // RegionBaseAddress ... NEED TO BE FILLED
-  0, // Size ... NEED TO BE FILLED
-  0, // StartLba
-
+/** @file  NorFlashDxe.c\r
+\r
+  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+#include "NorFlashDxe.h"\r
+\r
+\r
+//\r
+// Global variable declarations\r
+//\r
+NOR_FLASH_INSTANCE **mNorFlashInstances;\r
+\r
+NOR_FLASH_INSTANCE  mNorFlashInstanceTemplate = {\r
+  NOR_FLASH_SIGNATURE, // Signature\r
+  NULL, // Handle ... NEED TO BE FILLED\r
+\r
+  FALSE, // Initialized\r
+  NULL, // Initialize\r
+\r
+  0, // DeviceBaseAddress ... NEED TO BE FILLED\r
+  0, // RegionBaseAddress ... NEED TO BE FILLED\r
+  0, // Size ... NEED TO BE FILLED\r
+  0, // StartLba\r
+\r
   {\r
     EFI_BLOCK_IO_PROTOCOL_REVISION2, // Revision\r
     NULL, // Media ... NEED TO BE FILLED\r
     NorFlashBlockIoReset, // Reset;\r
   {\r
     EFI_BLOCK_IO_PROTOCOL_REVISION2, // Revision\r
     NULL, // Media ... NEED TO BE FILLED\r
     NorFlashBlockIoReset, // Reset;\r
-    NorFlashBlockIoReadBlocks,          // ReadBlocks
-    NorFlashBlockIoWriteBlocks,         // WriteBlocks
+    NorFlashBlockIoReadBlocks,          // ReadBlocks\r
+    NorFlashBlockIoWriteBlocks,         // WriteBlocks\r
     NorFlashBlockIoFlushBlocks          // FlushBlocks\r
     NorFlashBlockIoFlushBlocks          // FlushBlocks\r
-  }, // BlockIoProtocol
-
+  }, // BlockIoProtocol\r
+\r
   {\r
     0, // MediaId ... NEED TO BE FILLED\r
     FALSE, // RemovableMedia\r
   {\r
     0, // MediaId ... NEED TO BE FILLED\r
     FALSE, // RemovableMedia\r
@@ -59,767 +59,767 @@ NOR_FLASH_INSTANCE  mNorFlashInstanceTemplate = {
     0, // LastBlock ... NEED TO BE FILLED\r
     0, // LowestAlignedLba\r
     1, // LogicalBlocksPerPhysicalBlock\r
     0, // LastBlock ... NEED TO BE FILLED\r
     0, // LowestAlignedLba\r
     1, // LogicalBlocksPerPhysicalBlock\r
-  }, //Media;
-
-  FALSE, // SupportFvb ... NEED TO BE FILLED
+  }, //Media;\r
+\r
+  FALSE, // SupportFvb ... NEED TO BE FILLED\r
   {\r
   {\r
-    FvbGetAttributes, // GetAttributes
-    FvbSetAttributes, // SetAttributes
-    FvbGetPhysicalAddress,  // GetPhysicalAddress
-    FvbGetBlockSize,  // GetBlockSize
-    FvbRead,  // Read
-    FvbWrite, // Write
+    FvbGetAttributes, // GetAttributes\r
+    FvbSetAttributes, // SetAttributes\r
+    FvbGetPhysicalAddress,  // GetPhysicalAddress\r
+    FvbGetBlockSize,  // GetBlockSize\r
+    FvbRead,  // Read\r
+    FvbWrite, // Write\r
     FvbEraseBlocks, // EraseBlocks\r
     NULL, //ParentHandle\r
     FvbEraseBlocks, // EraseBlocks\r
     NULL, //ParentHandle\r
-  }, //  FvbProtoccol;
-
-  {
-    {
-      {
-        HARDWARE_DEVICE_PATH,
-        HW_VENDOR_DP,
-        (UINT8)( sizeof(VENDOR_DEVICE_PATH)      ),
-        (UINT8)((sizeof(VENDOR_DEVICE_PATH)) >> 8),
-      },
-      { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }, // GUID ... NEED TO BE FILLED
-    },
-    {
-      END_DEVICE_PATH_TYPE,
-      END_ENTIRE_DEVICE_PATH_SUBTYPE,
-      sizeof (EFI_DEVICE_PATH_PROTOCOL),
-      0
-    }
-    } // DevicePath
-};
-
-EFI_STATUS
-NorFlashCreateInstance (
-  IN UINTN                  NorFlashDeviceBase,
-  IN UINTN                  NorFlashRegionBase,
-  IN UINTN                  NorFlashSize,
-  IN UINT32                 MediaId,
-  IN UINT32                 BlockSize,
-  IN BOOLEAN                SupportFvb,
-  IN CONST GUID             *NorFlashGuid,
-  OUT NOR_FLASH_INSTANCE**  NorFlashInstance
-  )
-{
-  EFI_STATUS Status;
-  NOR_FLASH_INSTANCE* Instance;
-
-  ASSERT(NorFlashInstance != NULL);
-
-  Instance = AllocateCopyPool (sizeof(NOR_FLASH_INSTANCE),&mNorFlashInstanceTemplate);
-  if (Instance == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  Instance->DeviceBaseAddress = NorFlashDeviceBase;
-  Instance->RegionBaseAddress = NorFlashRegionBase;
-  Instance->Size = NorFlashSize;
-
-  Instance->BlockIoProtocol.Media = &Instance->Media;
-  Instance->Media.MediaId = MediaId;
-  Instance->Media.BlockSize = BlockSize;
-  Instance->Media.LastBlock = (NorFlashSize / BlockSize)-1;
+  }, //  FvbProtoccol;\r
+\r
+  {\r
+    {\r
+      {\r
+        HARDWARE_DEVICE_PATH,\r
+        HW_VENDOR_DP,\r
+        (UINT8)( sizeof(VENDOR_DEVICE_PATH)      ),\r
+        (UINT8)((sizeof(VENDOR_DEVICE_PATH)) >> 8),\r
+      },\r
+      { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }, // GUID ... NEED TO BE FILLED\r
+    },\r
+    {\r
+      END_DEVICE_PATH_TYPE,\r
+      END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+      sizeof (EFI_DEVICE_PATH_PROTOCOL),\r
+      0\r
+    }\r
+    } // DevicePath\r
+};\r
+\r
+EFI_STATUS\r
+NorFlashCreateInstance (\r
+  IN UINTN                  NorFlashDeviceBase,\r
+  IN UINTN                  NorFlashRegionBase,\r
+  IN UINTN                  NorFlashSize,\r
+  IN UINT32                 MediaId,\r
+  IN UINT32                 BlockSize,\r
+  IN BOOLEAN                SupportFvb,\r
+  IN CONST GUID             *NorFlashGuid,\r
+  OUT NOR_FLASH_INSTANCE**  NorFlashInstance\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  NOR_FLASH_INSTANCE* Instance;\r
+\r
+  ASSERT(NorFlashInstance != NULL);\r
+\r
+  Instance = AllocateCopyPool (sizeof(NOR_FLASH_INSTANCE),&mNorFlashInstanceTemplate);\r
+  if (Instance == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Instance->DeviceBaseAddress = NorFlashDeviceBase;\r
+  Instance->RegionBaseAddress = NorFlashRegionBase;\r
+  Instance->Size = NorFlashSize;\r
+\r
+  Instance->BlockIoProtocol.Media = &Instance->Media;\r
+  Instance->Media.MediaId = MediaId;\r
+  Instance->Media.BlockSize = BlockSize;\r
+  Instance->Media.LastBlock = (NorFlashSize / BlockSize)-1;\r
 \r
   CopyGuid (&Instance->DevicePath.Vendor.Guid,NorFlashGuid);\r
 \r
   CopyGuid (&Instance->DevicePath.Vendor.Guid,NorFlashGuid);\r
-
-  if (SupportFvb) {
-    Instance->SupportFvb = TRUE;
-    Instance->Initialize = NorFlashFvbInitialize;
-
-    Status = gBS->InstallMultipleProtocolInterfaces (
-                  &Instance->Handle,
-                  &gEfiDevicePathProtocolGuid, &Instance->DevicePath,
-                  &gEfiBlockIoProtocolGuid,  &Instance->BlockIoProtocol,
-                  &gEfiFirmwareVolumeBlockProtocolGuid, &Instance->FvbProtocol,
-                  NULL
-                  );
-    if (EFI_ERROR(Status)) {
-      FreePool(Instance);
-      return Status;
-    }
-  } else {
-    Instance->Initialized = TRUE;
-
-    Status = gBS->InstallMultipleProtocolInterfaces (
-                    &Instance->Handle,
-                    &gEfiDevicePathProtocolGuid, &Instance->DevicePath,
-                    &gEfiBlockIoProtocolGuid,  &Instance->BlockIoProtocol,
-                    NULL
-                    );
-    if (EFI_ERROR(Status)) {
-      FreePool(Instance);
-      return Status;
-    }
-  }
+\r
+  if (SupportFvb) {\r
+    Instance->SupportFvb = TRUE;\r
+    Instance->Initialize = NorFlashFvbInitialize;\r
+\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Instance->Handle,\r
+                  &gEfiDevicePathProtocolGuid, &Instance->DevicePath,\r
+                  &gEfiBlockIoProtocolGuid,  &Instance->BlockIoProtocol,\r
+                  &gEfiFirmwareVolumeBlockProtocolGuid, &Instance->FvbProtocol,\r
+                  NULL\r
+                  );\r
+    if (EFI_ERROR(Status)) {\r
+      FreePool(Instance);\r
+      return Status;\r
+    }\r
+  } else {\r
+    Instance->Initialized = TRUE;\r
+\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &Instance->Handle,\r
+                    &gEfiDevicePathProtocolGuid, &Instance->DevicePath,\r
+                    &gEfiBlockIoProtocolGuid,  &Instance->BlockIoProtocol,\r
+                    NULL\r
+                    );\r
+    if (EFI_ERROR(Status)) {\r
+      FreePool(Instance);\r
+      return Status;\r
+    }\r
+  }\r
 \r
   *NorFlashInstance = Instance;\r
 \r
   *NorFlashInstance = Instance;\r
-  return Status;
-}
-
-UINT32
-NorFlashReadStatusRegister (
-  IN NOR_FLASH_INSTANCE     *Instance,
-  IN UINTN                  SR_Address
-  )
-{
-  // Prepare to read the status register
-  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_STATUS_REGISTER);
-  return MmioRead32 (Instance->DeviceBaseAddress);
-}
-
-
-BOOLEAN
-NorFlashBlockIsLocked (
-  IN NOR_FLASH_INSTANCE     *Instance,
-  IN UINTN                  BlockAddress
-  )
-{
-  UINT32                LockStatus;
-  BOOLEAN               BlockIsLocked;
-
-  BlockIsLocked = TRUE;
-
-  // Send command for reading device id
-  SEND_NOR_COMMAND (BlockAddress, 2, P30_CMD_READ_DEVICE_ID);
-
-  // Read block lock status
-  LockStatus = MmioRead32 (CREATE_NOR_ADDRESS(BlockAddress, 2));
-
-  // Decode block lock status
-  LockStatus = FOLD_32BIT_INTO_16BIT(LockStatus);
-
-  if ((LockStatus & 0x2) != 0) {
-    DEBUG((EFI_D_ERROR, "NorFlashBlockIsLocked: WARNING: Block LOCKED DOWN\n"));
-  }
-
-  if ((LockStatus & 0x1) == 0) {
-    // This means the block is unlocked
-    DEBUG((DEBUG_BLKIO, "UnlockSingleBlock: Block 0x%08x unlocked\n", BlockAddress));
-    BlockIsLocked = FALSE;
-  }
-
-  return BlockIsLocked;
-}
-
-
-EFI_STATUS
-NorFlashUnlockSingleBlock (
-  IN NOR_FLASH_INSTANCE     *Instance,
-  IN UINTN                  BlockAddress
-  )
-{
-  EFI_STATUS            Status = EFI_SUCCESS;
-  UINT32                LockStatus;
-
-  // Raise the Task Priority Level to TPL_NOTIFY to serialise all its operations
-  // and to protect shared data structures.
-
-  if (FeaturePcdGet (PcdNorFlashCheckBlockLocked) == TRUE) {
-    do {
-      // Request a lock setup
-      SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_LOCK_BLOCK_SETUP);
-
-      // Request an unlock
-      SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_UNLOCK_BLOCK);
-
-      // Send command for reading device id
-      SEND_NOR_COMMAND (BlockAddress, 2, P30_CMD_READ_DEVICE_ID);
-
-      // Read block lock status
-      LockStatus = MmioRead32 (CREATE_NOR_ADDRESS(BlockAddress, 2));
-
-      // Decode block lock status
-      LockStatus = FOLD_32BIT_INTO_16BIT(LockStatus);
-    } while ((LockStatus & 0x1) == 1);
-  } else {
-    // Request a lock setup
-    SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_LOCK_BLOCK_SETUP);
-
-    // Request an unlock
-    SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_UNLOCK_BLOCK);
-
-    // Wait until the status register gives us the all clear
-    do {
-      LockStatus = NorFlashReadStatusRegister (Instance, BlockAddress);
-    } while ((LockStatus & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);
-  }
-
-  // Put device back into Read Array mode
-  SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_READ_ARRAY);
-
-  DEBUG((DEBUG_BLKIO, "UnlockSingleBlock: BlockAddress=0x%08x, Exit Status = \"%r\".\n", BlockAddress, Status));
-
-  return Status;
-}
-
-
-EFI_STATUS
-NorFlashUnlockSingleBlockIfNecessary (
-  IN NOR_FLASH_INSTANCE     *Instance,
-  IN UINTN                  BlockAddress
-  )
-{
-  EFI_STATUS Status = EFI_SUCCESS;
-
-  if (NorFlashBlockIsLocked (Instance, BlockAddress) == TRUE) {
-    Status = NorFlashUnlockSingleBlock (Instance, BlockAddress);
-  }
-
-  return Status;
-}
-
-
-/**
- * The following function presumes that the block has already been unlocked.
- **/
-EFI_STATUS
-NorFlashEraseSingleBlock (
-  IN NOR_FLASH_INSTANCE     *Instance,
-  IN UINTN                  BlockAddress
-  )
-{
-  EFI_STATUS            Status;
-  UINT32                StatusRegister;
-
-  Status = EFI_SUCCESS;
-
-  // Request a block erase and then confirm it
-  SEND_NOR_COMMAND(BlockAddress, 0, P30_CMD_BLOCK_ERASE_SETUP);
-  SEND_NOR_COMMAND(BlockAddress, 0, P30_CMD_BLOCK_ERASE_CONFIRM);
-
-  // Wait until the status register gives us the all clear
-  do {
-    StatusRegister = NorFlashReadStatusRegister (Instance, BlockAddress);
-  } while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);
-
-  if (StatusRegister & P30_SR_BIT_VPP) {
-    DEBUG((EFI_D_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: VPP Range Error\n", BlockAddress));
-    Status = EFI_DEVICE_ERROR;
-  }
-
-  if ((StatusRegister & (P30_SR_BIT_ERASE | P30_SR_BIT_PROGRAM)) == (P30_SR_BIT_ERASE | P30_SR_BIT_PROGRAM)) {
-    DEBUG((EFI_D_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Command Sequence Error\n", BlockAddress));
-    Status = EFI_DEVICE_ERROR;
-  }
-
-  if (StatusRegister & P30_SR_BIT_ERASE) {
-    DEBUG((EFI_D_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Block Erase Error StatusRegister:0x%X\n", BlockAddress, StatusRegister));
-    Status = EFI_DEVICE_ERROR;
-  }
-
-  if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) {
-    // The debug level message has been reduced because a device lock might happen. In this case we just retry it ...
-    DEBUG((EFI_D_INFO,"EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error\n", BlockAddress));
-    Status = EFI_WRITE_PROTECTED;
-  }
-
-  if (EFI_ERROR(Status)) {
-    // Clear the Status Register
-    SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER);
-  }
-
-  // Put device back into Read Array mode
-  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
-
-  return Status;
-}
-
-/**
- * The following function presumes that the block has already been unlocked.
- **/
-EFI_STATUS
-NorFlashUnlockAndEraseSingleBlock (
-  IN NOR_FLASH_INSTANCE     *Instance,
-  IN UINTN                  BlockAddress
-  )
-{
-  EFI_STATUS      Status;
-  UINTN           Index;
-  EFI_TPL         OriginalTPL;
-
-  // Raise TPL to TPL_HIGH to stop anyone from interrupting us.
-  OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);
-
-  Index = 0;
-  // The block erase might fail a first time (SW bug ?). Retry it ...
-  do {
-    // Unlock the block if we have to
-    Status = NorFlashUnlockSingleBlockIfNecessary (Instance, BlockAddress);
-    if (!EFI_ERROR(Status)) {
-      Status = NorFlashEraseSingleBlock (Instance, BlockAddress);
-    }
-    Index++;
-  } while ((Index < NOR_FLASH_ERASE_RETRY) && (Status == EFI_WRITE_PROTECTED));
-
-  if (Index == NOR_FLASH_ERASE_RETRY) {
-    DEBUG((EFI_D_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error (try to erase %d times)\n", BlockAddress,Index));
-  }
-
-  // Interruptions can resume.
-  gBS->RestoreTPL (OriginalTPL);
-
-  return Status;
-}
-
-
-EFI_STATUS
-NorFlashWriteSingleWord (
-  IN NOR_FLASH_INSTANCE     *Instance,
-  IN UINTN                  WordAddress,
-  IN UINT32                 WriteData
-  )
-{
-  EFI_STATUS            Status;
-  UINT32                StatusRegister;
-
-  Status = EFI_SUCCESS;
-
-  // Request a write single word command
-  SEND_NOR_COMMAND(WordAddress, 0, P30_CMD_WORD_PROGRAM_SETUP);
-
-  // Store the word into NOR Flash;
-  MmioWrite32 (WordAddress, WriteData);
-
-  // Wait for the write to complete and then check for any errors; i.e. check the Status Register
-  do {
-    // Prepare to read the status register
-    StatusRegister = NorFlashReadStatusRegister (Instance, WordAddress);
-    // The chip is busy while the WRITE bit is not asserted
-  } while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);
-
-
-  // Perform a full status check:
-  // Mask the relevant bits of Status Register.
-  // Everything should be zero, if not, we have a problem
-
-  if (StatusRegister & P30_SR_BIT_VPP) {
-    DEBUG((EFI_D_ERROR,"NorFlashWriteSingleWord(WordAddress:0x%X): VPP Range Error\n",WordAddress));
-    Status = EFI_DEVICE_ERROR;
-  }
-
-  if (StatusRegister & P30_SR_BIT_PROGRAM) {
-    DEBUG((EFI_D_ERROR,"NorFlashWriteSingleWord(WordAddress:0x%X): Program Error\n",WordAddress));
-    Status = EFI_DEVICE_ERROR;
-  }
-
-  if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) {
-    DEBUG((EFI_D_ERROR,"NorFlashWriteSingleWord(WordAddress:0x%X): Device Protect Error\n",WordAddress));
-    Status = EFI_DEVICE_ERROR;
-  }
-
-  if (!EFI_ERROR(Status)) {
-    // Clear the Status Register
-    SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER);
-  }
-
-  // Put device back into Read Array mode
-  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
-
-  return Status;
-}
-
-/*
- * Writes data to the NOR Flash using the Buffered Programming method.
- *
- * The maximum size of the on-chip buffer is 32-words, because of hardware restrictions.
- * Therefore this function will only handle buffers up to 32 words or 128 bytes.
- * To deal with larger buffers, call this function again.
- *
- * This function presumes that both the TargetAddress and the TargetAddress+BufferSize
- * exist entirely within the NOR Flash. Therefore these conditions will not be checked here.
- *
- * In buffered programming, if the target address not at the beginning of a 32-bit word boundary,
- * then programming time is doubled and power consumption is increased.
- * Therefore, it is a requirement to align buffer writes to 32-bit word boundaries.
- * i.e. the last 4 bits of the target start address must be zero: 0x......00
- */
-EFI_STATUS
-NorFlashWriteBuffer (
-  IN NOR_FLASH_INSTANCE     *Instance,
-  IN UINTN                  TargetAddress,
-  IN UINTN                  BufferSizeInBytes,
-  IN UINT32                 *Buffer
-  )
-{
-  EFI_STATUS            Status;
-  UINTN                 BufferSizeInWords;
-  UINTN                 Count;
-  volatile UINT32       *Data;
-  UINTN                 WaitForBuffer;
-  BOOLEAN               BufferAvailable;
-  UINT32                StatusRegister;
-
-  WaitForBuffer   = MAX_BUFFERED_PROG_ITERATIONS;
-  BufferAvailable = FALSE;
-
-  // Check that the target address does not cross a 32-word boundary.
-  if ((TargetAddress & BOUNDARY_OF_32_WORDS) != 0) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  // Check there are some data to program
-  if (BufferSizeInBytes == 0) {
-    return EFI_BUFFER_TOO_SMALL;
-  }
-
-  // Check that the buffer size does not exceed the maximum hardware buffer size on chip.
-  if (BufferSizeInBytes > P30_MAX_BUFFER_SIZE_IN_BYTES) {
-    return EFI_BAD_BUFFER_SIZE;
-  }
-
-  // Check that the buffer size is a multiple of 32-bit words
-  if ((BufferSizeInBytes % 4) != 0) {
-    return EFI_BAD_BUFFER_SIZE;
-  }
-
-  // Pre-programming conditions checked, now start the algorithm.
-
-  // Prepare the data destination address
-  Data = (UINT32 *)TargetAddress;
-
-  // Check the availability of the buffer
-  do {
-    // Issue the Buffered Program Setup command
-    SEND_NOR_COMMAND(TargetAddress, 0, P30_CMD_BUFFERED_PROGRAM_SETUP);
-
-    // Read back the status register bit#7 from the same address
-    if (((*Data) & P30_SR_BIT_WRITE) == P30_SR_BIT_WRITE) {
-      BufferAvailable = TRUE;
-    }
-
-    // Update the loop counter
-    WaitForBuffer--;
-
-  } while ((WaitForBuffer > 0) && (BufferAvailable == FALSE));
-
-  // The buffer was not available for writing
-  if (WaitForBuffer == 0) {
-    Status = EFI_DEVICE_ERROR;
-    goto EXIT;
-  }
-
-  // From now on we work in 32-bit words
-  BufferSizeInWords = BufferSizeInBytes / (UINTN)4;
-
-  // Write the word count, which is (buffer_size_in_words - 1),
-  // because word count 0 means one word.
-  SEND_NOR_COMMAND(TargetAddress, 0, (BufferSizeInWords - 1));
-
-  // Write the data to the NOR Flash, advancing each address by 4 bytes
-  for(Count=0; Count < BufferSizeInWords; Count++, Data++, Buffer++) {
-    *Data = *Buffer;
-  }
-
-  // Issue the Buffered Program Confirm command, to start the programming operation
-  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_BUFFERED_PROGRAM_CONFIRM);
-
-  // Wait for the write to complete and then check for any errors; i.e. check the Status Register
-  do {
-    StatusRegister = NorFlashReadStatusRegister (Instance, TargetAddress);
-    // The chip is busy while the WRITE bit is not asserted
-  } while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);
-
-
-  // Perform a full status check:
-  // Mask the relevant bits of Status Register.
-  // Everything should be zero, if not, we have a problem
-
-  Status          = EFI_SUCCESS;
-
-  if (StatusRegister & P30_SR_BIT_VPP) {
-    DEBUG((EFI_D_ERROR,"NorFlashWriteBuffer(TargetAddress:0x%X): VPP Range Error\n", TargetAddress));
-    Status = EFI_DEVICE_ERROR;
-  }
-
-  if (StatusRegister & P30_SR_BIT_PROGRAM) {
-    DEBUG((EFI_D_ERROR,"NorFlashWriteBuffer(TargetAddress:0x%X): Program Error\n", TargetAddress));
-    Status = EFI_DEVICE_ERROR;
-  }
-
-  if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) {
-    DEBUG((EFI_D_ERROR,"NorFlashWriteBuffer(TargetAddress:0x%X): Device Protect Error\n",TargetAddress));
-    Status = EFI_DEVICE_ERROR;
-  }
-
-  if (!EFI_ERROR(Status)) {
-    // Clear the Status Register
-    SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER);
-  }
-
-EXIT:
-  // Put device back into Read Array mode
-  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
-
-  return Status;
-}
-
-EFI_STATUS
-NorFlashWriteSingleBlock (
-  IN NOR_FLASH_INSTANCE     *Instance,
-  IN EFI_LBA                Lba,
-  IN UINT32                 *DataBuffer,
-  IN UINT32                 BlockSizeInWords
-  )
-{
-  EFI_STATUS    Status;
-  UINTN         WordAddress;
-  UINT32        WordIndex;
-  UINTN         BufferIndex;
-  UINTN         BlockAddress;
-  UINTN         BuffersInBlock;
-  UINTN         RemainingWords;
-  EFI_TPL       OriginalTPL;
-
-  Status = EFI_SUCCESS;
-
-  // Get the physical address of the block
-  BlockAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, Lba, BlockSizeInWords * 4);
-
-  // Start writing from the first address at the start of the block
-  WordAddress = BlockAddress;
-
-  // Raise TPL to TPL_HIGH to stop anyone from interrupting us.
-  OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);
-
-  Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress);
-  if (EFI_ERROR(Status)) {
-    DEBUG((EFI_D_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and Erase the single block at 0x%X\n", BlockAddress));
-    goto EXIT;
-  }
-
-  // To speed up the programming operation, NOR Flash is programmed using the Buffered Programming method.
-
-  // Check that the address starts at a 32-word boundary, i.e. last 7 bits must be zero
-  if ((WordAddress & BOUNDARY_OF_32_WORDS) == 0x00) {
-
-    // First, break the entire block into buffer-sized chunks.
-    BuffersInBlock = (UINTN)BlockSizeInWords / P30_MAX_BUFFER_SIZE_IN_BYTES;
-
-    // Then feed each buffer chunk to the NOR Flash
-    for(BufferIndex=0;
-         BufferIndex < BuffersInBlock;
-         BufferIndex++, WordAddress += P30_MAX_BUFFER_SIZE_IN_BYTES, DataBuffer += P30_MAX_BUFFER_SIZE_IN_WORDS
-      ) {
-      Status = NorFlashWriteBuffer (Instance, WordAddress, P30_MAX_BUFFER_SIZE_IN_BYTES, DataBuffer);
-      if (EFI_ERROR(Status)) {
-        goto EXIT;
-      }
-    }
-
-    // Finally, finish off any remaining words that are less than the maximum size of the buffer
-    RemainingWords = BlockSizeInWords % P30_MAX_BUFFER_SIZE_IN_WORDS;
-
-    if(RemainingWords != 0) {
-      Status = NorFlashWriteBuffer (Instance, WordAddress, (RemainingWords * 4), DataBuffer);
-      if (EFI_ERROR(Status)) {
-        goto EXIT;
-      }
-    }
-
-  } else {
-    // For now, use the single word programming algorithm
-    // It is unlikely that the NOR Flash will exist in an address which falls within a 32 word boundary range,
-    // i.e. which ends in the range 0x......01 - 0x......7F.
-    for(WordIndex=0; WordIndex<BlockSizeInWords; WordIndex++, DataBuffer++, WordAddress = WordAddress + 4) {
-      Status = NorFlashWriteSingleWord (Instance, WordAddress, *DataBuffer);
-      if (EFI_ERROR(Status)) {
-        goto EXIT;
-      }
-    }
-  }
-
-EXIT:
-  // Interruptions can resume.
-  gBS->RestoreTPL (OriginalTPL);
-
-  if (EFI_ERROR(Status)) {
-    DEBUG((EFI_D_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed at address 0x%08x. Exit Status = \"%r\".\n", WordAddress, Status));
-  }
-  return Status;
-}
-
-
-EFI_STATUS
-NorFlashWriteBlocks (
-  IN NOR_FLASH_INSTANCE     *Instance,
-  IN EFI_LBA                Lba,
-  IN UINTN                  BufferSizeInBytes,
-  IN VOID                   *Buffer
-  )
-{
-  UINT32          *pWriteBuffer;
-  EFI_STATUS      Status = EFI_SUCCESS;
-  EFI_LBA         CurrentBlock;
-  UINT32          BlockSizeInWords;
-  UINT32          NumBlocks;
-  UINT32          BlockCount;
-
-  // The buffer must be valid
-  if (Buffer == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  if(Instance->Media.ReadOnly == TRUE) {
-    return EFI_WRITE_PROTECTED;
-  }
-
-  // We must have some bytes to read
-  DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: BufferSizeInBytes=0x%x\n", BufferSizeInBytes));
-  if(BufferSizeInBytes == 0) {
-    return EFI_BAD_BUFFER_SIZE;
-  }
-
-  // The size of the buffer must be a multiple of the block size
-  DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: BlockSize in bytes =0x%x\n", Instance->Media.BlockSize));
-  if ((BufferSizeInBytes % Instance->Media.BlockSize) != 0) {
-    return EFI_BAD_BUFFER_SIZE;
-  }
-
-  // All blocks must be within the device
-  NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize ;
-
-  DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: NumBlocks=%d, LastBlock=%ld, Lba=%ld.\n", NumBlocks, Instance->Media.LastBlock, Lba));
-
-  if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {
-    DEBUG((EFI_D_ERROR, "NorFlashWriteBlocks: ERROR - Write will exceed last block.\n"));
-    return EFI_INVALID_PARAMETER;
-  }
-
-  BlockSizeInWords = Instance->Media.BlockSize / 4;
-
-  // Because the target *Buffer is a pointer to VOID, we must put all the data into a pointer
-  // to a proper data type, so use *ReadBuffer
-  pWriteBuffer = (UINT32 *)Buffer;
-
-  CurrentBlock = Lba;
-  for (BlockCount=0; BlockCount < NumBlocks; BlockCount++, CurrentBlock++, pWriteBuffer = pWriteBuffer + BlockSizeInWords) {
-
-    DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: Writing block #%d\n", (UINTN)CurrentBlock));
-
-    Status = NorFlashWriteSingleBlock (Instance, CurrentBlock, pWriteBuffer, BlockSizeInWords);
-
-    if (EFI_ERROR(Status)) {
-      break;
-    }
-  }
-
-  DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: Exit Status = \"%r\".\n", Status));
-  return Status;
-}
-
-EFI_STATUS
-NorFlashReadBlocks (
-  IN NOR_FLASH_INSTANCE   *Instance,
-  IN EFI_LBA              Lba,
-  IN UINTN                BufferSizeInBytes,
-  OUT VOID                *Buffer
-  )
-{
-  UINT32              NumBlocks;
-  UINTN               StartAddress;
-
-  // The buffer must be valid
-  if (Buffer == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  // We must have some bytes to read
-  DEBUG((DEBUG_BLKIO, "NorFlashReadBlocks: BufferSize=0x%x bytes.\n", BufferSizeInBytes));
-  if(BufferSizeInBytes == 0) {
-    return EFI_BAD_BUFFER_SIZE;
-  }
-
-  // The size of the buffer must be a multiple of the block size
-  DEBUG((DEBUG_BLKIO, "NorFlashReadBlocks: BlockSize=0x%x bytes.\n", Instance->Media.BlockSize));
-  if ((BufferSizeInBytes % Instance->Media.BlockSize) != 0) {
-    return EFI_BAD_BUFFER_SIZE;
-  }
-
-  // All blocks must be within the device
-  NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize ;
-
-  DEBUG((DEBUG_BLKIO, "NorFlashReadBlocks: NumBlocks=%d, LastBlock=%ld, Lba=%ld\n", NumBlocks, Instance->Media.LastBlock, Lba));
-
-  if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {
-    DEBUG((EFI_D_ERROR, "NorFlashReadBlocks: ERROR - Read will exceed last block\n"));
-    return EFI_INVALID_PARAMETER;
-  }
-
-  // Get the address to start reading from
-  StartAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress,
-                                        Lba,
-                                        Instance->Media.BlockSize
-                                       );
-
-  // Put the device into Read Array mode
-  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
-
-  // Readout the data
-  CopyMem(Buffer, (UINTN *)StartAddress, BufferSizeInBytes);
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-NorFlashReset (
-  IN  NOR_FLASH_INSTANCE *Instance
-  )
-{
-  // As there is no specific RESET to perform, ensure that the devices is in the default Read Array mode
-  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-NorFlashInitialise (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
-  )
-{
-  EFI_STATUS              Status;
-  UINT32                  Index;
-  NOR_FLASH_DESCRIPTION*  NorFlashDevices;
-  UINT32                  NorFlashDeviceCount;
-  BOOLEAN                 ContainVariableStorage;
-
-  Status = NorFlashPlatformInitialization ();
-  if (EFI_ERROR(Status)) {
-    DEBUG((EFI_D_ERROR,"NorFlashInitialise: Fail to initialize Nor Flash devices\n"));
-    return Status;
-  }
-
-  Status = NorFlashPlatformGetDevices (&NorFlashDevices,&NorFlashDeviceCount);
-  if (EFI_ERROR(Status)) {
-    DEBUG((EFI_D_ERROR,"NorFlashInitialise: Fail to get Nor Flash devices\n"));
-    return Status;
-  }
-
-  mNorFlashInstances = AllocatePool (sizeof(NOR_FLASH_INSTANCE*) * NorFlashDeviceCount);
-
-  for (Index = 0; Index < NorFlashDeviceCount; Index++) {
-    // Check if this NOR Flash device contain the variable storage region
-    ContainVariableStorage =
-        (NorFlashDevices[Index].RegionBaseAddress <= PcdGet32 (PcdFlashNvStorageVariableBase)) &&
-        (PcdGet32 (PcdFlashNvStorageVariableBase) + PcdGet32 (PcdFlashNvStorageVariableSize) <= NorFlashDevices[Index].RegionBaseAddress + NorFlashDevices[Index].Size);
-
-    Status = NorFlashCreateInstance (
-      NorFlashDevices[Index].DeviceBaseAddress,
-      NorFlashDevices[Index].RegionBaseAddress,
-      NorFlashDevices[Index].Size,
-      Index,
-      NorFlashDevices[Index].BlockSize,
-      ContainVariableStorage,
-      &NorFlashDevices[Index].Guid,
-      &mNorFlashInstances[Index]
-    );
-    if (EFI_ERROR(Status)) {
-      DEBUG((EFI_D_ERROR,"NorFlashInitialise: Fail to create instance for NorFlash[%d]\n",Index));
-    }
-  }
-
-  return Status;
-}
+  return Status;\r
+}\r
+\r
+UINT32\r
+NorFlashReadStatusRegister (\r
+  IN NOR_FLASH_INSTANCE     *Instance,\r
+  IN UINTN                  SR_Address\r
+  )\r
+{\r
+  // Prepare to read the status register\r
+  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_STATUS_REGISTER);\r
+  return MmioRead32 (Instance->DeviceBaseAddress);\r
+}\r
+\r
+\r
+BOOLEAN\r
+NorFlashBlockIsLocked (\r
+  IN NOR_FLASH_INSTANCE     *Instance,\r
+  IN UINTN                  BlockAddress\r
+  )\r
+{\r
+  UINT32                LockStatus;\r
+  BOOLEAN               BlockIsLocked;\r
+\r
+  BlockIsLocked = TRUE;\r
+\r
+  // Send command for reading device id\r
+  SEND_NOR_COMMAND (BlockAddress, 2, P30_CMD_READ_DEVICE_ID);\r
+\r
+  // Read block lock status\r
+  LockStatus = MmioRead32 (CREATE_NOR_ADDRESS(BlockAddress, 2));\r
+\r
+  // Decode block lock status\r
+  LockStatus = FOLD_32BIT_INTO_16BIT(LockStatus);\r
+\r
+  if ((LockStatus & 0x2) != 0) {\r
+    DEBUG((EFI_D_ERROR, "NorFlashBlockIsLocked: WARNING: Block LOCKED DOWN\n"));\r
+  }\r
+\r
+  if ((LockStatus & 0x1) == 0) {\r
+    // This means the block is unlocked\r
+    DEBUG((DEBUG_BLKIO, "UnlockSingleBlock: Block 0x%08x unlocked\n", BlockAddress));\r
+    BlockIsLocked = FALSE;\r
+  }\r
+\r
+  return BlockIsLocked;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+NorFlashUnlockSingleBlock (\r
+  IN NOR_FLASH_INSTANCE     *Instance,\r
+  IN UINTN                  BlockAddress\r
+  )\r
+{\r
+  EFI_STATUS            Status = EFI_SUCCESS;\r
+  UINT32                LockStatus;\r
+\r
+  // Raise the Task Priority Level to TPL_NOTIFY to serialise all its operations\r
+  // and to protect shared data structures.\r
+\r
+  if (FeaturePcdGet (PcdNorFlashCheckBlockLocked) == TRUE) {\r
+    do {\r
+      // Request a lock setup\r
+      SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_LOCK_BLOCK_SETUP);\r
+\r
+      // Request an unlock\r
+      SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_UNLOCK_BLOCK);\r
+\r
+      // Send command for reading device id\r
+      SEND_NOR_COMMAND (BlockAddress, 2, P30_CMD_READ_DEVICE_ID);\r
+\r
+      // Read block lock status\r
+      LockStatus = MmioRead32 (CREATE_NOR_ADDRESS(BlockAddress, 2));\r
+\r
+      // Decode block lock status\r
+      LockStatus = FOLD_32BIT_INTO_16BIT(LockStatus);\r
+    } while ((LockStatus & 0x1) == 1);\r
+  } else {\r
+    // Request a lock setup\r
+    SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_LOCK_BLOCK_SETUP);\r
+\r
+    // Request an unlock\r
+    SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_UNLOCK_BLOCK);\r
+\r
+    // Wait until the status register gives us the all clear\r
+    do {\r
+      LockStatus = NorFlashReadStatusRegister (Instance, BlockAddress);\r
+    } while ((LockStatus & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);\r
+  }\r
+\r
+  // Put device back into Read Array mode\r
+  SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_READ_ARRAY);\r
+\r
+  DEBUG((DEBUG_BLKIO, "UnlockSingleBlock: BlockAddress=0x%08x, Exit Status = \"%r\".\n", BlockAddress, Status));\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+NorFlashUnlockSingleBlockIfNecessary (\r
+  IN NOR_FLASH_INSTANCE     *Instance,\r
+  IN UINTN                  BlockAddress\r
+  )\r
+{\r
+  EFI_STATUS Status = EFI_SUCCESS;\r
+\r
+  if (NorFlashBlockIsLocked (Instance, BlockAddress) == TRUE) {\r
+    Status = NorFlashUnlockSingleBlock (Instance, BlockAddress);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+ * The following function presumes that the block has already been unlocked.\r
+ **/\r
+EFI_STATUS\r
+NorFlashEraseSingleBlock (\r
+  IN NOR_FLASH_INSTANCE     *Instance,\r
+  IN UINTN                  BlockAddress\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  UINT32                StatusRegister;\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+  // Request a block erase and then confirm it\r
+  SEND_NOR_COMMAND(BlockAddress, 0, P30_CMD_BLOCK_ERASE_SETUP);\r
+  SEND_NOR_COMMAND(BlockAddress, 0, P30_CMD_BLOCK_ERASE_CONFIRM);\r
+\r
+  // Wait until the status register gives us the all clear\r
+  do {\r
+    StatusRegister = NorFlashReadStatusRegister (Instance, BlockAddress);\r
+  } while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);\r
+\r
+  if (StatusRegister & P30_SR_BIT_VPP) {\r
+    DEBUG((EFI_D_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: VPP Range Error\n", BlockAddress));\r
+    Status = EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if ((StatusRegister & (P30_SR_BIT_ERASE | P30_SR_BIT_PROGRAM)) == (P30_SR_BIT_ERASE | P30_SR_BIT_PROGRAM)) {\r
+    DEBUG((EFI_D_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Command Sequence Error\n", BlockAddress));\r
+    Status = EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (StatusRegister & P30_SR_BIT_ERASE) {\r
+    DEBUG((EFI_D_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Block Erase Error StatusRegister:0x%X\n", BlockAddress, StatusRegister));\r
+    Status = EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) {\r
+    // The debug level message has been reduced because a device lock might happen. In this case we just retry it ...\r
+    DEBUG((EFI_D_INFO,"EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error\n", BlockAddress));\r
+    Status = EFI_WRITE_PROTECTED;\r
+  }\r
+\r
+  if (EFI_ERROR(Status)) {\r
+    // Clear the Status Register\r
+    SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER);\r
+  }\r
+\r
+  // Put device back into Read Array mode\r
+  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+ * The following function presumes that the block has already been unlocked.\r
+ **/\r
+EFI_STATUS\r
+NorFlashUnlockAndEraseSingleBlock (\r
+  IN NOR_FLASH_INSTANCE     *Instance,\r
+  IN UINTN                  BlockAddress\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+  UINTN           Index;\r
+  EFI_TPL         OriginalTPL;\r
+\r
+  // Raise TPL to TPL_HIGH to stop anyone from interrupting us.\r
+  OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+\r
+  Index = 0;\r
+  // The block erase might fail a first time (SW bug ?). Retry it ...\r
+  do {\r
+    // Unlock the block if we have to\r
+    Status = NorFlashUnlockSingleBlockIfNecessary (Instance, BlockAddress);\r
+    if (!EFI_ERROR(Status)) {\r
+      Status = NorFlashEraseSingleBlock (Instance, BlockAddress);\r
+    }\r
+    Index++;\r
+  } while ((Index < NOR_FLASH_ERASE_RETRY) && (Status == EFI_WRITE_PROTECTED));\r
+\r
+  if (Index == NOR_FLASH_ERASE_RETRY) {\r
+    DEBUG((EFI_D_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error (try to erase %d times)\n", BlockAddress,Index));\r
+  }\r
+\r
+  // Interruptions can resume.\r
+  gBS->RestoreTPL (OriginalTPL);\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+NorFlashWriteSingleWord (\r
+  IN NOR_FLASH_INSTANCE     *Instance,\r
+  IN UINTN                  WordAddress,\r
+  IN UINT32                 WriteData\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  UINT32                StatusRegister;\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+  // Request a write single word command\r
+  SEND_NOR_COMMAND(WordAddress, 0, P30_CMD_WORD_PROGRAM_SETUP);\r
+\r
+  // Store the word into NOR Flash;\r
+  MmioWrite32 (WordAddress, WriteData);\r
+\r
+  // Wait for the write to complete and then check for any errors; i.e. check the Status Register\r
+  do {\r
+    // Prepare to read the status register\r
+    StatusRegister = NorFlashReadStatusRegister (Instance, WordAddress);\r
+    // The chip is busy while the WRITE bit is not asserted\r
+  } while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);\r
+\r
+\r
+  // Perform a full status check:\r
+  // Mask the relevant bits of Status Register.\r
+  // Everything should be zero, if not, we have a problem\r
+\r
+  if (StatusRegister & P30_SR_BIT_VPP) {\r
+    DEBUG((EFI_D_ERROR,"NorFlashWriteSingleWord(WordAddress:0x%X): VPP Range Error\n",WordAddress));\r
+    Status = EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (StatusRegister & P30_SR_BIT_PROGRAM) {\r
+    DEBUG((EFI_D_ERROR,"NorFlashWriteSingleWord(WordAddress:0x%X): Program Error\n",WordAddress));\r
+    Status = EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) {\r
+    DEBUG((EFI_D_ERROR,"NorFlashWriteSingleWord(WordAddress:0x%X): Device Protect Error\n",WordAddress));\r
+    Status = EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (!EFI_ERROR(Status)) {\r
+    // Clear the Status Register\r
+    SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER);\r
+  }\r
+\r
+  // Put device back into Read Array mode\r
+  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);\r
+\r
+  return Status;\r
+}\r
+\r
+/*\r
+ * Writes data to the NOR Flash using the Buffered Programming method.\r
+ *\r
+ * The maximum size of the on-chip buffer is 32-words, because of hardware restrictions.\r
+ * Therefore this function will only handle buffers up to 32 words or 128 bytes.\r
+ * To deal with larger buffers, call this function again.\r
+ *\r
+ * This function presumes that both the TargetAddress and the TargetAddress+BufferSize\r
+ * exist entirely within the NOR Flash. Therefore these conditions will not be checked here.\r
+ *\r
+ * In buffered programming, if the target address not at the beginning of a 32-bit word boundary,\r
+ * then programming time is doubled and power consumption is increased.\r
+ * Therefore, it is a requirement to align buffer writes to 32-bit word boundaries.\r
+ * i.e. the last 4 bits of the target start address must be zero: 0x......00\r
+ */\r
+EFI_STATUS\r
+NorFlashWriteBuffer (\r
+  IN NOR_FLASH_INSTANCE     *Instance,\r
+  IN UINTN                  TargetAddress,\r
+  IN UINTN                  BufferSizeInBytes,\r
+  IN UINT32                 *Buffer\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  UINTN                 BufferSizeInWords;\r
+  UINTN                 Count;\r
+  volatile UINT32       *Data;\r
+  UINTN                 WaitForBuffer;\r
+  BOOLEAN               BufferAvailable;\r
+  UINT32                StatusRegister;\r
+\r
+  WaitForBuffer   = MAX_BUFFERED_PROG_ITERATIONS;\r
+  BufferAvailable = FALSE;\r
+\r
+  // Check that the target address does not cross a 32-word boundary.\r
+  if ((TargetAddress & BOUNDARY_OF_32_WORDS) != 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  // Check there are some data to program\r
+  if (BufferSizeInBytes == 0) {\r
+    return EFI_BUFFER_TOO_SMALL;\r
+  }\r
+\r
+  // Check that the buffer size does not exceed the maximum hardware buffer size on chip.\r
+  if (BufferSizeInBytes > P30_MAX_BUFFER_SIZE_IN_BYTES) {\r
+    return EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  // Check that the buffer size is a multiple of 32-bit words\r
+  if ((BufferSizeInBytes % 4) != 0) {\r
+    return EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  // Pre-programming conditions checked, now start the algorithm.\r
+\r
+  // Prepare the data destination address\r
+  Data = (UINT32 *)TargetAddress;\r
+\r
+  // Check the availability of the buffer\r
+  do {\r
+    // Issue the Buffered Program Setup command\r
+    SEND_NOR_COMMAND(TargetAddress, 0, P30_CMD_BUFFERED_PROGRAM_SETUP);\r
+\r
+    // Read back the status register bit#7 from the same address\r
+    if (((*Data) & P30_SR_BIT_WRITE) == P30_SR_BIT_WRITE) {\r
+      BufferAvailable = TRUE;\r
+    }\r
+\r
+    // Update the loop counter\r
+    WaitForBuffer--;\r
+\r
+  } while ((WaitForBuffer > 0) && (BufferAvailable == FALSE));\r
+\r
+  // The buffer was not available for writing\r
+  if (WaitForBuffer == 0) {\r
+    Status = EFI_DEVICE_ERROR;\r
+    goto EXIT;\r
+  }\r
+\r
+  // From now on we work in 32-bit words\r
+  BufferSizeInWords = BufferSizeInBytes / (UINTN)4;\r
+\r
+  // Write the word count, which is (buffer_size_in_words - 1),\r
+  // because word count 0 means one word.\r
+  SEND_NOR_COMMAND(TargetAddress, 0, (BufferSizeInWords - 1));\r
+\r
+  // Write the data to the NOR Flash, advancing each address by 4 bytes\r
+  for(Count=0; Count < BufferSizeInWords; Count++, Data++, Buffer++) {\r
+    *Data = *Buffer;\r
+  }\r
+\r
+  // Issue the Buffered Program Confirm command, to start the programming operation\r
+  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_BUFFERED_PROGRAM_CONFIRM);\r
+\r
+  // Wait for the write to complete and then check for any errors; i.e. check the Status Register\r
+  do {\r
+    StatusRegister = NorFlashReadStatusRegister (Instance, TargetAddress);\r
+    // The chip is busy while the WRITE bit is not asserted\r
+  } while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);\r
+\r
+\r
+  // Perform a full status check:\r
+  // Mask the relevant bits of Status Register.\r
+  // Everything should be zero, if not, we have a problem\r
+\r
+  Status          = EFI_SUCCESS;\r
+\r
+  if (StatusRegister & P30_SR_BIT_VPP) {\r
+    DEBUG((EFI_D_ERROR,"NorFlashWriteBuffer(TargetAddress:0x%X): VPP Range Error\n", TargetAddress));\r
+    Status = EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (StatusRegister & P30_SR_BIT_PROGRAM) {\r
+    DEBUG((EFI_D_ERROR,"NorFlashWriteBuffer(TargetAddress:0x%X): Program Error\n", TargetAddress));\r
+    Status = EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) {\r
+    DEBUG((EFI_D_ERROR,"NorFlashWriteBuffer(TargetAddress:0x%X): Device Protect Error\n",TargetAddress));\r
+    Status = EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (!EFI_ERROR(Status)) {\r
+    // Clear the Status Register\r
+    SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER);\r
+  }\r
+\r
+EXIT:\r
+  // Put device back into Read Array mode\r
+  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+NorFlashWriteSingleBlock (\r
+  IN NOR_FLASH_INSTANCE     *Instance,\r
+  IN EFI_LBA                Lba,\r
+  IN UINT32                 *DataBuffer,\r
+  IN UINT32                 BlockSizeInWords\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  UINTN         WordAddress;\r
+  UINT32        WordIndex;\r
+  UINTN         BufferIndex;\r
+  UINTN         BlockAddress;\r
+  UINTN         BuffersInBlock;\r
+  UINTN         RemainingWords;\r
+  EFI_TPL       OriginalTPL;\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+  // Get the physical address of the block\r
+  BlockAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, Lba, BlockSizeInWords * 4);\r
+\r
+  // Start writing from the first address at the start of the block\r
+  WordAddress = BlockAddress;\r
+\r
+  // Raise TPL to TPL_HIGH to stop anyone from interrupting us.\r
+  OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+\r
+  Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG((EFI_D_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and Erase the single block at 0x%X\n", BlockAddress));\r
+    goto EXIT;\r
+  }\r
+\r
+  // To speed up the programming operation, NOR Flash is programmed using the Buffered Programming method.\r
+\r
+  // Check that the address starts at a 32-word boundary, i.e. last 7 bits must be zero\r
+  if ((WordAddress & BOUNDARY_OF_32_WORDS) == 0x00) {\r
+\r
+    // First, break the entire block into buffer-sized chunks.\r
+    BuffersInBlock = (UINTN)BlockSizeInWords / P30_MAX_BUFFER_SIZE_IN_BYTES;\r
+\r
+    // Then feed each buffer chunk to the NOR Flash\r
+    for(BufferIndex=0;\r
+         BufferIndex < BuffersInBlock;\r
+         BufferIndex++, WordAddress += P30_MAX_BUFFER_SIZE_IN_BYTES, DataBuffer += P30_MAX_BUFFER_SIZE_IN_WORDS\r
+      ) {\r
+      Status = NorFlashWriteBuffer (Instance, WordAddress, P30_MAX_BUFFER_SIZE_IN_BYTES, DataBuffer);\r
+      if (EFI_ERROR(Status)) {\r
+        goto EXIT;\r
+      }\r
+    }\r
+\r
+    // Finally, finish off any remaining words that are less than the maximum size of the buffer\r
+    RemainingWords = BlockSizeInWords % P30_MAX_BUFFER_SIZE_IN_WORDS;\r
+\r
+    if(RemainingWords != 0) {\r
+      Status = NorFlashWriteBuffer (Instance, WordAddress, (RemainingWords * 4), DataBuffer);\r
+      if (EFI_ERROR(Status)) {\r
+        goto EXIT;\r
+      }\r
+    }\r
+\r
+  } else {\r
+    // For now, use the single word programming algorithm\r
+    // It is unlikely that the NOR Flash will exist in an address which falls within a 32 word boundary range,\r
+    // i.e. which ends in the range 0x......01 - 0x......7F.\r
+    for(WordIndex=0; WordIndex<BlockSizeInWords; WordIndex++, DataBuffer++, WordAddress = WordAddress + 4) {\r
+      Status = NorFlashWriteSingleWord (Instance, WordAddress, *DataBuffer);\r
+      if (EFI_ERROR(Status)) {\r
+        goto EXIT;\r
+      }\r
+    }\r
+  }\r
+\r
+EXIT:\r
+  // Interruptions can resume.\r
+  gBS->RestoreTPL (OriginalTPL);\r
+\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG((EFI_D_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed at address 0x%08x. Exit Status = \"%r\".\n", WordAddress, Status));\r
+  }\r
+  return Status;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+NorFlashWriteBlocks (\r
+  IN NOR_FLASH_INSTANCE     *Instance,\r
+  IN EFI_LBA                Lba,\r
+  IN UINTN                  BufferSizeInBytes,\r
+  IN VOID                   *Buffer\r
+  )\r
+{\r
+  UINT32          *pWriteBuffer;\r
+  EFI_STATUS      Status = EFI_SUCCESS;\r
+  EFI_LBA         CurrentBlock;\r
+  UINT32          BlockSizeInWords;\r
+  UINT32          NumBlocks;\r
+  UINT32          BlockCount;\r
+\r
+  // The buffer must be valid\r
+  if (Buffer == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if(Instance->Media.ReadOnly == TRUE) {\r
+    return EFI_WRITE_PROTECTED;\r
+  }\r
+\r
+  // We must have some bytes to read\r
+  DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: BufferSizeInBytes=0x%x\n", BufferSizeInBytes));\r
+  if(BufferSizeInBytes == 0) {\r
+    return EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  // The size of the buffer must be a multiple of the block size\r
+  DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: BlockSize in bytes =0x%x\n", Instance->Media.BlockSize));\r
+  if ((BufferSizeInBytes % Instance->Media.BlockSize) != 0) {\r
+    return EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  // All blocks must be within the device\r
+  NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize ;\r
+\r
+  DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: NumBlocks=%d, LastBlock=%ld, Lba=%ld.\n", NumBlocks, Instance->Media.LastBlock, Lba));\r
+\r
+  if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {\r
+    DEBUG((EFI_D_ERROR, "NorFlashWriteBlocks: ERROR - Write will exceed last block.\n"));\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  BlockSizeInWords = Instance->Media.BlockSize / 4;\r
+\r
+  // Because the target *Buffer is a pointer to VOID, we must put all the data into a pointer\r
+  // to a proper data type, so use *ReadBuffer\r
+  pWriteBuffer = (UINT32 *)Buffer;\r
+\r
+  CurrentBlock = Lba;\r
+  for (BlockCount=0; BlockCount < NumBlocks; BlockCount++, CurrentBlock++, pWriteBuffer = pWriteBuffer + BlockSizeInWords) {\r
+\r
+    DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: Writing block #%d\n", (UINTN)CurrentBlock));\r
+\r
+    Status = NorFlashWriteSingleBlock (Instance, CurrentBlock, pWriteBuffer, BlockSizeInWords);\r
+\r
+    if (EFI_ERROR(Status)) {\r
+      break;\r
+    }\r
+  }\r
+\r
+  DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: Exit Status = \"%r\".\n", Status));\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+NorFlashReadBlocks (\r
+  IN NOR_FLASH_INSTANCE   *Instance,\r
+  IN EFI_LBA              Lba,\r
+  IN UINTN                BufferSizeInBytes,\r
+  OUT VOID                *Buffer\r
+  )\r
+{\r
+  UINT32              NumBlocks;\r
+  UINTN               StartAddress;\r
+\r
+  // The buffer must be valid\r
+  if (Buffer == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  // We must have some bytes to read\r
+  DEBUG((DEBUG_BLKIO, "NorFlashReadBlocks: BufferSize=0x%x bytes.\n", BufferSizeInBytes));\r
+  if(BufferSizeInBytes == 0) {\r
+    return EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  // The size of the buffer must be a multiple of the block size\r
+  DEBUG((DEBUG_BLKIO, "NorFlashReadBlocks: BlockSize=0x%x bytes.\n", Instance->Media.BlockSize));\r
+  if ((BufferSizeInBytes % Instance->Media.BlockSize) != 0) {\r
+    return EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  // All blocks must be within the device\r
+  NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize ;\r
+\r
+  DEBUG((DEBUG_BLKIO, "NorFlashReadBlocks: NumBlocks=%d, LastBlock=%ld, Lba=%ld\n", NumBlocks, Instance->Media.LastBlock, Lba));\r
+\r
+  if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {\r
+    DEBUG((EFI_D_ERROR, "NorFlashReadBlocks: ERROR - Read will exceed last block\n"));\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  // Get the address to start reading from\r
+  StartAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress,\r
+                                        Lba,\r
+                                        Instance->Media.BlockSize\r
+                                       );\r
+\r
+  // Put the device into Read Array mode\r
+  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);\r
+\r
+  // Readout the data\r
+  CopyMem(Buffer, (UINTN *)StartAddress, BufferSizeInBytes);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+NorFlashReset (\r
+  IN  NOR_FLASH_INSTANCE *Instance\r
+  )\r
+{\r
+  // As there is no specific RESET to perform, ensure that the devices is in the default Read Array mode\r
+  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+NorFlashInitialise (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  UINT32                  Index;\r
+  NOR_FLASH_DESCRIPTION*  NorFlashDevices;\r
+  UINT32                  NorFlashDeviceCount;\r
+  BOOLEAN                 ContainVariableStorage;\r
+\r
+  Status = NorFlashPlatformInitialization ();\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG((EFI_D_ERROR,"NorFlashInitialise: Fail to initialize Nor Flash devices\n"));\r
+    return Status;\r
+  }\r
+\r
+  Status = NorFlashPlatformGetDevices (&NorFlashDevices,&NorFlashDeviceCount);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG((EFI_D_ERROR,"NorFlashInitialise: Fail to get Nor Flash devices\n"));\r
+    return Status;\r
+  }\r
+\r
+  mNorFlashInstances = AllocatePool (sizeof(NOR_FLASH_INSTANCE*) * NorFlashDeviceCount);\r
+\r
+  for (Index = 0; Index < NorFlashDeviceCount; Index++) {\r
+    // Check if this NOR Flash device contain the variable storage region\r
+    ContainVariableStorage =\r
+        (NorFlashDevices[Index].RegionBaseAddress <= PcdGet32 (PcdFlashNvStorageVariableBase)) &&\r
+        (PcdGet32 (PcdFlashNvStorageVariableBase) + PcdGet32 (PcdFlashNvStorageVariableSize) <= NorFlashDevices[Index].RegionBaseAddress + NorFlashDevices[Index].Size);\r
+\r
+    Status = NorFlashCreateInstance (\r
+      NorFlashDevices[Index].DeviceBaseAddress,\r
+      NorFlashDevices[Index].RegionBaseAddress,\r
+      NorFlashDevices[Index].Size,\r
+      Index,\r
+      NorFlashDevices[Index].BlockSize,\r
+      ContainVariableStorage,\r
+      &NorFlashDevices[Index].Guid,\r
+      &mNorFlashInstances[Index]\r
+    );\r
+    if (EFI_ERROR(Status)) {\r
+      DEBUG((EFI_D_ERROR,"NorFlashInitialise: Fail to create instance for NorFlash[%d]\n",Index));\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
index a284c151a9148d7a00354084c9ed00b468a7c84a..959c0c1905b71344858ce5ae700b0a8b75fe88ef 100644 (file)
-/** @file  NorFlashDxe.h
-
-  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __NOR_FLASH_DXE_H__
-#define __NOR_FLASH_DXE_H__
-
-
-#include <Base.h>
-#include <PiDxe.h>
-
-#include <Protocol/BlockIo.h>
-#include <Protocol/FirmwareVolumeBlock.h>
-
-#include <Library/DebugLib.h>
-#include <Library/IoLib.h>
-#include <Library/NorFlashPlatformLib.h>
-#include <Library/UefiLib.h>
-
-#define NOR_FLASH_ERASE_RETRY                     10
-
-// Device access macros
-// These are necessary because we use 2 x 16bit parts to make up 32bit data
-
-#define HIGH_16_BITS                              0xFFFF0000
-#define LOW_16_BITS                               0x0000FFFF
-#define LOW_8_BITS                                0x000000FF
-
-#define FOLD_32BIT_INTO_16BIT(value)              ( ( value >> 16 ) | ( value & LOW_16_BITS ) )
-
-#define GET_LOW_BYTE(value)                       ( value & LOW_8_BITS )
-#define GET_HIGH_BYTE(value)                      ( GET_LOW_BYTE( value >> 16 ) )
-
-// Each command must be sent simultaneously to both chips,
-// i.e. at the lower 16 bits AND at the higher 16 bits
-#define CREATE_NOR_ADDRESS(BaseAddr,OffsetAddr)   ((BaseAddr) + ((OffsetAddr) << 2))
-#define CREATE_DUAL_CMD(Cmd)                      ( ( Cmd << 16) | ( Cmd & LOW_16_BITS) )
-#define SEND_NOR_COMMAND(BaseAddr,Offset,Cmd) MmioWrite32 (CREATE_NOR_ADDRESS(BaseAddr,Offset), CREATE_DUAL_CMD(Cmd))
-#define GET_NOR_BLOCK_ADDRESS(BaseAddr,Lba,LbaSize)( BaseAddr + (UINTN)((Lba) * LbaSize) )
-
-// Status Register Bits
-#define P30_SR_BIT_WRITE                          (BIT7 << 16 | BIT7)
-#define P30_SR_BIT_ERASE_SUSPEND                  (BIT6 << 16 | BIT6)
-#define P30_SR_BIT_ERASE                          (BIT5 << 16 | BIT5)
-#define P30_SR_BIT_PROGRAM                        (BIT4 << 16 | BIT4)
-#define P30_SR_BIT_VPP                            (BIT3 << 16 | BIT3)
-#define P30_SR_BIT_PROGRAM_SUSPEND                (BIT2 << 16 | BIT2)
-#define P30_SR_BIT_BLOCK_LOCKED                   (BIT1 << 16 | BIT1)
-#define P30_SR_BIT_BEFP                           (BIT0 << 16 | BIT0)
-
-// Device Commands for Intel StrataFlash(R) Embedded Memory (P30) Family
-
-// On chip buffer size for buffered programming operations
-// There are 2 chips, each chip can buffer up to 32 (16-bit)words, and each word is 2 bytes.
-// Therefore the total size of the buffer is 2 x 32 x 2 = 128 bytes
-#define P30_MAX_BUFFER_SIZE_IN_BYTES              ((UINTN)128)
-#define P30_MAX_BUFFER_SIZE_IN_WORDS              (P30_MAX_BUFFER_SIZE_IN_BYTES/((UINTN)4))
-#define MAX_BUFFERED_PROG_ITERATIONS              10000000
-#define BOUNDARY_OF_32_WORDS                      0x7F
-
-// CFI Addresses
-#define P30_CFI_ADDR_QUERY_UNIQUE_QRY             0x10
-#define P30_CFI_ADDR_VENDOR_ID                    0x13
-
-// CFI Data
-#define CFI_QRY                                   0x00595251
-
-// READ Commands
-#define P30_CMD_READ_DEVICE_ID                    0x0090
-#define P30_CMD_READ_STATUS_REGISTER              0x0070
-#define P30_CMD_CLEAR_STATUS_REGISTER             0x0050
-#define P30_CMD_READ_ARRAY                        0x00FF
-#define P30_CMD_READ_CFI_QUERY                    0x0098
-
-// WRITE Commands
-#define P30_CMD_WORD_PROGRAM_SETUP                0x0040
-#define P30_CMD_ALTERNATE_WORD_PROGRAM_SETUP      0x0010
-#define P30_CMD_BUFFERED_PROGRAM_SETUP            0x00E8
-#define P30_CMD_BUFFERED_PROGRAM_CONFIRM          0x00D0
-#define P30_CMD_BEFP_SETUP                        0x0080
-#define P30_CMD_BEFP_CONFIRM                      0x00D0
-
-// ERASE Commands
-#define P30_CMD_BLOCK_ERASE_SETUP                 0x0020
-#define P30_CMD_BLOCK_ERASE_CONFIRM               0x00D0
-
-// SUSPEND Commands
-#define P30_CMD_PROGRAM_OR_ERASE_SUSPEND          0x00B0
-#define P30_CMD_SUSPEND_RESUME                    0x00D0
-
-// BLOCK LOCKING / UNLOCKING Commands
-#define P30_CMD_LOCK_BLOCK_SETUP                  0x0060
-#define P30_CMD_LOCK_BLOCK                        0x0001
-#define P30_CMD_UNLOCK_BLOCK                      0x00D0
-#define P30_CMD_LOCK_DOWN_BLOCK                   0x002F
-
-// PROTECTION Commands
-#define P30_CMD_PROGRAM_PROTECTION_REGISTER_SETUP 0x00C0
-
-// CONFIGURATION Commands
-#define P30_CMD_READ_CONFIGURATION_REGISTER_SETUP 0x0060
-#define P30_CMD_READ_CONFIGURATION_REGISTER       0x0003
-
-#define NOR_FLASH_SIGNATURE                       SIGNATURE_32('n', 'o', 'r', '0')
-#define INSTANCE_FROM_FVB_THIS(a)                 CR(a, NOR_FLASH_INSTANCE, FvbProtocol, NOR_FLASH_SIGNATURE)
-#define INSTANCE_FROM_BLKIO_THIS(a)               CR(a, NOR_FLASH_INSTANCE, BlockIoProtocol, NOR_FLASH_SIGNATURE)
-
-typedef struct _NOR_FLASH_INSTANCE                NOR_FLASH_INSTANCE;
-
-typedef EFI_STATUS (*NOR_FLASH_INITIALIZE)        (NOR_FLASH_INSTANCE* Instance);
-
-typedef struct {
-  VENDOR_DEVICE_PATH                  Vendor;
-  EFI_DEVICE_PATH_PROTOCOL            End;
-} NOR_FLASH_DEVICE_PATH;
-
-struct _NOR_FLASH_INSTANCE {
-  UINT32                              Signature;
-  EFI_HANDLE                          Handle;
-
-  BOOLEAN                             Initialized;
-  NOR_FLASH_INITIALIZE                Initialize;
-
-  UINTN                               DeviceBaseAddress;
-  UINTN                               RegionBaseAddress;
-  UINTN                               Size;
-  EFI_LBA                             StartLba;
-
-  EFI_BLOCK_IO_PROTOCOL               BlockIoProtocol;
-  EFI_BLOCK_IO_MEDIA                  Media;
-
-  BOOLEAN                             SupportFvb;
-  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol;
-
-  NOR_FLASH_DEVICE_PATH                      DevicePath;
-};
-
-EFI_STATUS
-NorFlashReadCfiData (
-  IN  UINTN                   DeviceBaseAddress,
-  IN  UINTN                   CFI_Offset,
-  IN  UINT32                  NumberOfBytes,
-  OUT UINT32                  *Data
-  );
-
-EFI_STATUS
-NorFlashWriteBuffer (
-  IN NOR_FLASH_INSTANCE     *Instance,
-  IN UINTN                  TargetAddress,
-  IN UINTN                  BufferSizeInBytes,
-  IN UINT32                 *Buffer
-  );
-
-//
-// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset
-//
-EFI_STATUS
-EFIAPI
-NorFlashBlockIoReset (
-  IN EFI_BLOCK_IO_PROTOCOL    *This,
-  IN BOOLEAN                  ExtendedVerification
-  );
-
-//
-// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks
-//
-EFI_STATUS
-EFIAPI
-NorFlashBlockIoReadBlocks (
-  IN  EFI_BLOCK_IO_PROTOCOL   *This,
-  IN  UINT32                  MediaId,
-  IN  EFI_LBA                 Lba,
-  IN  UINTN                   BufferSizeInBytes,
-  OUT VOID                    *Buffer
-);
-
-//
-// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
-//
-EFI_STATUS
-EFIAPI
-NorFlashBlockIoWriteBlocks (
-  IN  EFI_BLOCK_IO_PROTOCOL   *This,
-  IN  UINT32                  MediaId,
-  IN  EFI_LBA                 Lba,
-  IN  UINTN                   BufferSizeInBytes,
-  IN  VOID                    *Buffer
-);
-
-//
-// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
-//
-EFI_STATUS
-EFIAPI
-NorFlashBlockIoFlushBlocks (
-  IN EFI_BLOCK_IO_PROTOCOL    *This
-);
-
-
-//
-// NorFlashFvbDxe.c
-//
-
-EFI_STATUS
-EFIAPI
-NorFlashFvbInitialize (
-  IN NOR_FLASH_INSTANCE*                            Instance
-  );
-
-EFI_STATUS
-EFIAPI
-FvbGetAttributes(
-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,
-  OUT       EFI_FVB_ATTRIBUTES_2                    *Attributes
-  );
-
-EFI_STATUS
-EFIAPI
-FvbSetAttributes(
-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,
-  IN OUT    EFI_FVB_ATTRIBUTES_2                    *Attributes
-  );
-
-EFI_STATUS
-EFIAPI
-FvbGetPhysicalAddress(
-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,
-  OUT       EFI_PHYSICAL_ADDRESS                    *Address
-  );
-
-EFI_STATUS
-EFIAPI
-FvbGetBlockSize(
-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,
-  IN        EFI_LBA                                 Lba,
-  OUT       UINTN                                   *BlockSize,
-  OUT       UINTN                                   *NumberOfBlocks
-  );
-
-EFI_STATUS
-EFIAPI
-FvbRead(
-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,
-  IN        EFI_LBA                                 Lba,
-  IN        UINTN                                   Offset,
-  IN OUT    UINTN                                   *NumBytes,
-  IN OUT    UINT8                                   *Buffer
-  );
-
-EFI_STATUS
-EFIAPI
-FvbWrite(
-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,
-  IN        EFI_LBA                                 Lba,
-  IN        UINTN                                   Offset,
-  IN OUT    UINTN                                   *NumBytes,
-  IN        UINT8                                   *Buffer
-  );
-
-EFI_STATUS
-EFIAPI
-FvbEraseBlocks(
-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,
-  ...
-  );
-
-//
-// NorFlashDxe.c
-//
-
-EFI_STATUS
-NorFlashUnlockAndEraseSingleBlock (
-  IN NOR_FLASH_INSTANCE     *Instance,
-  IN UINTN                  BlockAddress
-  );
-
-EFI_STATUS
-NorFlashWriteSingleBlock (
-  IN NOR_FLASH_INSTANCE     *Instance,
-  IN EFI_LBA                Lba,
-  IN UINT32                 *DataBuffer,
-  IN UINT32                 BlockSizeInWords
-  );
-
-EFI_STATUS
-NorFlashWriteBlocks (
-  IN  NOR_FLASH_INSTANCE *Instance,
-  IN  EFI_LBA           Lba,
-  IN  UINTN             BufferSizeInBytes,
-  IN  VOID              *Buffer
-  );
-
-EFI_STATUS
-NorFlashReadBlocks (
-  IN NOR_FLASH_INSTANCE   *Instance,
-  IN EFI_LBA              Lba,
-  IN UINTN                BufferSizeInBytes,
-  OUT VOID                *Buffer
-  );
-
-EFI_STATUS
-NorFlashReset (
-  IN  NOR_FLASH_INSTANCE *Instance
-  );
-
-#endif /* __NOR_FLASH_DXE_H__ */
+/** @file  NorFlashDxe.h\r
+\r
+  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __NOR_FLASH_DXE_H__\r
+#define __NOR_FLASH_DXE_H__\r
+\r
+\r
+#include <Base.h>\r
+#include <PiDxe.h>\r
+\r
+#include <Protocol/BlockIo.h>\r
+#include <Protocol/FirmwareVolumeBlock.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/NorFlashPlatformLib.h>\r
+#include <Library/UefiLib.h>\r
+\r
+#define NOR_FLASH_ERASE_RETRY                     10\r
+\r
+// Device access macros\r
+// These are necessary because we use 2 x 16bit parts to make up 32bit data\r
+\r
+#define HIGH_16_BITS                              0xFFFF0000\r
+#define LOW_16_BITS                               0x0000FFFF\r
+#define LOW_8_BITS                                0x000000FF\r
+\r
+#define FOLD_32BIT_INTO_16BIT(value)              ( ( value >> 16 ) | ( value & LOW_16_BITS ) )\r
+\r
+#define GET_LOW_BYTE(value)                       ( value & LOW_8_BITS )\r
+#define GET_HIGH_BYTE(value)                      ( GET_LOW_BYTE( value >> 16 ) )\r
+\r
+// Each command must be sent simultaneously to both chips,\r
+// i.e. at the lower 16 bits AND at the higher 16 bits\r
+#define CREATE_NOR_ADDRESS(BaseAddr,OffsetAddr)   ((BaseAddr) + ((OffsetAddr) << 2))\r
+#define CREATE_DUAL_CMD(Cmd)                      ( ( Cmd << 16) | ( Cmd & LOW_16_BITS) )\r
+#define SEND_NOR_COMMAND(BaseAddr,Offset,Cmd) MmioWrite32 (CREATE_NOR_ADDRESS(BaseAddr,Offset), CREATE_DUAL_CMD(Cmd))\r
+#define GET_NOR_BLOCK_ADDRESS(BaseAddr,Lba,LbaSize)( BaseAddr + (UINTN)((Lba) * LbaSize) )\r
+\r
+// Status Register Bits\r
+#define P30_SR_BIT_WRITE                          (BIT7 << 16 | BIT7)\r
+#define P30_SR_BIT_ERASE_SUSPEND                  (BIT6 << 16 | BIT6)\r
+#define P30_SR_BIT_ERASE                          (BIT5 << 16 | BIT5)\r
+#define P30_SR_BIT_PROGRAM                        (BIT4 << 16 | BIT4)\r
+#define P30_SR_BIT_VPP                            (BIT3 << 16 | BIT3)\r
+#define P30_SR_BIT_PROGRAM_SUSPEND                (BIT2 << 16 | BIT2)\r
+#define P30_SR_BIT_BLOCK_LOCKED                   (BIT1 << 16 | BIT1)\r
+#define P30_SR_BIT_BEFP                           (BIT0 << 16 | BIT0)\r
+\r
+// Device Commands for Intel StrataFlash(R) Embedded Memory (P30) Family\r
+\r
+// On chip buffer size for buffered programming operations\r
+// There are 2 chips, each chip can buffer up to 32 (16-bit)words, and each word is 2 bytes.\r
+// Therefore the total size of the buffer is 2 x 32 x 2 = 128 bytes\r
+#define P30_MAX_BUFFER_SIZE_IN_BYTES              ((UINTN)128)\r
+#define P30_MAX_BUFFER_SIZE_IN_WORDS              (P30_MAX_BUFFER_SIZE_IN_BYTES/((UINTN)4))\r
+#define MAX_BUFFERED_PROG_ITERATIONS              10000000\r
+#define BOUNDARY_OF_32_WORDS                      0x7F\r
+\r
+// CFI Addresses\r
+#define P30_CFI_ADDR_QUERY_UNIQUE_QRY             0x10\r
+#define P30_CFI_ADDR_VENDOR_ID                    0x13\r
+\r
+// CFI Data\r
+#define CFI_QRY                                   0x00595251\r
+\r
+// READ Commands\r
+#define P30_CMD_READ_DEVICE_ID                    0x0090\r
+#define P30_CMD_READ_STATUS_REGISTER              0x0070\r
+#define P30_CMD_CLEAR_STATUS_REGISTER             0x0050\r
+#define P30_CMD_READ_ARRAY                        0x00FF\r
+#define P30_CMD_READ_CFI_QUERY                    0x0098\r
+\r
+// WRITE Commands\r
+#define P30_CMD_WORD_PROGRAM_SETUP                0x0040\r
+#define P30_CMD_ALTERNATE_WORD_PROGRAM_SETUP      0x0010\r
+#define P30_CMD_BUFFERED_PROGRAM_SETUP            0x00E8\r
+#define P30_CMD_BUFFERED_PROGRAM_CONFIRM          0x00D0\r
+#define P30_CMD_BEFP_SETUP                        0x0080\r
+#define P30_CMD_BEFP_CONFIRM                      0x00D0\r
+\r
+// ERASE Commands\r
+#define P30_CMD_BLOCK_ERASE_SETUP                 0x0020\r
+#define P30_CMD_BLOCK_ERASE_CONFIRM               0x00D0\r
+\r
+// SUSPEND Commands\r
+#define P30_CMD_PROGRAM_OR_ERASE_SUSPEND          0x00B0\r
+#define P30_CMD_SUSPEND_RESUME                    0x00D0\r
+\r
+// BLOCK LOCKING / UNLOCKING Commands\r
+#define P30_CMD_LOCK_BLOCK_SETUP                  0x0060\r
+#define P30_CMD_LOCK_BLOCK                        0x0001\r
+#define P30_CMD_UNLOCK_BLOCK                      0x00D0\r
+#define P30_CMD_LOCK_DOWN_BLOCK                   0x002F\r
+\r
+// PROTECTION Commands\r
+#define P30_CMD_PROGRAM_PROTECTION_REGISTER_SETUP 0x00C0\r
+\r
+// CONFIGURATION Commands\r
+#define P30_CMD_READ_CONFIGURATION_REGISTER_SETUP 0x0060\r
+#define P30_CMD_READ_CONFIGURATION_REGISTER       0x0003\r
+\r
+#define NOR_FLASH_SIGNATURE                       SIGNATURE_32('n', 'o', 'r', '0')\r
+#define INSTANCE_FROM_FVB_THIS(a)                 CR(a, NOR_FLASH_INSTANCE, FvbProtocol, NOR_FLASH_SIGNATURE)\r
+#define INSTANCE_FROM_BLKIO_THIS(a)               CR(a, NOR_FLASH_INSTANCE, BlockIoProtocol, NOR_FLASH_SIGNATURE)\r
+\r
+typedef struct _NOR_FLASH_INSTANCE                NOR_FLASH_INSTANCE;\r
+\r
+typedef EFI_STATUS (*NOR_FLASH_INITIALIZE)        (NOR_FLASH_INSTANCE* Instance);\r
+\r
+typedef struct {\r
+  VENDOR_DEVICE_PATH                  Vendor;\r
+  EFI_DEVICE_PATH_PROTOCOL            End;\r
+} NOR_FLASH_DEVICE_PATH;\r
+\r
+struct _NOR_FLASH_INSTANCE {\r
+  UINT32                              Signature;\r
+  EFI_HANDLE                          Handle;\r
+\r
+  BOOLEAN                             Initialized;\r
+  NOR_FLASH_INITIALIZE                Initialize;\r
+\r
+  UINTN                               DeviceBaseAddress;\r
+  UINTN                               RegionBaseAddress;\r
+  UINTN                               Size;\r
+  EFI_LBA                             StartLba;\r
+\r
+  EFI_BLOCK_IO_PROTOCOL               BlockIoProtocol;\r
+  EFI_BLOCK_IO_MEDIA                  Media;\r
+\r
+  BOOLEAN                             SupportFvb;\r
+  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol;\r
+\r
+  NOR_FLASH_DEVICE_PATH                      DevicePath;\r
+};\r
+\r
+EFI_STATUS\r
+NorFlashReadCfiData (\r
+  IN  UINTN                   DeviceBaseAddress,\r
+  IN  UINTN                   CFI_Offset,\r
+  IN  UINT32                  NumberOfBytes,\r
+  OUT UINT32                  *Data\r
+  );\r
+\r
+EFI_STATUS\r
+NorFlashWriteBuffer (\r
+  IN NOR_FLASH_INSTANCE     *Instance,\r
+  IN UINTN                  TargetAddress,\r
+  IN UINTN                  BufferSizeInBytes,\r
+  IN UINT32                 *Buffer\r
+  );\r
+\r
+//\r
+// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+NorFlashBlockIoReset (\r
+  IN EFI_BLOCK_IO_PROTOCOL    *This,\r
+  IN BOOLEAN                  ExtendedVerification\r
+  );\r
+\r
+//\r
+// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+NorFlashBlockIoReadBlocks (\r
+  IN  EFI_BLOCK_IO_PROTOCOL   *This,\r
+  IN  UINT32                  MediaId,\r
+  IN  EFI_LBA                 Lba,\r
+  IN  UINTN                   BufferSizeInBytes,\r
+  OUT VOID                    *Buffer\r
+);\r
+\r
+//\r
+// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+NorFlashBlockIoWriteBlocks (\r
+  IN  EFI_BLOCK_IO_PROTOCOL   *This,\r
+  IN  UINT32                  MediaId,\r
+  IN  EFI_LBA                 Lba,\r
+  IN  UINTN                   BufferSizeInBytes,\r
+  IN  VOID                    *Buffer\r
+);\r
+\r
+//\r
+// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+NorFlashBlockIoFlushBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL    *This\r
+);\r
+\r
+\r
+//\r
+// NorFlashFvbDxe.c\r
+//\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+NorFlashFvbInitialize (\r
+  IN NOR_FLASH_INSTANCE*                            Instance\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbGetAttributes(\r
+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,\r
+  OUT       EFI_FVB_ATTRIBUTES_2                    *Attributes\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbSetAttributes(\r
+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,\r
+  IN OUT    EFI_FVB_ATTRIBUTES_2                    *Attributes\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbGetPhysicalAddress(\r
+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,\r
+  OUT       EFI_PHYSICAL_ADDRESS                    *Address\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbGetBlockSize(\r
+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,\r
+  IN        EFI_LBA                                 Lba,\r
+  OUT       UINTN                                   *BlockSize,\r
+  OUT       UINTN                                   *NumberOfBlocks\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbRead(\r
+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,\r
+  IN        EFI_LBA                                 Lba,\r
+  IN        UINTN                                   Offset,\r
+  IN OUT    UINTN                                   *NumBytes,\r
+  IN OUT    UINT8                                   *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbWrite(\r
+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,\r
+  IN        EFI_LBA                                 Lba,\r
+  IN        UINTN                                   Offset,\r
+  IN OUT    UINTN                                   *NumBytes,\r
+  IN        UINT8                                   *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbEraseBlocks(\r
+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,\r
+  ...\r
+  );\r
+\r
+//\r
+// NorFlashDxe.c\r
+//\r
+\r
+EFI_STATUS\r
+NorFlashUnlockAndEraseSingleBlock (\r
+  IN NOR_FLASH_INSTANCE     *Instance,\r
+  IN UINTN                  BlockAddress\r
+  );\r
+\r
+EFI_STATUS\r
+NorFlashWriteSingleBlock (\r
+  IN NOR_FLASH_INSTANCE     *Instance,\r
+  IN EFI_LBA                Lba,\r
+  IN UINT32                 *DataBuffer,\r
+  IN UINT32                 BlockSizeInWords\r
+  );\r
+\r
+EFI_STATUS\r
+NorFlashWriteBlocks (\r
+  IN  NOR_FLASH_INSTANCE *Instance,\r
+  IN  EFI_LBA           Lba,\r
+  IN  UINTN             BufferSizeInBytes,\r
+  IN  VOID              *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+NorFlashReadBlocks (\r
+  IN NOR_FLASH_INSTANCE   *Instance,\r
+  IN EFI_LBA              Lba,\r
+  IN UINTN                BufferSizeInBytes,\r
+  OUT VOID                *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+NorFlashReset (\r
+  IN  NOR_FLASH_INSTANCE *Instance\r
+  );\r
+\r
+#endif /* __NOR_FLASH_DXE_H__ */\r
index d32f0f79ddffb56a506f5ef8c2c335405f591d72..97c66008f613cd838449cb758ff066cebd983b07 100644 (file)
@@ -1,68 +1,68 @@
-#/** @file
-#  
-#  Component description file for NorFlashDxe module
-#  
-#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
-#  
-#  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                      = ArmVeNorFlashDxe
-  FILE_GUID                      = 93E34C7E-B50E-11DF-9223-2443DFD72085
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-  ENTRY_POINT                    = NorFlashInitialise
-
-[Sources.common]
-  NorFlashDxe.c
-  NorFlashFvbDxe.c
-  NorFlashBlockIoDxe.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  IoLib
-  BaseLib
-  DebugLib
-  HobLib
-  NorFlashPlatformLib
-  UefiLib
-  UefiDriverEntryPoint
-  UefiBootServicesTableLib
-
-[Guids]
-  gEfiSystemNvDataFvGuid
-  gEfiVariableGuid
-
-[Protocols]
-  gEfiBlockIoProtocolGuid
-  gEfiDevicePathProtocolGuid
-  gEfiFirmwareVolumeBlockProtocolGuid
-  
-[Pcd.common]
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
-  
-  gArmPlatformTokenSpaceGuid.PcdNorFlashCheckBlockLocked
-
-[Depex]
-  #
-  # NorFlashDxe must be loaded before VariableRuntimeDxe in case empty flash needs populating with default values
-  # 
-  BEFORE gVariableRuntimeDxeFileGuid 
+#/** @file\r
+#  \r
+#  Component description file for NorFlashDxe module\r
+#  \r
+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>\r
+#  \r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = ArmVeNorFlashDxe\r
+  FILE_GUID                      = 93E34C7E-B50E-11DF-9223-2443DFD72085\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = NorFlashInitialise\r
+\r
+[Sources.common]\r
+  NorFlashDxe.c\r
+  NorFlashFvbDxe.c\r
+  NorFlashBlockIoDxe.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  IoLib\r
+  BaseLib\r
+  DebugLib\r
+  HobLib\r
+  NorFlashPlatformLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  UefiBootServicesTableLib\r
+\r
+[Guids]\r
+  gEfiSystemNvDataFvGuid\r
+  gEfiVariableGuid\r
+\r
+[Protocols]\r
+  gEfiBlockIoProtocolGuid\r
+  gEfiDevicePathProtocolGuid\r
+  gEfiFirmwareVolumeBlockProtocolGuid\r
+  \r
+[Pcd.common]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize\r
+  \r
+  gArmPlatformTokenSpaceGuid.PcdNorFlashCheckBlockLocked\r
+\r
+[Depex]\r
+  #\r
+  # NorFlashDxe must be loaded before VariableRuntimeDxe in case empty flash needs populating with default values\r
+  # \r
+  BEFORE gVariableRuntimeDxeFileGuid \r
index 29de964829042a9370de929e6fa39650fa6b0931..0c138a5ab2e7cb15203ed706ea9cbec7de4d11c6 100644 (file)
-/*++ @file  NorFlashFvbDxe.c
-
- Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
-
- 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 <PiDxe.h>
-
-#include <Library/PcdLib.h>
-#include <Library/BaseLib.h>
-#include <Library/HobLib.h>
-#include <Library/UefiLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-
-#include <Guid/VariableFormat.h>
-#include <Guid/SystemNvDataGuid.h>
-
-#include "NorFlashDxe.h"
-
-
-///
-/// The Firmware Volume Block Protocol is the low-level interface
-/// to a firmware volume. File-level access to a firmware volume
-/// should not be done using the Firmware Volume Block Protocol.
-/// Normal access to a firmware volume must use the Firmware
-/// Volume Protocol. Typically, only the file system driver that
-/// produces the Firmware Volume Protocol will bind to the
-/// Firmware Volume Block Protocol.
-///
-
-/**
-  Initialises the FV Header and Variable Store Header
-  to support variable operations.
-
-  @param[in]  Ptr - Location to initialise the headers
-
-**/
-EFI_STATUS
-InitializeFvAndVariableStoreHeaders (
-  IN NOR_FLASH_INSTANCE *Instance
-  )
-{
-  EFI_STATUS                          Status;
-  VOID*                               Headers;
-  UINTN                               HeadersLength;
-  EFI_FIRMWARE_VOLUME_HEADER          *FirmwareVolumeHeader;
-  VARIABLE_STORE_HEADER               *VariableStoreHeader;
-
-  if (!Instance->Initialized && Instance->Initialize) {
-    Instance->Initialize (Instance);
-  }
-
-  HeadersLength = sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(VARIABLE_STORE_HEADER);
-  Headers = AllocateZeroPool(HeadersLength);
-
-  // FirmwareVolumeHeader->FvLength is declared to have the Variable area AND the FTW working area AND the FTW Spare contiguous.
-  ASSERT(PcdGet32(PcdFlashNvStorageVariableBase) + PcdGet32(PcdFlashNvStorageVariableSize) == PcdGet32(PcdFlashNvStorageFtwWorkingBase));
-  ASSERT(PcdGet32(PcdFlashNvStorageFtwWorkingBase) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) == PcdGet32(PcdFlashNvStorageFtwSpareBase));
-
-  // Check if the size of the area is at least one block size
-  ASSERT((PcdGet32(PcdFlashNvStorageVariableSize) > 0) && (PcdGet32(PcdFlashNvStorageVariableSize) / Instance->Media.BlockSize > 0));
-  ASSERT((PcdGet32(PcdFlashNvStorageFtwWorkingSize) > 0) && (PcdGet32(PcdFlashNvStorageFtwWorkingSize) / Instance->Media.BlockSize > 0));
-  ASSERT((PcdGet32(PcdFlashNvStorageFtwSpareSize) > 0) && (PcdGet32(PcdFlashNvStorageFtwSpareSize) / Instance->Media.BlockSize > 0));
-
-  // Ensure the Variable area Base Addresses are aligned on a block size boundaries
-  ASSERT(PcdGet32(PcdFlashNvStorageVariableBase) % Instance->Media.BlockSize == 0);
-  ASSERT(PcdGet32(PcdFlashNvStorageFtwWorkingBase) % Instance->Media.BlockSize == 0);
-  ASSERT(PcdGet32(PcdFlashNvStorageFtwSpareBase) % Instance->Media.BlockSize == 0);
-
-  //
-  // EFI_FIRMWARE_VOLUME_HEADER
-  //
-  FirmwareVolumeHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Headers;
-  CopyGuid (&FirmwareVolumeHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid);
-  FirmwareVolumeHeader->FvLength =
-      PcdGet32(PcdFlashNvStorageVariableSize) +
-      PcdGet32(PcdFlashNvStorageFtwWorkingSize) +
-      PcdGet32(PcdFlashNvStorageFtwSpareSize);
-  FirmwareVolumeHeader->Signature = EFI_FVH_SIGNATURE;
-  FirmwareVolumeHeader->Attributes = (EFI_FVB_ATTRIBUTES_2) (
-                                          EFI_FVB2_READ_ENABLED_CAP   | // Reads may be enabled
-                                          EFI_FVB2_READ_STATUS        | // Reads are currently enabled
-                                          EFI_FVB2_STICKY_WRITE       | // A block erase is required to flip bits into EFI_FVB2_ERASE_POLARITY
-                                          EFI_FVB2_MEMORY_MAPPED      | // It is memory mapped
-                                          EFI_FVB2_ERASE_POLARITY     | // After erasure all bits take this value (i.e. '1')
-                                          EFI_FVB2_WRITE_STATUS       | // Writes are currently enabled
-                                          EFI_FVB2_WRITE_ENABLED_CAP    // Writes may be enabled
-                                      );
-  FirmwareVolumeHeader->HeaderLength = sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY);
-  FirmwareVolumeHeader->Revision = EFI_FVH_REVISION;
-  FirmwareVolumeHeader->BlockMap[0].NumBlocks = Instance->Media.LastBlock + 1;
-  FirmwareVolumeHeader->BlockMap[0].Length      = Instance->Media.BlockSize;
-  FirmwareVolumeHeader->BlockMap[1].NumBlocks = 0;
-  FirmwareVolumeHeader->BlockMap[1].Length      = 0;
-  FirmwareVolumeHeader->Checksum = CalculateCheckSum16 ((UINT16*)FirmwareVolumeHeader,FirmwareVolumeHeader->HeaderLength);
-
-  //
-  // VARIABLE_STORE_HEADER
-  //
-  VariableStoreHeader = (VARIABLE_STORE_HEADER*)((UINT32)Headers + FirmwareVolumeHeader->HeaderLength);
-  CopyGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid);
-  VariableStoreHeader->Size = PcdGet32(PcdFlashNvStorageVariableSize) - FirmwareVolumeHeader->HeaderLength;
-  VariableStoreHeader->Format            = VARIABLE_STORE_FORMATTED;
-  VariableStoreHeader->State             = VARIABLE_STORE_HEALTHY;
-
-  // Install the combined super-header in the NorFlash
-  Status = FvbWrite (&Instance->FvbProtocol, 0, 0, &HeadersLength, Headers);
-
-  FreePool (Headers);
-  return Status;
-}
-
-/**
-  Check the integrity of firmware volume header.
-
-  @param[in] FwVolHeader - A pointer to a firmware volume header
-
-  @retval  EFI_SUCCESS   - The firmware volume is consistent
-  @retval  EFI_NOT_FOUND - The firmware volume has been corrupted.
-
-**/
-EFI_STATUS
-ValidateFvHeader (
-  IN  NOR_FLASH_INSTANCE *Instance
-  )
-{
-  UINT16                      Checksum;
-  EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader;
-  VARIABLE_STORE_HEADER       *VariableStoreHeader;
-  UINTN                       VariableStoreLength;
-  UINTN                                                  FvLength;
-
-  FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Instance->RegionBaseAddress;
-
-  FvLength = PcdGet32(PcdFlashNvStorageVariableSize) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) +
-      PcdGet32(PcdFlashNvStorageFtwSpareSize);
-
-  //
-  // 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  != FvLength)
-      )
-  {
-    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: No Firmware Volume header present\n"));
-    return EFI_NOT_FOUND;
-  }
-
-  // Check the Firmware Volume Guid
-  if( CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid) == FALSE ) {
-    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: Firmware Volume Guid non-compatible\n"));
-    return EFI_NOT_FOUND;
-  }
-
-  // Verify the header checksum
-  Checksum = CalculateSum16((UINT16*)FwVolHeader, FwVolHeader->HeaderLength);
-  if (Checksum != 0) {
-    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: FV checksum is invalid (Checksum:0x%X)\n",Checksum));
-    return EFI_NOT_FOUND;
-  }
-
-  VariableStoreHeader = (VARIABLE_STORE_HEADER*)((UINT32)FwVolHeader + FwVolHeader->HeaderLength);
-
-  // Check the Variable Store Guid
-  if( CompareGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid) == FALSE ) {
-    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: Variable Store Guid non-compatible\n"));
-    return EFI_NOT_FOUND;
-  }
-
-  VariableStoreLength = PcdGet32 (PcdFlashNvStorageVariableSize) - FwVolHeader->HeaderLength;
-  if (VariableStoreHeader->Size != VariableStoreLength) {
-    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: Variable Store Length does not match\n"));
-    return EFI_NOT_FOUND;
-  }
-
-  return EFI_SUCCESS;
-}
-
-/**
- The GetAttributes() function retrieves the attributes and
- current settings of the block.
-
- @param This         Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
-
- @param Attributes   Pointer to EFI_FVB_ATTRIBUTES_2 in which the attributes and
-                     current settings are returned.
-                     Type EFI_FVB_ATTRIBUTES_2 is defined in EFI_FIRMWARE_VOLUME_HEADER.
-
- @retval EFI_SUCCESS The firmware volume attributes were returned.
-
- **/
-EFI_STATUS
-EFIAPI
-FvbGetAttributes(
-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL    *This,
-  OUT       EFI_FVB_ATTRIBUTES_2                   *Attributes
-  )
-{
-  EFI_FVB_ATTRIBUTES_2  FlashFvbAttributes;
-  NOR_FLASH_INSTANCE *Instance;
-
-  Instance = INSTANCE_FROM_FVB_THIS(This);
-
-  FlashFvbAttributes = (EFI_FVB_ATTRIBUTES_2) (
-
-      EFI_FVB2_READ_ENABLED_CAP | // Reads may be enabled
-      EFI_FVB2_READ_STATUS      | // Reads are currently enabled
-      EFI_FVB2_STICKY_WRITE     | // A block erase is required to flip bits into EFI_FVB2_ERASE_POLARITY
-      EFI_FVB2_MEMORY_MAPPED    | // It is memory mapped
-      EFI_FVB2_ERASE_POLARITY     // After erasure all bits take this value (i.e. '1')
-
-      );
-
-  // Check if it is write protected
-  if (Instance->Media.ReadOnly != TRUE) {
-
-    FlashFvbAttributes = FlashFvbAttributes         |
-                         EFI_FVB2_WRITE_STATUS      | // Writes are currently enabled
-                         EFI_FVB2_WRITE_ENABLED_CAP;  // Writes may be enabled
-  }
-
-  *Attributes = FlashFvbAttributes;
-
-  DEBUG ((DEBUG_BLKIO, "FvbGetAttributes(0x%X)\n", *Attributes));
-
-  return EFI_SUCCESS;
-}
-
-/**
- The SetAttributes() function sets configurable firmware volume attributes
- and returns the new settings of the firmware volume.
-
-
- @param This                     Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
-
- @param Attributes               On input, Attributes is a pointer to EFI_FVB_ATTRIBUTES_2
-                                 that contains the desired firmware volume settings.
-                                 On successful return, it contains the new settings of
-                                 the firmware volume.
-                                 Type EFI_FVB_ATTRIBUTES_2 is defined in EFI_FIRMWARE_VOLUME_HEADER.
-
- @retval EFI_SUCCESS             The firmware volume attributes were returned.
-
- @retval EFI_INVALID_PARAMETER   The attributes requested are in conflict with the capabilities
-                                 as declared in the firmware volume header.
-
- **/
-EFI_STATUS
-EFIAPI
-FvbSetAttributes(
-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,
-  IN OUT    EFI_FVB_ATTRIBUTES_2                 *Attributes
-  )
-{
-  DEBUG ((DEBUG_BLKIO, "FvbSetAttributes(0x%X) is not supported\n",*Attributes));
-  return EFI_UNSUPPORTED;
-}
-
-/**
- The GetPhysicalAddress() function retrieves the base address of
- a memory-mapped firmware volume. This function should be called
- only for memory-mapped firmware volumes.
-
- @param This               Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
-
- @param Address            Pointer to a caller-allocated
-                           EFI_PHYSICAL_ADDRESS that, on successful
-                           return from GetPhysicalAddress(), contains the
-                           base address of the firmware volume.
-
- @retval EFI_SUCCESS       The firmware volume base address was returned.
-
- @retval EFI_NOT_SUPPORTED The firmware volume is not memory mapped.
-
- **/
-EFI_STATUS
-EFIAPI
-FvbGetPhysicalAddress (
-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,
-  OUT       EFI_PHYSICAL_ADDRESS                 *Address
-  )
-{
-  NOR_FLASH_INSTANCE *Instance;
-
-  Instance = INSTANCE_FROM_FVB_THIS(This);
-
-  DEBUG ((DEBUG_BLKIO, "FvbGetPhysicalAddress(BaseAddress=0x%08x)\n", Instance->RegionBaseAddress));
-
-  ASSERT(Address != NULL);
-
-  *Address = PcdGet32 (PcdFlashNvStorageVariableBase);
-  return EFI_SUCCESS;
-}
-
-/**
- The GetBlockSize() function retrieves the size of the requested
- block. It also returns the number of additional blocks with
- the identical size. The GetBlockSize() function is used to
- retrieve the block map (see EFI_FIRMWARE_VOLUME_HEADER).
-
-
- @param This                     Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
-
- @param Lba                      Indicates the block for which to return the size.
-
- @param BlockSize                Pointer to a caller-allocated UINTN in which
-                                 the size of the block is returned.
-
- @param NumberOfBlocks           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.
-
-
- @retval EFI_SUCCESS             The firmware volume base address was returned.
-
- @retval EFI_INVALID_PARAMETER   The requested LBA is out of range.
-
- **/
-EFI_STATUS
-EFIAPI
-FvbGetBlockSize (
-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,
-  IN        EFI_LBA                              Lba,
-  OUT       UINTN                                *BlockSize,
-  OUT       UINTN                                *NumberOfBlocks
-  )
-{
-  EFI_STATUS Status;
-  NOR_FLASH_INSTANCE *Instance;
-
-  Instance = INSTANCE_FROM_FVB_THIS(This);
-
-  DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize(Lba=%ld, BlockSize=0x%x, LastBlock=%ld)\n", Lba, Instance->Media.BlockSize, Instance->Media.LastBlock));
-
-  if (Lba > Instance->Media.LastBlock) {
-    DEBUG ((EFI_D_ERROR, "FvbGetBlockSize: ERROR - Parameter LBA %ld is beyond the last Lba (%ld).\n", Lba, Instance->Media.LastBlock));
-    Status = EFI_INVALID_PARAMETER;
-  } else {
-    // This is easy because in this platform each NorFlash device has equal sized blocks.
-    *BlockSize = (UINTN) Instance->Media.BlockSize;
-    *NumberOfBlocks = (UINTN) (Instance->Media.LastBlock - Lba + 1);
-
-    DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize: *BlockSize=0x%x, *NumberOfBlocks=0x%x.\n", *BlockSize, *NumberOfBlocks));
-
-    Status = EFI_SUCCESS;
-  }
-
-  return Status;
-}
-
-/**
- Reads the specified number of bytes into a buffer from the specified block.
-
- The Read() function reads the requested number of bytes from the
- requested block and stores them in the provided buffer.
- Implementations should be mindful that the firmware volume
- might be in the ReadDisabled state. If it is in this state,
- the Read() function must return the status code
- EFI_ACCESS_DENIED without modifying the contents of the
- buffer. The Read() function must also prevent spanning block
- boundaries. If a read is requested that would span a block
- boundary, the read must read up to the boundary but not
- beyond. The output parameter NumBytes must be set to correctly
- indicate the number of bytes actually read. The caller must be
- aware that a read may be partially completed.
-
- @param This                 Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
-
- @param Lba                  The starting logical block index from which to read.
-
- @param Offset               Offset into the block at which to begin reading.
-
- @param NumBytes             Pointer to a UINTN.
-                             At entry, *NumBytes contains the total size of the buffer.
-                             At exit, *NumBytes contains the total number of bytes read.
-
- @param Buffer               Pointer to a caller-allocated buffer that will be used
-                             to hold the data that is read.
-
- @retval EFI_SUCCESS         The firmware volume was read successfully,  and contents are
-                             in Buffer.
-
- @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA boundary.
-                             On output, NumBytes contains the total number of bytes
-                             returned in Buffer.
-
- @retval EFI_ACCESS_DENIED   The firmware volume is in the ReadDisabled state.
-
- @retval EFI_DEVICE_ERROR    The block device is not functioning correctly and could not be read.
-
- **/
-EFI_STATUS
-EFIAPI
-FvbRead (
-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL   *This,
-  IN        EFI_LBA                               Lba,
-  IN        UINTN                                 Offset,
-  IN OUT    UINTN                                 *NumBytes,
-  IN OUT    UINT8                                 *Buffer
-  )
-{
-  EFI_STATUS    Status;
-  EFI_STATUS    TempStatus;
-  UINTN         BlockSize;
-  UINT8         *BlockBuffer;
-  NOR_FLASH_INSTANCE *Instance;
-
-  Instance = INSTANCE_FROM_FVB_THIS(This);
-
-  DEBUG ((DEBUG_BLKIO, "FvbRead(Parameters: Lba=%ld, Offset=0x%x, *NumBytes=0x%x, Buffer @ 0x%08x)\n", Instance->StartLba + Lba, Offset, *NumBytes, Buffer));
-
-  if (!Instance->Initialized && Instance->Initialize) {
-    Instance->Initialize(Instance);
-  }
-
-  Status = EFI_SUCCESS;
-  TempStatus = Status;
-
-  // Cache the block size to avoid de-referencing pointers all the time
-  BlockSize = Instance->Media.BlockSize;
-
-  DEBUG ((DEBUG_BLKIO, "FvbRead: Check if (Offset=0x%x + NumBytes=0x%x) <= BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));
-
-  // The read must not span block boundaries.
-  // We need to check each variable individually because adding two large values together overflows.
-  if ((Offset               >= BlockSize) ||
-      (*NumBytes            >  BlockSize) ||
-      ((Offset + *NumBytes) >  BlockSize)) {
-    DEBUG ((EFI_D_ERROR, "FvbRead: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));
-    return EFI_BAD_BUFFER_SIZE;
-  }
-
-  // We must have some bytes to read
-  if (*NumBytes == 0) {
-    return EFI_BAD_BUFFER_SIZE;
-  }
-
-  // FixMe: Allow an arbitrary number of bytes to be read out, not just a multiple of block size.
-
-  // Allocate runtime memory to read in the NOR Flash data. Variable Services are runtime.
-  BlockBuffer = AllocateRuntimePool (BlockSize);
-
-  // Check if the memory allocation was successful
-  if (BlockBuffer == NULL) {
-    DEBUG ((EFI_D_ERROR, "FvbRead: ERROR - Could not allocate BlockBuffer @ 0x%08x.\n", BlockBuffer));
-    return EFI_DEVICE_ERROR;
-  }
-
-  // Read NOR Flash data into shadow buffer
-  TempStatus = NorFlashReadBlocks (Instance, Instance->StartLba + Lba, BlockSize, BlockBuffer);
-  if (EFI_ERROR (TempStatus)) {
-    // Return one of the pre-approved error statuses
-    Status = EFI_DEVICE_ERROR;
-    goto FREE_MEMORY;
-  }
-
-  // Put the data at the appropriate location inside the buffer area
-  DEBUG ((DEBUG_BLKIO, "FvbRead: CopyMem( Dst=0x%08x, Src=0x%08x, Size=0x%x ).\n", Buffer, BlockBuffer + Offset, *NumBytes));
-
-  CopyMem(Buffer, BlockBuffer + Offset, *NumBytes);
-
-FREE_MEMORY:
-  FreePool(BlockBuffer);
-  return Status;
-}
-
-/**
- Writes the specified number of bytes from the input buffer to the block.
-
- The Write() function writes the specified number of bytes from
- the provided buffer to the specified block and offset. If the
- firmware volume is sticky write, the caller must ensure that
- all the bits of the specified range to write are in the
- EFI_FVB_ERASE_POLARITY state before calling the Write()
- function, or else the result will be unpredictable. This
- unpredictability arises because, for a sticky-write firmware
- volume, a write may negate a bit in the EFI_FVB_ERASE_POLARITY
- state but cannot flip it back again.  Before calling the
- Write() function,  it is recommended for the caller to first call
- the EraseBlocks() function to erase the specified block to
- write. A block erase cycle will transition bits from the
- (NOT)EFI_FVB_ERASE_POLARITY state back to the
- EFI_FVB_ERASE_POLARITY state. Implementations should be
- mindful that the firmware volume might be in the WriteDisabled
- state. If it is in this state, the Write() function must
- return the status code EFI_ACCESS_DENIED without modifying the
- contents of the firmware volume. The Write() function must
- also prevent spanning block boundaries. If a write is
- requested that spans a block boundary, the write must store up
- to the boundary but not beyond. The output parameter NumBytes
- must be set to correctly indicate the number of bytes actually
- written. The caller must be aware that a write may be
- partially completed. All writes, partial or otherwise, must be
- fully flushed to the hardware before the Write() service
- returns.
-
- @param This                 Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
-
- @param Lba                  The starting logical block index to write to.
-
- @param Offset               Offset into the block at which to begin writing.
-
- @param NumBytes             The pointer to a UINTN.
-                             At entry, *NumBytes contains the total size of the buffer.
-                             At exit, *NumBytes contains the total number of bytes actually written.
-
- @param Buffer               The pointer to a caller-allocated buffer that contains the source for the write.
-
- @retval EFI_SUCCESS         The firmware volume was written successfully.
-
- @retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundary.
-                             On output, NumBytes contains the total number of bytes
-                             actually written.
-
- @retval EFI_ACCESS_DENIED   The firmware volume is in the WriteDisabled state.
-
- @retval EFI_DEVICE_ERROR    The block device is malfunctioning and could not be written.
-
-
- **/
-EFI_STATUS
-EFIAPI
-FvbWrite (
-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL   *This,
-  IN        EFI_LBA                               Lba,
-  IN        UINTN                                 Offset,
-  IN OUT    UINTN                                 *NumBytes,
-  IN        UINT8                                 *Buffer
-  )
-{
-  EFI_STATUS  Status;
-  EFI_STATUS  TempStatus;
-  UINTN       BlockSize;
-  UINT8       *BlockBuffer;
-  NOR_FLASH_INSTANCE *Instance;
-
-  Instance = INSTANCE_FROM_FVB_THIS(This);
-
-  if (!Instance->Initialized && Instance->Initialize) {
-    Instance->Initialize(Instance);
-  }
-
-  DEBUG ((DEBUG_BLKIO, "FvbWrite(Parameters: Lba=%ld, Offset=0x%x, *NumBytes=0x%x, Buffer @ 0x%08x)\n", Instance->StartLba + Lba, Offset, *NumBytes, Buffer));
-
-  Status = EFI_SUCCESS;
-  TempStatus = Status;
-
-  // Detect WriteDisabled state
-  if (Instance->Media.ReadOnly == TRUE) {
-    DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - Can not write: Device is in WriteDisabled state.\n"));
-    // It is in WriteDisabled state, return an error right away
-    return EFI_ACCESS_DENIED;
-  }
-
-  // Cache the block size to avoid de-referencing pointers all the time
-  BlockSize = Instance->Media.BlockSize;
-
-  // The write must not span block boundaries.
-  // We need to check each variable individually because adding two large values together overflows.
-  if ( ( Offset               >= BlockSize ) ||
-       ( *NumBytes            >  BlockSize ) ||
-       ( (Offset + *NumBytes) >  BlockSize )    ) {
-    DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));
-    return EFI_BAD_BUFFER_SIZE;
-  }
-
-  // We must have some bytes to write
-  if (*NumBytes == 0) {
-    DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));
-    return EFI_BAD_BUFFER_SIZE;
-  }
-
-  // Allocate runtime memory to read in the NOR Flash data.
-  // Since the intention is to use this with Variable Services and since these are runtime,
-  // allocate the memory from the runtime pool.
-  BlockBuffer = AllocateRuntimePool (BlockSize);
-
-  // Check we did get some memory
-  if( BlockBuffer == NULL ) {
-    DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - Can not allocate BlockBuffer @ 0x%08x.\n", BlockBuffer));
-    return EFI_DEVICE_ERROR;
-  }
-
-  // Read NOR Flash data into shadow buffer
-  TempStatus = NorFlashReadBlocks (Instance, Instance->StartLba + Lba, BlockSize, BlockBuffer);
-  if (EFI_ERROR (TempStatus)) {
-    // Return one of the pre-approved error statuses
-    Status = EFI_DEVICE_ERROR;
-    goto FREE_MEMORY;
-  }
-
-  // Put the data at the appropriate location inside the buffer area
-  CopyMem((BlockBuffer + Offset), Buffer, *NumBytes);
-
-  // Write the modified buffer back to the NorFlash
-  Status = NorFlashWriteBlocks (Instance, Instance->StartLba + Lba, BlockSize, BlockBuffer);
-  if (EFI_ERROR (TempStatus)) {
-    // Return one of the pre-approved error statuses
-    Status = EFI_DEVICE_ERROR;
-    goto FREE_MEMORY;
-  }
-
-FREE_MEMORY:
-  FreePool(BlockBuffer);
-  return Status;
-}
-
-/**
- Erases and initialises a firmware volume block.
-
- The EraseBlocks() function erases one or more blocks as denoted
- by the variable argument list. The entire parameter list of
- blocks must be verified before 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 EraseBlocks() function must return the
- status code EFI_INVALID_PARAMETER without modifying the contents
- of the firmware volume. Implementations should be mindful that
- the firmware volume might be in the WriteDisabled state. If it
- is in this state, the EraseBlocks() function must return the
- status code EFI_ACCESS_DENIED without modifying the contents of
- the firmware volume. All calls to EraseBlocks() must be fully
- flushed to the hardware before the EraseBlocks() service
- returns.
-
- @param This                     Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL
- instance.
-
- @param ...                      The variable argument list is a list of tuples.
-                                 Each tuple describes a range of LBAs to erase
-                                 and consists of the following:
-                                 - An EFI_LBA that indicates the starting LBA
-                                 - A UINTN that indicates the number of blocks to erase.
-
-                                 The list is terminated with an EFI_LBA_LIST_TERMINATOR.
-                                 For example, the following indicates that two ranges of blocks
-                                 (5-7 and 10-11) are to be erased:
-                                 EraseBlocks (This, 5, 3, 10, 2, EFI_LBA_LIST_TERMINATOR);
-
- @retval EFI_SUCCESS             The erase request successfully completed.
-
- @retval EFI_ACCESS_DENIED       The firmware volume is in the WriteDisabled state.
-
- @retval EFI_DEVICE_ERROR        The block device is not functioning correctly and could not be written.
-                                 The firmware device may have been partially erased.
-
- @retval EFI_INVALID_PARAMETER   One or more of the LBAs listed in the variable argument list do
-                                 not exist in the firmware volume.
-
- **/
-EFI_STATUS
-EFIAPI
-FvbEraseBlocks (
-  IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
-  ...
-  )
-{
-  EFI_STATUS  Status;
-  VA_LIST     Args;
-  UINTN       BlockAddress; // Physical address of Lba to erase
-  EFI_LBA     StartingLba; // Lba from which we start erasing
-  UINTN       NumOfLba; // Number of Lba blocks to erase
-  NOR_FLASH_INSTANCE *Instance;
-
-  Instance = INSTANCE_FROM_FVB_THIS(This);
-
-  DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks()\n"));
-
-  Status = EFI_SUCCESS;
-
-  // Detect WriteDisabled state
-  if (Instance->Media.ReadOnly == TRUE) {
-    // Firmware volume is in WriteDisabled state
-    DEBUG ((EFI_D_ERROR, "FvbEraseBlocks: ERROR - Device is in WriteDisabled state.\n"));
-    return EFI_ACCESS_DENIED;
-  }
-
-  // Before erasing, check the entire list of parameters to ensure all specified blocks are valid
-
-  VA_START (Args, This);
-  do {
-    // Get the Lba from which we start erasing
-    StartingLba = VA_ARG (Args, EFI_LBA);
-
-    // Have we reached the end of the list?
-    if (StartingLba == EFI_LBA_LIST_TERMINATOR) {
-      //Exit the while loop
-      break;
-    }
-
-    // How many Lba blocks are we requested to erase?
-    NumOfLba = VA_ARG (Args, UINT32);
-
-    // All blocks must be within range
-    DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks: Check if: ( StartingLba=%ld + NumOfLba=%d - 1 ) > LastBlock=%ld.\n", Instance->StartLba + StartingLba, NumOfLba, Instance->Media.LastBlock));
-    if ((NumOfLba == 0) || ((Instance->StartLba + StartingLba + NumOfLba - 1) > Instance->Media.LastBlock)) {
-      VA_END (Args);
-      DEBUG ((EFI_D_ERROR, "FvbEraseBlocks: ERROR - Lba range goes past the last Lba.\n"));
-      Status = EFI_INVALID_PARAMETER;
-      goto EXIT;
-    }
-  } while (TRUE);
-  VA_END (Args);
-
-  //
-  // To get here, all must be ok, so start erasing
-  //
-  VA_START (Args, This);
-  do {
-    // Get the Lba from which we start erasing
-    StartingLba = VA_ARG (Args, EFI_LBA);
-
-    // Have we reached the end of the list?
-    if (StartingLba == EFI_LBA_LIST_TERMINATOR) {
-      // Exit the while loop
-      break;
-    }
-
-    // How many Lba blocks are we requested to erase?
-    NumOfLba = VA_ARG (Args, UINT32);
-
-    // Go through each one and erase it
-    while (NumOfLba > 0) {
-
-      // Get the physical address of Lba to erase
-      BlockAddress = GET_NOR_BLOCK_ADDRESS (
-          Instance->RegionBaseAddress,
-          Instance->StartLba + StartingLba,
-          Instance->Media.BlockSize
-      );
-
-      // Erase it
-      DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks: Erasing Lba=%ld @ 0x%08x.\n", Instance->StartLba + StartingLba, BlockAddress));
-      Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress);
-      if (EFI_ERROR(Status)) {
-        VA_END (Args);
-        Status = EFI_DEVICE_ERROR;
-        goto EXIT;
-      }
-
-      // Move to the next Lba
-      StartingLba++;
-      NumOfLba--;
-    }
-  } while (TRUE);
-  VA_END (Args);
-
-EXIT:
-  return Status;
-}
-
-EFI_STATUS
-EFIAPI
-NorFlashFvbInitialize (
-  IN NOR_FLASH_INSTANCE* Instance
-  )
-{
-  EFI_STATUS  Status;
-  UINT32      FvbNumLba;
-  EFI_BOOT_MODE BootMode;
-
-  DEBUG((DEBUG_BLKIO,"NorFlashFvbInitialize\n"));
-
-  Instance->Initialized = TRUE;
-
-  // Set the index of the first LBA for the FVB
-  Instance->StartLba = (PcdGet32 (PcdFlashNvStorageVariableBase) - Instance->RegionBaseAddress) / Instance->Media.BlockSize;
-
-  BootMode = GetBootModeHob ();
-  if (BootMode == BOOT_WITH_DEFAULT_SETTINGS) {
-    Status = EFI_INVALID_PARAMETER;
-  } else {
-    // Determine if there is a valid header at the beginning of the NorFlash
-    Status = ValidateFvHeader (Instance);
-  }
-
-  // Install the Default FVB header if required  
-  if (EFI_ERROR(Status)) {
-    // There is no valid header, so time to install one.
-    DEBUG((EFI_D_ERROR,"NorFlashFvbInitialize: ERROR - The FVB Header is not valid. Installing a correct one for this volume.\n"));
-
-    // Erase all the NorFlash that is reserved for variable storage
-    FvbNumLba = (PcdGet32(PcdFlashNvStorageVariableSize) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) + PcdGet32(PcdFlashNvStorageFtwSpareSize)) / Instance->Media.BlockSize;
-
-    Status = FvbEraseBlocks (&Instance->FvbProtocol, (EFI_LBA)0, FvbNumLba, EFI_LBA_LIST_TERMINATOR);
-    if (EFI_ERROR(Status)) {
-      return Status;
-    }
-
-    // Install all appropriate headers
-    Status = InitializeFvAndVariableStoreHeaders (Instance);
-    if (EFI_ERROR(Status)) {
-      return Status;
-    }
-  }
-  return Status;
-}
+/*++ @file  NorFlashFvbDxe.c\r
+\r
+ Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>\r
+\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution.  The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ --*/\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Library/PcdLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#include <Guid/VariableFormat.h>\r
+#include <Guid/SystemNvDataGuid.h>\r
+\r
+#include "NorFlashDxe.h"\r
+\r
+\r
+///\r
+/// The Firmware Volume Block Protocol is the low-level interface\r
+/// to a firmware volume. File-level access to a firmware volume\r
+/// should not be done using the Firmware Volume Block Protocol.\r
+/// Normal access to a firmware volume must use the Firmware\r
+/// Volume Protocol. Typically, only the file system driver that\r
+/// produces the Firmware Volume Protocol will bind to the\r
+/// Firmware Volume Block Protocol.\r
+///\r
+\r
+/**\r
+  Initialises the FV Header and Variable Store Header\r
+  to support variable operations.\r
+\r
+  @param[in]  Ptr - Location to initialise the headers\r
+\r
+**/\r
+EFI_STATUS\r
+InitializeFvAndVariableStoreHeaders (\r
+  IN NOR_FLASH_INSTANCE *Instance\r
+  )\r
+{\r
+  EFI_STATUS                          Status;\r
+  VOID*                               Headers;\r
+  UINTN                               HeadersLength;\r
+  EFI_FIRMWARE_VOLUME_HEADER          *FirmwareVolumeHeader;\r
+  VARIABLE_STORE_HEADER               *VariableStoreHeader;\r
+\r
+  if (!Instance->Initialized && Instance->Initialize) {\r
+    Instance->Initialize (Instance);\r
+  }\r
+\r
+  HeadersLength = sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(VARIABLE_STORE_HEADER);\r
+  Headers = AllocateZeroPool(HeadersLength);\r
+\r
+  // FirmwareVolumeHeader->FvLength is declared to have the Variable area AND the FTW working area AND the FTW Spare contiguous.\r
+  ASSERT(PcdGet32(PcdFlashNvStorageVariableBase) + PcdGet32(PcdFlashNvStorageVariableSize) == PcdGet32(PcdFlashNvStorageFtwWorkingBase));\r
+  ASSERT(PcdGet32(PcdFlashNvStorageFtwWorkingBase) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) == PcdGet32(PcdFlashNvStorageFtwSpareBase));\r
+\r
+  // Check if the size of the area is at least one block size\r
+  ASSERT((PcdGet32(PcdFlashNvStorageVariableSize) > 0) && (PcdGet32(PcdFlashNvStorageVariableSize) / Instance->Media.BlockSize > 0));\r
+  ASSERT((PcdGet32(PcdFlashNvStorageFtwWorkingSize) > 0) && (PcdGet32(PcdFlashNvStorageFtwWorkingSize) / Instance->Media.BlockSize > 0));\r
+  ASSERT((PcdGet32(PcdFlashNvStorageFtwSpareSize) > 0) && (PcdGet32(PcdFlashNvStorageFtwSpareSize) / Instance->Media.BlockSize > 0));\r
+\r
+  // Ensure the Variable area Base Addresses are aligned on a block size boundaries\r
+  ASSERT(PcdGet32(PcdFlashNvStorageVariableBase) % Instance->Media.BlockSize == 0);\r
+  ASSERT(PcdGet32(PcdFlashNvStorageFtwWorkingBase) % Instance->Media.BlockSize == 0);\r
+  ASSERT(PcdGet32(PcdFlashNvStorageFtwSpareBase) % Instance->Media.BlockSize == 0);\r
+\r
+  //\r
+  // EFI_FIRMWARE_VOLUME_HEADER\r
+  //\r
+  FirmwareVolumeHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Headers;\r
+  CopyGuid (&FirmwareVolumeHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid);\r
+  FirmwareVolumeHeader->FvLength =\r
+      PcdGet32(PcdFlashNvStorageVariableSize) +\r
+      PcdGet32(PcdFlashNvStorageFtwWorkingSize) +\r
+      PcdGet32(PcdFlashNvStorageFtwSpareSize);\r
+  FirmwareVolumeHeader->Signature = EFI_FVH_SIGNATURE;\r
+  FirmwareVolumeHeader->Attributes = (EFI_FVB_ATTRIBUTES_2) (\r
+                                          EFI_FVB2_READ_ENABLED_CAP   | // Reads may be enabled\r
+                                          EFI_FVB2_READ_STATUS        | // Reads are currently enabled\r
+                                          EFI_FVB2_STICKY_WRITE       | // A block erase is required to flip bits into EFI_FVB2_ERASE_POLARITY\r
+                                          EFI_FVB2_MEMORY_MAPPED      | // It is memory mapped\r
+                                          EFI_FVB2_ERASE_POLARITY     | // After erasure all bits take this value (i.e. '1')\r
+                                          EFI_FVB2_WRITE_STATUS       | // Writes are currently enabled\r
+                                          EFI_FVB2_WRITE_ENABLED_CAP    // Writes may be enabled\r
+                                      );\r
+  FirmwareVolumeHeader->HeaderLength = sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY);\r
+  FirmwareVolumeHeader->Revision = EFI_FVH_REVISION;\r
+  FirmwareVolumeHeader->BlockMap[0].NumBlocks = Instance->Media.LastBlock + 1;\r
+  FirmwareVolumeHeader->BlockMap[0].Length      = Instance->Media.BlockSize;\r
+  FirmwareVolumeHeader->BlockMap[1].NumBlocks = 0;\r
+  FirmwareVolumeHeader->BlockMap[1].Length      = 0;\r
+  FirmwareVolumeHeader->Checksum = CalculateCheckSum16 ((UINT16*)FirmwareVolumeHeader,FirmwareVolumeHeader->HeaderLength);\r
+\r
+  //\r
+  // VARIABLE_STORE_HEADER\r
+  //\r
+  VariableStoreHeader = (VARIABLE_STORE_HEADER*)((UINT32)Headers + FirmwareVolumeHeader->HeaderLength);\r
+  CopyGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid);\r
+  VariableStoreHeader->Size = PcdGet32(PcdFlashNvStorageVariableSize) - FirmwareVolumeHeader->HeaderLength;\r
+  VariableStoreHeader->Format            = VARIABLE_STORE_FORMATTED;\r
+  VariableStoreHeader->State             = VARIABLE_STORE_HEALTHY;\r
+\r
+  // Install the combined super-header in the NorFlash\r
+  Status = FvbWrite (&Instance->FvbProtocol, 0, 0, &HeadersLength, Headers);\r
+\r
+  FreePool (Headers);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Check the integrity of firmware volume header.\r
+\r
+  @param[in] FwVolHeader - A pointer to a firmware volume header\r
+\r
+  @retval  EFI_SUCCESS   - The firmware volume is consistent\r
+  @retval  EFI_NOT_FOUND - The firmware volume has been corrupted.\r
+\r
+**/\r
+EFI_STATUS\r
+ValidateFvHeader (\r
+  IN  NOR_FLASH_INSTANCE *Instance\r
+  )\r
+{\r
+  UINT16                      Checksum;\r
+  EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader;\r
+  VARIABLE_STORE_HEADER       *VariableStoreHeader;\r
+  UINTN                       VariableStoreLength;\r
+  UINTN                                                  FvLength;\r
+\r
+  FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Instance->RegionBaseAddress;\r
+\r
+  FvLength = PcdGet32(PcdFlashNvStorageVariableSize) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) +\r
+      PcdGet32(PcdFlashNvStorageFtwSpareSize);\r
+\r
+  //\r
+  // Verify the header revision, header signature, length\r
+  // Length of FvBlock cannot be 2**64-1\r
+  // HeaderLength cannot be an odd number\r
+  //\r
+  if (   (FwVolHeader->Revision  != EFI_FVH_REVISION)\r
+      || (FwVolHeader->Signature != EFI_FVH_SIGNATURE)\r
+      || (FwVolHeader->FvLength  != FvLength)\r
+      )\r
+  {\r
+    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: No Firmware Volume header present\n"));\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  // Check the Firmware Volume Guid\r
+  if( CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid) == FALSE ) {\r
+    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: Firmware Volume Guid non-compatible\n"));\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  // Verify the header checksum\r
+  Checksum = CalculateSum16((UINT16*)FwVolHeader, FwVolHeader->HeaderLength);\r
+  if (Checksum != 0) {\r
+    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: FV checksum is invalid (Checksum:0x%X)\n",Checksum));\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  VariableStoreHeader = (VARIABLE_STORE_HEADER*)((UINT32)FwVolHeader + FwVolHeader->HeaderLength);\r
+\r
+  // Check the Variable Store Guid\r
+  if( CompareGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid) == FALSE ) {\r
+    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: Variable Store Guid non-compatible\n"));\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  VariableStoreLength = PcdGet32 (PcdFlashNvStorageVariableSize) - FwVolHeader->HeaderLength;\r
+  if (VariableStoreHeader->Size != VariableStoreLength) {\r
+    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: Variable Store Length does not match\n"));\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ The GetAttributes() function retrieves the attributes and\r
+ current settings of the block.\r
+\r
+ @param This         Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r
+\r
+ @param Attributes   Pointer to EFI_FVB_ATTRIBUTES_2 in which the attributes and\r
+                     current settings are returned.\r
+                     Type EFI_FVB_ATTRIBUTES_2 is defined in EFI_FIRMWARE_VOLUME_HEADER.\r
+\r
+ @retval EFI_SUCCESS The firmware volume attributes were returned.\r
+\r
+ **/\r
+EFI_STATUS\r
+EFIAPI\r
+FvbGetAttributes(\r
+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL    *This,\r
+  OUT       EFI_FVB_ATTRIBUTES_2                   *Attributes\r
+  )\r
+{\r
+  EFI_FVB_ATTRIBUTES_2  FlashFvbAttributes;\r
+  NOR_FLASH_INSTANCE *Instance;\r
+\r
+  Instance = INSTANCE_FROM_FVB_THIS(This);\r
+\r
+  FlashFvbAttributes = (EFI_FVB_ATTRIBUTES_2) (\r
+\r
+      EFI_FVB2_READ_ENABLED_CAP | // Reads may be enabled\r
+      EFI_FVB2_READ_STATUS      | // Reads are currently enabled\r
+      EFI_FVB2_STICKY_WRITE     | // A block erase is required to flip bits into EFI_FVB2_ERASE_POLARITY\r
+      EFI_FVB2_MEMORY_MAPPED    | // It is memory mapped\r
+      EFI_FVB2_ERASE_POLARITY     // After erasure all bits take this value (i.e. '1')\r
+\r
+      );\r
+\r
+  // Check if it is write protected\r
+  if (Instance->Media.ReadOnly != TRUE) {\r
+\r
+    FlashFvbAttributes = FlashFvbAttributes         |\r
+                         EFI_FVB2_WRITE_STATUS      | // Writes are currently enabled\r
+                         EFI_FVB2_WRITE_ENABLED_CAP;  // Writes may be enabled\r
+  }\r
+\r
+  *Attributes = FlashFvbAttributes;\r
+\r
+  DEBUG ((DEBUG_BLKIO, "FvbGetAttributes(0x%X)\n", *Attributes));\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ The SetAttributes() function sets configurable firmware volume attributes\r
+ and returns the new settings of the firmware volume.\r
+\r
+\r
+ @param This                     Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r
+\r
+ @param Attributes               On input, Attributes is a pointer to EFI_FVB_ATTRIBUTES_2\r
+                                 that contains the desired firmware volume settings.\r
+                                 On successful return, it contains the new settings of\r
+                                 the firmware volume.\r
+                                 Type EFI_FVB_ATTRIBUTES_2 is defined in EFI_FIRMWARE_VOLUME_HEADER.\r
+\r
+ @retval EFI_SUCCESS             The firmware volume attributes were returned.\r
+\r
+ @retval EFI_INVALID_PARAMETER   The attributes requested are in conflict with the capabilities\r
+                                 as declared in the firmware volume header.\r
+\r
+ **/\r
+EFI_STATUS\r
+EFIAPI\r
+FvbSetAttributes(\r
+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,\r
+  IN OUT    EFI_FVB_ATTRIBUTES_2                 *Attributes\r
+  )\r
+{\r
+  DEBUG ((DEBUG_BLKIO, "FvbSetAttributes(0x%X) is not supported\n",*Attributes));\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+ The GetPhysicalAddress() function retrieves the base address of\r
+ a memory-mapped firmware volume. This function should be called\r
+ only for memory-mapped firmware volumes.\r
+\r
+ @param This               Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r
+\r
+ @param Address            Pointer to a caller-allocated\r
+                           EFI_PHYSICAL_ADDRESS that, on successful\r
+                           return from GetPhysicalAddress(), contains the\r
+                           base address of the firmware volume.\r
+\r
+ @retval EFI_SUCCESS       The firmware volume base address was returned.\r
+\r
+ @retval EFI_NOT_SUPPORTED The firmware volume is not memory mapped.\r
+\r
+ **/\r
+EFI_STATUS\r
+EFIAPI\r
+FvbGetPhysicalAddress (\r
+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,\r
+  OUT       EFI_PHYSICAL_ADDRESS                 *Address\r
+  )\r
+{\r
+  NOR_FLASH_INSTANCE *Instance;\r
+\r
+  Instance = INSTANCE_FROM_FVB_THIS(This);\r
+\r
+  DEBUG ((DEBUG_BLKIO, "FvbGetPhysicalAddress(BaseAddress=0x%08x)\n", Instance->RegionBaseAddress));\r
+\r
+  ASSERT(Address != NULL);\r
+\r
+  *Address = PcdGet32 (PcdFlashNvStorageVariableBase);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ The GetBlockSize() function retrieves the size of the requested\r
+ block. It also returns the number of additional blocks with\r
+ the identical size. The GetBlockSize() function is used to\r
+ retrieve the block map (see EFI_FIRMWARE_VOLUME_HEADER).\r
+\r
+\r
+ @param This                     Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r
+\r
+ @param Lba                      Indicates the block for which to return the size.\r
+\r
+ @param BlockSize                Pointer to a caller-allocated UINTN in which\r
+                                 the size of the block is returned.\r
+\r
+ @param NumberOfBlocks           Pointer to a caller-allocated UINTN in\r
+                                 which the number of consecutive blocks,\r
+                                 starting with Lba, is returned. All\r
+                                 blocks in this range have a size of\r
+                                 BlockSize.\r
+\r
+\r
+ @retval EFI_SUCCESS             The firmware volume base address was returned.\r
+\r
+ @retval EFI_INVALID_PARAMETER   The requested LBA is out of range.\r
+\r
+ **/\r
+EFI_STATUS\r
+EFIAPI\r
+FvbGetBlockSize (\r
+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,\r
+  IN        EFI_LBA                              Lba,\r
+  OUT       UINTN                                *BlockSize,\r
+  OUT       UINTN                                *NumberOfBlocks\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  NOR_FLASH_INSTANCE *Instance;\r
+\r
+  Instance = INSTANCE_FROM_FVB_THIS(This);\r
+\r
+  DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize(Lba=%ld, BlockSize=0x%x, LastBlock=%ld)\n", Lba, Instance->Media.BlockSize, Instance->Media.LastBlock));\r
+\r
+  if (Lba > Instance->Media.LastBlock) {\r
+    DEBUG ((EFI_D_ERROR, "FvbGetBlockSize: ERROR - Parameter LBA %ld is beyond the last Lba (%ld).\n", Lba, Instance->Media.LastBlock));\r
+    Status = EFI_INVALID_PARAMETER;\r
+  } else {\r
+    // This is easy because in this platform each NorFlash device has equal sized blocks.\r
+    *BlockSize = (UINTN) Instance->Media.BlockSize;\r
+    *NumberOfBlocks = (UINTN) (Instance->Media.LastBlock - Lba + 1);\r
+\r
+    DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize: *BlockSize=0x%x, *NumberOfBlocks=0x%x.\n", *BlockSize, *NumberOfBlocks));\r
+\r
+    Status = EFI_SUCCESS;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+ Reads the specified number of bytes into a buffer from the specified block.\r
+\r
+ The Read() function reads the requested number of bytes from the\r
+ requested block and stores them in the provided buffer.\r
+ Implementations should be mindful that the firmware volume\r
+ might be in the ReadDisabled state. If it is in this state,\r
+ the Read() function must return the status code\r
+ EFI_ACCESS_DENIED without modifying the contents of the\r
+ buffer. The Read() function must also prevent spanning block\r
+ boundaries. If a read is requested that would span a block\r
+ boundary, the read must read up to the boundary but not\r
+ beyond. The output parameter NumBytes must be set to correctly\r
+ indicate the number of bytes actually read. The caller must be\r
+ aware that a read may be partially completed.\r
+\r
+ @param This                 Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r
+\r
+ @param Lba                  The starting logical block index from which to read.\r
+\r
+ @param Offset               Offset into the block at which to begin reading.\r
+\r
+ @param NumBytes             Pointer to a UINTN.\r
+                             At entry, *NumBytes contains the total size of the buffer.\r
+                             At exit, *NumBytes contains the total number of bytes read.\r
+\r
+ @param Buffer               Pointer to a caller-allocated buffer that will be used\r
+                             to hold the data that is read.\r
+\r
+ @retval EFI_SUCCESS         The firmware volume was read successfully,  and contents are\r
+                             in Buffer.\r
+\r
+ @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA boundary.\r
+                             On output, NumBytes contains the total number of bytes\r
+                             returned in Buffer.\r
+\r
+ @retval EFI_ACCESS_DENIED   The firmware volume is in the ReadDisabled state.\r
+\r
+ @retval EFI_DEVICE_ERROR    The block device is not functioning correctly and could not be read.\r
+\r
+ **/\r
+EFI_STATUS\r
+EFIAPI\r
+FvbRead (\r
+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL   *This,\r
+  IN        EFI_LBA                               Lba,\r
+  IN        UINTN                                 Offset,\r
+  IN OUT    UINTN                                 *NumBytes,\r
+  IN OUT    UINT8                                 *Buffer\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  EFI_STATUS    TempStatus;\r
+  UINTN         BlockSize;\r
+  UINT8         *BlockBuffer;\r
+  NOR_FLASH_INSTANCE *Instance;\r
+\r
+  Instance = INSTANCE_FROM_FVB_THIS(This);\r
+\r
+  DEBUG ((DEBUG_BLKIO, "FvbRead(Parameters: Lba=%ld, Offset=0x%x, *NumBytes=0x%x, Buffer @ 0x%08x)\n", Instance->StartLba + Lba, Offset, *NumBytes, Buffer));\r
+\r
+  if (!Instance->Initialized && Instance->Initialize) {\r
+    Instance->Initialize(Instance);\r
+  }\r
+\r
+  Status = EFI_SUCCESS;\r
+  TempStatus = Status;\r
+\r
+  // Cache the block size to avoid de-referencing pointers all the time\r
+  BlockSize = Instance->Media.BlockSize;\r
+\r
+  DEBUG ((DEBUG_BLKIO, "FvbRead: Check if (Offset=0x%x + NumBytes=0x%x) <= BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));\r
+\r
+  // The read must not span block boundaries.\r
+  // We need to check each variable individually because adding two large values together overflows.\r
+  if ((Offset               >= BlockSize) ||\r
+      (*NumBytes            >  BlockSize) ||\r
+      ((Offset + *NumBytes) >  BlockSize)) {\r
+    DEBUG ((EFI_D_ERROR, "FvbRead: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));\r
+    return EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  // We must have some bytes to read\r
+  if (*NumBytes == 0) {\r
+    return EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  // FixMe: Allow an arbitrary number of bytes to be read out, not just a multiple of block size.\r
+\r
+  // Allocate runtime memory to read in the NOR Flash data. Variable Services are runtime.\r
+  BlockBuffer = AllocateRuntimePool (BlockSize);\r
+\r
+  // Check if the memory allocation was successful\r
+  if (BlockBuffer == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "FvbRead: ERROR - Could not allocate BlockBuffer @ 0x%08x.\n", BlockBuffer));\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  // Read NOR Flash data into shadow buffer\r
+  TempStatus = NorFlashReadBlocks (Instance, Instance->StartLba + Lba, BlockSize, BlockBuffer);\r
+  if (EFI_ERROR (TempStatus)) {\r
+    // Return one of the pre-approved error statuses\r
+    Status = EFI_DEVICE_ERROR;\r
+    goto FREE_MEMORY;\r
+  }\r
+\r
+  // Put the data at the appropriate location inside the buffer area\r
+  DEBUG ((DEBUG_BLKIO, "FvbRead: CopyMem( Dst=0x%08x, Src=0x%08x, Size=0x%x ).\n", Buffer, BlockBuffer + Offset, *NumBytes));\r
+\r
+  CopyMem(Buffer, BlockBuffer + Offset, *NumBytes);\r
+\r
+FREE_MEMORY:\r
+  FreePool(BlockBuffer);\r
+  return Status;\r
+}\r
+\r
+/**\r
+ Writes the specified number of bytes from the input buffer to the block.\r
+\r
+ The Write() function writes the specified number of bytes from\r
+ the provided buffer to the specified block and offset. If the\r
+ firmware volume is sticky write, the caller must ensure that\r
+ all the bits of the specified range to write are in the\r
+ EFI_FVB_ERASE_POLARITY state before calling the Write()\r
+ function, or else the result will be unpredictable. This\r
+ unpredictability arises because, for a sticky-write firmware\r
+ volume, a write may negate a bit in the EFI_FVB_ERASE_POLARITY\r
+ state but cannot flip it back again.  Before calling the\r
+ Write() function,  it is recommended for the caller to first call\r
+ the EraseBlocks() function to erase the specified block to\r
+ write. A block erase cycle will transition bits from the\r
+ (NOT)EFI_FVB_ERASE_POLARITY state back to the\r
+ EFI_FVB_ERASE_POLARITY state. Implementations should be\r
+ mindful that the firmware volume might be in the WriteDisabled\r
+ state. If it is in this state, the Write() function must\r
+ return the status code EFI_ACCESS_DENIED without modifying the\r
+ contents of the firmware volume. The Write() function must\r
+ also prevent spanning block boundaries. If a write is\r
+ requested that spans a block boundary, the write must store up\r
+ to the boundary but not beyond. The output parameter NumBytes\r
+ must be set to correctly indicate the number of bytes actually\r
+ written. The caller must be aware that a write may be\r
+ partially completed. All writes, partial or otherwise, must be\r
+ fully flushed to the hardware before the Write() service\r
+ returns.\r
+\r
+ @param This                 Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r
+\r
+ @param Lba                  The starting logical block index to write to.\r
+\r
+ @param Offset               Offset into the block at which to begin writing.\r
+\r
+ @param NumBytes             The pointer to a UINTN.\r
+                             At entry, *NumBytes contains the total size of the buffer.\r
+                             At exit, *NumBytes contains the total number of bytes actually written.\r
+\r
+ @param Buffer               The pointer to a caller-allocated buffer that contains the source for the write.\r
+\r
+ @retval EFI_SUCCESS         The firmware volume was written successfully.\r
+\r
+ @retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundary.\r
+                             On output, NumBytes contains the total number of bytes\r
+                             actually written.\r
+\r
+ @retval EFI_ACCESS_DENIED   The firmware volume is in the WriteDisabled state.\r
+\r
+ @retval EFI_DEVICE_ERROR    The block device is malfunctioning and could not be written.\r
+\r
+\r
+ **/\r
+EFI_STATUS\r
+EFIAPI\r
+FvbWrite (\r
+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL   *This,\r
+  IN        EFI_LBA                               Lba,\r
+  IN        UINTN                                 Offset,\r
+  IN OUT    UINTN                                 *NumBytes,\r
+  IN        UINT8                                 *Buffer\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_STATUS  TempStatus;\r
+  UINTN       BlockSize;\r
+  UINT8       *BlockBuffer;\r
+  NOR_FLASH_INSTANCE *Instance;\r
+\r
+  Instance = INSTANCE_FROM_FVB_THIS(This);\r
+\r
+  if (!Instance->Initialized && Instance->Initialize) {\r
+    Instance->Initialize(Instance);\r
+  }\r
+\r
+  DEBUG ((DEBUG_BLKIO, "FvbWrite(Parameters: Lba=%ld, Offset=0x%x, *NumBytes=0x%x, Buffer @ 0x%08x)\n", Instance->StartLba + Lba, Offset, *NumBytes, Buffer));\r
+\r
+  Status = EFI_SUCCESS;\r
+  TempStatus = Status;\r
+\r
+  // Detect WriteDisabled state\r
+  if (Instance->Media.ReadOnly == TRUE) {\r
+    DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - Can not write: Device is in WriteDisabled state.\n"));\r
+    // It is in WriteDisabled state, return an error right away\r
+    return EFI_ACCESS_DENIED;\r
+  }\r
+\r
+  // Cache the block size to avoid de-referencing pointers all the time\r
+  BlockSize = Instance->Media.BlockSize;\r
+\r
+  // The write must not span block boundaries.\r
+  // We need to check each variable individually because adding two large values together overflows.\r
+  if ( ( Offset               >= BlockSize ) ||\r
+       ( *NumBytes            >  BlockSize ) ||\r
+       ( (Offset + *NumBytes) >  BlockSize )    ) {\r
+    DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));\r
+    return EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  // We must have some bytes to write\r
+  if (*NumBytes == 0) {\r
+    DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));\r
+    return EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  // Allocate runtime memory to read in the NOR Flash data.\r
+  // Since the intention is to use this with Variable Services and since these are runtime,\r
+  // allocate the memory from the runtime pool.\r
+  BlockBuffer = AllocateRuntimePool (BlockSize);\r
+\r
+  // Check we did get some memory\r
+  if( BlockBuffer == NULL ) {\r
+    DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - Can not allocate BlockBuffer @ 0x%08x.\n", BlockBuffer));\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  // Read NOR Flash data into shadow buffer\r
+  TempStatus = NorFlashReadBlocks (Instance, Instance->StartLba + Lba, BlockSize, BlockBuffer);\r
+  if (EFI_ERROR (TempStatus)) {\r
+    // Return one of the pre-approved error statuses\r
+    Status = EFI_DEVICE_ERROR;\r
+    goto FREE_MEMORY;\r
+  }\r
+\r
+  // Put the data at the appropriate location inside the buffer area\r
+  CopyMem((BlockBuffer + Offset), Buffer, *NumBytes);\r
+\r
+  // Write the modified buffer back to the NorFlash\r
+  Status = NorFlashWriteBlocks (Instance, Instance->StartLba + Lba, BlockSize, BlockBuffer);\r
+  if (EFI_ERROR (TempStatus)) {\r
+    // Return one of the pre-approved error statuses\r
+    Status = EFI_DEVICE_ERROR;\r
+    goto FREE_MEMORY;\r
+  }\r
+\r
+FREE_MEMORY:\r
+  FreePool(BlockBuffer);\r
+  return Status;\r
+}\r
+\r
+/**\r
+ Erases and initialises a firmware volume block.\r
+\r
+ The EraseBlocks() function erases one or more blocks as denoted\r
+ by the variable argument list. The entire parameter list of\r
+ blocks must be verified before erasing any blocks. If a block is\r
+ requested that does not exist within the associated firmware\r
+ volume (it has a larger index than the last block of the\r
+ firmware volume), the EraseBlocks() function must return the\r
+ status code EFI_INVALID_PARAMETER without modifying the contents\r
+ of the firmware volume. Implementations should be mindful that\r
+ the firmware volume might be in the WriteDisabled state. If it\r
+ is in this state, the EraseBlocks() function must return the\r
+ status code EFI_ACCESS_DENIED without modifying the contents of\r
+ the firmware volume. All calls to EraseBlocks() must be fully\r
+ flushed to the hardware before the EraseBlocks() service\r
+ returns.\r
+\r
+ @param This                     Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL\r
+ instance.\r
+\r
+ @param ...                      The variable argument list is a list of tuples.\r
+                                 Each tuple describes a range of LBAs to erase\r
+                                 and consists of the following:\r
+                                 - An EFI_LBA that indicates the starting LBA\r
+                                 - A UINTN that indicates the number of blocks to erase.\r
+\r
+                                 The list is terminated with an EFI_LBA_LIST_TERMINATOR.\r
+                                 For example, the following indicates that two ranges of blocks\r
+                                 (5-7 and 10-11) are to be erased:\r
+                                 EraseBlocks (This, 5, 3, 10, 2, EFI_LBA_LIST_TERMINATOR);\r
+\r
+ @retval EFI_SUCCESS             The erase request successfully completed.\r
+\r
+ @retval EFI_ACCESS_DENIED       The firmware volume is in the WriteDisabled state.\r
+\r
+ @retval EFI_DEVICE_ERROR        The block device is not functioning correctly and could not be written.\r
+                                 The firmware device may have been partially erased.\r
+\r
+ @retval EFI_INVALID_PARAMETER   One or more of the LBAs listed in the variable argument list do\r
+                                 not exist in the firmware volume.\r
+\r
+ **/\r
+EFI_STATUS\r
+EFIAPI\r
+FvbEraseBlocks (\r
+  IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,\r
+  ...\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  VA_LIST     Args;\r
+  UINTN       BlockAddress; // Physical address of Lba to erase\r
+  EFI_LBA     StartingLba; // Lba from which we start erasing\r
+  UINTN       NumOfLba; // Number of Lba blocks to erase\r
+  NOR_FLASH_INSTANCE *Instance;\r
+\r
+  Instance = INSTANCE_FROM_FVB_THIS(This);\r
+\r
+  DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks()\n"));\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+  // Detect WriteDisabled state\r
+  if (Instance->Media.ReadOnly == TRUE) {\r
+    // Firmware volume is in WriteDisabled state\r
+    DEBUG ((EFI_D_ERROR, "FvbEraseBlocks: ERROR - Device is in WriteDisabled state.\n"));\r
+    return EFI_ACCESS_DENIED;\r
+  }\r
+\r
+  // Before erasing, check the entire list of parameters to ensure all specified blocks are valid\r
+\r
+  VA_START (Args, This);\r
+  do {\r
+    // Get the Lba from which we start erasing\r
+    StartingLba = VA_ARG (Args, EFI_LBA);\r
+\r
+    // Have we reached the end of the list?\r
+    if (StartingLba == EFI_LBA_LIST_TERMINATOR) {\r
+      //Exit the while loop\r
+      break;\r
+    }\r
+\r
+    // How many Lba blocks are we requested to erase?\r
+    NumOfLba = VA_ARG (Args, UINT32);\r
+\r
+    // All blocks must be within range\r
+    DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks: Check if: ( StartingLba=%ld + NumOfLba=%d - 1 ) > LastBlock=%ld.\n", Instance->StartLba + StartingLba, NumOfLba, Instance->Media.LastBlock));\r
+    if ((NumOfLba == 0) || ((Instance->StartLba + StartingLba + NumOfLba - 1) > Instance->Media.LastBlock)) {\r
+      VA_END (Args);\r
+      DEBUG ((EFI_D_ERROR, "FvbEraseBlocks: ERROR - Lba range goes past the last Lba.\n"));\r
+      Status = EFI_INVALID_PARAMETER;\r
+      goto EXIT;\r
+    }\r
+  } while (TRUE);\r
+  VA_END (Args);\r
+\r
+  //\r
+  // To get here, all must be ok, so start erasing\r
+  //\r
+  VA_START (Args, This);\r
+  do {\r
+    // Get the Lba from which we start erasing\r
+    StartingLba = VA_ARG (Args, EFI_LBA);\r
+\r
+    // Have we reached the end of the list?\r
+    if (StartingLba == EFI_LBA_LIST_TERMINATOR) {\r
+      // Exit the while loop\r
+      break;\r
+    }\r
+\r
+    // How many Lba blocks are we requested to erase?\r
+    NumOfLba = VA_ARG (Args, UINT32);\r
+\r
+    // Go through each one and erase it\r
+    while (NumOfLba > 0) {\r
+\r
+      // Get the physical address of Lba to erase\r
+      BlockAddress = GET_NOR_BLOCK_ADDRESS (\r
+          Instance->RegionBaseAddress,\r
+          Instance->StartLba + StartingLba,\r
+          Instance->Media.BlockSize\r
+      );\r
+\r
+      // Erase it\r
+      DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks: Erasing Lba=%ld @ 0x%08x.\n", Instance->StartLba + StartingLba, BlockAddress));\r
+      Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress);\r
+      if (EFI_ERROR(Status)) {\r
+        VA_END (Args);\r
+        Status = EFI_DEVICE_ERROR;\r
+        goto EXIT;\r
+      }\r
+\r
+      // Move to the next Lba\r
+      StartingLba++;\r
+      NumOfLba--;\r
+    }\r
+  } while (TRUE);\r
+  VA_END (Args);\r
+\r
+EXIT:\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+NorFlashFvbInitialize (\r
+  IN NOR_FLASH_INSTANCE* Instance\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT32      FvbNumLba;\r
+  EFI_BOOT_MODE BootMode;\r
+\r
+  DEBUG((DEBUG_BLKIO,"NorFlashFvbInitialize\n"));\r
+\r
+  Instance->Initialized = TRUE;\r
+\r
+  // Set the index of the first LBA for the FVB\r
+  Instance->StartLba = (PcdGet32 (PcdFlashNvStorageVariableBase) - Instance->RegionBaseAddress) / Instance->Media.BlockSize;\r
+\r
+  BootMode = GetBootModeHob ();\r
+  if (BootMode == BOOT_WITH_DEFAULT_SETTINGS) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+  } else {\r
+    // Determine if there is a valid header at the beginning of the NorFlash\r
+    Status = ValidateFvHeader (Instance);\r
+  }\r
+\r
+  // Install the Default FVB header if required  \r
+  if (EFI_ERROR(Status)) {\r
+    // There is no valid header, so time to install one.\r
+    DEBUG((EFI_D_ERROR,"NorFlashFvbInitialize: ERROR - The FVB Header is not valid. Installing a correct one for this volume.\n"));\r
+\r
+    // Erase all the NorFlash that is reserved for variable storage\r
+    FvbNumLba = (PcdGet32(PcdFlashNvStorageVariableSize) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) + PcdGet32(PcdFlashNvStorageFtwSpareSize)) / Instance->Media.BlockSize;\r
+\r
+    Status = FvbEraseBlocks (&Instance->FvbProtocol, (EFI_LBA)0, FvbNumLba, EFI_LBA_LIST_TERMINATOR);\r
+    if (EFI_ERROR(Status)) {\r
+      return Status;\r
+    }\r
+\r
+    // Install all appropriate headers\r
+    Status = InitializeFvAndVariableStoreHeaders (Instance);\r
+    if (EFI_ERROR(Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+  return Status;\r
+}\r
index cb811d89d6740c5e498764a6fd141730dbbf16b6..ff05662b885d71611adafe7aeeaa97eec6faf872 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011, ARM Limited. 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 <PiDxe.h>
-
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/DebugLib.h>
-#include <Library/IoLib.h>
-#include <Library/PcdLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-
-#include <Protocol/EmbeddedGpio.h>
-#include <Drivers/PL061Gpio.h>
-
-BOOLEAN     mPL061Initialized = FALSE;
-
-/**
-  Function implementations
-**/
-
-EFI_STATUS
-PL061Identify (
-  VOID
-  )
-{
-  // Check if this is a PrimeCell Peripheral
-  if (    (MmioRead8 (PL061_GPIO_PCELL_ID0) != 0x0D)
-      ||  (MmioRead8 (PL061_GPIO_PCELL_ID1) != 0xF0)
-      ||  (MmioRead8 (PL061_GPIO_PCELL_ID2) != 0x05)
-      ||  (MmioRead8 (PL061_GPIO_PCELL_ID3) != 0xB1)) {
-    return EFI_NOT_FOUND;
-  }
-
-  // Check if this PrimeCell Peripheral is the PL061 GPIO
-  if (    (MmioRead8 (PL061_GPIO_PERIPH_ID0) != 0x61)
-      ||  (MmioRead8 (PL061_GPIO_PERIPH_ID1) != 0x10)
-      ||  ((MmioRead8 (PL061_GPIO_PERIPH_ID2) & 0xF) != 0x04)
-      ||  (MmioRead8 (PL061_GPIO_PERIPH_ID3) != 0x00)) {
-    return EFI_NOT_FOUND;
-  }
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-PL061Initialize (
-  VOID
-  )
-{
-  EFI_STATUS  Status;
-
-  // Check if the PL061 GPIO module exists on board
-  Status = PL061Identify();
-  if (EFI_ERROR (Status)) {
-    Status = EFI_DEVICE_ERROR;
-    goto EXIT;
-  }
-
-  // Do other hardware initialisation things here as required
-
-  // Disable Interrupts
-  //if (MmioRead8 (PL061_GPIO_IE_REG) != 0) {
-  //   // Ensure interrupts are disabled
-  //}
-
-  mPL061Initialized = TRUE;
-
-  EXIT:
-  return Status;
-}
-
-/**
-
-Routine Description:
-
-  Gets the state of a GPIO pin
-
-Arguments:
-
-  This  - pointer to protocol
-  Gpio  - which pin to read
-  Value - state of the pin
-
-Returns:
-
-  EFI_SUCCESS           - GPIO state returned in Value
-  EFI_INVALID_PARAMETER - Value is NULL pointer or Gpio pin is out of range
-**/
-EFI_STATUS
-EFIAPI
-Get (
-  IN  EMBEDDED_GPIO     *This,
-  IN  EMBEDDED_GPIO_PIN Gpio,
-  OUT UINTN             *Value
-  )
-{
-  EFI_STATUS    Status = EFI_SUCCESS;
-
-  if (    (Value == NULL)
-      ||  (Gpio > LAST_GPIO_PIN))
-  {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  // Initialize the hardware if not already done
-  if (!mPL061Initialized) {
-    Status = PL061Initialize();
-    if (EFI_ERROR(Status)) {
-      goto EXIT;
-    }
-  }
-
-  if (MmioRead8 (PL061_GPIO_DATA_REG) & GPIO_PIN_MASK_HIGH_8BIT(Gpio)) {
-    *Value = 1;
-  } else {
-    *Value = 0;
-  }
-
-  EXIT:
-  return Status;
-}
-
-/**
-
-Routine Description:
-
-  Sets the state of a GPIO pin
-
-Arguments:
-
-  This  - pointer to protocol
-  Gpio  - which pin to modify
-  Mode  - mode to set
-
-Returns:
-
-  EFI_SUCCESS           - GPIO set as requested
-  EFI_UNSUPPORTED       - Mode is not supported
-  EFI_INVALID_PARAMETER - Gpio pin is out of range
-**/
-EFI_STATUS
-EFIAPI
-Set (
-  IN  EMBEDDED_GPIO       *This,
-  IN  EMBEDDED_GPIO_PIN   Gpio,
-  IN  EMBEDDED_GPIO_MODE  Mode
-  )
-{
-  EFI_STATUS    Status = EFI_SUCCESS;
-
-  // Check for errors
-  if (Gpio > LAST_GPIO_PIN) {
-    Status = EFI_INVALID_PARAMETER;
-    goto EXIT;
-  }
-
-  // Initialize the hardware if not already done
-  if (!mPL061Initialized) {
-    Status = PL061Initialize();
-    if (EFI_ERROR(Status)) {
-      goto EXIT;
-    }
-  }
-
-  switch (Mode)
-  {
-    case GPIO_MODE_INPUT:
-      // Set the corresponding direction bit to LOW for input
-      MmioAnd8 (PL061_GPIO_DIR_REG, GPIO_PIN_MASK_LOW_8BIT(Gpio));
-      break;
-
-    case GPIO_MODE_OUTPUT_0:
-      // Set the corresponding data bit to LOW for 0
-      MmioAnd8 (PL061_GPIO_DATA_REG, GPIO_PIN_MASK_LOW_8BIT(Gpio));
-      // Set the corresponding direction bit to HIGH for output
-      MmioOr8 (PL061_GPIO_DIR_REG, GPIO_PIN_MASK_HIGH_8BIT(Gpio));
-      break;
-
-    case GPIO_MODE_OUTPUT_1:
-      // Set the corresponding data bit to HIGH for 1
-      MmioOr8 (PL061_GPIO_DATA_REG, GPIO_PIN_MASK_HIGH_8BIT(Gpio));
-      // Set the corresponding direction bit to HIGH for output
-      MmioOr8 (PL061_GPIO_DIR_REG, GPIO_PIN_MASK_HIGH_8BIT(Gpio));
-      break;
-
-    default:
-      // Other modes are not supported
-      return EFI_UNSUPPORTED;
-  }
-
-EXIT:
-  return Status;
-}
-
-/**
-
-Routine Description:
-
-  Gets the mode (function) of a GPIO pin
-
-Arguments:
-
-  This  - pointer to protocol
-  Gpio  - which pin
-  Mode  - pointer to output mode value
-
-Returns:
-
-  EFI_SUCCESS           - mode value retrieved
-  EFI_INVALID_PARAMETER - Mode is a null pointer or Gpio pin is out of range
-
-**/
-EFI_STATUS
-EFIAPI
-GetMode (
-  IN  EMBEDDED_GPIO       *This,
-  IN  EMBEDDED_GPIO_PIN   Gpio,
-  OUT EMBEDDED_GPIO_MODE  *Mode
-  )
-{
-  EFI_STATUS Status;
-
-  // Check for errors
-  if (    (Mode == NULL)
-      ||  (Gpio > LAST_GPIO_PIN)) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  // Initialize the hardware if not already done
-  if (!mPL061Initialized) {
-    Status = PL061Initialize();
-    if (EFI_ERROR(Status)) {
-      return Status;
-    }
-  }
-
-  // Check if it is input or output
-  if (MmioRead8 (PL061_GPIO_DIR_REG) & GPIO_PIN_MASK_HIGH_8BIT(Gpio)) {
-    // Pin set to output
-    if (MmioRead8 (PL061_GPIO_DATA_REG) & GPIO_PIN_MASK_HIGH_8BIT(Gpio)) {
-      *Mode = GPIO_MODE_OUTPUT_1;
-    } else {
-      *Mode = GPIO_MODE_OUTPUT_0;
-    }
-  } else {
-    // Pin set to input
-    *Mode = GPIO_MODE_INPUT;
-  }
-
-  return EFI_SUCCESS;
-}
-
-/**
-
-Routine Description:
-
-  Sets the pull-up / pull-down resistor of a GPIO pin
-
-Arguments:
-
-  This  - pointer to protocol
-  Gpio  - which pin
-  Direction - pull-up, pull-down, or none
-
-Returns:
-
-  EFI_UNSUPPORTED - Can not perform the requested operation
-
-**/
-EFI_STATUS
-EFIAPI
-SetPull (
-  IN  EMBEDDED_GPIO       *This,
-  IN  EMBEDDED_GPIO_PIN   Gpio,
-  IN  EMBEDDED_GPIO_PULL  Direction
-  )
-{
-  return EFI_UNSUPPORTED;
-}
-
-/**
- Protocol variable definition
- **/
-EMBEDDED_GPIO gGpio = {
-  Get,
-  Set,
-  GetMode,
-  SetPull
-};
-
-/**
-  Initialize the state information for the Embedded Gpio protocol.
-
-  @param  ImageHandle   of the loaded driver
-  @param  SystemTable   Pointer to the System Table
-
-  @retval EFI_SUCCESS           Protocol registered
-  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure
-  @retval EFI_DEVICE_ERROR      Hardware problems
-
-**/
-EFI_STATUS
-EFIAPI
-PL061InstallProtocol (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
-  )
-{
-  EFI_STATUS  Status;
-  EFI_HANDLE  Handle;
-
-  //
-  // Make sure the Gpio protocol has not been installed in the system yet.
-  //
-  ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEmbeddedGpioProtocolGuid);
-
-  // Install the Embedded GPIO Protocol onto a new handle
-  Handle = NULL;
-  Status = gBS->InstallMultipleProtocolInterfaces(
-                  &Handle,
-                  &gEmbeddedGpioProtocolGuid, &gGpio,
-                  NULL
-                 );
-  if (EFI_ERROR(Status)) {
-    Status = EFI_OUT_OF_RESOURCES;
-  }
-
-  return Status;
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+*\r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*\r
+**/\r
+\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+\r
+#include <Protocol/EmbeddedGpio.h>\r
+#include <Drivers/PL061Gpio.h>\r
+\r
+BOOLEAN     mPL061Initialized = FALSE;\r
+\r
+/**\r
+  Function implementations\r
+**/\r
+\r
+EFI_STATUS\r
+PL061Identify (\r
+  VOID\r
+  )\r
+{\r
+  // Check if this is a PrimeCell Peripheral\r
+  if (    (MmioRead8 (PL061_GPIO_PCELL_ID0) != 0x0D)\r
+      ||  (MmioRead8 (PL061_GPIO_PCELL_ID1) != 0xF0)\r
+      ||  (MmioRead8 (PL061_GPIO_PCELL_ID2) != 0x05)\r
+      ||  (MmioRead8 (PL061_GPIO_PCELL_ID3) != 0xB1)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  // Check if this PrimeCell Peripheral is the PL061 GPIO\r
+  if (    (MmioRead8 (PL061_GPIO_PERIPH_ID0) != 0x61)\r
+      ||  (MmioRead8 (PL061_GPIO_PERIPH_ID1) != 0x10)\r
+      ||  ((MmioRead8 (PL061_GPIO_PERIPH_ID2) & 0xF) != 0x04)\r
+      ||  (MmioRead8 (PL061_GPIO_PERIPH_ID3) != 0x00)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+PL061Initialize (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  // Check if the PL061 GPIO module exists on board\r
+  Status = PL061Identify();\r
+  if (EFI_ERROR (Status)) {\r
+    Status = EFI_DEVICE_ERROR;\r
+    goto EXIT;\r
+  }\r
+\r
+  // Do other hardware initialisation things here as required\r
+\r
+  // Disable Interrupts\r
+  //if (MmioRead8 (PL061_GPIO_IE_REG) != 0) {\r
+  //   // Ensure interrupts are disabled\r
+  //}\r
+\r
+  mPL061Initialized = TRUE;\r
+\r
+  EXIT:\r
+  return Status;\r
+}\r
+\r
+/**\r
+\r
+Routine Description:\r
+\r
+  Gets the state of a GPIO pin\r
+\r
+Arguments:\r
+\r
+  This  - pointer to protocol\r
+  Gpio  - which pin to read\r
+  Value - state of the pin\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - GPIO state returned in Value\r
+  EFI_INVALID_PARAMETER - Value is NULL pointer or Gpio pin is out of range\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Get (\r
+  IN  EMBEDDED_GPIO     *This,\r
+  IN  EMBEDDED_GPIO_PIN Gpio,\r
+  OUT UINTN             *Value\r
+  )\r
+{\r
+  EFI_STATUS    Status = EFI_SUCCESS;\r
+\r
+  if (    (Value == NULL)\r
+      ||  (Gpio > LAST_GPIO_PIN))\r
+  {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  // Initialize the hardware if not already done\r
+  if (!mPL061Initialized) {\r
+    Status = PL061Initialize();\r
+    if (EFI_ERROR(Status)) {\r
+      goto EXIT;\r
+    }\r
+  }\r
+\r
+  if (MmioRead8 (PL061_GPIO_DATA_REG) & GPIO_PIN_MASK_HIGH_8BIT(Gpio)) {\r
+    *Value = 1;\r
+  } else {\r
+    *Value = 0;\r
+  }\r
+\r
+  EXIT:\r
+  return Status;\r
+}\r
+\r
+/**\r
+\r
+Routine Description:\r
+\r
+  Sets the state of a GPIO pin\r
+\r
+Arguments:\r
+\r
+  This  - pointer to protocol\r
+  Gpio  - which pin to modify\r
+  Mode  - mode to set\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - GPIO set as requested\r
+  EFI_UNSUPPORTED       - Mode is not supported\r
+  EFI_INVALID_PARAMETER - Gpio pin is out of range\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Set (\r
+  IN  EMBEDDED_GPIO       *This,\r
+  IN  EMBEDDED_GPIO_PIN   Gpio,\r
+  IN  EMBEDDED_GPIO_MODE  Mode\r
+  )\r
+{\r
+  EFI_STATUS    Status = EFI_SUCCESS;\r
+\r
+  // Check for errors\r
+  if (Gpio > LAST_GPIO_PIN) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto EXIT;\r
+  }\r
+\r
+  // Initialize the hardware if not already done\r
+  if (!mPL061Initialized) {\r
+    Status = PL061Initialize();\r
+    if (EFI_ERROR(Status)) {\r
+      goto EXIT;\r
+    }\r
+  }\r
+\r
+  switch (Mode)\r
+  {\r
+    case GPIO_MODE_INPUT:\r
+      // Set the corresponding direction bit to LOW for input\r
+      MmioAnd8 (PL061_GPIO_DIR_REG, GPIO_PIN_MASK_LOW_8BIT(Gpio));\r
+      break;\r
+\r
+    case GPIO_MODE_OUTPUT_0:\r
+      // Set the corresponding data bit to LOW for 0\r
+      MmioAnd8 (PL061_GPIO_DATA_REG, GPIO_PIN_MASK_LOW_8BIT(Gpio));\r
+      // Set the corresponding direction bit to HIGH for output\r
+      MmioOr8 (PL061_GPIO_DIR_REG, GPIO_PIN_MASK_HIGH_8BIT(Gpio));\r
+      break;\r
+\r
+    case GPIO_MODE_OUTPUT_1:\r
+      // Set the corresponding data bit to HIGH for 1\r
+      MmioOr8 (PL061_GPIO_DATA_REG, GPIO_PIN_MASK_HIGH_8BIT(Gpio));\r
+      // Set the corresponding direction bit to HIGH for output\r
+      MmioOr8 (PL061_GPIO_DIR_REG, GPIO_PIN_MASK_HIGH_8BIT(Gpio));\r
+      break;\r
+\r
+    default:\r
+      // Other modes are not supported\r
+      return EFI_UNSUPPORTED;\r
+  }\r
+\r
+EXIT:\r
+  return Status;\r
+}\r
+\r
+/**\r
+\r
+Routine Description:\r
+\r
+  Gets the mode (function) of a GPIO pin\r
+\r
+Arguments:\r
+\r
+  This  - pointer to protocol\r
+  Gpio  - which pin\r
+  Mode  - pointer to output mode value\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - mode value retrieved\r
+  EFI_INVALID_PARAMETER - Mode is a null pointer or Gpio pin is out of range\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetMode (\r
+  IN  EMBEDDED_GPIO       *This,\r
+  IN  EMBEDDED_GPIO_PIN   Gpio,\r
+  OUT EMBEDDED_GPIO_MODE  *Mode\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  // Check for errors\r
+  if (    (Mode == NULL)\r
+      ||  (Gpio > LAST_GPIO_PIN)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  // Initialize the hardware if not already done\r
+  if (!mPL061Initialized) {\r
+    Status = PL061Initialize();\r
+    if (EFI_ERROR(Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  // Check if it is input or output\r
+  if (MmioRead8 (PL061_GPIO_DIR_REG) & GPIO_PIN_MASK_HIGH_8BIT(Gpio)) {\r
+    // Pin set to output\r
+    if (MmioRead8 (PL061_GPIO_DATA_REG) & GPIO_PIN_MASK_HIGH_8BIT(Gpio)) {\r
+      *Mode = GPIO_MODE_OUTPUT_1;\r
+    } else {\r
+      *Mode = GPIO_MODE_OUTPUT_0;\r
+    }\r
+  } else {\r
+    // Pin set to input\r
+    *Mode = GPIO_MODE_INPUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+\r
+Routine Description:\r
+\r
+  Sets the pull-up / pull-down resistor of a GPIO pin\r
+\r
+Arguments:\r
+\r
+  This  - pointer to protocol\r
+  Gpio  - which pin\r
+  Direction - pull-up, pull-down, or none\r
+\r
+Returns:\r
+\r
+  EFI_UNSUPPORTED - Can not perform the requested operation\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SetPull (\r
+  IN  EMBEDDED_GPIO       *This,\r
+  IN  EMBEDDED_GPIO_PIN   Gpio,\r
+  IN  EMBEDDED_GPIO_PULL  Direction\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+ Protocol variable definition\r
+ **/\r
+EMBEDDED_GPIO gGpio = {\r
+  Get,\r
+  Set,\r
+  GetMode,\r
+  SetPull\r
+};\r
+\r
+/**\r
+  Initialize the state information for the Embedded Gpio protocol.\r
+\r
+  @param  ImageHandle   of the loaded driver\r
+  @param  SystemTable   Pointer to the System Table\r
+\r
+  @retval EFI_SUCCESS           Protocol registered\r
+  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure\r
+  @retval EFI_DEVICE_ERROR      Hardware problems\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PL061InstallProtocol (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_HANDLE  Handle;\r
+\r
+  //\r
+  // Make sure the Gpio protocol has not been installed in the system yet.\r
+  //\r
+  ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEmbeddedGpioProtocolGuid);\r
+\r
+  // Install the Embedded GPIO Protocol onto a new handle\r
+  Handle = NULL;\r
+  Status = gBS->InstallMultipleProtocolInterfaces(\r
+                  &Handle,\r
+                  &gEmbeddedGpioProtocolGuid, &gGpio,\r
+                  NULL\r
+                 );\r
+  if (EFI_ERROR(Status)) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  return Status;\r
+}\r
index b5adda3a8928b6988a0a852473965ce808e8a976..49284d0a079b81f24f6c5cd9a5bf850b470bc6ca 100644 (file)
@@ -1,50 +1,50 @@
-/** @file
-*
-*  Copyright (c) 2011, ARM Limited. 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                      = PL061GpioDxe
-  FILE_GUID                      = 5c1997d7-8d45-4f21-af3c-2206b8ed8bec
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-
-  ENTRY_POINT                    = PL061InstallProtocol
-[Sources.common]
-  PL061Gpio.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  ArmPkg/ArmPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  BaseLib
-  BaseMemoryLib
-  DebugLib
-  IoLib
-  PcdLib
-  UefiBootServicesTableLib
-  UefiDriverEntryPoint
-  UefiLib
-  UefiRuntimeServicesTableLib
-
-[Pcd]
-  gArmPlatformTokenSpaceGuid.PcdPL061GpioBase
-
-[Protocols]
-  gEmbeddedGpioProtocolGuid  
-
-[Depex]
-  TRUE
+/** @file\r
+*\r
+*  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PL061GpioDxe\r
+  FILE_GUID                      = 5c1997d7-8d45-4f21-af3c-2206b8ed8bec\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = PL061InstallProtocol\r
+[Sources.common]\r
+  PL061Gpio.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  IoLib\r
+  PcdLib\r
+  UefiBootServicesTableLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  UefiRuntimeServicesTableLib\r
+\r
+[Pcd]\r
+  gArmPlatformTokenSpaceGuid.PcdPL061GpioBase\r
+\r
+[Protocols]\r
+  gEmbeddedGpioProtocolGuid  \r
+\r
+[Depex]\r
+  TRUE\r
index 71b7a32d6d8e3384e0bb44173f2cfcb0a62dc223..839d34d41437d23bf583c99660d97b7f62fd4704 100644 (file)
-/** @file
-  Template for Timer Architecture Protocol driver of the ARM flavor
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
-  
-  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 <PiDxe.h>
-
-#include <Library/BaseLib.h>
-#include <Library/DebugLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiLib.h>
-#include <Library/PcdLib.h>
-#include <Library/IoLib.h>
-
-#include <Protocol/Timer.h>
-#include <Protocol/HardwareInterrupt.h>
-
-#include <Drivers/SP804Timer.h>
-
-#define SP804_TIMER_PERIODIC_BASE     ((UINTN)PcdGet32 (PcdSP804TimerPeriodicBase))
-#define SP804_TIMER_METRONOME_BASE    ((UINTN)PcdGet32 (PcdSP804TimerMetronomeBase))
-#define SP804_TIMER_PERFORMANCE_BASE  ((UINTN)PcdGet32 (PcdSP804TimerPerformanceBase))
-
-// The notification function to call on every timer interrupt.
-EFI_TIMER_NOTIFY      mTimerNotifyFunction     = (EFI_TIMER_NOTIFY)NULL;
-EFI_EVENT             EfiExitBootServicesEvent = (EFI_EVENT)NULL;
-
-// The current period of the timer interrupt
-UINT64 mTimerPeriod = 0;
-
-// Cached copy of the Hardware Interrupt protocol instance
-EFI_HARDWARE_INTERRUPT_PROTOCOL *gInterrupt = NULL;
-
-// Cached interrupt vector
-UINTN  gVector;
-
-
-/**
-
-  C Interrupt Handler called in the interrupt context when Source interrupt is active.
-
-
-  @param Source         Source of the interrupt. Hardware routing off a specific platform defines
-                        what source means.
-
-  @param SystemContext  Pointer to system register context. Mostly used by debuggers and will
-                        update the system context after the return from the interrupt if 
-                        modified. Don't change these values unless you know what you are doing
-
-**/
-VOID
-EFIAPI
-TimerInterruptHandler (
-  IN  HARDWARE_INTERRUPT_SOURCE   Source,
-  IN  EFI_SYSTEM_CONTEXT          SystemContext       
-  )
-{
-  EFI_TPL OriginalTPL;
-
-  //
-  // DXE core uses this callback for the EFI timer tick. The DXE core uses locks 
-  // that raise to TPL_HIGH and then restore back to current level. Thus we need
-  // to make sure TPL level is set to TPL_HIGH while we are handling the timer tick. 
-  //
-  OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);
-
-  // If the interrupt is shared then we must check if this interrupt source is the one associated to this Timer
-  if (MmioRead32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_MSK_INT_STS_REG) != 0) {
-    // Clear the periodic interrupt
-    MmioWrite32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_INT_CLR_REG, 0);
-
-    // Signal end of interrupt early to help avoid losing subsequent ticks from long duration handlers
-    gInterrupt->EndOfInterrupt (gInterrupt, Source);
-
-    if (mTimerNotifyFunction) {
-      mTimerNotifyFunction (mTimerPeriod);
-    }
-  }
-
-  gBS->RestoreTPL (OriginalTPL);
-}
-
-/**
-  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.
-
-  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.
-  @param  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.
-  @retval EFI_SUCCESS           The timer handler was registered.
-  @retval EFI_UNSUPPORTED       The platform does not support timer interrupts.
-  @retval EFI_ALREADY_STARTED   NotifyFunction is not NULL, and a handler is already
-                                registered.
-  @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not
-                                previously registered.
-  @retval EFI_DEVICE_ERROR      The timer handler could not be registered.
-
-**/
-EFI_STATUS
-EFIAPI
-TimerDriverRegisterHandler (
-  IN EFI_TIMER_ARCH_PROTOCOL  *This,
-  IN EFI_TIMER_NOTIFY         NotifyFunction
-  )
-{
-  if ((NotifyFunction == NULL) && (mTimerNotifyFunction == NULL)) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  if ((NotifyFunction != NULL) && (mTimerNotifyFunction != NULL)) {
-    return EFI_ALREADY_STARTED;
-  }
-
-  mTimerNotifyFunction = NotifyFunction;
-
-  return EFI_SUCCESS;
-}
-
-/**
-    Make sure all Dual Timers are disabled
-**/
-VOID
-EFIAPI
-ExitBootServicesEvent (
-  IN EFI_EVENT  Event,
-  IN VOID       *Context
-  )
-{
-  // Disable 'Periodic Operation' timer if enabled
-  if (MmioRead32(SP804_TIMER_PERIODIC_BASE + SP804_TIMER_CONTROL_REG) & SP804_TIMER_CTRL_ENABLE) {
-    MmioAnd32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_CONTROL_REG, 0);
-  }
-
-  // Disable 'Metronome/Delay' timer if enabled
-  if (MmioRead32(SP804_TIMER_METRONOME_BASE + SP804_TIMER_CONTROL_REG) & SP804_TIMER_CTRL_ENABLE) {
-    MmioAnd32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CONTROL_REG, 0);
-  }
-
-  // Disable 'Performance' timer if enabled
-  if (MmioRead32(SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CONTROL_REG) & SP804_TIMER_CTRL_ENABLE) {
-    MmioAnd32 (SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CONTROL_REG, 0);
-  }
-}
-
-/**
-
-  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. 
-
-  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.
-  @param  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.
-
-
-  @retval EFI_SUCCESS           The timer period was changed.
-  @retval EFI_UNSUPPORTED       The platform cannot change the period of the timer interrupt.
-  @retval EFI_DEVICE_ERROR      The timer period could not be changed due to a device error.
-
-**/
-EFI_STATUS
-EFIAPI
-TimerDriverSetTimerPeriod (
-  IN EFI_TIMER_ARCH_PROTOCOL  *This,
-  IN UINT64                   TimerPeriod
-  )
-{
-  EFI_STATUS  Status;
-  UINT64      TimerTicks;
-  
-  // always disable the timer
-  MmioAnd32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_CONTROL_REG, ~SP804_TIMER_CTRL_ENABLE);
-
-  if (TimerPeriod == 0) {
-    // Leave timer disabled from above, and...
-
-    // Disable timer 0/1 interrupt for a TimerPeriod of 0
-    Status = gInterrupt->DisableInterruptSource (gInterrupt, gVector);    
-  } else {  
-    // Convert TimerPeriod into 1MHz clock counts (us units = 100ns units * 10)
-    TimerTicks = DivU64x32 (TimerPeriod, 10);
-    TimerTicks = MultU64x32 (TimerTicks, PcdGet32(PcdSP804TimerFrequencyInMHz));
-
-    // if it's larger than 32-bits, pin to highest value
-    if (TimerTicks > 0xffffffff) {
-      TimerTicks = 0xffffffff;
-    }
-
-    // Program the SP804 timer with the new count value
-    MmioWrite32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_LOAD_REG, TimerTicks);
-
-    // enable the timer
-    MmioOr32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_ENABLE);
-
-    // enable timer 0/1 interrupts
-    Status = gInterrupt->EnableInterruptSource (gInterrupt, gVector);    
-  }
-
-  // Save the new timer period
-  mTimerPeriod = TimerPeriod;
-  return Status;
-}
-
-/**
-  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.
-
-  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.
-  @param  TimerPeriod      A pointer to the timer period to retrieve in 100 ns units. If
-                           0 is returned, then the timer is currently disabled.
-
-
-  @retval EFI_SUCCESS           The timer period was returned in TimerPeriod.
-  @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
-
-**/
-EFI_STATUS
-EFIAPI
-TimerDriverGetTimerPeriod (
-  IN EFI_TIMER_ARCH_PROTOCOL   *This,
-  OUT UINT64                   *TimerPeriod
-  )
-{
-  if (TimerPeriod == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  *TimerPeriod = mTimerPeriod;
-  return EFI_SUCCESS;
-}
-
-/**
-  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.
-
-  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.
-
-  @retval EFI_SUCCESS           The soft timer interrupt was generated.
-  @retval EFI_UNSUPPORTED       The platform does not support the generation of soft timer interrupts.
-
-**/
-EFI_STATUS
-EFIAPI
-TimerDriverGenerateSoftInterrupt (
-  IN EFI_TIMER_ARCH_PROTOCOL  *This
-  )
-{
-  return EFI_UNSUPPORTED;
-}
-
-/**
-  Interface structure for the Timer Architectural Protocol.
-
-  @par Protocol Description:
-  This protocol provides the services to initialize a periodic timer 
-  interrupt, and to register a handler that is called each time the timer
-  interrupt fires.  It may also provide a service to adjust the rate of the
-  periodic timer interrupt.  When a timer interrupt occurs, the handler is 
-  passed the amount of time that has passed since the previous timer 
-  interrupt.
-
-  @param RegisterHandler
-  Registers a handler that will be called each time the 
-  timer interrupt fires.  TimerPeriod defines the minimum 
-  time between timer interrupts, so TimerPeriod will also 
-  be the minimum time between calls to the registered 
-  handler.
-
-  @param SetTimerPeriod
-  Sets the period of the timer interrupt in 100 nS units.  
-  This function is optional, and may return EFI_UNSUPPORTED.  
-  If this function is supported, then the timer period will 
-  be rounded up to the nearest supported timer period.
-
-
-  @param GetTimerPeriod
-  Retrieves the period of the timer interrupt in 100 nS units.
-
-  @param GenerateSoftInterrupt
-  Generates a soft timer interrupt that simulates the firing of 
-  the timer interrupt. This service can be used to invoke the   registered handler if the timer interrupt has been masked for 
-  a period of time.
-
-**/
-EFI_TIMER_ARCH_PROTOCOL   gTimer = {
-  TimerDriverRegisterHandler,
-  TimerDriverSetTimerPeriod,
-  TimerDriverGetTimerPeriod,
-  TimerDriverGenerateSoftInterrupt
-};
-
-
-/**
-  Initialize the state information for the Timer Architectural Protocol and
-  the Timer Debug support protocol that allows the debugger to break into a
-  running program.
-
-  @param  ImageHandle   of the loaded driver
-  @param  SystemTable   Pointer to the System Table
-
-  @retval EFI_SUCCESS           Protocol registered
-  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure
-  @retval EFI_DEVICE_ERROR      Hardware problems
-
-**/
-EFI_STATUS
-EFIAPI
-TimerInitialize (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
-  )
-{
-  EFI_HANDLE  Handle = NULL;
-  EFI_STATUS  Status;
-
-  // Set the interrupt timer number
-  gVector = PcdGet32(PcdSP804TimerPeriodicInterruptNum);
-
-  // Find the interrupt controller protocol.  ASSERT if not found.
-  Status = gBS->LocateProtocol (&gHardwareInterruptProtocolGuid, NULL, (VOID **)&gInterrupt);
-  ASSERT_EFI_ERROR (Status);
-
-  // Disable the timer
-  Status = TimerDriverSetTimerPeriod (&gTimer, 0);
-  ASSERT_EFI_ERROR (Status);
-
-  // Install interrupt handler
-  Status = gInterrupt->RegisterInterruptSource (gInterrupt, gVector, TimerInterruptHandler);
-  ASSERT_EFI_ERROR (Status);
-
-  // configure timer 0 for periodic operation, 32 bits, no prescaler, and interrupt enabled
-  MmioWrite32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_PERIODIC | SP804_TIMER_CTRL_32BIT | SP804_PRESCALE_DIV_1 | SP804_TIMER_CTRL_INT_ENABLE);
-
-  // Set up default timer
-  Status = TimerDriverSetTimerPeriod (&gTimer, FixedPcdGet32(PcdTimerPeriod)); // TIMER_DEFAULT_PERIOD
-  ASSERT_EFI_ERROR (Status);
-
-  // Install the Timer Architectural Protocol onto a new handle
-  Status = gBS->InstallMultipleProtocolInterfaces(
-                  &Handle,
-                  &gEfiTimerArchProtocolGuid,      &gTimer,
-                  NULL
-                  );
-  ASSERT_EFI_ERROR(Status);
-
-  // Register for an ExitBootServicesEvent
-  Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent);
-  ASSERT_EFI_ERROR (Status);
-
-  return Status;
-}
+/** @file\r
+  Template for Timer Architecture Protocol driver of the ARM flavor\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials                          \r
+  are licensed and made available under the terms and conditions of the BSD License         \r
+  which accompanies this distribution.  The full text of the license may be found at        \r
+  http://opensource.org/licenses/bsd-license.php                                            \r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+**/\r
+\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/IoLib.h>\r
+\r
+#include <Protocol/Timer.h>\r
+#include <Protocol/HardwareInterrupt.h>\r
+\r
+#include <Drivers/SP804Timer.h>\r
+\r
+#define SP804_TIMER_PERIODIC_BASE     ((UINTN)PcdGet32 (PcdSP804TimerPeriodicBase))\r
+#define SP804_TIMER_METRONOME_BASE    ((UINTN)PcdGet32 (PcdSP804TimerMetronomeBase))\r
+#define SP804_TIMER_PERFORMANCE_BASE  ((UINTN)PcdGet32 (PcdSP804TimerPerformanceBase))\r
+\r
+// The notification function to call on every timer interrupt.\r
+EFI_TIMER_NOTIFY      mTimerNotifyFunction     = (EFI_TIMER_NOTIFY)NULL;\r
+EFI_EVENT             EfiExitBootServicesEvent = (EFI_EVENT)NULL;\r
+\r
+// The current period of the timer interrupt\r
+UINT64 mTimerPeriod = 0;\r
+\r
+// Cached copy of the Hardware Interrupt protocol instance\r
+EFI_HARDWARE_INTERRUPT_PROTOCOL *gInterrupt = NULL;\r
+\r
+// Cached interrupt vector\r
+UINTN  gVector;\r
+\r
+\r
+/**\r
+\r
+  C Interrupt Handler called in the interrupt context when Source interrupt is active.\r
+\r
+\r
+  @param Source         Source of the interrupt. Hardware routing off a specific platform defines\r
+                        what source means.\r
+\r
+  @param SystemContext  Pointer to system register context. Mostly used by debuggers and will\r
+                        update the system context after the return from the interrupt if \r
+                        modified. Don't change these values unless you know what you are doing\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+TimerInterruptHandler (\r
+  IN  HARDWARE_INTERRUPT_SOURCE   Source,\r
+  IN  EFI_SYSTEM_CONTEXT          SystemContext       \r
+  )\r
+{\r
+  EFI_TPL OriginalTPL;\r
+\r
+  //\r
+  // DXE core uses this callback for the EFI timer tick. The DXE core uses locks \r
+  // that raise to TPL_HIGH and then restore back to current level. Thus we need\r
+  // to make sure TPL level is set to TPL_HIGH while we are handling the timer tick. \r
+  //\r
+  OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+\r
+  // If the interrupt is shared then we must check if this interrupt source is the one associated to this Timer\r
+  if (MmioRead32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_MSK_INT_STS_REG) != 0) {\r
+    // Clear the periodic interrupt\r
+    MmioWrite32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_INT_CLR_REG, 0);\r
+\r
+    // Signal end of interrupt early to help avoid losing subsequent ticks from long duration handlers\r
+    gInterrupt->EndOfInterrupt (gInterrupt, Source);\r
+\r
+    if (mTimerNotifyFunction) {\r
+      mTimerNotifyFunction (mTimerPeriod);\r
+    }\r
+  }\r
+\r
+  gBS->RestoreTPL (OriginalTPL);\r
+}\r
+\r
+/**\r
+  This function registers the handler NotifyFunction so it is called every time \r
+  the timer interrupt fires.  It also passes the amount of time since the last \r
+  handler call to the NotifyFunction.  If NotifyFunction is NULL, then the \r
+  handler is unregistered.  If the handler is registered, then EFI_SUCCESS is \r
+  returned.  If the CPU does not support registering a timer interrupt handler, \r
+  then EFI_UNSUPPORTED is returned.  If an attempt is made to register a handler \r
+  when a handler is already registered, then EFI_ALREADY_STARTED is returned.  \r
+  If an attempt is made to unregister a handler when a handler is not registered, \r
+  then EFI_INVALID_PARAMETER is returned.  If an error occurs attempting to \r
+  register the NotifyFunction with the timer interrupt, then EFI_DEVICE_ERROR \r
+  is returned.\r
+\r
+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param  NotifyFunction   The function to call when a timer interrupt fires. This\r
+                           function executes at TPL_HIGH_LEVEL. The DXE Core will\r
+                           register a handler for the timer interrupt, so it can know\r
+                           how much time has passed. This information is used to\r
+                           signal timer based events. NULL will unregister the handler.\r
+  @retval EFI_SUCCESS           The timer handler was registered.\r
+  @retval EFI_UNSUPPORTED       The platform does not support timer interrupts.\r
+  @retval EFI_ALREADY_STARTED   NotifyFunction is not NULL, and a handler is already\r
+                                registered.\r
+  @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not\r
+                                previously registered.\r
+  @retval EFI_DEVICE_ERROR      The timer handler could not be registered.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverRegisterHandler (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  IN EFI_TIMER_NOTIFY         NotifyFunction\r
+  )\r
+{\r
+  if ((NotifyFunction == NULL) && (mTimerNotifyFunction == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if ((NotifyFunction != NULL) && (mTimerNotifyFunction != NULL)) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  mTimerNotifyFunction = NotifyFunction;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+    Make sure all Dual Timers are disabled\r
+**/\r
+VOID\r
+EFIAPI\r
+ExitBootServicesEvent (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+  // Disable 'Periodic Operation' timer if enabled\r
+  if (MmioRead32(SP804_TIMER_PERIODIC_BASE + SP804_TIMER_CONTROL_REG) & SP804_TIMER_CTRL_ENABLE) {\r
+    MmioAnd32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_CONTROL_REG, 0);\r
+  }\r
+\r
+  // Disable 'Metronome/Delay' timer if enabled\r
+  if (MmioRead32(SP804_TIMER_METRONOME_BASE + SP804_TIMER_CONTROL_REG) & SP804_TIMER_CTRL_ENABLE) {\r
+    MmioAnd32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CONTROL_REG, 0);\r
+  }\r
+\r
+  // Disable 'Performance' timer if enabled\r
+  if (MmioRead32(SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CONTROL_REG) & SP804_TIMER_CTRL_ENABLE) {\r
+    MmioAnd32 (SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CONTROL_REG, 0);\r
+  }\r
+}\r
+\r
+/**\r
+\r
+  This function adjusts the period of timer interrupts to the value specified \r
+  by TimerPeriod.  If the timer period is updated, then the selected timer \r
+  period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned.  If \r
+  the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.  \r
+  If an error occurs while attempting to update the timer period, then the \r
+  timer hardware will be put back in its state prior to this call, and \r
+  EFI_DEVICE_ERROR is returned.  If TimerPeriod is 0, then the timer interrupt \r
+  is disabled.  This is not the same as disabling the CPU's interrupts.  \r
+  Instead, it must either turn off the timer hardware, or it must adjust the \r
+  interrupt controller so that a CPU interrupt is not generated when the timer \r
+  interrupt fires. \r
+\r
+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param  TimerPeriod      The rate to program the timer interrupt in 100 nS units. If\r
+                           the timer hardware is not programmable, then EFI_UNSUPPORTED is\r
+                           returned. If the timer is programmable, then the timer period\r
+                           will be rounded up to the nearest timer period that is supported\r
+                           by the timer hardware. If TimerPeriod is set to 0, then the\r
+                           timer interrupts will be disabled.\r
+\r
+\r
+  @retval EFI_SUCCESS           The timer period was changed.\r
+  @retval EFI_UNSUPPORTED       The platform cannot change the period of the timer interrupt.\r
+  @retval EFI_DEVICE_ERROR      The timer period could not be changed due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverSetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  IN UINT64                   TimerPeriod\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT64      TimerTicks;\r
+  \r
+  // always disable the timer\r
+  MmioAnd32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_CONTROL_REG, ~SP804_TIMER_CTRL_ENABLE);\r
+\r
+  if (TimerPeriod == 0) {\r
+    // Leave timer disabled from above, and...\r
+\r
+    // Disable timer 0/1 interrupt for a TimerPeriod of 0\r
+    Status = gInterrupt->DisableInterruptSource (gInterrupt, gVector);    \r
+  } else {  \r
+    // Convert TimerPeriod into 1MHz clock counts (us units = 100ns units * 10)\r
+    TimerTicks = DivU64x32 (TimerPeriod, 10);\r
+    TimerTicks = MultU64x32 (TimerTicks, PcdGet32(PcdSP804TimerFrequencyInMHz));\r
+\r
+    // if it's larger than 32-bits, pin to highest value\r
+    if (TimerTicks > 0xffffffff) {\r
+      TimerTicks = 0xffffffff;\r
+    }\r
+\r
+    // Program the SP804 timer with the new count value\r
+    MmioWrite32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_LOAD_REG, TimerTicks);\r
+\r
+    // enable the timer\r
+    MmioOr32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_ENABLE);\r
+\r
+    // enable timer 0/1 interrupts\r
+    Status = gInterrupt->EnableInterruptSource (gInterrupt, gVector);    \r
+  }\r
+\r
+  // Save the new timer period\r
+  mTimerPeriod = TimerPeriod;\r
+  return Status;\r
+}\r
+\r
+/**\r
+  This function retrieves the period of timer interrupts in 100 ns units, \r
+  returns that value in TimerPeriod, and returns EFI_SUCCESS.  If TimerPeriod \r
+  is NULL, then EFI_INVALID_PARAMETER is returned.  If a TimerPeriod of 0 is \r
+  returned, then the timer is currently disabled.\r
+\r
+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param  TimerPeriod      A pointer to the timer period to retrieve in 100 ns units. If\r
+                           0 is returned, then the timer is currently disabled.\r
+\r
+\r
+  @retval EFI_SUCCESS           The timer period was returned in TimerPeriod.\r
+  @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverGetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL   *This,\r
+  OUT UINT64                   *TimerPeriod\r
+  )\r
+{\r
+  if (TimerPeriod == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *TimerPeriod = mTimerPeriod;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This function generates a soft timer interrupt. If the platform does not support soft \r
+  timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCESS is returned. \r
+  If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.RegisterHandler() \r
+  service, then a soft timer interrupt will be generated. If the timer interrupt is \r
+  enabled when this service is called, then the registered handler will be invoked. The \r
+  registered handler should not be able to distinguish a hardware-generated timer \r
+  interrupt from a software-generated timer interrupt.\r
+\r
+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.\r
+\r
+  @retval EFI_SUCCESS           The soft timer interrupt was generated.\r
+  @retval EFI_UNSUPPORTED       The platform does not support the generation of soft timer interrupts.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverGenerateSoftInterrupt (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Interface structure for the Timer Architectural Protocol.\r
+\r
+  @par Protocol Description:\r
+  This protocol provides the services to initialize a periodic timer \r
+  interrupt, and to register a handler that is called each time the timer\r
+  interrupt fires.  It may also provide a service to adjust the rate of the\r
+  periodic timer interrupt.  When a timer interrupt occurs, the handler is \r
+  passed the amount of time that has passed since the previous timer \r
+  interrupt.\r
+\r
+  @param RegisterHandler\r
+  Registers a handler that will be called each time the \r
+  timer interrupt fires.  TimerPeriod defines the minimum \r
+  time between timer interrupts, so TimerPeriod will also \r
+  be the minimum time between calls to the registered \r
+  handler.\r
+\r
+  @param SetTimerPeriod\r
+  Sets the period of the timer interrupt in 100 nS units.  \r
+  This function is optional, and may return EFI_UNSUPPORTED.  \r
+  If this function is supported, then the timer period will \r
+  be rounded up to the nearest supported timer period.\r
+\r
+\r
+  @param GetTimerPeriod\r
+  Retrieves the period of the timer interrupt in 100 nS units.\r
+\r
+  @param GenerateSoftInterrupt\r
+  Generates a soft timer interrupt that simulates the firing of \r
+  the timer interrupt. This service can be used to invoke the   registered handler if the timer interrupt has been masked for \r
+  a period of time.\r
+\r
+**/\r
+EFI_TIMER_ARCH_PROTOCOL   gTimer = {\r
+  TimerDriverRegisterHandler,\r
+  TimerDriverSetTimerPeriod,\r
+  TimerDriverGetTimerPeriod,\r
+  TimerDriverGenerateSoftInterrupt\r
+};\r
+\r
+\r
+/**\r
+  Initialize the state information for the Timer Architectural Protocol and\r
+  the Timer Debug support protocol that allows the debugger to break into a\r
+  running program.\r
+\r
+  @param  ImageHandle   of the loaded driver\r
+  @param  SystemTable   Pointer to the System Table\r
+\r
+  @retval EFI_SUCCESS           Protocol registered\r
+  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure\r
+  @retval EFI_DEVICE_ERROR      Hardware problems\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_HANDLE  Handle = NULL;\r
+  EFI_STATUS  Status;\r
+\r
+  // Set the interrupt timer number\r
+  gVector = PcdGet32(PcdSP804TimerPeriodicInterruptNum);\r
+\r
+  // Find the interrupt controller protocol.  ASSERT if not found.\r
+  Status = gBS->LocateProtocol (&gHardwareInterruptProtocolGuid, NULL, (VOID **)&gInterrupt);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  // Disable the timer\r
+  Status = TimerDriverSetTimerPeriod (&gTimer, 0);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  // Install interrupt handler\r
+  Status = gInterrupt->RegisterInterruptSource (gInterrupt, gVector, TimerInterruptHandler);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  // configure timer 0 for periodic operation, 32 bits, no prescaler, and interrupt enabled\r
+  MmioWrite32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_PERIODIC | SP804_TIMER_CTRL_32BIT | SP804_PRESCALE_DIV_1 | SP804_TIMER_CTRL_INT_ENABLE);\r
+\r
+  // Set up default timer\r
+  Status = TimerDriverSetTimerPeriod (&gTimer, FixedPcdGet32(PcdTimerPeriod)); // TIMER_DEFAULT_PERIOD\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  // Install the Timer Architectural Protocol onto a new handle\r
+  Status = gBS->InstallMultipleProtocolInterfaces(\r
+                  &Handle,\r
+                  &gEfiTimerArchProtocolGuid,      &gTimer,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  // Register for an ExitBootServicesEvent\r
+  Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
index 405563b86ff762166daf6394a72a1d01b53739f1..8e87adcf073a6a3667566514af13c1a4c2bf2b65 100644 (file)
@@ -1,59 +1,59 @@
-#/** @file
-#  
-#    Component description file for Timer module
-#  
-#  Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>
-#  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                      = ArmVeTimerDxe
-  FILE_GUID                      = a73d663d-a491-4278-9a69-9521be3379f2 
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-
-  ENTRY_POINT                    = TimerInitialize
-
-[Sources.common]
-  SP804Timer.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  ArmPkg/ArmPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  BaseLib
-  UefiRuntimeServicesTableLib
-  UefiLib
-  UefiBootServicesTableLib
-  BaseMemoryLib
-  DebugLib
-  UefiDriverEntryPoint
-  IoLib
-
-[Guids]
-
-[Protocols]
-  gEfiTimerArchProtocolGuid  
-  gHardwareInterruptProtocolGuid
-
-[Pcd.common]
-  gArmPlatformTokenSpaceGuid.PcdSP804TimerFrequencyInMHz
-  gArmPlatformTokenSpaceGuid.PcdSP804TimerPeriodicInterruptNum
-  gArmPlatformTokenSpaceGuid.PcdSP804TimerPeriodicBase
-  gArmPlatformTokenSpaceGuid.PcdSP804TimerPerformanceBase
-  gArmPlatformTokenSpaceGuid.PcdSP804TimerMetronomeBase
-  gEmbeddedTokenSpaceGuid.PcdTimerPeriod
-
-[Depex]
-  gHardwareInterruptProtocolGuid
+#/** @file\r
+#  \r
+#    Component description file for Timer module\r
+#  \r
+#  Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = ArmVeTimerDxe\r
+  FILE_GUID                      = a73d663d-a491-4278-9a69-9521be3379f2 \r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = TimerInitialize\r
+\r
+[Sources.common]\r
+  SP804Timer.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  UefiRuntimeServicesTableLib\r
+  UefiLib\r
+  UefiBootServicesTableLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  UefiDriverEntryPoint\r
+  IoLib\r
+\r
+[Guids]\r
+\r
+[Protocols]\r
+  gEfiTimerArchProtocolGuid  \r
+  gHardwareInterruptProtocolGuid\r
+\r
+[Pcd.common]\r
+  gArmPlatformTokenSpaceGuid.PcdSP804TimerFrequencyInMHz\r
+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPeriodicInterruptNum\r
+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPeriodicBase\r
+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPerformanceBase\r
+  gArmPlatformTokenSpaceGuid.PcdSP804TimerMetronomeBase\r
+  gEmbeddedTokenSpaceGuid.PcdTimerPeriod\r
+\r
+[Depex]\r
+  gHardwareInterruptProtocolGuid\r
index 5b78b2b3f4395bb591426b639dc20680c7cea5ab..d1da60b5ac7507e021d4e2b4a7b5d68db2aac766 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 <PiDxe.h>
-
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/DebugLib.h>
-#include <Library/IoLib.h>
-#include <Library/PcdLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/UefiLib.h>
-
-#include <Protocol/WatchdogTimer.h>
-#include <Drivers/SP805Watchdog.h>
-
-EFI_EVENT                           EfiExitBootServicesEvent = (EFI_EVENT)NULL;
-
-/**
-  Make sure the SP805 registers are unlocked for writing.
-
-  Note: The SP805 Watchdog Timer supports locking of its registers,
-  i.e. it inhibits all writes to avoid rogue software accidentally
-  corrupting their contents.
-**/
-inline
-VOID
-SP805Unlock (
-  VOID
-  )
-{
-  if( MmioRead32(SP805_WDOG_LOCK_REG) == SP805_WDOG_LOCK_IS_LOCKED ) {
-    MmioWrite32(SP805_WDOG_LOCK_REG, SP805_WDOG_SPECIAL_UNLOCK_CODE);
-  }
-}
-
-/**
-  Make sure the SP805 registers are locked and can not be overwritten.
-
-  Note: The SP805 Watchdog Timer supports locking of its registers,
-  i.e. it inhibits all writes to avoid rogue software accidentally
-  corrupting their contents.
-**/
-inline
-VOID
-SP805Lock (
-  VOID
-  )
-{
-  if( MmioRead32(SP805_WDOG_LOCK_REG) == SP805_WDOG_LOCK_IS_UNLOCKED ) {
-    // To lock it, just write in any number (except the special unlock code).
-    MmioWrite32(SP805_WDOG_LOCK_REG, SP805_WDOG_LOCK_IS_LOCKED);
-  }
-}
-
-/**
-  Stop the SP805 watchdog timer from counting down by disabling interrupts.
-**/
-inline
-VOID
-SP805Stop (
-  VOID
-  )
-{
-  // Disable interrupts
-  if ( (MmioRead32(SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_INTEN) != 0 ) {
-    MmioAnd32(SP805_WDOG_CONTROL_REG, ~SP805_WDOG_CTRL_INTEN);
-  }
-}
-
-/**
-  Starts the SP805 counting down by enabling interrupts.
-  The count down will start from the value stored in the Load register,
-  not from the value where it was previously stopped.
-**/
-inline
-VOID
-SP805Start (
-  VOID
-  )
-{
-  // Enable interrupts
-  if ( (MmioRead32(SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_INTEN) == 0 ) {
-    MmioOr32(SP805_WDOG_CONTROL_REG, SP805_WDOG_CTRL_INTEN);
-  }
-}
-
-/**
-    On exiting boot services we must make sure the SP805 Watchdog Timer
-    is stopped.
-**/
-VOID
-EFIAPI
-ExitBootServicesEvent (
-  IN EFI_EVENT  Event,
-  IN VOID       *Context
-  )
-{
-  SP805Unlock();
-  SP805Stop();
-  SP805Lock();
-}
-
-/**
-  This function registers the handler NotifyFunction so it is called every time
-  the watchdog timer expires.  It also passes the amount of time since the last
-  handler call to the NotifyFunction.
-  If NotifyFunction is not NULL and a handler is not already registered,
-  then the new handler is registered and EFI_SUCCESS is returned.
-  If NotifyFunction is NULL, and a handler is already registered,
-  then that handler is unregistered.
-  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.
-
-  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.
-  @param  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.
-
-  @retval EFI_SUCCESS           The watchdog timer handler was registered.
-  @retval EFI_ALREADY_STARTED   NotifyFunction is not NULL, and a handler is already
-                                registered.
-  @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not
-                                previously registered.
-
-**/
-EFI_STATUS
-EFIAPI
-SP805RegisterHandler (
-  IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL   *This,
-  IN EFI_WATCHDOG_TIMER_NOTIFY                NotifyFunction
-  )
-{
-  // ERROR: This function is not supported.
-  // The hardware watchdog will reset the board
-  return EFI_INVALID_PARAMETER;
-}
-
-/**
-
-  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.
-
-  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.
-  @param  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.
-
-
-  @retval EFI_SUCCESS           The timer period was changed.
-  @retval EFI_UNSUPPORTED       The platform cannot change the period of the timer interrupt.
-  @retval EFI_DEVICE_ERROR      The timer period could not be changed due to a device error.
-
-**/
-EFI_STATUS
-EFIAPI
-SP805SetTimerPeriod (
-  IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL   *This,
-  IN UINT64                                   TimerPeriod   // In 100ns units
-  )
-{
-  EFI_STATUS  Status = EFI_SUCCESS;
-  UINT64      Ticks64bit;
-
-  SP805Unlock();
-
-  if( TimerPeriod == 0 ) {
-    // This is a watchdog stop request
-    SP805Stop();
-    goto EXIT;
-  } else {
-    // Calculate the Watchdog ticks required for a delay of (TimerTicks * 100) nanoseconds
-    // The SP805 will count down to ZERO once, generate an interrupt and
-    // then it will again reload the initial value and start again.
-    // On the second time when it reaches ZERO, it will actually reset the board.
-    // Therefore, we need to load half the required delay.
-    //
-    // WatchdogTicks = ((TimerPeriod * 100 * SP805_CLOCK_FREQUENCY) / 1GHz) / 2 ;
-    //
-    // i.e.:
-    //
-    // WatchdogTicks = (TimerPeriod * SP805_CLOCK_FREQUENCY) / 20 MHz ;
-
-    Ticks64bit = DivU64x32(MultU64x32(TimerPeriod, (UINTN)PcdGet32(PcdSP805WatchdogClockFrequencyInHz)), 20000000);
-
-    // The registers in the SP805 are only 32 bits
-    if(Ticks64bit > (UINT64)0xFFFFFFFF) {
-      // We could load the watchdog with the maximum supported value but
-      // if a smaller value was requested, this could have the watchdog
-      // triggering before it was intended.
-      // Better generate an error to let the caller know.
-      Status = EFI_DEVICE_ERROR;
-      goto EXIT;
-    }
-
-    // Update the watchdog with a 32-bit value.
-    MmioWrite32(SP805_WDOG_LOAD_REG, (UINT32)Ticks64bit);
-
-    // Start the watchdog
-    SP805Start();
-  }
-
-  EXIT:
-  // Ensure the watchdog is locked before exiting.
-  SP805Lock();
-  return Status;
-}
-
-/**
-  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.
-
-  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.
-  @param  TimerPeriod      A pointer to the timer period to retrieve in 100 ns units. If
-                           0 is returned, then the timer is currently disabled.
-
-
-  @retval EFI_SUCCESS           The timer period was returned in TimerPeriod.
-  @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
-
-**/
-EFI_STATUS
-EFIAPI
-SP805GetTimerPeriod (
-  IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL   *This,
-  OUT UINT64                                  *TimerPeriod
-  )
-{
-  EFI_STATUS  Status = EFI_SUCCESS;
-  UINT64      ReturnValue;
-
-  if (TimerPeriod == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  // Check if the watchdog is stopped
-  if ( (MmioRead32(SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_INTEN) == 0 ) {
-    // It is stopped, so return zero.
-    ReturnValue = 0;
-  } else {
-    // Convert the Watchdog ticks into TimerPeriod
-    // Ensure 64bit arithmetic throughout because the Watchdog ticks may already
-    // be at the maximum 32 bit value and we still need to multiply that by 600.
-    ReturnValue = MultU64x32( MmioRead32(SP805_WDOG_LOAD_REG), 600 );
-  }
-
-  *TimerPeriod = ReturnValue;
-
-  return Status;
-}
-
-/**
-  Interface structure for the Watchdog Architectural Protocol.
-
-  @par Protocol Description:
-  This protocol provides a service to set the amount of time to wait
-  before firing the watchdog timer, and it also provides a service to
-  register a handler that is invoked when the watchdog timer fires.
-
-  @par When the watchdog timer fires, control will be passed to a handler
-  if one has been registered.  If no handler has been registered,
-  or the registered handler returns, then the system will be
-  reset by calling the Runtime Service ResetSystem().
-
-  @param RegisterHandler
-  Registers a handler that will be called each time the
-  watchdogtimer interrupt fires.  TimerPeriod defines the minimum
-  time between timer interrupts, so TimerPeriod will also
-  be the minimum time between calls to the registered
-  handler.
-  NOTE: If the watchdog resets the system in hardware, then
-        this function will not have any chance of executing.
-
-  @param SetTimerPeriod
-  Sets the period of the timer interrupt in 100 nS units.
-  This function is optional, and may return EFI_UNSUPPORTED.
-  If this function is supported, then the timer period will
-  be rounded up to the nearest supported timer period.
-
-  @param GetTimerPeriod
-  Retrieves the period of the timer interrupt in 100 nS units.
-
-**/
-EFI_WATCHDOG_TIMER_ARCH_PROTOCOL    gWatchdogTimer = {
-  (EFI_WATCHDOG_TIMER_REGISTER_HANDLER) SP805RegisterHandler,
-  (EFI_WATCHDOG_TIMER_SET_TIMER_PERIOD) SP805SetTimerPeriod,
-  (EFI_WATCHDOG_TIMER_GET_TIMER_PERIOD) SP805GetTimerPeriod
-};
-
-/**
-  Initialize the state information for the Watchdog Timer Architectural Protocol.
-
-  @param  ImageHandle   of the loaded driver
-  @param  SystemTable   Pointer to the System Table
-
-  @retval EFI_SUCCESS           Protocol registered
-  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure
-  @retval EFI_DEVICE_ERROR      Hardware problems
-
-**/
-EFI_STATUS
-EFIAPI
-SP805Initialize (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
-  )
-{
-  EFI_STATUS  Status;
-  EFI_HANDLE  Handle;
-
-  // Unlock access to the SP805 registers
-  SP805Unlock ();
-
-  // Stop the watchdog from triggering unexpectedly
-  SP805Stop ();
-
-  // Set the watchdog to reset the board when triggered
-  if ((MmioRead32(SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_RESEN) == 0) {
-    MmioOr32 (SP805_WDOG_CONTROL_REG, SP805_WDOG_CTRL_RESEN);
-  }
-
-  // Prohibit any rogue access to SP805 registers
-  SP805Lock();
-  
-  //
-  // Make sure the Watchdog Timer Architectural Protocol has not been installed in the system yet.
-  // This will avoid conflicts with the universal watchdog
-  //
-  ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid);
-
-  // Register for an ExitBootServicesEvent
-  Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent);
-  if (EFI_ERROR(Status)) {
-    Status = EFI_OUT_OF_RESOURCES;
-    goto EXIT;
-  }
-
-  // Install the Timer Architectural Protocol onto a new handle
-  Handle = NULL;
-  Status = gBS->InstallMultipleProtocolInterfaces(
-                  &Handle,
-                  &gEfiWatchdogTimerArchProtocolGuid, &gWatchdogTimer,
-                  NULL
-                  );
-  if (EFI_ERROR(Status)) {
-    Status = EFI_OUT_OF_RESOURCES;
-    goto EXIT;
-  }
-
-EXIT:
-  if(EFI_ERROR(Status)) {
-    // The watchdog failed to initialize
-    ASSERT(FALSE);
-  }
-  return Status;
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*\r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*\r
+**/\r
+\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+\r
+#include <Protocol/WatchdogTimer.h>\r
+#include <Drivers/SP805Watchdog.h>\r
+\r
+EFI_EVENT                           EfiExitBootServicesEvent = (EFI_EVENT)NULL;\r
+\r
+/**\r
+  Make sure the SP805 registers are unlocked for writing.\r
+\r
+  Note: The SP805 Watchdog Timer supports locking of its registers,\r
+  i.e. it inhibits all writes to avoid rogue software accidentally\r
+  corrupting their contents.\r
+**/\r
+inline\r
+VOID\r
+SP805Unlock (\r
+  VOID\r
+  )\r
+{\r
+  if( MmioRead32(SP805_WDOG_LOCK_REG) == SP805_WDOG_LOCK_IS_LOCKED ) {\r
+    MmioWrite32(SP805_WDOG_LOCK_REG, SP805_WDOG_SPECIAL_UNLOCK_CODE);\r
+  }\r
+}\r
+\r
+/**\r
+  Make sure the SP805 registers are locked and can not be overwritten.\r
+\r
+  Note: The SP805 Watchdog Timer supports locking of its registers,\r
+  i.e. it inhibits all writes to avoid rogue software accidentally\r
+  corrupting their contents.\r
+**/\r
+inline\r
+VOID\r
+SP805Lock (\r
+  VOID\r
+  )\r
+{\r
+  if( MmioRead32(SP805_WDOG_LOCK_REG) == SP805_WDOG_LOCK_IS_UNLOCKED ) {\r
+    // To lock it, just write in any number (except the special unlock code).\r
+    MmioWrite32(SP805_WDOG_LOCK_REG, SP805_WDOG_LOCK_IS_LOCKED);\r
+  }\r
+}\r
+\r
+/**\r
+  Stop the SP805 watchdog timer from counting down by disabling interrupts.\r
+**/\r
+inline\r
+VOID\r
+SP805Stop (\r
+  VOID\r
+  )\r
+{\r
+  // Disable interrupts\r
+  if ( (MmioRead32(SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_INTEN) != 0 ) {\r
+    MmioAnd32(SP805_WDOG_CONTROL_REG, ~SP805_WDOG_CTRL_INTEN);\r
+  }\r
+}\r
+\r
+/**\r
+  Starts the SP805 counting down by enabling interrupts.\r
+  The count down will start from the value stored in the Load register,\r
+  not from the value where it was previously stopped.\r
+**/\r
+inline\r
+VOID\r
+SP805Start (\r
+  VOID\r
+  )\r
+{\r
+  // Enable interrupts\r
+  if ( (MmioRead32(SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_INTEN) == 0 ) {\r
+    MmioOr32(SP805_WDOG_CONTROL_REG, SP805_WDOG_CTRL_INTEN);\r
+  }\r
+}\r
+\r
+/**\r
+    On exiting boot services we must make sure the SP805 Watchdog Timer\r
+    is stopped.\r
+**/\r
+VOID\r
+EFIAPI\r
+ExitBootServicesEvent (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+  SP805Unlock();\r
+  SP805Stop();\r
+  SP805Lock();\r
+}\r
+\r
+/**\r
+  This function registers the handler NotifyFunction so it is called every time\r
+  the watchdog timer expires.  It also passes the amount of time since the last\r
+  handler call to the NotifyFunction.\r
+  If NotifyFunction is not NULL and a handler is not already registered,\r
+  then the new handler is registered and EFI_SUCCESS is returned.\r
+  If NotifyFunction is NULL, and a handler is already registered,\r
+  then that handler is unregistered.\r
+  If an attempt is made to register a handler when a handler is already registered,\r
+  then EFI_ALREADY_STARTED is returned.\r
+  If an attempt is made to unregister a handler when a handler is not registered,\r
+  then EFI_INVALID_PARAMETER is returned.\r
+\r
+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param  NotifyFunction   The function to call when a timer interrupt fires. This\r
+                           function executes at TPL_HIGH_LEVEL. The DXE Core will\r
+                           register a handler for the timer interrupt, so it can know\r
+                           how much time has passed. This information is used to\r
+                           signal timer based events. NULL will unregister the handler.\r
+\r
+  @retval EFI_SUCCESS           The watchdog timer handler was registered.\r
+  @retval EFI_ALREADY_STARTED   NotifyFunction is not NULL, and a handler is already\r
+                                registered.\r
+  @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not\r
+                                previously registered.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SP805RegisterHandler (\r
+  IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL   *This,\r
+  IN EFI_WATCHDOG_TIMER_NOTIFY                NotifyFunction\r
+  )\r
+{\r
+  // ERROR: This function is not supported.\r
+  // The hardware watchdog will reset the board\r
+  return EFI_INVALID_PARAMETER;\r
+}\r
+\r
+/**\r
+\r
+  This function adjusts the period of timer interrupts to the value specified\r
+  by TimerPeriod.  If the timer period is updated, then the selected timer\r
+  period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned.  If\r
+  the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.\r
+  If an error occurs while attempting to update the timer period, then the\r
+  timer hardware will be put back in its state prior to this call, and\r
+  EFI_DEVICE_ERROR is returned.  If TimerPeriod is 0, then the timer interrupt\r
+  is disabled.  This is not the same as disabling the CPU's interrupts.\r
+  Instead, it must either turn off the timer hardware, or it must adjust the\r
+  interrupt controller so that a CPU interrupt is not generated when the timer\r
+  interrupt fires.\r
+\r
+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param  TimerPeriod      The rate to program the timer interrupt in 100 nS units. If\r
+                           the timer hardware is not programmable, then EFI_UNSUPPORTED is\r
+                           returned. If the timer is programmable, then the timer period\r
+                           will be rounded up to the nearest timer period that is supported\r
+                           by the timer hardware. If TimerPeriod is set to 0, then the\r
+                           timer interrupts will be disabled.\r
+\r
+\r
+  @retval EFI_SUCCESS           The timer period was changed.\r
+  @retval EFI_UNSUPPORTED       The platform cannot change the period of the timer interrupt.\r
+  @retval EFI_DEVICE_ERROR      The timer period could not be changed due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SP805SetTimerPeriod (\r
+  IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL   *This,\r
+  IN UINT64                                   TimerPeriod   // In 100ns units\r
+  )\r
+{\r
+  EFI_STATUS  Status = EFI_SUCCESS;\r
+  UINT64      Ticks64bit;\r
+\r
+  SP805Unlock();\r
+\r
+  if( TimerPeriod == 0 ) {\r
+    // This is a watchdog stop request\r
+    SP805Stop();\r
+    goto EXIT;\r
+  } else {\r
+    // Calculate the Watchdog ticks required for a delay of (TimerTicks * 100) nanoseconds\r
+    // The SP805 will count down to ZERO once, generate an interrupt and\r
+    // then it will again reload the initial value and start again.\r
+    // On the second time when it reaches ZERO, it will actually reset the board.\r
+    // Therefore, we need to load half the required delay.\r
+    //\r
+    // WatchdogTicks = ((TimerPeriod * 100 * SP805_CLOCK_FREQUENCY) / 1GHz) / 2 ;\r
+    //\r
+    // i.e.:\r
+    //\r
+    // WatchdogTicks = (TimerPeriod * SP805_CLOCK_FREQUENCY) / 20 MHz ;\r
+\r
+    Ticks64bit = DivU64x32(MultU64x32(TimerPeriod, (UINTN)PcdGet32(PcdSP805WatchdogClockFrequencyInHz)), 20000000);\r
+\r
+    // The registers in the SP805 are only 32 bits\r
+    if(Ticks64bit > (UINT64)0xFFFFFFFF) {\r
+      // We could load the watchdog with the maximum supported value but\r
+      // if a smaller value was requested, this could have the watchdog\r
+      // triggering before it was intended.\r
+      // Better generate an error to let the caller know.\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto EXIT;\r
+    }\r
+\r
+    // Update the watchdog with a 32-bit value.\r
+    MmioWrite32(SP805_WDOG_LOAD_REG, (UINT32)Ticks64bit);\r
+\r
+    // Start the watchdog\r
+    SP805Start();\r
+  }\r
+\r
+  EXIT:\r
+  // Ensure the watchdog is locked before exiting.\r
+  SP805Lock();\r
+  return Status;\r
+}\r
+\r
+/**\r
+  This function retrieves the period of timer interrupts in 100 ns units,\r
+  returns that value in TimerPeriod, and returns EFI_SUCCESS.  If TimerPeriod\r
+  is NULL, then EFI_INVALID_PARAMETER is returned.  If a TimerPeriod of 0 is\r
+  returned, then the timer is currently disabled.\r
+\r
+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param  TimerPeriod      A pointer to the timer period to retrieve in 100 ns units. If\r
+                           0 is returned, then the timer is currently disabled.\r
+\r
+\r
+  @retval EFI_SUCCESS           The timer period was returned in TimerPeriod.\r
+  @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SP805GetTimerPeriod (\r
+  IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL   *This,\r
+  OUT UINT64                                  *TimerPeriod\r
+  )\r
+{\r
+  EFI_STATUS  Status = EFI_SUCCESS;\r
+  UINT64      ReturnValue;\r
+\r
+  if (TimerPeriod == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  // Check if the watchdog is stopped\r
+  if ( (MmioRead32(SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_INTEN) == 0 ) {\r
+    // It is stopped, so return zero.\r
+    ReturnValue = 0;\r
+  } else {\r
+    // Convert the Watchdog ticks into TimerPeriod\r
+    // Ensure 64bit arithmetic throughout because the Watchdog ticks may already\r
+    // be at the maximum 32 bit value and we still need to multiply that by 600.\r
+    ReturnValue = MultU64x32( MmioRead32(SP805_WDOG_LOAD_REG), 600 );\r
+  }\r
+\r
+  *TimerPeriod = ReturnValue;\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Interface structure for the Watchdog Architectural Protocol.\r
+\r
+  @par Protocol Description:\r
+  This protocol provides a service to set the amount of time to wait\r
+  before firing the watchdog timer, and it also provides a service to\r
+  register a handler that is invoked when the watchdog timer fires.\r
+\r
+  @par When the watchdog timer fires, control will be passed to a handler\r
+  if one has been registered.  If no handler has been registered,\r
+  or the registered handler returns, then the system will be\r
+  reset by calling the Runtime Service ResetSystem().\r
+\r
+  @param RegisterHandler\r
+  Registers a handler that will be called each time the\r
+  watchdogtimer interrupt fires.  TimerPeriod defines the minimum\r
+  time between timer interrupts, so TimerPeriod will also\r
+  be the minimum time between calls to the registered\r
+  handler.\r
+  NOTE: If the watchdog resets the system in hardware, then\r
+        this function will not have any chance of executing.\r
+\r
+  @param SetTimerPeriod\r
+  Sets the period of the timer interrupt in 100 nS units.\r
+  This function is optional, and may return EFI_UNSUPPORTED.\r
+  If this function is supported, then the timer period will\r
+  be rounded up to the nearest supported timer period.\r
+\r
+  @param GetTimerPeriod\r
+  Retrieves the period of the timer interrupt in 100 nS units.\r
+\r
+**/\r
+EFI_WATCHDOG_TIMER_ARCH_PROTOCOL    gWatchdogTimer = {\r
+  (EFI_WATCHDOG_TIMER_REGISTER_HANDLER) SP805RegisterHandler,\r
+  (EFI_WATCHDOG_TIMER_SET_TIMER_PERIOD) SP805SetTimerPeriod,\r
+  (EFI_WATCHDOG_TIMER_GET_TIMER_PERIOD) SP805GetTimerPeriod\r
+};\r
+\r
+/**\r
+  Initialize the state information for the Watchdog Timer Architectural Protocol.\r
+\r
+  @param  ImageHandle   of the loaded driver\r
+  @param  SystemTable   Pointer to the System Table\r
+\r
+  @retval EFI_SUCCESS           Protocol registered\r
+  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure\r
+  @retval EFI_DEVICE_ERROR      Hardware problems\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SP805Initialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_HANDLE  Handle;\r
+\r
+  // Unlock access to the SP805 registers\r
+  SP805Unlock ();\r
+\r
+  // Stop the watchdog from triggering unexpectedly\r
+  SP805Stop ();\r
+\r
+  // Set the watchdog to reset the board when triggered\r
+  if ((MmioRead32(SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_RESEN) == 0) {\r
+    MmioOr32 (SP805_WDOG_CONTROL_REG, SP805_WDOG_CTRL_RESEN);\r
+  }\r
+\r
+  // Prohibit any rogue access to SP805 registers\r
+  SP805Lock();\r
+  \r
+  //\r
+  // Make sure the Watchdog Timer Architectural Protocol has not been installed in the system yet.\r
+  // This will avoid conflicts with the universal watchdog\r
+  //\r
+  ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid);\r
+\r
+  // Register for an ExitBootServicesEvent\r
+  Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent);\r
+  if (EFI_ERROR(Status)) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto EXIT;\r
+  }\r
+\r
+  // Install the Timer Architectural Protocol onto a new handle\r
+  Handle = NULL;\r
+  Status = gBS->InstallMultipleProtocolInterfaces(\r
+                  &Handle,\r
+                  &gEfiWatchdogTimerArchProtocolGuid, &gWatchdogTimer,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR(Status)) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto EXIT;\r
+  }\r
+\r
+EXIT:\r
+  if(EFI_ERROR(Status)) {\r
+    // The watchdog failed to initialize\r
+    ASSERT(FALSE);\r
+  }\r
+  return Status;\r
+}\r
index ffcd501aae019c90ca1d619dda4089c6e857be3f..5ec35188c97f651450e9470d9acec0ad704aab14 100644 (file)
@@ -1,52 +1,52 @@
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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                      = SP805WatchdogDxe
-  FILE_GUID                      = ebd705fb-fa92-46a7-b32b-7f566d944614 
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-
-  ENTRY_POINT                    = SP805Initialize
-
-[Sources.common]
-  SP805Watchdog.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  ArmPkg/ArmPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  BaseLib
-  BaseMemoryLib
-  DebugLib
-  IoLib
-  PcdLib
-  UefiLib
-  UefiBootServicesTableLib
-  UefiDriverEntryPoint
-  UefiRuntimeServicesTableLib
-
-[Pcd]
-  gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase
-  gArmPlatformTokenSpaceGuid.PcdSP805WatchdogClockFrequencyInHz
-
-[Protocols]
-  gEfiWatchdogTimerArchProtocolGuid  
-
-[Depex]
-  TRUE
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = SP805WatchdogDxe\r
+  FILE_GUID                      = ebd705fb-fa92-46a7-b32b-7f566d944614 \r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = SP805Initialize\r
+\r
+[Sources.common]\r
+  SP805Watchdog.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  IoLib\r
+  PcdLib\r
+  UefiLib\r
+  UefiBootServicesTableLib\r
+  UefiDriverEntryPoint\r
+  UefiRuntimeServicesTableLib\r
+\r
+[Pcd]\r
+  gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase\r
+  gArmPlatformTokenSpaceGuid.PcdSP805WatchdogClockFrequencyInHz\r
+\r
+[Protocols]\r
+  gEfiWatchdogTimerArchProtocolGuid  \r
+\r
+[Depex]\r
+  TRUE\r
index d68acd83b343a6fefa81198b67870d46947219a5..8c1c29de6cdd39253e743c335f87aa50050450e0 100644 (file)
-/** @file  PL111Lcd.h
-
- Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>
- 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.
-
- **/
-
-#ifndef _PL111LCD_H__
-#define _PL111LCD_H__
-
-/**********************************************************************
- *
- *  This header file contains all the bits of the PL111 that are
- *  platform independent.
- *
- **********************************************************************/
-
-// Controller Register Offsets
-#define PL111_REG_LCD_TIMING_0            ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x000)
-#define PL111_REG_LCD_TIMING_1            ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x004)
-#define PL111_REG_LCD_TIMING_2            ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x008)
-#define PL111_REG_LCD_TIMING_3            ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x00C)
-#define PL111_REG_LCD_UP_BASE             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x010)
-#define PL111_REG_LCD_LP_BASE             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x014)
-#define PL111_REG_LCD_CONTROL             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x018)
-#define PL111_REG_LCD_IMSC                ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x01C)
-#define PL111_REG_LCD_RIS                 ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x020)
-#define PL111_REG_LCD_MIS                 ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x024)
-#define PL111_REG_LCD_ICR                 ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x028)
-#define PL111_REG_LCD_UP_CURR             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x02C)
-#define PL111_REG_LCD_LP_CURR             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x030)
-#define PL111_REG_LCD_PALETTE             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x200)
-
-// Identification Register Offsets
-#define PL111_REG_CLCD_PERIPH_ID_0        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFE0)
-#define PL111_REG_CLCD_PERIPH_ID_1        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFE4)
-#define PL111_REG_CLCD_PERIPH_ID_2        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFE8)
-#define PL111_REG_CLCD_PERIPH_ID_3        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFEC)
-#define PL111_REG_CLCD_P_CELL_ID_0        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFF0)
-#define PL111_REG_CLCD_P_CELL_ID_1        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFF4)
-#define PL111_REG_CLCD_P_CELL_ID_2        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFF8)
-#define PL111_REG_CLCD_P_CELL_ID_3        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFFC)
-
-/**********************************************************************/
-
-// Register components (register bits)
-
-// This should make life easier to program specific settings in the different registers
-// by simplifying the setting up of the individual bits of each register
-// and then assembling the final register value.
-
-/**********************************************************************/
-
-// Register: PL111_REG_LCD_TIMING_0
-#define HOR_AXIS_PANEL(hbp,hfp,hsw,hor_res) (UINT32)(((UINT32)(hbp) << 24) | ((UINT32)(hfp) << 16) | ((UINT32)(hsw) << 8) | (((UINT32)((hor_res)/16)-1) << 2))
-
-// Register: PL111_REG_LCD_TIMING_1
-#define VER_AXIS_PANEL(vbp,vfp,vsw,ver_res) (UINT32)(((UINT32)(vbp) << 24) | ((UINT32)(vfp) << 16) | ((UINT32)(vsw) << 10) | ((ver_res)-1))
-
-// Register: PL111_REG_LCD_TIMING_2
-#define PL111_BIT_SHIFT_PCD_HI            27
-#define PL111_BIT_SHIFT_BCD               26
-#define PL111_BIT_SHIFT_CPL               16
-#define PL111_BIT_SHIFT_IOE               14
-#define PL111_BIT_SHIFT_IPC               13
-#define PL111_BIT_SHIFT_IHS               12
-#define PL111_BIT_SHIFT_IVS               11
-#define PL111_BIT_SHIFT_ACB               6
-#define PL111_BIT_SHIFT_CLKSEL            5
-#define PL111_BIT_SHIFT_PCD_LO            0
-
-#define PL111_BCD                         (1 << 26)
-#define PL111_IPC                         (1 << 13)
-#define PL111_IHS                         (1 << 12)
-#define PL111_IVS                         (1 << 11)
-
-#define CLK_SIG_POLARITY(hor_res)         (UINT32)(PL111_BCD | PL111_IPC | PL111_IHS | PL111_IVS | (((hor_res)-1) << 16))
-
-// Register: PL111_REG_LCD_TIMING_3
-#define PL111_BIT_SHIFT_LEE               16
-#define PL111_BIT_SHIFT_LED               0
-
-#define PL111_CTRL_WATERMARK              (1 << 16)
-#define PL111_CTRL_LCD_V_COMP             (1 << 12)
-#define PL111_CTRL_LCD_PWR                (1 << 11)
-#define PL111_CTRL_BEPO                   (1 << 10)
-#define PL111_CTRL_BEBO                   (1 << 9)
-#define PL111_CTRL_BGR                    (1 << 8)
-#define PL111_CTRL_LCD_DUAL               (1 << 7)
-#define PL111_CTRL_LCD_MONO_8             (1 << 6)
-#define PL111_CTRL_LCD_TFT                (1 << 5)
-#define PL111_CTRL_LCD_BW                 (1 << 4)
-#define PL111_CTRL_LCD_1BPP               (0 << 1)
-#define PL111_CTRL_LCD_2BPP               (1 << 1)
-#define PL111_CTRL_LCD_4BPP               (2 << 1)
-#define PL111_CTRL_LCD_8BPP               (3 << 1)
-#define PL111_CTRL_LCD_16BPP              (4 << 1)
-#define PL111_CTRL_LCD_24BPP              (5 << 1)
-#define PL111_CTRL_LCD_16BPP_565          (6 << 1)
-#define PL111_CTRL_LCD_12BPP_444          (7 << 1)
-#define PL111_CTRL_LCD_BPP(Bpp)           ((Bpp) << 1)
-#define PL111_CTRL_LCD_EN                 1
-
-/**********************************************************************/
-
-// Register: PL111_REG_LCD_TIMING_0
-#define PL111_LCD_TIMING_0_HBP(hbp)       (((hbp) & 0xFF) << 24)
-#define PL111_LCD_TIMING_0_HFP(hfp)       (((hfp) & 0xFF) << 16)
-#define PL111_LCD_TIMING_0_HSW(hsw)       (((hsw) & 0xFF) << 8)
-#define PL111_LCD_TIMING_0_PPL(ppl)       (((hsw) & 0x3F) << 2)
-
-// Register: PL111_REG_LCD_TIMING_1
-#define PL111_LCD_TIMING_1_VBP(vbp)       (((vbp) & 0xFF) << 24)
-#define PL111_LCD_TIMING_1_VFP(vfp)       (((vfp) & 0xFF) << 16)
-#define PL111_LCD_TIMING_1_VSW(vsw)       (((vsw) & 0x3F) << 10)
-#define PL111_LCD_TIMING_1_LPP(lpp)        ((lpp) & 0xFC)
-
-// Register: PL111_REG_LCD_TIMING_2
-#define PL111_BIT_MASK_PCD_HI             0xF8000000
-#define PL111_BIT_MASK_BCD                0x04000000
-#define PL111_BIT_MASK_CPL                0x03FF0000
-#define PL111_BIT_MASK_IOE                0x00004000
-#define PL111_BIT_MASK_IPC                0x00002000
-#define PL111_BIT_MASK_IHS                0x00001000
-#define PL111_BIT_MASK_IVS                0x00000800
-#define PL111_BIT_MASK_ACB                0x000007C0
-#define PL111_BIT_MASK_CLKSEL             0x00000020
-#define PL111_BIT_MASK_PCD_LO             0x0000001F
-
-// Register: PL111_REG_LCD_TIMING_3
-#define PL111_BIT_MASK_LEE                0x00010000
-#define PL111_BIT_MASK_LED                0x0000007F
-
-#endif /* _PL111LCD_H__ */
+/** @file  PL111Lcd.h\r
+\r
+ Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution.  The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ **/\r
+\r
+#ifndef _PL111LCD_H__\r
+#define _PL111LCD_H__\r
+\r
+/**********************************************************************\r
+ *\r
+ *  This header file contains all the bits of the PL111 that are\r
+ *  platform independent.\r
+ *\r
+ **********************************************************************/\r
+\r
+// Controller Register Offsets\r
+#define PL111_REG_LCD_TIMING_0            ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x000)\r
+#define PL111_REG_LCD_TIMING_1            ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x004)\r
+#define PL111_REG_LCD_TIMING_2            ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x008)\r
+#define PL111_REG_LCD_TIMING_3            ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x00C)\r
+#define PL111_REG_LCD_UP_BASE             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x010)\r
+#define PL111_REG_LCD_LP_BASE             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x014)\r
+#define PL111_REG_LCD_CONTROL             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x018)\r
+#define PL111_REG_LCD_IMSC                ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x01C)\r
+#define PL111_REG_LCD_RIS                 ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x020)\r
+#define PL111_REG_LCD_MIS                 ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x024)\r
+#define PL111_REG_LCD_ICR                 ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x028)\r
+#define PL111_REG_LCD_UP_CURR             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x02C)\r
+#define PL111_REG_LCD_LP_CURR             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x030)\r
+#define PL111_REG_LCD_PALETTE             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x200)\r
+\r
+// Identification Register Offsets\r
+#define PL111_REG_CLCD_PERIPH_ID_0        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFE0)\r
+#define PL111_REG_CLCD_PERIPH_ID_1        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFE4)\r
+#define PL111_REG_CLCD_PERIPH_ID_2        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFE8)\r
+#define PL111_REG_CLCD_PERIPH_ID_3        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFEC)\r
+#define PL111_REG_CLCD_P_CELL_ID_0        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFF0)\r
+#define PL111_REG_CLCD_P_CELL_ID_1        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFF4)\r
+#define PL111_REG_CLCD_P_CELL_ID_2        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFF8)\r
+#define PL111_REG_CLCD_P_CELL_ID_3        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFFC)\r
+\r
+/**********************************************************************/\r
+\r
+// Register components (register bits)\r
+\r
+// This should make life easier to program specific settings in the different registers\r
+// by simplifying the setting up of the individual bits of each register\r
+// and then assembling the final register value.\r
+\r
+/**********************************************************************/\r
+\r
+// Register: PL111_REG_LCD_TIMING_0\r
+#define HOR_AXIS_PANEL(hbp,hfp,hsw,hor_res) (UINT32)(((UINT32)(hbp) << 24) | ((UINT32)(hfp) << 16) | ((UINT32)(hsw) << 8) | (((UINT32)((hor_res)/16)-1) << 2))\r
+\r
+// Register: PL111_REG_LCD_TIMING_1\r
+#define VER_AXIS_PANEL(vbp,vfp,vsw,ver_res) (UINT32)(((UINT32)(vbp) << 24) | ((UINT32)(vfp) << 16) | ((UINT32)(vsw) << 10) | ((ver_res)-1))\r
+\r
+// Register: PL111_REG_LCD_TIMING_2\r
+#define PL111_BIT_SHIFT_PCD_HI            27\r
+#define PL111_BIT_SHIFT_BCD               26\r
+#define PL111_BIT_SHIFT_CPL               16\r
+#define PL111_BIT_SHIFT_IOE               14\r
+#define PL111_BIT_SHIFT_IPC               13\r
+#define PL111_BIT_SHIFT_IHS               12\r
+#define PL111_BIT_SHIFT_IVS               11\r
+#define PL111_BIT_SHIFT_ACB               6\r
+#define PL111_BIT_SHIFT_CLKSEL            5\r
+#define PL111_BIT_SHIFT_PCD_LO            0\r
+\r
+#define PL111_BCD                         (1 << 26)\r
+#define PL111_IPC                         (1 << 13)\r
+#define PL111_IHS                         (1 << 12)\r
+#define PL111_IVS                         (1 << 11)\r
+\r
+#define CLK_SIG_POLARITY(hor_res)         (UINT32)(PL111_BCD | PL111_IPC | PL111_IHS | PL111_IVS | (((hor_res)-1) << 16))\r
+\r
+// Register: PL111_REG_LCD_TIMING_3\r
+#define PL111_BIT_SHIFT_LEE               16\r
+#define PL111_BIT_SHIFT_LED               0\r
+\r
+#define PL111_CTRL_WATERMARK              (1 << 16)\r
+#define PL111_CTRL_LCD_V_COMP             (1 << 12)\r
+#define PL111_CTRL_LCD_PWR                (1 << 11)\r
+#define PL111_CTRL_BEPO                   (1 << 10)\r
+#define PL111_CTRL_BEBO                   (1 << 9)\r
+#define PL111_CTRL_BGR                    (1 << 8)\r
+#define PL111_CTRL_LCD_DUAL               (1 << 7)\r
+#define PL111_CTRL_LCD_MONO_8             (1 << 6)\r
+#define PL111_CTRL_LCD_TFT                (1 << 5)\r
+#define PL111_CTRL_LCD_BW                 (1 << 4)\r
+#define PL111_CTRL_LCD_1BPP               (0 << 1)\r
+#define PL111_CTRL_LCD_2BPP               (1 << 1)\r
+#define PL111_CTRL_LCD_4BPP               (2 << 1)\r
+#define PL111_CTRL_LCD_8BPP               (3 << 1)\r
+#define PL111_CTRL_LCD_16BPP              (4 << 1)\r
+#define PL111_CTRL_LCD_24BPP              (5 << 1)\r
+#define PL111_CTRL_LCD_16BPP_565          (6 << 1)\r
+#define PL111_CTRL_LCD_12BPP_444          (7 << 1)\r
+#define PL111_CTRL_LCD_BPP(Bpp)           ((Bpp) << 1)\r
+#define PL111_CTRL_LCD_EN                 1\r
+\r
+/**********************************************************************/\r
+\r
+// Register: PL111_REG_LCD_TIMING_0\r
+#define PL111_LCD_TIMING_0_HBP(hbp)       (((hbp) & 0xFF) << 24)\r
+#define PL111_LCD_TIMING_0_HFP(hfp)       (((hfp) & 0xFF) << 16)\r
+#define PL111_LCD_TIMING_0_HSW(hsw)       (((hsw) & 0xFF) << 8)\r
+#define PL111_LCD_TIMING_0_PPL(ppl)       (((hsw) & 0x3F) << 2)\r
+\r
+// Register: PL111_REG_LCD_TIMING_1\r
+#define PL111_LCD_TIMING_1_VBP(vbp)       (((vbp) & 0xFF) << 24)\r
+#define PL111_LCD_TIMING_1_VFP(vfp)       (((vfp) & 0xFF) << 16)\r
+#define PL111_LCD_TIMING_1_VSW(vsw)       (((vsw) & 0x3F) << 10)\r
+#define PL111_LCD_TIMING_1_LPP(lpp)        ((lpp) & 0xFC)\r
+\r
+// Register: PL111_REG_LCD_TIMING_2\r
+#define PL111_BIT_MASK_PCD_HI             0xF8000000\r
+#define PL111_BIT_MASK_BCD                0x04000000\r
+#define PL111_BIT_MASK_CPL                0x03FF0000\r
+#define PL111_BIT_MASK_IOE                0x00004000\r
+#define PL111_BIT_MASK_IPC                0x00002000\r
+#define PL111_BIT_MASK_IHS                0x00001000\r
+#define PL111_BIT_MASK_IVS                0x00000800\r
+#define PL111_BIT_MASK_ACB                0x000007C0\r
+#define PL111_BIT_MASK_CLKSEL             0x00000020\r
+#define PL111_BIT_MASK_PCD_LO             0x0000001F\r
+\r
+// Register: PL111_REG_LCD_TIMING_3\r
+#define PL111_BIT_MASK_LEE                0x00010000\r
+#define PL111_BIT_MASK_LED                0x0000007F\r
+\r
+#endif /* _PL111LCD_H__ */\r
index 1bf936ff78e021b9835079146f1b0e880a2d8a1c..ae941839f08bc28a094cb2483ed8bdad23cf8cf4 100644 (file)
@@ -1,21 +1,21 @@
-/** @file
-*
-*  Copyright (c) 2011, ARM Limited. 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.
-*
-**/
-
-#ifndef PL301AXI_H_
-#define PL301AXI_H_
-
-VOID PL301AxiInit(UINTN FAxiBase);
-
-
-#endif /* PL301AXI_H_ */
+/** @file\r
+*\r
+*  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+*\r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*\r
+**/\r
+\r
+#ifndef PL301AXI_H_\r
+#define PL301AXI_H_\r
+\r
+VOID PL301AxiInit(UINTN FAxiBase);\r
+\r
+\r
+#endif /* PL301AXI_H_ */\r
index 0227ced45420b45efbfa1cc0eb5a61614a423612..268b6da5c0cd9a6fc72861f90e158bea2a4f25ca 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011, ARM Limited. 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.
-*
-**/
-
-#ifndef _PL341DMC_H_
-#define _PL341DMC_H_
-
-
-typedef struct  {
-    UINTN      HasQos;        // has QoS registers
-    UINTN      MaxChip;       // number of memory chips accessible
-    BOOLEAN  IsUserCfg;
-    UINT32  User0Cfg;
-    UINT32  User2Cfg;
-    UINT32     RefreshPeriod;
-    UINT32     CasLatency;
-    UINT32     WriteLatency;
-    UINT32     t_mrd;
-    UINT32     t_ras;
-    UINT32     t_rc;
-    UINT32     t_rcd;
-    UINT32     t_rfc;
-    UINT32     t_rp;
-    UINT32     t_rrd;
-    UINT32     t_wr;
-    UINT32     t_wtr;
-    UINT32     t_xp;
-    UINT32     t_xsr;
-    UINT32     t_esr;
-    UINT32     MemoryCfg;
-    UINT32     MemoryCfg2;
-    UINT32     MemoryCfg3;
-    UINT32     ChipCfg0;
-    UINT32     ChipCfg1;
-    UINT32     ChipCfg2;
-    UINT32     ChipCfg3;
-    UINT32     t_faw;
-    UINT32     t_data_en;
-    UINT32     t_wdata_en;
-    UINT32  ModeReg;
-    UINT32  ExtModeReg;
-} PL341_DMC_CONFIG;
-
-/* Memory config bit fields */
-#define DMC_MEMORY_CONFIG_COLUMN_ADDRESS_9      0x1
-#define DMC_MEMORY_CONFIG_COLUMN_ADDRESS_10     0x2
-#define DMC_MEMORY_CONFIG_COLUMN_ADDRESS_11     0x3
-#define DMC_MEMORY_CONFIG_COLUMN_ADDRESS_12     0x4
-#define DMC_MEMORY_CONFIG_ROW_ADDRESS_11        (0x0 << 3)
-#define DMC_MEMORY_CONFIG_ROW_ADDRESS_12        (0x1 << 3)
-#define DMC_MEMORY_CONFIG_ROW_ADDRESS_13        (0x2 << 3)
-#define DMC_MEMORY_CONFIG_ROW_ADDRESS_14        (0x3 << 3)
-#define DMC_MEMORY_CONFIG_ROW_ADDRESS_15        (0x4 << 3)
-#define DMC_MEMORY_CONFIG_ROW_ADDRESS_16        (0x5 << 3)
-#define DMC_MEMORY_CONFIG_BURST_2               (0x1 << 15)
-#define DMC_MEMORY_CONFIG_BURST_4               (0x2 << 15)
-#define DMC_MEMORY_CONFIG_BURST_8               (0x3 << 15)
-#define DMC_MEMORY_CONFIG_BURST_16              (0x4 << 15)
-#define DMC_MEMORY_CONFIG_ACTIVE_CHIP_1    (0x0 << 21)
-#define DMC_MEMORY_CONFIG_ACTIVE_CHIP_2    (0x1 << 21)
-#define DMC_MEMORY_CONFIG_ACTIVE_CHIP_3    (0x2 << 21)
-#define DMC_MEMORY_CONFIG_ACTIVE_CHIP_4    (0x3 << 21)
-
-#define DMC_MEMORY_CFG2_CLK_ASYNC    (0x0 << 0)
-#define DMC_MEMORY_CFG2_CLK_SYNC    (0x1 << 0)
-#define DMC_MEMORY_CFG2_DQM_INIT    (0x1 << 2)
-#define DMC_MEMORY_CFG2_CKE_INIT    (0x1 << 3)
-#define DMC_MEMORY_CFG2_BANK_BITS_2    (0x0 << 4)
-#define DMC_MEMORY_CFG2_BANK_BITS_3    (0x3 << 4)
-#define DMC_MEMORY_CFG2_MEM_WIDTH_16    (0x0 << 6)
-#define DMC_MEMORY_CFG2_MEM_WIDTH_32    (0x1 << 6)
-#define DMC_MEMORY_CFG2_MEM_WIDTH_64    (0x2 << 6)
-#define DMC_MEMORY_CFG2_MEM_WIDTH_RESERVED  (0x3 << 6)
-
-//
-// DMC Configuration Register Map
-//
-#define DMC_STATUS_REG              0x00
-#define DMC_COMMAND_REG             0x04
-#define DMC_DIRECT_CMD_REG          0x08
-#define DMC_MEMORY_CONFIG_REG       0x0C
-#define DMC_REFRESH_PRD_REG         0x10
-#define DMC_CAS_LATENCY_REG         0x14
-#define DMC_WRITE_LATENCY_REG       0x18
-#define DMC_T_MRD_REG               0x1C
-#define DMC_T_RAS_REG               0x20
-#define DMC_T_RC_REG                0x24
-#define DMC_T_RCD_REG               0x28
-#define DMC_T_RFC_REG               0x2C
-#define DMC_T_RP_REG                0x30
-#define DMC_T_RRD_REG               0x34
-#define DMC_T_WR_REG                0x38
-#define DMC_T_WTR_REG               0x3C
-#define DMC_T_XP_REG                0x40
-#define DMC_T_XSR_REG               0x44
-#define DMC_T_ESR_REG               0x48
-#define DMC_MEMORY_CFG2_REG         0x4C
-#define DMC_MEMORY_CFG3_REG         0x50
-#define DMC_T_FAW_REG               0x54
-#define DMC_T_RDATA_EN              0x5C       /* DFI read data enable register */
-#define DMC_T_WRLAT_DIFF            0x60        /* DFI write data enable register */
-
-// Returns the state of the memory controller:
-#define DMC_STATUS_CONFIG       0x0
-#define DMC_STATUS_READY        0x1
-#define DMC_STATUS_PAUSED       0x2
-#define DMC_STATUS_LOWPOWER     0x3
-
-// Changes the state of the memory controller:
-#define DMC_COMMAND_GO              0x0
-#define DMC_COMMAND_SLEEP           0x1
-#define DMC_COMMAND_WAKEUP          0x2
-#define DMC_COMMAND_PAUSE           0x3
-#define DMC_COMMAND_CONFIGURE       0x4
-#define DMC_COMMAND_ACTIVEPAUSE     0x7
-
-// Determines the command required
-#define DMC_DIRECT_CMD_MEMCMD_PRECHARGEALL      0x0
-#define DMC_DIRECT_CMD_MEMCMD_AUTOREFRESH       (0x1 << 18)
-#define DMC_DIRECT_CMD_MEMCMD_MODEREG           (0x2 << 18)
-#define DMC_DIRECT_CMD_MEMCMD_EXTMODEREG        (0x2 << 18)
-#define DMC_DIRECT_CMD_MEMCMD_NOP               (0x3 << 18)
-#define DMC_DIRECT_CMD_MEMCMD_DPD               (0x1 << 22)
-#define DMC_DIRECT_CMD_BANKADDR(n)              ((n & 0x3) << 16)
-#define DMC_DIRECT_CMD_CHIP_ADDR(n)             ((n & 0x3) << 20)
-
-
-//
-// AXI ID configuration register map
-//
-#define DMC_ID_0_CFG_REG            0x100
-#define DMC_ID_1_CFG_REG            0x104
-#define DMC_ID_2_CFG_REG            0x108
-#define DMC_ID_3_CFG_REG            0x10C
-#define DMC_ID_4_CFG_REG            0x110
-#define DMC_ID_5_CFG_REG            0x114
-#define DMC_ID_6_CFG_REG            0x118
-#define DMC_ID_7_CFG_REG            0x11C
-#define DMC_ID_8_CFG_REG            0x120
-#define DMC_ID_9_CFG_REG            0x124
-#define DMC_ID_10_CFG_REG           0x128
-#define DMC_ID_11_CFG_REG           0x12C
-#define DMC_ID_12_CFG_REG           0x130
-#define DMC_ID_13_CFG_REG           0x134
-#define DMC_ID_14_CFG_REG           0x138
-#define DMC_ID_15_CFG_REG           0x13C
-
-// Set the QoS
-#define DMC_ID_CFG_QOS_DISABLE      0
-#define DMC_ID_CFG_QOS_ENABLE       1
-#define DMC_ID_CFG_QOS_MIN          2
-
-
-//
-// Chip configuration register map
-//
-#define DMC_CHIP_0_CFG_REG          0x200
-#define DMC_CHIP_1_CFG_REG          0x204
-#define DMC_CHIP_2_CFG_REG          0x208
-#define DMC_CHIP_3_CFG_REG          0x20C
-
-//
-// User Defined Pins
-//
-#define DMC_USER_STATUS_REG         0x300
-#define DMC_USER_0_CFG_REG          0x304
-#define DMC_USER_1_CFG_REG          0x308
-#define DMC_FEATURE_CRTL_REG        0x30C
-#define DMC_USER_2_CFG_REG          0x310
-
-
-//
-// PHY Register Settings
-//
-#define PHY_PTM_DFI_CLK_RANGE                                  0xE00           // DDR2 PHY PTM register offset
-#define PHY_PTM_IOTERM                                                 0xE04
-#define PHY_PTM_PLL_EN                                         0xe0c
-#define PHY_PTM_PLL_RANGE                                      0xe18
-#define PHY_PTM_FEEBACK_DIV                                    0xe1c
-#define PHY_PTM_RCLK_DIV                                       0xe20
-#define PHY_PTM_LOCK_STATUS                                    0xe28
-#define PHY_PTM_INIT_DONE                                      0xe34
-#define PHY_PTM_ADDCOM_IOSTR_OFF                               0xec8
-#define PHY_PTM_SQU_TRAINING                                   0xee8
-#define PHY_PTM_SQU_STAT                                       0xeec
-
-// ==============================================================================
-// PIPD 40G DDR2/DDR3 PHY Register definitions
-//
-// Offsets from APB Base Address
-// ==============================================================================
-#define PHY_BYTE0_OFFSET                                       0x000
-#define PHY_BYTE1_OFFSET                                       0x200
-#define PHY_BYTE2_OFFSET                                       0x400
-#define PHY_BYTE3_OFFSET                                       0x600
-
-#define PHY_BYTE0_COARSE_SQADJ_INIT                    0x064   ;// Coarse squelch adjust
-#define PHY_BYTE1_COARSE_SQADJ_INIT                    0x264   ;// Coarse squelch adjust
-#define PHY_BYTE2_COARSE_SQADJ_INIT                    0x464   ;// Coarse squelch adjust
-#define PHY_BYTE3_COARSE_SQADJ_INIT                    0x664   ;// Coarse squelch adjust
-
-#define PHY_BYTE0_IOSTR_OFFSET                         0x004
-#define PHY_BYTE1_IOSTR_OFFSET                         0x204
-#define PHY_BYTE2_IOSTR_OFFSET                         0x404
-#define PHY_BYTE3_IOSTR_OFFSET                         0x604
-
-
-;//--------------------------------------------------------------------------
-
-// DFI Clock ranges:
-
-#define PHY_PTM_DFI_CLK_RANGE_200MHz                   0x0
-#define PHY_PTM_DFI_CLK_RANGE_201_267MHz       0x1
-#define PHY_PTM_DFI_CLK_RANGE_268_333MHz       0x2
-#define PHY_PTM_DFI_CLK_RANGE_334_400MHz       0x3
-#define PHY_PTM_DFI_CLK_RANGE_401_533MHz       0x4
-#define PHY_PTM_DFI_CLK_RANGE_534_667MHz       0x5
-#define PHY_PTM_DFI_CLK_RANGE_668_800MHz       0x6
-
-
-
-#define  PHY_PTM_DFI_CLK_RANGE_VAL                     PHY_PTM_DFI_CLK_RANGE_334_400MHz
-
-//--------------------------------------------------------------------------
-
-
-// PLL Range
-
-#define PHY_PTM_PLL_RANGE_200_400MHz           0x0     // b0 = frequency >= 200 MHz and < 400 MHz
-#define PHY_PTM_PLL_RANGE_400_800MHz           0x1     // b1 = frequency >= 400 MHz.
-#define PHY_PTM_FEEBACK_DIV_200_400MHz         0x0     // b0 = frequency >= 200 MHz and < 400 MHz
-#define PHY_PTM_FEEBACK_DIV_400_800MHz         0x1     // b1 = frequency >= 400 MHz.
-#define PHY_PTM_REFCLK_DIV_200_400MHz          0x0
-#define PHY_PTM_REFCLK_DIV_400_800MHz          0x1
-
-#define TC_UIOLHNC_MASK                         0x000003C0
-#define TC_UIOLHNC_SHIFT                        0x6
-#define TC_UIOLHPC_MASK                         0x0000003F
-#define TC_UIOLHPC_SHIFT                        0x2
-#define TC_UIOHOCT_MASK                         0x2
-#define TC_UIOHOCT_SHIFT                        0x1
-#define TC_UIOHSTOP_SHIFT                       0x0
-#define TC_UIOLHXC_VALUE                        0x4
-
-#define PHY_PTM_SQU_TRAINING_ENABLE                            0x1
-#define PHY_PTM_SQU_TRAINING_DISABLE                           0x0
-
-
-//--------------------------------------
-// JEDEC DDR2 Device Register definitions and settings
-//--------------------------------------
-#define DDR_MODESET_SHFT                                               14
-#define DDR_MODESET_MR                                                 0x0             ;// Mode register
-#define DDR_MODESET_EMR                                                        0x1             ;// Extended Mode register
-#define DDR_MODESET_EMR2                                               0x2
-#define DDR_MODESET_EMR3                                               0x3
-
-//
-// Extended Mode Register settings
-//
-#define DDR_EMR_OCD_MASK                        0x0000380
-#define DDR_EMR_OCD_SHIFT                       0x7
-#define DDR_EMR_RTT_MASK                        0x00000044                  // DDR2 Device RTT (ODT) settings
-#define DDR_EMR_RTT_SHIFT                       0x2
-#define DDR_EMR_ODS_MASK                        0x00000002                  // DDR2 Output Drive Strength
-#define DDR_EMR_ODS_SHIFT                       0x0001
-
-// Termination Values:
-#define DDR_EMR_RTT_50R                         0x00000044                  // DDR2 50 Ohm termination
-#define DDR_EMR_RTT_75R                         0x00000004                  // DDR2 75 Ohm termination
-#define DDR_EMR_RTT_150                         0x00000040                  // DDR2 150 Ohm termination
-
-// Output Drive Strength Values:
-#define DDR_EMR_ODS_FULL                        0x0                         // DDR2 Full Drive Strength
-#define DDR_EMR_ODS_HALF                        0x1                         // DDR2 Half Drive Strength
-
-// OCD values
-#define DDR_EMR_OCD_DEFAULT                     0x7
-#define DDR_EMR_OCD_NS                          0x0
-
-#define DDR_EMR_ODS_VAL                         DDR_EMR_ODS_FULL
-
-#define DDR_SDRAM_START_ADDR                                   0x10000000
-
-
-// ----------------------------------------
-// PHY IOTERM values
-// ----------------------------------------
-#define PHY_PTM_IOTERM_OFF                                     0x0
-#define PHY_PTM_IOTERM_150R                                    0x1
-#define PHY_PTM_IOTERM_75R                                     0x2
-#define PHY_PTM_IOTERM_50R                                     0x3
-
-#define PHY_BYTE_IOSTR_60OHM                           0x0
-#define PHY_BYTE_IOSTR_40OHM                           0x1
-#define PHY_BYTE_IOSTR_30OHM                           0x2
-#define PHY_BYTE_IOSTR_30AOHM                          0x3
-
-#define DDR2_MR_BURST_LENGTH_4     (2)
-#define DDR2_MR_BURST_LENGTH_8     (3)
-#define DDR2_MR_DLL_RESET          (1 << 8)
-#define DDR2_MR_CAS_LATENCY_4      (4 << 4)
-#define DDR2_MR_CAS_LATENCY_5      (5 << 4)
-#define DDR2_MR_CAS_LATENCY_6      (6 << 4)
-#define DDR2_MR_WR_CYCLES_2        (1 << 9)
-#define DDR2_MR_WR_CYCLES_3        (2 << 9)
-#define DDR2_MR_WR_CYCLES_4        (3 << 9)
-#define DDR2_MR_WR_CYCLES_5        (4 << 9)
-#define DDR2_MR_WR_CYCLES_6        (5 << 9)
-
-
-VOID
-PL341DmcInit (
-  IN  UINTN             DmcBase,
-  IN  PL341_DMC_CONFIG* DmcConfig
-  );
-
-VOID PL341DmcPhyInit (
-  IN UINTN   DmcPhyBase
-  );
-
-VOID PL341DmcTrainPHY (
-  IN UINTN   DmcPhyBase
-  );
-
-#endif /* _PL341DMC_H_ */
+/** @file\r
+*\r
+*  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+*\r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*\r
+**/\r
+\r
+#ifndef _PL341DMC_H_\r
+#define _PL341DMC_H_\r
+\r
+\r
+typedef struct  {\r
+    UINTN      HasQos;        // has QoS registers\r
+    UINTN      MaxChip;       // number of memory chips accessible\r
+    BOOLEAN  IsUserCfg;\r
+    UINT32  User0Cfg;\r
+    UINT32  User2Cfg;\r
+    UINT32     RefreshPeriod;\r
+    UINT32     CasLatency;\r
+    UINT32     WriteLatency;\r
+    UINT32     t_mrd;\r
+    UINT32     t_ras;\r
+    UINT32     t_rc;\r
+    UINT32     t_rcd;\r
+    UINT32     t_rfc;\r
+    UINT32     t_rp;\r
+    UINT32     t_rrd;\r
+    UINT32     t_wr;\r
+    UINT32     t_wtr;\r
+    UINT32     t_xp;\r
+    UINT32     t_xsr;\r
+    UINT32     t_esr;\r
+    UINT32     MemoryCfg;\r
+    UINT32     MemoryCfg2;\r
+    UINT32     MemoryCfg3;\r
+    UINT32     ChipCfg0;\r
+    UINT32     ChipCfg1;\r
+    UINT32     ChipCfg2;\r
+    UINT32     ChipCfg3;\r
+    UINT32     t_faw;\r
+    UINT32     t_data_en;\r
+    UINT32     t_wdata_en;\r
+    UINT32  ModeReg;\r
+    UINT32  ExtModeReg;\r
+} PL341_DMC_CONFIG;\r
+\r
+/* Memory config bit fields */\r
+#define DMC_MEMORY_CONFIG_COLUMN_ADDRESS_9      0x1\r
+#define DMC_MEMORY_CONFIG_COLUMN_ADDRESS_10     0x2\r
+#define DMC_MEMORY_CONFIG_COLUMN_ADDRESS_11     0x3\r
+#define DMC_MEMORY_CONFIG_COLUMN_ADDRESS_12     0x4\r
+#define DMC_MEMORY_CONFIG_ROW_ADDRESS_11        (0x0 << 3)\r
+#define DMC_MEMORY_CONFIG_ROW_ADDRESS_12        (0x1 << 3)\r
+#define DMC_MEMORY_CONFIG_ROW_ADDRESS_13        (0x2 << 3)\r
+#define DMC_MEMORY_CONFIG_ROW_ADDRESS_14        (0x3 << 3)\r
+#define DMC_MEMORY_CONFIG_ROW_ADDRESS_15        (0x4 << 3)\r
+#define DMC_MEMORY_CONFIG_ROW_ADDRESS_16        (0x5 << 3)\r
+#define DMC_MEMORY_CONFIG_BURST_2               (0x1 << 15)\r
+#define DMC_MEMORY_CONFIG_BURST_4               (0x2 << 15)\r
+#define DMC_MEMORY_CONFIG_BURST_8               (0x3 << 15)\r
+#define DMC_MEMORY_CONFIG_BURST_16              (0x4 << 15)\r
+#define DMC_MEMORY_CONFIG_ACTIVE_CHIP_1    (0x0 << 21)\r
+#define DMC_MEMORY_CONFIG_ACTIVE_CHIP_2    (0x1 << 21)\r
+#define DMC_MEMORY_CONFIG_ACTIVE_CHIP_3    (0x2 << 21)\r
+#define DMC_MEMORY_CONFIG_ACTIVE_CHIP_4    (0x3 << 21)\r
+\r
+#define DMC_MEMORY_CFG2_CLK_ASYNC    (0x0 << 0)\r
+#define DMC_MEMORY_CFG2_CLK_SYNC    (0x1 << 0)\r
+#define DMC_MEMORY_CFG2_DQM_INIT    (0x1 << 2)\r
+#define DMC_MEMORY_CFG2_CKE_INIT    (0x1 << 3)\r
+#define DMC_MEMORY_CFG2_BANK_BITS_2    (0x0 << 4)\r
+#define DMC_MEMORY_CFG2_BANK_BITS_3    (0x3 << 4)\r
+#define DMC_MEMORY_CFG2_MEM_WIDTH_16    (0x0 << 6)\r
+#define DMC_MEMORY_CFG2_MEM_WIDTH_32    (0x1 << 6)\r
+#define DMC_MEMORY_CFG2_MEM_WIDTH_64    (0x2 << 6)\r
+#define DMC_MEMORY_CFG2_MEM_WIDTH_RESERVED  (0x3 << 6)\r
+\r
+//\r
+// DMC Configuration Register Map\r
+//\r
+#define DMC_STATUS_REG              0x00\r
+#define DMC_COMMAND_REG             0x04\r
+#define DMC_DIRECT_CMD_REG          0x08\r
+#define DMC_MEMORY_CONFIG_REG       0x0C\r
+#define DMC_REFRESH_PRD_REG         0x10\r
+#define DMC_CAS_LATENCY_REG         0x14\r
+#define DMC_WRITE_LATENCY_REG       0x18\r
+#define DMC_T_MRD_REG               0x1C\r
+#define DMC_T_RAS_REG               0x20\r
+#define DMC_T_RC_REG                0x24\r
+#define DMC_T_RCD_REG               0x28\r
+#define DMC_T_RFC_REG               0x2C\r
+#define DMC_T_RP_REG                0x30\r
+#define DMC_T_RRD_REG               0x34\r
+#define DMC_T_WR_REG                0x38\r
+#define DMC_T_WTR_REG               0x3C\r
+#define DMC_T_XP_REG                0x40\r
+#define DMC_T_XSR_REG               0x44\r
+#define DMC_T_ESR_REG               0x48\r
+#define DMC_MEMORY_CFG2_REG         0x4C\r
+#define DMC_MEMORY_CFG3_REG         0x50\r
+#define DMC_T_FAW_REG               0x54\r
+#define DMC_T_RDATA_EN              0x5C       /* DFI read data enable register */\r
+#define DMC_T_WRLAT_DIFF            0x60        /* DFI write data enable register */\r
+\r
+// Returns the state of the memory controller:\r
+#define DMC_STATUS_CONFIG       0x0\r
+#define DMC_STATUS_READY        0x1\r
+#define DMC_STATUS_PAUSED       0x2\r
+#define DMC_STATUS_LOWPOWER     0x3\r
+\r
+// Changes the state of the memory controller:\r
+#define DMC_COMMAND_GO              0x0\r
+#define DMC_COMMAND_SLEEP           0x1\r
+#define DMC_COMMAND_WAKEUP          0x2\r
+#define DMC_COMMAND_PAUSE           0x3\r
+#define DMC_COMMAND_CONFIGURE       0x4\r
+#define DMC_COMMAND_ACTIVEPAUSE     0x7\r
+\r
+// Determines the command required\r
+#define DMC_DIRECT_CMD_MEMCMD_PRECHARGEALL      0x0\r
+#define DMC_DIRECT_CMD_MEMCMD_AUTOREFRESH       (0x1 << 18)\r
+#define DMC_DIRECT_CMD_MEMCMD_MODEREG           (0x2 << 18)\r
+#define DMC_DIRECT_CMD_MEMCMD_EXTMODEREG        (0x2 << 18)\r
+#define DMC_DIRECT_CMD_MEMCMD_NOP               (0x3 << 18)\r
+#define DMC_DIRECT_CMD_MEMCMD_DPD               (0x1 << 22)\r
+#define DMC_DIRECT_CMD_BANKADDR(n)              ((n & 0x3) << 16)\r
+#define DMC_DIRECT_CMD_CHIP_ADDR(n)             ((n & 0x3) << 20)\r
+\r
+\r
+//\r
+// AXI ID configuration register map\r
+//\r
+#define DMC_ID_0_CFG_REG            0x100\r
+#define DMC_ID_1_CFG_REG            0x104\r
+#define DMC_ID_2_CFG_REG            0x108\r
+#define DMC_ID_3_CFG_REG            0x10C\r
+#define DMC_ID_4_CFG_REG            0x110\r
+#define DMC_ID_5_CFG_REG            0x114\r
+#define DMC_ID_6_CFG_REG            0x118\r
+#define DMC_ID_7_CFG_REG            0x11C\r
+#define DMC_ID_8_CFG_REG            0x120\r
+#define DMC_ID_9_CFG_REG            0x124\r
+#define DMC_ID_10_CFG_REG           0x128\r
+#define DMC_ID_11_CFG_REG           0x12C\r
+#define DMC_ID_12_CFG_REG           0x130\r
+#define DMC_ID_13_CFG_REG           0x134\r
+#define DMC_ID_14_CFG_REG           0x138\r
+#define DMC_ID_15_CFG_REG           0x13C\r
+\r
+// Set the QoS\r
+#define DMC_ID_CFG_QOS_DISABLE      0\r
+#define DMC_ID_CFG_QOS_ENABLE       1\r
+#define DMC_ID_CFG_QOS_MIN          2\r
+\r
+\r
+//\r
+// Chip configuration register map\r
+//\r
+#define DMC_CHIP_0_CFG_REG          0x200\r
+#define DMC_CHIP_1_CFG_REG          0x204\r
+#define DMC_CHIP_2_CFG_REG          0x208\r
+#define DMC_CHIP_3_CFG_REG          0x20C\r
+\r
+//\r
+// User Defined Pins\r
+//\r
+#define DMC_USER_STATUS_REG         0x300\r
+#define DMC_USER_0_CFG_REG          0x304\r
+#define DMC_USER_1_CFG_REG          0x308\r
+#define DMC_FEATURE_CRTL_REG        0x30C\r
+#define DMC_USER_2_CFG_REG          0x310\r
+\r
+\r
+//\r
+// PHY Register Settings\r
+//\r
+#define PHY_PTM_DFI_CLK_RANGE                                  0xE00           // DDR2 PHY PTM register offset\r
+#define PHY_PTM_IOTERM                                                 0xE04\r
+#define PHY_PTM_PLL_EN                                         0xe0c\r
+#define PHY_PTM_PLL_RANGE                                      0xe18\r
+#define PHY_PTM_FEEBACK_DIV                                    0xe1c\r
+#define PHY_PTM_RCLK_DIV                                       0xe20\r
+#define PHY_PTM_LOCK_STATUS                                    0xe28\r
+#define PHY_PTM_INIT_DONE                                      0xe34\r
+#define PHY_PTM_ADDCOM_IOSTR_OFF                               0xec8\r
+#define PHY_PTM_SQU_TRAINING                                   0xee8\r
+#define PHY_PTM_SQU_STAT                                       0xeec\r
+\r
+// ==============================================================================\r
+// PIPD 40G DDR2/DDR3 PHY Register definitions\r
+//\r
+// Offsets from APB Base Address\r
+// ==============================================================================\r
+#define PHY_BYTE0_OFFSET                                       0x000\r
+#define PHY_BYTE1_OFFSET                                       0x200\r
+#define PHY_BYTE2_OFFSET                                       0x400\r
+#define PHY_BYTE3_OFFSET                                       0x600\r
+\r
+#define PHY_BYTE0_COARSE_SQADJ_INIT                    0x064   ;// Coarse squelch adjust\r
+#define PHY_BYTE1_COARSE_SQADJ_INIT                    0x264   ;// Coarse squelch adjust\r
+#define PHY_BYTE2_COARSE_SQADJ_INIT                    0x464   ;// Coarse squelch adjust\r
+#define PHY_BYTE3_COARSE_SQADJ_INIT                    0x664   ;// Coarse squelch adjust\r
+\r
+#define PHY_BYTE0_IOSTR_OFFSET                         0x004\r
+#define PHY_BYTE1_IOSTR_OFFSET                         0x204\r
+#define PHY_BYTE2_IOSTR_OFFSET                         0x404\r
+#define PHY_BYTE3_IOSTR_OFFSET                         0x604\r
+\r
+\r
+;//--------------------------------------------------------------------------\r
+\r
+// DFI Clock ranges:\r
+\r
+#define PHY_PTM_DFI_CLK_RANGE_200MHz                   0x0\r
+#define PHY_PTM_DFI_CLK_RANGE_201_267MHz       0x1\r
+#define PHY_PTM_DFI_CLK_RANGE_268_333MHz       0x2\r
+#define PHY_PTM_DFI_CLK_RANGE_334_400MHz       0x3\r
+#define PHY_PTM_DFI_CLK_RANGE_401_533MHz       0x4\r
+#define PHY_PTM_DFI_CLK_RANGE_534_667MHz       0x5\r
+#define PHY_PTM_DFI_CLK_RANGE_668_800MHz       0x6\r
+\r
+\r
+\r
+#define  PHY_PTM_DFI_CLK_RANGE_VAL                     PHY_PTM_DFI_CLK_RANGE_334_400MHz\r
+\r
+//--------------------------------------------------------------------------\r
+\r
+\r
+// PLL Range\r
+\r
+#define PHY_PTM_PLL_RANGE_200_400MHz           0x0     // b0 = frequency >= 200 MHz and < 400 MHz\r
+#define PHY_PTM_PLL_RANGE_400_800MHz           0x1     // b1 = frequency >= 400 MHz.\r
+#define PHY_PTM_FEEBACK_DIV_200_400MHz         0x0     // b0 = frequency >= 200 MHz and < 400 MHz\r
+#define PHY_PTM_FEEBACK_DIV_400_800MHz         0x1     // b1 = frequency >= 400 MHz.\r
+#define PHY_PTM_REFCLK_DIV_200_400MHz          0x0\r
+#define PHY_PTM_REFCLK_DIV_400_800MHz          0x1\r
+\r
+#define TC_UIOLHNC_MASK                         0x000003C0\r
+#define TC_UIOLHNC_SHIFT                        0x6\r
+#define TC_UIOLHPC_MASK                         0x0000003F\r
+#define TC_UIOLHPC_SHIFT                        0x2\r
+#define TC_UIOHOCT_MASK                         0x2\r
+#define TC_UIOHOCT_SHIFT                        0x1\r
+#define TC_UIOHSTOP_SHIFT                       0x0\r
+#define TC_UIOLHXC_VALUE                        0x4\r
+\r
+#define PHY_PTM_SQU_TRAINING_ENABLE                            0x1\r
+#define PHY_PTM_SQU_TRAINING_DISABLE                           0x0\r
+\r
+\r
+//--------------------------------------\r
+// JEDEC DDR2 Device Register definitions and settings\r
+//--------------------------------------\r
+#define DDR_MODESET_SHFT                                               14\r
+#define DDR_MODESET_MR                                                 0x0             ;// Mode register\r
+#define DDR_MODESET_EMR                                                        0x1             ;// Extended Mode register\r
+#define DDR_MODESET_EMR2                                               0x2\r
+#define DDR_MODESET_EMR3                                               0x3\r
+\r
+//\r
+// Extended Mode Register settings\r
+//\r
+#define DDR_EMR_OCD_MASK                        0x0000380\r
+#define DDR_EMR_OCD_SHIFT                       0x7\r
+#define DDR_EMR_RTT_MASK                        0x00000044                  // DDR2 Device RTT (ODT) settings\r
+#define DDR_EMR_RTT_SHIFT                       0x2\r
+#define DDR_EMR_ODS_MASK                        0x00000002                  // DDR2 Output Drive Strength\r
+#define DDR_EMR_ODS_SHIFT                       0x0001\r
+\r
+// Termination Values:\r
+#define DDR_EMR_RTT_50R                         0x00000044                  // DDR2 50 Ohm termination\r
+#define DDR_EMR_RTT_75R                         0x00000004                  // DDR2 75 Ohm termination\r
+#define DDR_EMR_RTT_150                         0x00000040                  // DDR2 150 Ohm termination\r
+\r
+// Output Drive Strength Values:\r
+#define DDR_EMR_ODS_FULL                        0x0                         // DDR2 Full Drive Strength\r
+#define DDR_EMR_ODS_HALF                        0x1                         // DDR2 Half Drive Strength\r
+\r
+// OCD values\r
+#define DDR_EMR_OCD_DEFAULT                     0x7\r
+#define DDR_EMR_OCD_NS                          0x0\r
+\r
+#define DDR_EMR_ODS_VAL                         DDR_EMR_ODS_FULL\r
+\r
+#define DDR_SDRAM_START_ADDR                                   0x10000000\r
+\r
+\r
+// ----------------------------------------\r
+// PHY IOTERM values\r
+// ----------------------------------------\r
+#define PHY_PTM_IOTERM_OFF                                     0x0\r
+#define PHY_PTM_IOTERM_150R                                    0x1\r
+#define PHY_PTM_IOTERM_75R                                     0x2\r
+#define PHY_PTM_IOTERM_50R                                     0x3\r
+\r
+#define PHY_BYTE_IOSTR_60OHM                           0x0\r
+#define PHY_BYTE_IOSTR_40OHM                           0x1\r
+#define PHY_BYTE_IOSTR_30OHM                           0x2\r
+#define PHY_BYTE_IOSTR_30AOHM                          0x3\r
+\r
+#define DDR2_MR_BURST_LENGTH_4     (2)\r
+#define DDR2_MR_BURST_LENGTH_8     (3)\r
+#define DDR2_MR_DLL_RESET          (1 << 8)\r
+#define DDR2_MR_CAS_LATENCY_4      (4 << 4)\r
+#define DDR2_MR_CAS_LATENCY_5      (5 << 4)\r
+#define DDR2_MR_CAS_LATENCY_6      (6 << 4)\r
+#define DDR2_MR_WR_CYCLES_2        (1 << 9)\r
+#define DDR2_MR_WR_CYCLES_3        (2 << 9)\r
+#define DDR2_MR_WR_CYCLES_4        (3 << 9)\r
+#define DDR2_MR_WR_CYCLES_5        (4 << 9)\r
+#define DDR2_MR_WR_CYCLES_6        (5 << 9)\r
+\r
+\r
+VOID\r
+PL341DmcInit (\r
+  IN  UINTN             DmcBase,\r
+  IN  PL341_DMC_CONFIG* DmcConfig\r
+  );\r
+\r
+VOID PL341DmcPhyInit (\r
+  IN UINTN   DmcPhyBase\r
+  );\r
+\r
+VOID PL341DmcTrainPHY (\r
+  IN UINTN   DmcPhyBase\r
+  );\r
+\r
+#endif /* _PL341DMC_H_ */\r
index 7414b10050565a26c7ef221ab65ce6b39606fe30..f61036840d1dcbf220246f1ac14af8c46c2c7c08 100644 (file)
@@ -1,48 +1,48 @@
-/** @file
-*
-*  Copyright (c) 2011, ARM Limited. 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.
-*
-**/
-
-#ifndef __ARM_GLOBAL_VARIABLE_GUID_H__
-#define __ARM_GLOBAL_VARIABLE_GUID_H__
-
-#define ARM_HOB_GLOBAL_VARIABLE_GUID  \
-  { 0xc3253c90, 0xa24f, 0x4599, { 0xa6, 0x64, 0x1f, 0x88, 0x13, 0x77, 0x8f, 0xc9} };
-
-extern EFI_GUID gArmGlobalVariableGuid;
-
-///
-/// Describes all memory ranges used during the HOB producer 
-/// phase that exist outside the HOB list. This HOB type 
-/// describes how memory is used, not the physical attributes of memory.
-///
-typedef struct {
-  ///
-  /// The Guid HOB header. Header.HobType = EFI_HOB_TYPE_GUID_EXTENSION
-  ///                 and  Header.Name    = gArmGlobalVariableGuid
-  ///
-  EFI_HOB_GUID_TYPE            Header;
-
-  ///
-  /// The base address of memory allocated by this HOB. Type
-  /// EFI_PHYSICAL_ADDRESS is defined in AllocatePages() in the UEFI 2.0
-  /// specification.
-  ///
-  EFI_PHYSICAL_ADDRESS        GlobalVariableBase;
-
-  /// 
-  /// The length in bytes of memory allocated by this HOB.
-  /// 
-  UINT32                      GlobalVariableSize;
-} ARM_HOB_GLOBAL_VARIABLE;
-
-#endif
+/** @file\r
+*\r
+*  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+*\r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*\r
+**/\r
+\r
+#ifndef __ARM_GLOBAL_VARIABLE_GUID_H__\r
+#define __ARM_GLOBAL_VARIABLE_GUID_H__\r
+\r
+#define ARM_HOB_GLOBAL_VARIABLE_GUID  \\r
+  { 0xc3253c90, 0xa24f, 0x4599, { 0xa6, 0x64, 0x1f, 0x88, 0x13, 0x77, 0x8f, 0xc9} };\r
+\r
+extern EFI_GUID gArmGlobalVariableGuid;\r
+\r
+///\r
+/// Describes all memory ranges used during the HOB producer \r
+/// phase that exist outside the HOB list. This HOB type \r
+/// describes how memory is used, not the physical attributes of memory.\r
+///\r
+typedef struct {\r
+  ///\r
+  /// The Guid HOB header. Header.HobType = EFI_HOB_TYPE_GUID_EXTENSION\r
+  ///                 and  Header.Name    = gArmGlobalVariableGuid\r
+  ///\r
+  EFI_HOB_GUID_TYPE            Header;\r
+\r
+  ///\r
+  /// The base address of memory allocated by this HOB. Type\r
+  /// EFI_PHYSICAL_ADDRESS is defined in AllocatePages() in the UEFI 2.0\r
+  /// specification.\r
+  ///\r
+  EFI_PHYSICAL_ADDRESS        GlobalVariableBase;\r
+\r
+  /// \r
+  /// The length in bytes of memory allocated by this HOB.\r
+  /// \r
+  UINT32                      GlobalVariableSize;\r
+} ARM_HOB_GLOBAL_VARIABLE;\r
+\r
+#endif\r
index 02ef1ea8326bd5ee3714403ceedf6250b77c35e1..b1a080c00aa26b3dde489989d66942b9643145cb 100644 (file)
@@ -1,38 +1,38 @@
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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.
-*
-**/
-
-#ifndef __ARM_PLATFORM_GLOBAL_VARIABLE_LIB_H_
-#define __ARM_PLATFORM_GLOBAL_VARIABLE_LIB_H_
-
-VOID
-ArmPlatformGetGlobalVariable (
-  IN  UINTN     VariableOffset,
-  IN  UINTN     VariableSize,
-  OUT VOID*     Variable
-  );
-
-VOID
-ArmPlatformSetGlobalVariable (
-  IN  UINTN     VariableOffset,
-  IN  UINTN     VariableSize,
-  OUT VOID*     Variable
-  );
-
-VOID*
-ArmPlatformGetGlobalVariableAddress (
-  IN  UINTN     VariableOffset
-  );
-
-#endif
-
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*\r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*\r
+**/\r
+\r
+#ifndef __ARM_PLATFORM_GLOBAL_VARIABLE_LIB_H_\r
+#define __ARM_PLATFORM_GLOBAL_VARIABLE_LIB_H_\r
+\r
+VOID\r
+ArmPlatformGetGlobalVariable (\r
+  IN  UINTN     VariableOffset,\r
+  IN  UINTN     VariableSize,\r
+  OUT VOID*     Variable\r
+  );\r
+\r
+VOID\r
+ArmPlatformSetGlobalVariable (\r
+  IN  UINTN     VariableOffset,\r
+  IN  UINTN     VariableSize,\r
+  OUT VOID*     Variable\r
+  );\r
+\r
+VOID*\r
+ArmPlatformGetGlobalVariableAddress (\r
+  IN  UINTN     VariableOffset\r
+  );\r
+\r
+#endif\r
+\r
index 9f2de60a4a70a17f9d0c6e97179043aea02b860d..7bbd9664709070c916524a0261957157e847a149 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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.             
-*
-**/
-
-#ifndef _ARMPLATFORMLIB_H_
-#define _ARMPLATFORMLIB_H_
-
-//
-// 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>
-#include <Guid/MemoryTypeInformation.h>
-
-#include <Library/ArmLib.h>
-
-/**
-  This structure is used to describe a region of the EFI memory map
-
-  Every EFI regions of the system memory described by their physical start address and their size
-  can have different attributes. Some regions can be tested and other untested.
-
-**/
-typedef struct {
-  EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute;
-  EFI_PHYSICAL_ADDRESS         PhysicalStart;
-  UINT64                       NumberOfBytes;
-} ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR;
-
-UINTN
-ArmPlatformGetCorePosition (
-  IN UINTN MpId
-  );
-
-/**
-  Return the current Boot Mode
-
-  This function returns the boot reason on the platform
-
-  @return   Return the current Boot Mode of the platform
-
-**/
-EFI_BOOT_MODE
-ArmPlatformGetBootMode (
-  VOID
-  );
-
-/**
-  Initialize controllers that must setup in the normal world
-
-  This function is called by the ArmPlatformPkg/PrePi or ArmPlatformPkg/PlatformPei
-  in the PEI phase.
-
-**/
-RETURN_STATUS
-ArmPlatformInitialize (
-  IN  UINTN                     MpId
-  );
-
-/**
-  Initialize the system (or sometimes called permanent) memory
-
-  This memory is generally represented by the DRAM.
-
-**/
-VOID
-ArmPlatformInitializeSystemMemory (
-  VOID
-  );
-
-/**
-  Return the Virtual Memory Map of your platform
-
-  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.
-
-  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-
-                                    Virtual Memory mapping. This array must be ended by a zero-filled
-                                    entry
-
-**/
-VOID
-ArmPlatformGetVirtualMemoryMap (
-  OUT ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
-  );
-
-/**
-  Return the EFI Memory Map of your platform
-
-  This EFI Memory Map of the System Memory is used by MemoryInitPei module to create the Resource
-  Descriptor HOBs used by DXE core.
-
-  @param[out]   EfiMemoryMap        Array of ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR describing an
-                                    EFI Memory region. This array must be ended by a zero-filled entry
-
-**/
-EFI_STATUS
-ArmPlatformGetAdditionalSystemMemory (
-  OUT ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR** EfiMemoryMap
-  );
-
-/**
-  Return the Platform specific PPIs
-
-  This function exposes the Platform Specific PPIs. They can be used by any PrePi modules or passed
-  to the PeiCore by PrePeiCore.
-
-  @param[out]   PpiListSize         Size in Bytes of the Platform PPI List
-  @param[out]   PpiList             Platform PPI List
-
-**/
-VOID
-ArmPlatformGetPlatformPpiList (
-  OUT UINTN                   *PpiListSize,
-  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList
-  );
-
-#endif
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#ifndef _ARMPLATFORMLIB_H_\r
+#define _ARMPLATFORMLIB_H_\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiPei.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Ppi/MasterBootMode.h>\r
+#include <Ppi/BootInRecoveryMode.h>\r
+#include <Guid/MemoryTypeInformation.h>\r
+\r
+#include <Library/ArmLib.h>\r
+\r
+/**\r
+  This structure is used to describe a region of the EFI memory map\r
+\r
+  Every EFI regions of the system memory described by their physical start address and their size\r
+  can have different attributes. Some regions can be tested and other untested.\r
+\r
+**/\r
+typedef struct {\r
+  EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute;\r
+  EFI_PHYSICAL_ADDRESS         PhysicalStart;\r
+  UINT64                       NumberOfBytes;\r
+} ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR;\r
+\r
+UINTN\r
+ArmPlatformGetCorePosition (\r
+  IN UINTN MpId\r
+  );\r
+\r
+/**\r
+  Return the current Boot Mode\r
+\r
+  This function returns the boot reason on the platform\r
+\r
+  @return   Return the current Boot Mode of the platform\r
+\r
+**/\r
+EFI_BOOT_MODE\r
+ArmPlatformGetBootMode (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Initialize controllers that must setup in the normal world\r
+\r
+  This function is called by the ArmPlatformPkg/PrePi or ArmPlatformPkg/PlatformPei\r
+  in the PEI phase.\r
+\r
+**/\r
+RETURN_STATUS\r
+ArmPlatformInitialize (\r
+  IN  UINTN                     MpId\r
+  );\r
+\r
+/**\r
+  Initialize the system (or sometimes called permanent) memory\r
+\r
+  This memory is generally represented by the DRAM.\r
+\r
+**/\r
+VOID\r
+ArmPlatformInitializeSystemMemory (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Return the Virtual Memory Map of your platform\r
+\r
+  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.\r
+\r
+  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-\r
+                                    Virtual Memory mapping. This array must be ended by a zero-filled\r
+                                    entry\r
+\r
+**/\r
+VOID\r
+ArmPlatformGetVirtualMemoryMap (\r
+  OUT ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap\r
+  );\r
+\r
+/**\r
+  Return the EFI Memory Map of your platform\r
+\r
+  This EFI Memory Map of the System Memory is used by MemoryInitPei module to create the Resource\r
+  Descriptor HOBs used by DXE core.\r
+\r
+  @param[out]   EfiMemoryMap        Array of ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR describing an\r
+                                    EFI Memory region. This array must be ended by a zero-filled entry\r
+\r
+**/\r
+EFI_STATUS\r
+ArmPlatformGetAdditionalSystemMemory (\r
+  OUT ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR** EfiMemoryMap\r
+  );\r
+\r
+/**\r
+  Return the Platform specific PPIs\r
+\r
+  This function exposes the Platform Specific PPIs. They can be used by any PrePi modules or passed\r
+  to the PeiCore by PrePeiCore.\r
+\r
+  @param[out]   PpiListSize         Size in Bytes of the Platform PPI List\r
+  @param[out]   PpiList             Platform PPI List\r
+\r
+**/\r
+VOID\r
+ArmPlatformGetPlatformPpiList (\r
+  OUT UINTN                   *PpiListSize,\r
+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList\r
+  );\r
+\r
+#endif\r
index 32f1eb5088944e9867a3a2cd837b2791ede28e4a..ece80649036020e68bbed221c4f32e44a6bfe93a 100644 (file)
@@ -1,88 +1,88 @@
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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.             
-*
-**/
-
-#ifndef _ARMPLATFORMSECLIB_H_
-#define _ARMPLATFORMSECLIB_H_
-
-#define ARM_SEC_BOOT_MASK                 ~0
-#define ARM_SEC_COLD_BOOT                 (1 << 0)
-#define ARM_SEC_SECONDARY_COLD_BOOT       (1 << 1)
-
-/**
-  Initialize the memory where the initial stacks will reside
-
-  This memory can contain the initial stacks (Secure and Secure Monitor stacks).
-  In some platform, this region is already initialized and the implementation of this function can
-  do nothing. This memory can also represent the Secure RAM.
-  This function is called before the satck has been set up. Its implementation must ensure the stack
-  pointer is not used (probably required to use assembly language)
-
-**/
-VOID
-ArmPlatformSecBootMemoryInit (
-  VOID
-  );
-
-/**
-  Call at the beginning of the platform boot up
-
-  This function allows the firmware platform to do extra actions at the early
-  stage of the platform power up.
-
-  Note: This function must be implemented in assembler as there is no stack set up yet
-
-**/
-VOID
-ArmPlatformSecBootAction (
-  VOID
-  );
-
-/**
-  Initialize controllers that must setup at the early stage
-
-  Some peripherals must be initialized in Secure World.
-  For example: Some L2 controller, interconnect, clock, DMC, etc
-
-**/
-RETURN_STATUS
-ArmPlatformSecInitialize (
-  IN  UINTN                     MpId
-  );
-
-/**
-  Call before jumping to Normal World
-
-  This function allows the firmware platform to do extra actions before
-  jumping to the Normal World
-
-**/
-VOID
-ArmPlatformSecExtraAction (
-  IN  UINTN         MpId,
-  OUT UINTN*        JumpAddress
-  );
-
-/**
-  Initialize the Secure peripherals and memory regions
-
-  If Trustzone is supported by your platform then this function makes the required initialization
-  of the secure peripherals and memory regions.
-
-**/
-VOID
-ArmPlatformSecTrustzoneInit (
-  IN  UINTN                     MpId
-  );
-
-#endif
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#ifndef _ARMPLATFORMSECLIB_H_\r
+#define _ARMPLATFORMSECLIB_H_\r
+\r
+#define ARM_SEC_BOOT_MASK                 ~0\r
+#define ARM_SEC_COLD_BOOT                 (1 << 0)\r
+#define ARM_SEC_SECONDARY_COLD_BOOT       (1 << 1)\r
+\r
+/**\r
+  Initialize the memory where the initial stacks will reside\r
+\r
+  This memory can contain the initial stacks (Secure and Secure Monitor stacks).\r
+  In some platform, this region is already initialized and the implementation of this function can\r
+  do nothing. This memory can also represent the Secure RAM.\r
+  This function is called before the satck has been set up. Its implementation must ensure the stack\r
+  pointer is not used (probably required to use assembly language)\r
+\r
+**/\r
+VOID\r
+ArmPlatformSecBootMemoryInit (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Call at the beginning of the platform boot up\r
+\r
+  This function allows the firmware platform to do extra actions at the early\r
+  stage of the platform power up.\r
+\r
+  Note: This function must be implemented in assembler as there is no stack set up yet\r
+\r
+**/\r
+VOID\r
+ArmPlatformSecBootAction (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Initialize controllers that must setup at the early stage\r
+\r
+  Some peripherals must be initialized in Secure World.\r
+  For example: Some L2 controller, interconnect, clock, DMC, etc\r
+\r
+**/\r
+RETURN_STATUS\r
+ArmPlatformSecInitialize (\r
+  IN  UINTN                     MpId\r
+  );\r
+\r
+/**\r
+  Call before jumping to Normal World\r
+\r
+  This function allows the firmware platform to do extra actions before\r
+  jumping to the Normal World\r
+\r
+**/\r
+VOID\r
+ArmPlatformSecExtraAction (\r
+  IN  UINTN         MpId,\r
+  OUT UINTN*        JumpAddress\r
+  );\r
+\r
+/**\r
+  Initialize the Secure peripherals and memory regions\r
+\r
+  If Trustzone is supported by your platform then this function makes the required initialization\r
+  of the secure peripherals and memory regions.\r
+\r
+**/\r
+VOID\r
+ArmPlatformSecTrustzoneInit (\r
+  IN  UINTN                     MpId\r
+  );\r
+\r
+#endif\r
index 3c59bcc39017bbdff5755f4ec18e7f16351737f8..39a0cc7f734c0e9e7c3c539b4339fbe90e96d330 100644 (file)
@@ -1,63 +1,63 @@
-/** @file  ArmPlatformSysConfigLib.h
-
-  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __ARM_PLATFORM_SYS_CONFIG_H__
-#define __ARM_PLATFORM_SYS_CONFIG_H__
-
-#include <Base.h>
-
-/* This header file makes it easier to access the System Configuration Registers
- * in the ARM Versatile Express motherboard.
- */
-
-//
-// Typedef
-//
-typedef UINT32  SYS_CONFIG_FUNCTION;
-
-//
-// Functions
-//
-RETURN_STATUS
-ArmPlatformSysConfigInitialize (
-  VOID
-  );
-
-RETURN_STATUS
-ArmPlatformSysConfigGet (
-  IN  SYS_CONFIG_FUNCTION   Function,
-  OUT UINT32*               Value
-  );
-
-RETURN_STATUS
-ArmPlatformSysConfigGetValues (
-  IN  SYS_CONFIG_FUNCTION   Function,
-  IN  UINTN                 Size,
-  OUT UINT32*               Values
-  );
-
-RETURN_STATUS
-ArmPlatformSysConfigSet (
-  IN  SYS_CONFIG_FUNCTION   Function,
-  IN  UINT32                Value
-  );
-
-RETURN_STATUS
-ArmPlatformSysConfigSetDevice (
-  IN  SYS_CONFIG_FUNCTION   Function,
-  IN  UINT32                Device,
-  IN  UINT32                Value
-  );
-
-#endif /* __SYS_CFG_REGISTERS_H__ */
+/** @file  ArmPlatformSysConfigLib.h\r
+\r
+  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __ARM_PLATFORM_SYS_CONFIG_H__\r
+#define __ARM_PLATFORM_SYS_CONFIG_H__\r
+\r
+#include <Base.h>\r
+\r
+/* This header file makes it easier to access the System Configuration Registers\r
+ * in the ARM Versatile Express motherboard.\r
+ */\r
+\r
+//\r
+// Typedef\r
+//\r
+typedef UINT32  SYS_CONFIG_FUNCTION;\r
+\r
+//\r
+// Functions\r
+//\r
+RETURN_STATUS\r
+ArmPlatformSysConfigInitialize (\r
+  VOID\r
+  );\r
+\r
+RETURN_STATUS\r
+ArmPlatformSysConfigGet (\r
+  IN  SYS_CONFIG_FUNCTION   Function,\r
+  OUT UINT32*               Value\r
+  );\r
+\r
+RETURN_STATUS\r
+ArmPlatformSysConfigGetValues (\r
+  IN  SYS_CONFIG_FUNCTION   Function,\r
+  IN  UINTN                 Size,\r
+  OUT UINT32*               Values\r
+  );\r
+\r
+RETURN_STATUS\r
+ArmPlatformSysConfigSet (\r
+  IN  SYS_CONFIG_FUNCTION   Function,\r
+  IN  UINT32                Value\r
+  );\r
+\r
+RETURN_STATUS\r
+ArmPlatformSysConfigSetDevice (\r
+  IN  SYS_CONFIG_FUNCTION   Function,\r
+  IN  UINT32                Device,\r
+  IN  UINT32                Value\r
+  );\r
+\r
+#endif /* __SYS_CFG_REGISTERS_H__ */\r
index 278138759f376e68548c3422afd2a1bb3ec890d8..511d0f69de6087a5426aadc3db16578e122f2f60 100644 (file)
@@ -1,76 +1,76 @@
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 <PiDxe.h>
-#include <Library/ArmPlatformGlobalVariableLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/DebugLib.h>
-#include <Library/HobLib.h>
-#include <Library/PcdLib.h>
-
-#include <Guid/ArmGlobalVariableHob.h>
-
-UINTN  mGlobalVariableBase = 0;
-
-RETURN_STATUS
-EFIAPI
-ArmPlatformGlobalVariableConstructor (
-  VOID
-  )
-{
-  ARM_HOB_GLOBAL_VARIABLE  *Hob;
-
-  Hob = GetFirstGuidHob (&gArmGlobalVariableGuid);
-  ASSERT (Hob != NULL);
-
-  mGlobalVariableBase = Hob->GlobalVariableBase;
-
-  return EFI_SUCCESS;
-}
-
-VOID
-ArmPlatformGetGlobalVariable (
-  IN  UINTN     VariableOffset,
-  IN  UINTN     VariableSize,
-  OUT VOID*     Variable
-  )
-{
-  if (mGlobalVariableBase == 0) {
-    ArmPlatformGlobalVariableConstructor ();
-  }
-
-  CopyMem (Variable, (VOID*)(mGlobalVariableBase + VariableOffset), VariableSize);
-}
-
-VOID
-ArmPlatformSetGlobalVariable (
-  IN  UINTN     VariableOffset,
-  IN  UINTN     VariableSize,
-  OUT VOID*     Variable
-  )
-{
-  if (mGlobalVariableBase == 0) {
-    ArmPlatformGlobalVariableConstructor ();
-  }
-
-  CopyMem ((VOID*)(mGlobalVariableBase + VariableOffset), Variable, VariableSize);
-}
-
-VOID*
-ArmPlatformGetGlobalVariableAddress (
-  IN  UINTN     VariableOffset
-  )
-{
-  return (VOID*)(mGlobalVariableBase + VariableOffset);
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*\r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*\r
+**/\r
+\r
+#include <PiDxe.h>\r
+#include <Library/ArmPlatformGlobalVariableLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+#include <Guid/ArmGlobalVariableHob.h>\r
+\r
+UINTN  mGlobalVariableBase = 0;\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+ArmPlatformGlobalVariableConstructor (\r
+  VOID\r
+  )\r
+{\r
+  ARM_HOB_GLOBAL_VARIABLE  *Hob;\r
+\r
+  Hob = GetFirstGuidHob (&gArmGlobalVariableGuid);\r
+  ASSERT (Hob != NULL);\r
+\r
+  mGlobalVariableBase = Hob->GlobalVariableBase;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+VOID\r
+ArmPlatformGetGlobalVariable (\r
+  IN  UINTN     VariableOffset,\r
+  IN  UINTN     VariableSize,\r
+  OUT VOID*     Variable\r
+  )\r
+{\r
+  if (mGlobalVariableBase == 0) {\r
+    ArmPlatformGlobalVariableConstructor ();\r
+  }\r
+\r
+  CopyMem (Variable, (VOID*)(mGlobalVariableBase + VariableOffset), VariableSize);\r
+}\r
+\r
+VOID\r
+ArmPlatformSetGlobalVariable (\r
+  IN  UINTN     VariableOffset,\r
+  IN  UINTN     VariableSize,\r
+  OUT VOID*     Variable\r
+  )\r
+{\r
+  if (mGlobalVariableBase == 0) {\r
+    ArmPlatformGlobalVariableConstructor ();\r
+  }\r
+\r
+  CopyMem ((VOID*)(mGlobalVariableBase + VariableOffset), Variable, VariableSize);\r
+}\r
+\r
+VOID*\r
+ArmPlatformGetGlobalVariableAddress (\r
+  IN  UINTN     VariableOffset\r
+  )\r
+{\r
+  return (VOID*)(mGlobalVariableBase + VariableOffset);\r
+}\r
index f2284ce4ca58f35e2b21acf6e15f505160996619..a0835d25f9c236caf35ce11641dd0fe594d14dd7 100644 (file)
@@ -1,44 +1,44 @@
-#/** @file
-# Timer library implementation
-#  
-#  
-#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
-#
-#  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                      = DxeArmPlatformGlobalVariableLib
-  FILE_GUID                      = 53fa3cc3-23b7-4ec2-9bfa-30257d7e1135 
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = ArmPlatformGlobalVariableLib
-  
-  CONSTRUCTOR                    = ArmPlatformGlobalVariableConstructor
-
-[Sources.common]
-  DxeArmPlatformGlobalVariableLib.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  BaseLib
-  DebugLib
-  HobLib
-
-[Guids]
-  gArmGlobalVariableGuid
-
-[FixedPcd]
-  gArmPlatformTokenSpaceGuid.PcdPeiGlobalVariableSize
-
+#/** @file\r
+# Timer library implementation\r
+#  \r
+#  \r
+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DxeArmPlatformGlobalVariableLib\r
+  FILE_GUID                      = 53fa3cc3-23b7-4ec2-9bfa-30257d7e1135 \r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ArmPlatformGlobalVariableLib\r
+  \r
+  CONSTRUCTOR                    = ArmPlatformGlobalVariableConstructor\r
+\r
+[Sources.common]\r
+  DxeArmPlatformGlobalVariableLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  HobLib\r
+\r
+[Guids]\r
+  gArmGlobalVariableGuid\r
+\r
+[FixedPcd]\r
+  gArmPlatformTokenSpaceGuid.PcdPeiGlobalVariableSize\r
+\r
index 63aa3199fed3c6d9f415893105126119716bbfc1..df3e12944db1305dbf2169f2d8da0dc3a7ea6cac 100644 (file)
@@ -1,84 +1,84 @@
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 <Uefi.h>
-#include <Library/ArmPlatformGlobalVariableLib.h>
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/PcdLib.h>
-#include <Library/DebugLib.h>
-
-// Declared by ArmPlatformPkg/PrePi Module
-extern UINTN mGlobalVariableBase;
-
-VOID
-ArmPlatformGetGlobalVariable (
-  IN  UINTN     VariableOffset,
-  IN  UINTN     VariableSize,
-  OUT VOID*     Variable
-  )
-{
-  UINTN  GlobalVariableBase;
-
-  // Ensure the Global Variable Size have been initialized
-  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
-
-  GlobalVariableBase = PcdGet32 (PcdCPUCoresStackBase) + PcdGet32 (PcdCPUCorePrimaryStackSize) - PcdGet32 (PcdPeiGlobalVariableSize);
-
-  if (VariableSize == 4) {
-    *(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));
-  } else if (VariableSize == 8) {
-    *(UINT64*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));
-  } else {
-    CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);
-  }
-}
-
-VOID
-ArmPlatformSetGlobalVariable (
-  IN  UINTN     VariableOffset,
-  IN  UINTN     VariableSize,
-  OUT VOID*     Variable
-  )
-{
-  UINTN  GlobalVariableBase;
-
-  // Ensure the Global Variable Size have been initialized
-  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
-
-  GlobalVariableBase = PcdGet32 (PcdCPUCoresStackBase) + PcdGet32 (PcdCPUCorePrimaryStackSize) - PcdGet32 (PcdPeiGlobalVariableSize);
-
-  if (VariableSize == 4) {
-    WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);
-  } else if (VariableSize == 8) {
-    WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);
-  } else {
-    CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);
-  }
-}
-
-VOID*
-ArmPlatformGetGlobalVariableAddress (
-  IN  UINTN     VariableOffset
-  )
-{
-  UINTN  GlobalVariableBase;
-
-  // Ensure the Global Variable Size have been initialized
-  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
-
-  GlobalVariableBase = PcdGet32 (PcdCPUCoresStackBase) + PcdGet32 (PcdCPUCorePrimaryStackSize) - PcdGet32 (PcdPeiGlobalVariableSize);
-
-  return (VOID*)(GlobalVariableBase + VariableOffset);
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*\r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*\r
+**/\r
+\r
+#include <Uefi.h>\r
+#include <Library/ArmPlatformGlobalVariableLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+// Declared by ArmPlatformPkg/PrePi Module\r
+extern UINTN mGlobalVariableBase;\r
+\r
+VOID\r
+ArmPlatformGetGlobalVariable (\r
+  IN  UINTN     VariableOffset,\r
+  IN  UINTN     VariableSize,\r
+  OUT VOID*     Variable\r
+  )\r
+{\r
+  UINTN  GlobalVariableBase;\r
+\r
+  // Ensure the Global Variable Size have been initialized\r
+  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));\r
+\r
+  GlobalVariableBase = PcdGet32 (PcdCPUCoresStackBase) + PcdGet32 (PcdCPUCorePrimaryStackSize) - PcdGet32 (PcdPeiGlobalVariableSize);\r
+\r
+  if (VariableSize == 4) {\r
+    *(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));\r
+  } else if (VariableSize == 8) {\r
+    *(UINT64*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));\r
+  } else {\r
+    CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);\r
+  }\r
+}\r
+\r
+VOID\r
+ArmPlatformSetGlobalVariable (\r
+  IN  UINTN     VariableOffset,\r
+  IN  UINTN     VariableSize,\r
+  OUT VOID*     Variable\r
+  )\r
+{\r
+  UINTN  GlobalVariableBase;\r
+\r
+  // Ensure the Global Variable Size have been initialized\r
+  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));\r
+\r
+  GlobalVariableBase = PcdGet32 (PcdCPUCoresStackBase) + PcdGet32 (PcdCPUCorePrimaryStackSize) - PcdGet32 (PcdPeiGlobalVariableSize);\r
+\r
+  if (VariableSize == 4) {\r
+    WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);\r
+  } else if (VariableSize == 8) {\r
+    WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);\r
+  } else {\r
+    CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);\r
+  }\r
+}\r
+\r
+VOID*\r
+ArmPlatformGetGlobalVariableAddress (\r
+  IN  UINTN     VariableOffset\r
+  )\r
+{\r
+  UINTN  GlobalVariableBase;\r
+\r
+  // Ensure the Global Variable Size have been initialized\r
+  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));\r
+\r
+  GlobalVariableBase = PcdGet32 (PcdCPUCoresStackBase) + PcdGet32 (PcdCPUCorePrimaryStackSize) - PcdGet32 (PcdPeiGlobalVariableSize);\r
+\r
+  return (VOID*)(GlobalVariableBase + VariableOffset);\r
+}\r
index a14f9332215aa3dff57029bdf65403f5544c868d..8eea9d3821d96ebe7ea86f9038ef30b64d2f14db 100644 (file)
@@ -1,40 +1,40 @@
-#/** @file
-# ArmPlatformGlobalVariableLib library implementation
-#  
-#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
-#  
-#  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                      = PeiArmPlatformGlobalVariableLib
-  FILE_GUID                      = 3e03daf2-b7b4-45f7-80b2-12aba043391f
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = ArmPlatformGlobalVariableLib
-
-[Sources.common]
-  PeiArmPlatformGlobalVariableLib.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  BaseLib
-  DebugLib
-  PcdLib
-
-[FixedPcd]
-  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase
-  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize
-  gArmPlatformTokenSpaceGuid.PcdPeiGlobalVariableSize
-
+#/** @file\r
+# ArmPlatformGlobalVariableLib library implementation\r
+#  \r
+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>\r
+#  \r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PeiArmPlatformGlobalVariableLib\r
+  FILE_GUID                      = 3e03daf2-b7b4-45f7-80b2-12aba043391f\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ArmPlatformGlobalVariableLib\r
+\r
+[Sources.common]\r
+  PeiArmPlatformGlobalVariableLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  PcdLib\r
+\r
+[FixedPcd]\r
+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase\r
+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize\r
+  gArmPlatformTokenSpaceGuid.PcdPeiGlobalVariableSize\r
+\r
index 563e405f664ad2582c2aef3c7330e35ef04e0293..47430e302b99b55c41b175e7363a9ae6a0054d50 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 <Uefi.h>
-#include <Library/ArmPlatformGlobalVariableLib.h>
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/PcdLib.h>
-#include <Library/DebugLib.h>
-
-#define IS_XIP() (((UINT32)PcdGet32 (PcdFdBaseAddress) > (UINT32)(PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize))) || \
-                  ((PcdGet32 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) < PcdGet32 (PcdSystemMemoryBase)))
-
-// Declared by ArmPlatformPkg/PrePi Module
-extern UINTN mGlobalVariableBase;
-
-VOID
-ArmPlatformGetGlobalVariable (
-  IN  UINTN     VariableOffset,
-  IN  UINTN     VariableSize,
-  OUT VOID*     Variable
-  )
-{
-  UINTN  GlobalVariableBase;
-
-  // Ensure the Global Variable Size have been initialized
-  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
-
-  if (IS_XIP()) {
-    // In Case of XIP, we expect the Primary Stack at the top of the System Memory
-    // The size must be 64bit aligned to allow 64bit variable to be aligned
-    GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);
-  } else {
-    GlobalVariableBase = mGlobalVariableBase;
-  }
-
-  if (VariableSize == 4) {
-    *(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));
-  } else if (VariableSize == 8) {
-    *(UINT64*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));
-  } else {
-    CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);
-  }
-}
-
-VOID
-ArmPlatformSetGlobalVariable (
-  IN  UINTN     VariableOffset,
-  IN  UINTN     VariableSize,
-  OUT VOID*     Variable
-  )
-{
-  UINTN  GlobalVariableBase;
-
-  // Ensure the Global Variable Size have been initialized
-  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
-
-  if (IS_XIP()) {
-    // In Case of XIP, we expect the Primary Stack at the top of the System Memory
-    // The size must be 64bit aligned to allow 64bit variable to be aligned
-    GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);
-  } else {
-    GlobalVariableBase = mGlobalVariableBase;
-  }
-
-  if (VariableSize == 4) {
-    WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);
-  } else if (VariableSize == 8) {
-    WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);
-  } else {
-    CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);
-  }
-}
-
-VOID*
-ArmPlatformGetGlobalVariableAddress (
-  IN  UINTN     VariableOffset
-  )
-{
-  UINTN  GlobalVariableBase;
-
-  // Ensure the Global Variable Size have been initialized
-  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
-
-  if (IS_XIP()) {
-    // In Case of XIP, we expect the Primary Stack at the top of the System Memory
-    // The size must be 64bit aligned to allow 64bit variable to be aligned
-    GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);
-  } else {
-    GlobalVariableBase = mGlobalVariableBase;
-  }
-
-  return (VOID*)(GlobalVariableBase + VariableOffset);
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*\r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*\r
+**/\r
+\r
+#include <Uefi.h>\r
+#include <Library/ArmPlatformGlobalVariableLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#define IS_XIP() (((UINT32)PcdGet32 (PcdFdBaseAddress) > (UINT32)(PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize))) || \\r
+                  ((PcdGet32 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) < PcdGet32 (PcdSystemMemoryBase)))\r
+\r
+// Declared by ArmPlatformPkg/PrePi Module\r
+extern UINTN mGlobalVariableBase;\r
+\r
+VOID\r
+ArmPlatformGetGlobalVariable (\r
+  IN  UINTN     VariableOffset,\r
+  IN  UINTN     VariableSize,\r
+  OUT VOID*     Variable\r
+  )\r
+{\r
+  UINTN  GlobalVariableBase;\r
+\r
+  // Ensure the Global Variable Size have been initialized\r
+  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));\r
+\r
+  if (IS_XIP()) {\r
+    // In Case of XIP, we expect the Primary Stack at the top of the System Memory\r
+    // The size must be 64bit aligned to allow 64bit variable to be aligned\r
+    GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);\r
+  } else {\r
+    GlobalVariableBase = mGlobalVariableBase;\r
+  }\r
+\r
+  if (VariableSize == 4) {\r
+    *(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));\r
+  } else if (VariableSize == 8) {\r
+    *(UINT64*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));\r
+  } else {\r
+    CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);\r
+  }\r
+}\r
+\r
+VOID\r
+ArmPlatformSetGlobalVariable (\r
+  IN  UINTN     VariableOffset,\r
+  IN  UINTN     VariableSize,\r
+  OUT VOID*     Variable\r
+  )\r
+{\r
+  UINTN  GlobalVariableBase;\r
+\r
+  // Ensure the Global Variable Size have been initialized\r
+  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));\r
+\r
+  if (IS_XIP()) {\r
+    // In Case of XIP, we expect the Primary Stack at the top of the System Memory\r
+    // The size must be 64bit aligned to allow 64bit variable to be aligned\r
+    GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);\r
+  } else {\r
+    GlobalVariableBase = mGlobalVariableBase;\r
+  }\r
+\r
+  if (VariableSize == 4) {\r
+    WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);\r
+  } else if (VariableSize == 8) {\r
+    WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);\r
+  } else {\r
+    CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);\r
+  }\r
+}\r
+\r
+VOID*\r
+ArmPlatformGetGlobalVariableAddress (\r
+  IN  UINTN     VariableOffset\r
+  )\r
+{\r
+  UINTN  GlobalVariableBase;\r
+\r
+  // Ensure the Global Variable Size have been initialized\r
+  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));\r
+\r
+  if (IS_XIP()) {\r
+    // In Case of XIP, we expect the Primary Stack at the top of the System Memory\r
+    // The size must be 64bit aligned to allow 64bit variable to be aligned\r
+    GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);\r
+  } else {\r
+    GlobalVariableBase = mGlobalVariableBase;\r
+  }\r
+\r
+  return (VOID*)(GlobalVariableBase + VariableOffset);\r
+}\r
index 42d903f3d6af1538aec75a2cc8d9870fd414f4aa..978ba33369cb6cfe2ad5656c1f2414ee5c248b51 100644 (file)
@@ -1,81 +1,81 @@
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 <Uefi.h>
-#include <Library/ArmPlatformGlobalVariableLib.h>
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/PcdLib.h>
-#include <Library/DebugLib.h>
-
-VOID
-ArmPlatformGetGlobalVariable (
-  IN  UINTN     VariableOffset,
-  IN  UINTN     VariableSize,
-  OUT VOID*     Variable
-  )
-{
-  UINTN  GlobalVariableBase;
-
-  // Ensure the Global Variable Size have been initialized
-  ASSERT (VariableOffset < PcdGet32 (PcdSecGlobalVariableSize));
-
-  GlobalVariableBase = PcdGet32 (PcdCPUCoresSecStackBase) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize) - PcdGet32 (PcdSecGlobalVariableSize);
-  
-  if (VariableSize == 4) {
-    *(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));
-  } else if (VariableSize == 8) {
-    *(UINT64*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));
-  } else {
-    CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);
-  }
-}
-
-VOID
-ArmPlatformSetGlobalVariable (
-  IN  UINTN     VariableOffset,
-  IN  UINTN     VariableSize,
-  OUT VOID*     Variable
-  )
-{
-  UINTN  GlobalVariableBase;
-
-  // Ensure the Global Variable Size have been initialized
-  ASSERT (VariableOffset < PcdGet32 (PcdSecGlobalVariableSize));
-
-  GlobalVariableBase = PcdGet32 (PcdCPUCoresSecStackBase) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize) - PcdGet32 (PcdSecGlobalVariableSize);
-
-  if (VariableSize == 4) {
-    WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);
-  } else if (VariableSize == 8) {
-    WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);
-  } else {
-    CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);
-  }
-}
-
-VOID*
-ArmPlatformGetGlobalVariableAddress (
-  IN  UINTN     VariableOffset
-  )
-{
-  UINTN  GlobalVariableBase;
-
-  // Ensure the Global Variable Size have been initialized
-  ASSERT (VariableOffset < PcdGet32 (PcdSecGlobalVariableSize));
-
-  GlobalVariableBase = PcdGet32 (PcdCPUCoresSecStackBase) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize) - PcdGet32 (PcdSecGlobalVariableSize);
-
-  return (VOID*)(GlobalVariableBase + VariableOffset);
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*\r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*\r
+**/\r
+\r
+#include <Uefi.h>\r
+#include <Library/ArmPlatformGlobalVariableLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+VOID\r
+ArmPlatformGetGlobalVariable (\r
+  IN  UINTN     VariableOffset,\r
+  IN  UINTN     VariableSize,\r
+  OUT VOID*     Variable\r
+  )\r
+{\r
+  UINTN  GlobalVariableBase;\r
+\r
+  // Ensure the Global Variable Size have been initialized\r
+  ASSERT (VariableOffset < PcdGet32 (PcdSecGlobalVariableSize));\r
+\r
+  GlobalVariableBase = PcdGet32 (PcdCPUCoresSecStackBase) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize) - PcdGet32 (PcdSecGlobalVariableSize);\r
+  \r
+  if (VariableSize == 4) {\r
+    *(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));\r
+  } else if (VariableSize == 8) {\r
+    *(UINT64*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));\r
+  } else {\r
+    CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);\r
+  }\r
+}\r
+\r
+VOID\r
+ArmPlatformSetGlobalVariable (\r
+  IN  UINTN     VariableOffset,\r
+  IN  UINTN     VariableSize,\r
+  OUT VOID*     Variable\r
+  )\r
+{\r
+  UINTN  GlobalVariableBase;\r
+\r
+  // Ensure the Global Variable Size have been initialized\r
+  ASSERT (VariableOffset < PcdGet32 (PcdSecGlobalVariableSize));\r
+\r
+  GlobalVariableBase = PcdGet32 (PcdCPUCoresSecStackBase) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize) - PcdGet32 (PcdSecGlobalVariableSize);\r
+\r
+  if (VariableSize == 4) {\r
+    WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);\r
+  } else if (VariableSize == 8) {\r
+    WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);\r
+  } else {\r
+    CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);\r
+  }\r
+}\r
+\r
+VOID*\r
+ArmPlatformGetGlobalVariableAddress (\r
+  IN  UINTN     VariableOffset\r
+  )\r
+{\r
+  UINTN  GlobalVariableBase;\r
+\r
+  // Ensure the Global Variable Size have been initialized\r
+  ASSERT (VariableOffset < PcdGet32 (PcdSecGlobalVariableSize));\r
+\r
+  GlobalVariableBase = PcdGet32 (PcdCPUCoresSecStackBase) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize) - PcdGet32 (PcdSecGlobalVariableSize);\r
+\r
+  return (VOID*)(GlobalVariableBase + VariableOffset);\r
+}\r
index 235eb673f7c7af12f4003473e7a15680bc08757d..f3a7efcae0abde10c2fa74d85edd4537d3f31bd8 100644 (file)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 <Library/ArmLib.h>
-#include <Library/ArmPlatformLib.h>
-
-#include <Ppi/ArmMpCoreInfo.h>
-
-
-ARM_CORE_INFO mArmPlatformNullMpCoreInfoTable[] = {
-  {
-    // Cluster 0, Core 0
-    0x0, 0x0,
-
-    // MP Core MailBox Set/Get/Clear Addresses and Clear Value
-    (EFI_PHYSICAL_ADDRESS)0,
-    (EFI_PHYSICAL_ADDRESS)0,
-    (EFI_PHYSICAL_ADDRESS)0,
-    (UINT64)0xFFFFFFFF
-  },
-  {
-    // Cluster 0, Core 1
-    0x0, 0x1,
-
-    // MP Core MailBox Set/Get/Clear Addresses and Clear Value
-    (EFI_PHYSICAL_ADDRESS)0,
-    (EFI_PHYSICAL_ADDRESS)0,
-    (EFI_PHYSICAL_ADDRESS)0,
-    (UINT64)0xFFFFFFFF
-  },
-  {
-    // Cluster 0, Core 2
-    0x0, 0x2,
-
-    // MP Core MailBox Set/Get/Clear Addresses and Clear Value
-    (EFI_PHYSICAL_ADDRESS)0,
-    (EFI_PHYSICAL_ADDRESS)0,
-    (EFI_PHYSICAL_ADDRESS)0,
-    (UINT64)0xFFFFFFFF
-  },
-  {
-    // Cluster 0, Core 3
-    0x0, 0x3,
-
-    // MP Core MailBox Set/Get/Clear Addresses and Clear Value
-    (EFI_PHYSICAL_ADDRESS)0,
-    (EFI_PHYSICAL_ADDRESS)0,
-    (EFI_PHYSICAL_ADDRESS)0,
-    (UINT64)0xFFFFFFFF
-  }
-};
-
-// This function should be better located into TimerLib implementation
-RETURN_STATUS
-EFIAPI
-TimerConstructor (
-  VOID
-  )
-{
-  return EFI_SUCCESS;
-}
-
-/**
-  Return the current Boot Mode
-
-  This function returns the boot reason on the platform
-
-**/
-EFI_BOOT_MODE
-ArmPlatformGetBootMode (
-  VOID
-  )
-{
-  return BOOT_WITH_FULL_CONFIGURATION;
-}
-
-/**
-  Initialize controllers that must setup in the normal world
-
-  This function is called by the ArmPlatformPkg/PrePi or ArmPlatformPkg/PlatformPei
-  in the PEI phase.
-
-**/
-RETURN_STATUS
-ArmPlatformInitialize (
-  IN  UINTN                     MpId
-  )
-{
-  if (!IS_PRIMARY_CORE(MpId)) {
-    return RETURN_SUCCESS;
-  }
-
-  //TODO: Implement me
-
-  return RETURN_SUCCESS;
-}
-
-/**
-  Initialize the system (or sometimes called permanent) memory
-
-  This memory is generally represented by the DRAM.
-
-**/
-VOID
-ArmPlatformInitializeSystemMemory (
-  VOID
-  )
-{
-  //TODO: Implement me
-}
-
-EFI_STATUS
-PrePeiCoreGetMpCoreInfo (
-  OUT UINTN                   *CoreCount,
-  OUT ARM_CORE_INFO           **ArmCoreTable
-  )
-{
-  if (ArmIsMpCore()) {
-    *CoreCount    = sizeof(mArmPlatformNullMpCoreInfoTable) / sizeof(ARM_CORE_INFO);
-    *ArmCoreTable = mArmPlatformNullMpCoreInfoTable;
-    return EFI_SUCCESS;
-  } else {
-    return EFI_UNSUPPORTED;
-  }
-}
-
-// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore
-EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;
-ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };
-
-EFI_PEI_PPI_DESCRIPTOR      gPlatformPpiTable[] = {
-  {
-    EFI_PEI_PPI_DESCRIPTOR_PPI,
-    &mArmMpCoreInfoPpiGuid,
-    &mMpCoreInfoPpi
-  }
-};
-
-VOID
-ArmPlatformGetPlatformPpiList (
-  OUT UINTN                   *PpiListSize,
-  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList
-  )
-{
-  if (ArmIsMpCore()) {
-    *PpiListSize = sizeof(gPlatformPpiTable);
-    *PpiList = gPlatformPpiTable;
-  } else {
-    *PpiListSize = 0;
-    *PpiList = NULL;
-  }
-}
-
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include <Library/ArmLib.h>\r
+#include <Library/ArmPlatformLib.h>\r
+\r
+#include <Ppi/ArmMpCoreInfo.h>\r
+\r
+\r
+ARM_CORE_INFO mArmPlatformNullMpCoreInfoTable[] = {\r
+  {\r
+    // Cluster 0, Core 0\r
+    0x0, 0x0,\r
+\r
+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value\r
+    (EFI_PHYSICAL_ADDRESS)0,\r
+    (EFI_PHYSICAL_ADDRESS)0,\r
+    (EFI_PHYSICAL_ADDRESS)0,\r
+    (UINT64)0xFFFFFFFF\r
+  },\r
+  {\r
+    // Cluster 0, Core 1\r
+    0x0, 0x1,\r
+\r
+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value\r
+    (EFI_PHYSICAL_ADDRESS)0,\r
+    (EFI_PHYSICAL_ADDRESS)0,\r
+    (EFI_PHYSICAL_ADDRESS)0,\r
+    (UINT64)0xFFFFFFFF\r
+  },\r
+  {\r
+    // Cluster 0, Core 2\r
+    0x0, 0x2,\r
+\r
+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value\r
+    (EFI_PHYSICAL_ADDRESS)0,\r
+    (EFI_PHYSICAL_ADDRESS)0,\r
+    (EFI_PHYSICAL_ADDRESS)0,\r
+    (UINT64)0xFFFFFFFF\r
+  },\r
+  {\r
+    // Cluster 0, Core 3\r
+    0x0, 0x3,\r
+\r
+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value\r
+    (EFI_PHYSICAL_ADDRESS)0,\r
+    (EFI_PHYSICAL_ADDRESS)0,\r
+    (EFI_PHYSICAL_ADDRESS)0,\r
+    (UINT64)0xFFFFFFFF\r
+  }\r
+};\r
+\r
+// This function should be better located into TimerLib implementation\r
+RETURN_STATUS\r
+EFIAPI\r
+TimerConstructor (\r
+  VOID\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Return the current Boot Mode\r
+\r
+  This function returns the boot reason on the platform\r
+\r
+**/\r
+EFI_BOOT_MODE\r
+ArmPlatformGetBootMode (\r
+  VOID\r
+  )\r
+{\r
+  return BOOT_WITH_FULL_CONFIGURATION;\r
+}\r
+\r
+/**\r
+  Initialize controllers that must setup in the normal world\r
+\r
+  This function is called by the ArmPlatformPkg/PrePi or ArmPlatformPkg/PlatformPei\r
+  in the PEI phase.\r
+\r
+**/\r
+RETURN_STATUS\r
+ArmPlatformInitialize (\r
+  IN  UINTN                     MpId\r
+  )\r
+{\r
+  if (!IS_PRIMARY_CORE(MpId)) {\r
+    return RETURN_SUCCESS;\r
+  }\r
+\r
+  //TODO: Implement me\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Initialize the system (or sometimes called permanent) memory\r
+\r
+  This memory is generally represented by the DRAM.\r
+\r
+**/\r
+VOID\r
+ArmPlatformInitializeSystemMemory (\r
+  VOID\r
+  )\r
+{\r
+  //TODO: Implement me\r
+}\r
+\r
+EFI_STATUS\r
+PrePeiCoreGetMpCoreInfo (\r
+  OUT UINTN                   *CoreCount,\r
+  OUT ARM_CORE_INFO           **ArmCoreTable\r
+  )\r
+{\r
+  if (ArmIsMpCore()) {\r
+    *CoreCount    = sizeof(mArmPlatformNullMpCoreInfoTable) / sizeof(ARM_CORE_INFO);\r
+    *ArmCoreTable = mArmPlatformNullMpCoreInfoTable;\r
+    return EFI_SUCCESS;\r
+  } else {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+}\r
+\r
+// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore\r
+EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;\r
+ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };\r
+\r
+EFI_PEI_PPI_DESCRIPTOR      gPlatformPpiTable[] = {\r
+  {\r
+    EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+    &mArmMpCoreInfoPpiGuid,\r
+    &mMpCoreInfoPpi\r
+  }\r
+};\r
+\r
+VOID\r
+ArmPlatformGetPlatformPpiList (\r
+  OUT UINTN                   *PpiListSize,\r
+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList\r
+  )\r
+{\r
+  if (ArmIsMpCore()) {\r
+    *PpiListSize = sizeof(gPlatformPpiTable);\r
+    *PpiList = gPlatformPpiTable;\r
+  } else {\r
+    *PpiListSize = 0;\r
+    *PpiList = NULL;\r
+  }\r
+}\r
+\r
index c548d8b3f962f83787c1d9dd3df75dc35d8a25de..1a83882030f900ed1772a2edf8744cfb83d99203 100644 (file)
@@ -1,74 +1,74 @@
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 <Library/ArmPlatformLib.h>
-#include <Library/DebugLib.h>
-#include <Library/PcdLib.h>
-
-/**
-  Initialize the Secure peripherals and memory regions
-
-  If Trustzone is supported by your platform then this function makes the required initialization
-  of the secure peripherals and memory regions.
-
-**/
-VOID
-ArmPlatformSecTrustzoneInit (
-  IN  UINTN                     MpId
-  )
-{
-  // Secondary cores might have to set the Secure SGIs into the GICD_IGROUPR0
-  if (!IS_PRIMARY_CORE(MpId)) {
-    return;
-  }
-
-  ASSERT(FALSE);
-}
-
-/**
-  Initialize controllers that must setup at the early stage
-
-  Some peripherals must be initialized in Secure World.
-  For example, some L2x0 requires to be initialized in Secure World
-
-**/
-RETURN_STATUS
-ArmPlatformSecInitialize (
-  IN  UINTN                     MpId
-  )
-{
-  // If it is not the primary core then there is nothing to do
-  if (!IS_PRIMARY_CORE(MpId)) {
-    return RETURN_SUCCESS;
-  }
-
-  // Do nothing yet
-  return RETURN_SUCCESS;
-}
-
-/**
-  Call before jumping to Normal World
-
-  This function allows the firmware platform to do extra actions before
-  jumping to the Normal World
-
-**/
-VOID
-ArmPlatformSecExtraAction (
-  IN  UINTN         MpId,
-  OUT UINTN*        JumpAddress
-  )
-{
-  *JumpAddress = PcdGet32(PcdFvBaseAddress);
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include <Library/ArmPlatformLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+/**\r
+  Initialize the Secure peripherals and memory regions\r
+\r
+  If Trustzone is supported by your platform then this function makes the required initialization\r
+  of the secure peripherals and memory regions.\r
+\r
+**/\r
+VOID\r
+ArmPlatformSecTrustzoneInit (\r
+  IN  UINTN                     MpId\r
+  )\r
+{\r
+  // Secondary cores might have to set the Secure SGIs into the GICD_IGROUPR0\r
+  if (!IS_PRIMARY_CORE(MpId)) {\r
+    return;\r
+  }\r
+\r
+  ASSERT(FALSE);\r
+}\r
+\r
+/**\r
+  Initialize controllers that must setup at the early stage\r
+\r
+  Some peripherals must be initialized in Secure World.\r
+  For example, some L2x0 requires to be initialized in Secure World\r
+\r
+**/\r
+RETURN_STATUS\r
+ArmPlatformSecInitialize (\r
+  IN  UINTN                     MpId\r
+  )\r
+{\r
+  // If it is not the primary core then there is nothing to do\r
+  if (!IS_PRIMARY_CORE(MpId)) {\r
+    return RETURN_SUCCESS;\r
+  }\r
+\r
+  // Do nothing yet\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Call before jumping to Normal World\r
+\r
+  This function allows the firmware platform to do extra actions before\r
+  jumping to the Normal World\r
+\r
+**/\r
+VOID\r
+ArmPlatformSecExtraAction (\r
+  IN  UINTN         MpId,\r
+  OUT UINTN*        JumpAddress\r
+  )\r
+{\r
+  *JumpAddress = PcdGet32(PcdFvBaseAddress);\r
+}\r
index 2962ffe5d8510dbf1761008981e17bd9386cbfe7..26afb34b23e266fbe196ae500d3b74da380f00f6 100755 (executable)
@@ -1,55 +1,55 @@
-#/* @file
-#  Copyright (c) 2011-2012, ARM Limited. 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                      = DebugSecExtraActionLib
-  FILE_GUID                      = 8fff7a60-a6f8-11e0-990a-0002a5d5c51b
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = ArmPlatformSecExtraActionLib
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-#  VALID_ARCHITECTURES           = ARM
-#
-
-[Sources.common]
-  DebugSecExtraActionLib.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  ArmPkg/ArmPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  DebugLib
-  PcdLib
-  ArmGicLib
-  PrintLib
-  SerialPortLib
-
-[FeaturePcd]
-  gArmPlatformTokenSpaceGuid.PcdStandalone
-  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec
-
-[FixedPcd]
-  gArmTokenSpaceGuid.PcdFvBaseAddress
-  
-  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask
-  gArmTokenSpaceGuid.PcdArmPrimaryCore
-
-  gArmTokenSpaceGuid.PcdGicDistributorBase
-  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase
-  gArmTokenSpaceGuid.PcdGicSgiIntId
+#/* @file\r
+#  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+#*/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DebugSecExtraActionLib\r
+  FILE_GUID                      = 8fff7a60-a6f8-11e0-990a-0002a5d5c51b\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ArmPlatformSecExtraActionLib\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = ARM\r
+#\r
+\r
+[Sources.common]\r
+  DebugSecExtraActionLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  PcdLib\r
+  ArmGicLib\r
+  PrintLib\r
+  SerialPortLib\r
+\r
+[FeaturePcd]\r
+  gArmPlatformTokenSpaceGuid.PcdStandalone\r
+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec\r
+\r
+[FixedPcd]\r
+  gArmTokenSpaceGuid.PcdFvBaseAddress\r
+  \r
+  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask\r
+  gArmTokenSpaceGuid.PcdArmPrimaryCore\r
+\r
+  gArmTokenSpaceGuid.PcdGicDistributorBase\r
+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase\r
+  gArmTokenSpaceGuid.PcdGicSgiIntId\r
index 7ccd09bd48ab6f50d5ad77c53cc8a8769afa0e5c..20e8882713b3fc0acbea347b1b285880a39cdc17 100644 (file)
-/** @file
-  Serial I/O Port library functions with no library constructor/destructor
-
-  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-  Copyright (c) 2012, ARM Ltd. All rights reserved.<BR>
-  
-  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 <Base.h>
-
-#include <Library/IoLib.h>
-#include <Library/PcdLib.h>
-#include <Library/SerialPortLib.h>
-#include <Library/SerialPortExtLib.h>
-
-#include <Drivers/PL011Uart.h>
-
-
-/**
-
-  Programmed hardware of Serial port.
-
-  @return    Always return RETURN_UNSUPPORTED.
-
-**/
-RETURN_STATUS
-EFIAPI
-SerialPortInitialize (
-  VOID
-  )
-{
-  return PL011UartInitializePort (
-      (UINTN)PcdGet64 (PcdSerialRegisterBase),
-      (UINTN)PcdGet64 (PcdUartDefaultBaudRate),
-      0, // Use the default value for Fifo depth
-      (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity),
-      PcdGet8 (PcdUartDefaultDataBits),
-      (EFI_STOP_BITS_TYPE) PcdGet8 (PcdUartDefaultStopBits));
-}
-
-/**
-  Write data to serial device.
-
-  @param  Buffer           Point of data buffer which need to be written.
-  @param  NumberOfBytes    Number of output bytes which are cached in Buffer.
-
-  @retval 0                Write data failed.
-  @retval !0               Actual number of bytes written to serial device.
-
-**/
-UINTN
-EFIAPI
-SerialPortWrite (
-  IN UINT8     *Buffer,
-  IN UINTN     NumberOfBytes
-  )
-{
-  return PL011UartWrite ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);
-}
-
-/**
-  Read data from serial device and save the data in buffer.
-
-  @param  Buffer           Point of data buffer which need to be written.
-  @param  NumberOfBytes    Number of output bytes which are cached in Buffer.
-
-  @retval 0                Read data failed.
-  @retval !0               Actual number of bytes read from serial device.
-
-**/
-UINTN
-EFIAPI
-SerialPortRead (
-  OUT UINT8     *Buffer,
-  IN  UINTN     NumberOfBytes
-)
-{
-  return PL011UartRead ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);
-}
-
-/**
-  Check to see if any data is available to be read from the debug device.
-
-  @retval EFI_SUCCESS       At least one byte of data is available to be read
-  @retval EFI_NOT_READY     No data is available to be read
-  @retval EFI_DEVICE_ERROR  The serial device is not functioning properly
-
-**/
-BOOLEAN
-EFIAPI
-SerialPortPoll (
-  VOID
-  )
-{
-  return PL011UartPoll ((UINTN)PcdGet64 (PcdSerialRegisterBase));
-}
-
-/**
-  Set new attributes to PL011.
-
-  @param  BaudRate                The baud rate of the serial device. If the baud rate is not supported,
-                                  the speed will be reduced down to the nearest supported one and the
-                                  variable's value will be updated accordingly.
-  @param  ReceiveFifoDepth        The number of characters the device will buffer on input. If the specified
-                                  value is not supported, the variable's value will be reduced down to the
-                                  nearest supported one.
-  @param  Timeout                 If applicable, the number of microseconds the device will wait
-                                  before timing out a Read or a Write operation.
-  @param  Parity                  If applicable, this is the EFI_PARITY_TYPE that is computer or checked
-                                  as each character is transmitted or received. If the device does not
-                                  support parity, the value is the default parity value.
-  @param  DataBits                The number of data bits in each character
-  @param  StopBits                If applicable, the EFI_STOP_BITS_TYPE number of stop bits per character.
-                                  If the device does not support stop bits, the value is the default stop
-                                  bit value.
-
-  @retval EFI_SUCCESS             All attributes were set correctly on the serial device.
-  @retval EFI_INVALID_PARAMETERS  One or more of the attributes has an unsupported value.
-
-**/
-RETURN_STATUS
-EFIAPI
-SerialPortSetAttributes (
-  IN UINT64              BaudRate,
-  IN UINT32              ReceiveFifoDepth,
-  IN UINT32              Timeout,
-  IN EFI_PARITY_TYPE     Parity,
-  IN UINT8               DataBits,
-  IN EFI_STOP_BITS_TYPE  StopBits
-  )
-{
-  return PL011UartInitializePort (
-        (UINTN)PcdGet64 (PcdSerialRegisterBase),
-        BaudRate,
-        ReceiveFifoDepth,
-        Parity,
-        DataBits,
-        StopBits);
-}
-
-/**
-  Set the serial device control bits.
-
-  @param  Control                 Control bits which are to be set on the serial device.
-
-  @retval EFI_SUCCESS             The new control bits were set on the serial device.
-  @retval EFI_UNSUPPORTED         The serial device does not support this operation.
-  @retval EFI_DEVICE_ERROR        The serial device is not functioning correctly.
-
-**/
-RETURN_STATUS
-EFIAPI
-SerialPortSetControl (
-  IN UINT32                  Control
-  )
-{
-  return PL011UartSetControl((UINTN)PcdGet64 (PcdSerialRegisterBase), Control);
-}
-
-/**
-  Get the serial device control bits.
-
-  @param  Control                 Control signals read from the serial device.
-
-  @retval EFI_SUCCESS             The control bits were read from the serial device.
-  @retval EFI_DEVICE_ERROR        The serial device is not functioning correctly.
-
-**/
-RETURN_STATUS
-EFIAPI
-SerialPortGetControl (
-  OUT UINT32                  *Control
-  )
-{
-  return PL011UartGetControl((UINTN)PcdGet64 (PcdSerialRegisterBase), Control);
-}
+/** @file\r
+  Serial I/O Port library functions with no library constructor/destructor\r
+\r
+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+  Copyright (c) 2012, ARM Ltd. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Base.h>\r
+\r
+#include <Library/IoLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/SerialPortLib.h>\r
+#include <Library/SerialPortExtLib.h>\r
+\r
+#include <Drivers/PL011Uart.h>\r
+\r
+\r
+/**\r
+\r
+  Programmed hardware of Serial port.\r
+\r
+  @return    Always return RETURN_UNSUPPORTED.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SerialPortInitialize (\r
+  VOID\r
+  )\r
+{\r
+  return PL011UartInitializePort (\r
+      (UINTN)PcdGet64 (PcdSerialRegisterBase),\r
+      (UINTN)PcdGet64 (PcdUartDefaultBaudRate),\r
+      0, // Use the default value for Fifo depth\r
+      (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity),\r
+      PcdGet8 (PcdUartDefaultDataBits),\r
+      (EFI_STOP_BITS_TYPE) PcdGet8 (PcdUartDefaultStopBits));\r
+}\r
+\r
+/**\r
+  Write data to serial device.\r
+\r
+  @param  Buffer           Point of data buffer which need to be written.\r
+  @param  NumberOfBytes    Number of output bytes which are cached in Buffer.\r
+\r
+  @retval 0                Write data failed.\r
+  @retval !0               Actual number of bytes written to serial device.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+SerialPortWrite (\r
+  IN UINT8     *Buffer,\r
+  IN UINTN     NumberOfBytes\r
+  )\r
+{\r
+  return PL011UartWrite ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);\r
+}\r
+\r
+/**\r
+  Read data from serial device and save the data in buffer.\r
+\r
+  @param  Buffer           Point of data buffer which need to be written.\r
+  @param  NumberOfBytes    Number of output bytes which are cached in Buffer.\r
+\r
+  @retval 0                Read data failed.\r
+  @retval !0               Actual number of bytes read from serial device.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+SerialPortRead (\r
+  OUT UINT8     *Buffer,\r
+  IN  UINTN     NumberOfBytes\r
+)\r
+{\r
+  return PL011UartRead ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);\r
+}\r
+\r
+/**\r
+  Check to see if any data is available to be read from the debug device.\r
+\r
+  @retval EFI_SUCCESS       At least one byte of data is available to be read\r
+  @retval EFI_NOT_READY     No data is available to be read\r
+  @retval EFI_DEVICE_ERROR  The serial device is not functioning properly\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+SerialPortPoll (\r
+  VOID\r
+  )\r
+{\r
+  return PL011UartPoll ((UINTN)PcdGet64 (PcdSerialRegisterBase));\r
+}\r
+\r
+/**\r
+  Set new attributes to PL011.\r
+\r
+  @param  BaudRate                The baud rate of the serial device. If the baud rate is not supported,\r
+                                  the speed will be reduced down to the nearest supported one and the\r
+                                  variable's value will be updated accordingly.\r
+  @param  ReceiveFifoDepth        The number of characters the device will buffer on input. If the specified\r
+                                  value is not supported, the variable's value will be reduced down to the\r
+                                  nearest supported one.\r
+  @param  Timeout                 If applicable, the number of microseconds the device will wait\r
+                                  before timing out a Read or a Write operation.\r
+  @param  Parity                  If applicable, this is the EFI_PARITY_TYPE that is computer or checked\r
+                                  as each character is transmitted or received. If the device does not\r
+                                  support parity, the value is the default parity value.\r
+  @param  DataBits                The number of data bits in each character\r
+  @param  StopBits                If applicable, the EFI_STOP_BITS_TYPE number of stop bits per character.\r
+                                  If the device does not support stop bits, the value is the default stop\r
+                                  bit value.\r
+\r
+  @retval EFI_SUCCESS             All attributes were set correctly on the serial device.\r
+  @retval EFI_INVALID_PARAMETERS  One or more of the attributes has an unsupported value.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SerialPortSetAttributes (\r
+  IN UINT64              BaudRate,\r
+  IN UINT32              ReceiveFifoDepth,\r
+  IN UINT32              Timeout,\r
+  IN EFI_PARITY_TYPE     Parity,\r
+  IN UINT8               DataBits,\r
+  IN EFI_STOP_BITS_TYPE  StopBits\r
+  )\r
+{\r
+  return PL011UartInitializePort (\r
+        (UINTN)PcdGet64 (PcdSerialRegisterBase),\r
+        BaudRate,\r
+        ReceiveFifoDepth,\r
+        Parity,\r
+        DataBits,\r
+        StopBits);\r
+}\r
+\r
+/**\r
+  Set the serial device control bits.\r
+\r
+  @param  Control                 Control bits which are to be set on the serial device.\r
+\r
+  @retval EFI_SUCCESS             The new control bits were set on the serial device.\r
+  @retval EFI_UNSUPPORTED         The serial device does not support this operation.\r
+  @retval EFI_DEVICE_ERROR        The serial device is not functioning correctly.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SerialPortSetControl (\r
+  IN UINT32                  Control\r
+  )\r
+{\r
+  return PL011UartSetControl((UINTN)PcdGet64 (PcdSerialRegisterBase), Control);\r
+}\r
+\r
+/**\r
+  Get the serial device control bits.\r
+\r
+  @param  Control                 Control signals read from the serial device.\r
+\r
+  @retval EFI_SUCCESS             The control bits were read from the serial device.\r
+  @retval EFI_DEVICE_ERROR        The serial device is not functioning correctly.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SerialPortGetControl (\r
+  OUT UINT32                  *Control\r
+  )\r
+{\r
+  return PL011UartGetControl((UINTN)PcdGet64 (PcdSerialRegisterBase), Control);\r
+}\r
index fcaa23eddee91caa169e2287ae836a68585d9756..a042dac9a3f396ce0eb72942221be5e0aca4f695 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-  Copyright (c) 2011, ARM Limited. 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 <Base.h>
-
-#include <Library/BaseLib.h>
-#include <Library/TimerLib.h>
-#include <Library/DebugLib.h>
-#include <Library/PcdLib.h>
-#include <Library/IoLib.h>
-#include <Drivers/SP804Timer.h>
-
-#define SP804_TIMER_METRONOME_BASE    ((UINTN)PcdGet32 (PcdSP804TimerMetronomeBase))
-#define SP804_TIMER_PERFORMANCE_BASE  ((UINTN)PcdGet32 (PcdSP804TimerPerformanceBase))
-
-// Setup SP810's Timer2 for managing delay functions. And Timer3 for Performance counter
-// Note: ArmVE's Timer0 and Timer1 are used by TimerDxe.
-RETURN_STATUS
-EFIAPI
-TimerConstructor (
-  VOID
-  )
-{
-  // Check if the Metronome Timer is already initialized
-  if (MmioRead32(SP804_TIMER_METRONOME_BASE + SP804_TIMER_CONTROL_REG) & SP804_TIMER_CTRL_ENABLE) {
-    return RETURN_SUCCESS;
-  } else {
-    // Configure the Metronome Timer for free running operation, 32 bits, no prescaler, and interrupt disabled
-    MmioWrite32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_32BIT | SP804_PRESCALE_DIV_1);
-
-    // Start the Metronome Timer ticking
-    MmioOr32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_ENABLE);
-  }
-
-  // Check if the Performance Timer is already initialized
-  if (MmioRead32(SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CONTROL_REG) & SP804_TIMER_CTRL_ENABLE) {
-    return RETURN_SUCCESS;
-  } else {
-    // Configure the Performance timer for free running operation, 32 bits, no prescaler, interrupt disabled
-    MmioWrite32 (SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_32BIT | SP804_PRESCALE_DIV_1);
-
-    // Start the Performance Timer ticking
-    MmioOr32 (SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_ENABLE);
-  }
-
-  return RETURN_SUCCESS;
-}
-
-/**
-  Stalls the CPU for at least the given number of microseconds.
-
-  Stalls the CPU for the number of microseconds specified by MicroSeconds.
-  The hardware timer is 32 bits.
-  The maximum possible delay is (0xFFFFFFFF / TimerFrequencyMHz), i.e. ([32bits] / FreqInMHz)
-  For example:
-  +----------------+------------+----------+----------+
-  | TimerFrequency |  MaxDelay  | MaxDelay | MaxDelay |
-  |     (MHz)      |    (us)    |   (s)    |  (min)   |
-  +----------------+------------+----------+----------+
-  |        1       | 0xFFFFFFFF |   4294   |   71.5   |
-  |        5       | 0x33333333 |    859   |   14.3   |
-  |       10       | 0x19999999 |    429   |    7.2   |
-  |       50       | 0x051EB851 |     86   |    1.4   |
-  +----------------+------------+----------+----------+
-  If it becomes necessary to support higher delays, then consider using the
-  real time clock.
-
-  During this delay, the cpu is not yielded to any other process, with one exception:
-  events that are triggered off a timer and which execute at a higher TPL than
-  this function. These events may call MicroSecondDelay (or NanoSecondDelay) to
-  fulfil their own needs.
-  Therefore, this function must be re-entrant, as it may be interrupted and re-started.
-
-  @param  MicroSeconds  The minimum number of microseconds to delay.
-
-  @return The value of MicroSeconds inputted.
-
-**/
-UINTN
-EFIAPI
-MicroSecondDelay (
-  IN  UINTN MicroSeconds
-  )
-{
-  UINT64    DelayTicks64;         // Convert from microseconds to timer ticks, more bits to detect over-range conditions.
-  UINTN     DelayTicks;           // Convert from microseconds to timer ticks, native size for general calculations.
-  UINTN     StartTicks;           // Timer value snapshot at the start of the delay
-  UINTN     TargetTicks;          // Timer value to signal the end of the delay
-  UINTN     CurrentTicks;         // Current value of the 64-bit timer value at any given moment
-
-  // If we snapshot the timer at the start of the delay function then we minimise unaccounted overheads.
-  StartTicks = MmioRead32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CURRENT_REG);
-
-  // We are operating at the limit of 32bits. For the range checking work in 64 bits to avoid overflows.
-  DelayTicks64 = MultU64x32((UINT64)MicroSeconds, PcdGet32(PcdSP804TimerFrequencyInMHz));
-
-  // We are limited to 32 bits.
-  // If the specified delay is exactly equal to the max range of the timer,
-  // then the start will be equal to the stop plus one timer overflow (wrap-around).
-  // To avoid having to check for that, reduce the maximum acceptable range by 1 tick,
-  // i.e. reject delays equal or greater than the max range of the timer.
-  if (DelayTicks64 >= (UINT64)SP804_MAX_TICKS) {
-    DEBUG((EFI_D_ERROR,"MicroSecondDelay: ERROR: MicroSeconds=%d exceed SP804 count range. Max MicroSeconds=%d\n",
-      MicroSeconds,
-      ((UINTN)SP804_MAX_TICKS/PcdGet32(PcdSP804TimerFrequencyInMHz))));
-  }
-  ASSERT(DelayTicks64 < (UINT64)SP804_MAX_TICKS);
-
-  // From now on do calculations only in native bit size.
-  DelayTicks = (UINTN)DelayTicks64;
-
-  // Calculate the target value of the timer.
-
-  //Note: SP804 timer is counting down
-  if (StartTicks >= DelayTicks) {
-    // In this case we do not expect a wrap-around of the timer to occur.
-    // CurrentTicks must be less than StartTicks and higher than TargetTicks.
-    // If this is not the case, then the delay has been reached and may even have been exceeded if this
-    // function was suspended by a higher priority interrupt.
-
-    TargetTicks = StartTicks - DelayTicks;
-
-    do {
-      CurrentTicks = MmioRead32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CURRENT_REG);
-    } while ((CurrentTicks > TargetTicks) && (CurrentTicks <= StartTicks));
-
-  } else {
-    // In this case TargetTicks is larger than StartTicks.
-    // This means we expect a wrap-around of the timer to occur and we must wait for it.
-    // Before the wrap-around, CurrentTicks must be less than StartTicks and less than TargetTicks.
-    // After the wrap-around, CurrentTicks must be larger than StartTicks and larger than TargetTicks.
-    // If this is not the case, then the delay has been reached and may even have been exceeded if this
-    // function was suspended by a higher priority interrupt.
-
-    // The order of operations is essential to avoid arithmetic overflow problems
-    TargetTicks = ((UINTN)SP804_MAX_TICKS - DelayTicks) + StartTicks;
-
-    // First wait for the wrap-around to occur
-    do {
-      CurrentTicks = MmioRead32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CURRENT_REG);
-    } while (CurrentTicks <= StartTicks);
-
-    // Then wait for the target
-    do {
-      CurrentTicks = MmioRead32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CURRENT_REG);
-    } while (CurrentTicks > TargetTicks);
-  }
-
-  return MicroSeconds;
-}
-
-/**
-  Stalls the CPU for at least the given number of nanoseconds.
-
-  Stalls the CPU for the number of nanoseconds specified by NanoSeconds.
-
-  When the timer frequency is 1MHz, each tick corresponds to 1 microsecond.
-  Therefore, the nanosecond delay will be rounded up to the nearest 1 microsecond.
-
-  @param  NanoSeconds The minimum number of nanoseconds to delay.
-
-  @return The value of NanoSeconds inputted.
-
-**/
-UINTN
-EFIAPI
-NanoSecondDelay (
-  IN  UINTN NanoSeconds
-  )
-{
-  UINTN  MicroSeconds;
-
-  // Round up to 1us Tick Number
-  MicroSeconds = NanoSeconds / 1000;
-  MicroSeconds += ((NanoSeconds % 1000) == 0) ? 0 : 1;
-
-  MicroSecondDelay (MicroSeconds);
-
-  return NanoSeconds;
-}
-
-/**
-  Retrieves the current value of a 64-bit free running performance counter.
-
-  The counter can either count up by 1 or count down by 1. If the physical
-  performance counter counts by a larger increment, then the counter values
-  must be translated. The properties of the counter can be retrieved from
-  GetPerformanceCounterProperties().
-
-  @return The current value of the free running performance counter.
-
-**/
-UINT64
-EFIAPI
-GetPerformanceCounter (
-  VOID
-  )
-{ 
-  // Free running 64-bit/32-bit counter is needed here.
-  // Don't think we need this to boot, just to do performance profile
-  UINT64 Value;
-  Value = MmioRead32 (SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CURRENT_REG);
-  return Value;
-}
-
-
-/**
-  Retrieves the 64-bit frequency in Hz and the range of performance counter
-  values.
-
-  If StartValue is not NULL, then the value that the performance counter starts
-  with immediately after is it rolls over is returned in StartValue. If
-  EndValue is not NULL, then the value that the performance counter end with
-  immediately before it rolls over is returned in EndValue. The 64-bit
-  frequency of the performance counter in Hz is always returned. If StartValue
-  is less than EndValue, then the performance counter counts up. If StartValue
-  is greater than EndValue, then the performance counter counts down. For
-  example, a 64-bit free running counter that counts up would have a StartValue
-  of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter
-  that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.
-
-  @param  StartValue  The value the performance counter starts with when it
-                      rolls over.
-  @param  EndValue    The value that the performance counter ends with before
-                      it rolls over.
-
-  @return The frequency in Hz.
-
-**/
-UINT64
-EFIAPI
-GetPerformanceCounterProperties (
-  OUT UINT64  *StartValue,  OPTIONAL
-  OUT UINT64  *EndValue     OPTIONAL
-  )
-{
-  if (StartValue != NULL) {
-    // Timer starts with the reload value
-    *StartValue = 0xFFFFFFFF;
-  }
-  
-  if (EndValue != NULL) {
-    // Timer counts down to 0x0
-    *EndValue = (UINT64)0ULL;
-  }
-  
-  return PcdGet64 (PcdEmbeddedPerformanceCounterFrequencyInHz);
-}
+/** @file\r
+\r
+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Base.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Drivers/SP804Timer.h>\r
+\r
+#define SP804_TIMER_METRONOME_BASE    ((UINTN)PcdGet32 (PcdSP804TimerMetronomeBase))\r
+#define SP804_TIMER_PERFORMANCE_BASE  ((UINTN)PcdGet32 (PcdSP804TimerPerformanceBase))\r
+\r
+// Setup SP810's Timer2 for managing delay functions. And Timer3 for Performance counter\r
+// Note: ArmVE's Timer0 and Timer1 are used by TimerDxe.\r
+RETURN_STATUS\r
+EFIAPI\r
+TimerConstructor (\r
+  VOID\r
+  )\r
+{\r
+  // Check if the Metronome Timer is already initialized\r
+  if (MmioRead32(SP804_TIMER_METRONOME_BASE + SP804_TIMER_CONTROL_REG) & SP804_TIMER_CTRL_ENABLE) {\r
+    return RETURN_SUCCESS;\r
+  } else {\r
+    // Configure the Metronome Timer for free running operation, 32 bits, no prescaler, and interrupt disabled\r
+    MmioWrite32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_32BIT | SP804_PRESCALE_DIV_1);\r
+\r
+    // Start the Metronome Timer ticking\r
+    MmioOr32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_ENABLE);\r
+  }\r
+\r
+  // Check if the Performance Timer is already initialized\r
+  if (MmioRead32(SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CONTROL_REG) & SP804_TIMER_CTRL_ENABLE) {\r
+    return RETURN_SUCCESS;\r
+  } else {\r
+    // Configure the Performance timer for free running operation, 32 bits, no prescaler, interrupt disabled\r
+    MmioWrite32 (SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_32BIT | SP804_PRESCALE_DIV_1);\r
+\r
+    // Start the Performance Timer ticking\r
+    MmioOr32 (SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_ENABLE);\r
+  }\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Stalls the CPU for at least the given number of microseconds.\r
+\r
+  Stalls the CPU for the number of microseconds specified by MicroSeconds.\r
+  The hardware timer is 32 bits.\r
+  The maximum possible delay is (0xFFFFFFFF / TimerFrequencyMHz), i.e. ([32bits] / FreqInMHz)\r
+  For example:\r
+  +----------------+------------+----------+----------+\r
+  | TimerFrequency |  MaxDelay  | MaxDelay | MaxDelay |\r
+  |     (MHz)      |    (us)    |   (s)    |  (min)   |\r
+  +----------------+------------+----------+----------+\r
+  |        1       | 0xFFFFFFFF |   4294   |   71.5   |\r
+  |        5       | 0x33333333 |    859   |   14.3   |\r
+  |       10       | 0x19999999 |    429   |    7.2   |\r
+  |       50       | 0x051EB851 |     86   |    1.4   |\r
+  +----------------+------------+----------+----------+\r
+  If it becomes necessary to support higher delays, then consider using the\r
+  real time clock.\r
+\r
+  During this delay, the cpu is not yielded to any other process, with one exception:\r
+  events that are triggered off a timer and which execute at a higher TPL than\r
+  this function. These events may call MicroSecondDelay (or NanoSecondDelay) to\r
+  fulfil their own needs.\r
+  Therefore, this function must be re-entrant, as it may be interrupted and re-started.\r
+\r
+  @param  MicroSeconds  The minimum number of microseconds to delay.\r
+\r
+  @return The value of MicroSeconds inputted.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+MicroSecondDelay (\r
+  IN  UINTN MicroSeconds\r
+  )\r
+{\r
+  UINT64    DelayTicks64;         // Convert from microseconds to timer ticks, more bits to detect over-range conditions.\r
+  UINTN     DelayTicks;           // Convert from microseconds to timer ticks, native size for general calculations.\r
+  UINTN     StartTicks;           // Timer value snapshot at the start of the delay\r
+  UINTN     TargetTicks;          // Timer value to signal the end of the delay\r
+  UINTN     CurrentTicks;         // Current value of the 64-bit timer value at any given moment\r
+\r
+  // If we snapshot the timer at the start of the delay function then we minimise unaccounted overheads.\r
+  StartTicks = MmioRead32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CURRENT_REG);\r
+\r
+  // We are operating at the limit of 32bits. For the range checking work in 64 bits to avoid overflows.\r
+  DelayTicks64 = MultU64x32((UINT64)MicroSeconds, PcdGet32(PcdSP804TimerFrequencyInMHz));\r
+\r
+  // We are limited to 32 bits.\r
+  // If the specified delay is exactly equal to the max range of the timer,\r
+  // then the start will be equal to the stop plus one timer overflow (wrap-around).\r
+  // To avoid having to check for that, reduce the maximum acceptable range by 1 tick,\r
+  // i.e. reject delays equal or greater than the max range of the timer.\r
+  if (DelayTicks64 >= (UINT64)SP804_MAX_TICKS) {\r
+    DEBUG((EFI_D_ERROR,"MicroSecondDelay: ERROR: MicroSeconds=%d exceed SP804 count range. Max MicroSeconds=%d\n",\r
+      MicroSeconds,\r
+      ((UINTN)SP804_MAX_TICKS/PcdGet32(PcdSP804TimerFrequencyInMHz))));\r
+  }\r
+  ASSERT(DelayTicks64 < (UINT64)SP804_MAX_TICKS);\r
+\r
+  // From now on do calculations only in native bit size.\r
+  DelayTicks = (UINTN)DelayTicks64;\r
+\r
+  // Calculate the target value of the timer.\r
+\r
+  //Note: SP804 timer is counting down\r
+  if (StartTicks >= DelayTicks) {\r
+    // In this case we do not expect a wrap-around of the timer to occur.\r
+    // CurrentTicks must be less than StartTicks and higher than TargetTicks.\r
+    // If this is not the case, then the delay has been reached and may even have been exceeded if this\r
+    // function was suspended by a higher priority interrupt.\r
+\r
+    TargetTicks = StartTicks - DelayTicks;\r
+\r
+    do {\r
+      CurrentTicks = MmioRead32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CURRENT_REG);\r
+    } while ((CurrentTicks > TargetTicks) && (CurrentTicks <= StartTicks));\r
+\r
+  } else {\r
+    // In this case TargetTicks is larger than StartTicks.\r
+    // This means we expect a wrap-around of the timer to occur and we must wait for it.\r
+    // Before the wrap-around, CurrentTicks must be less than StartTicks and less than TargetTicks.\r
+    // After the wrap-around, CurrentTicks must be larger than StartTicks and larger than TargetTicks.\r
+    // If this is not the case, then the delay has been reached and may even have been exceeded if this\r
+    // function was suspended by a higher priority interrupt.\r
+\r
+    // The order of operations is essential to avoid arithmetic overflow problems\r
+    TargetTicks = ((UINTN)SP804_MAX_TICKS - DelayTicks) + StartTicks;\r
+\r
+    // First wait for the wrap-around to occur\r
+    do {\r
+      CurrentTicks = MmioRead32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CURRENT_REG);\r
+    } while (CurrentTicks <= StartTicks);\r
+\r
+    // Then wait for the target\r
+    do {\r
+      CurrentTicks = MmioRead32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CURRENT_REG);\r
+    } while (CurrentTicks > TargetTicks);\r
+  }\r
+\r
+  return MicroSeconds;\r
+}\r
+\r
+/**\r
+  Stalls the CPU for at least the given number of nanoseconds.\r
+\r
+  Stalls the CPU for the number of nanoseconds specified by NanoSeconds.\r
+\r
+  When the timer frequency is 1MHz, each tick corresponds to 1 microsecond.\r
+  Therefore, the nanosecond delay will be rounded up to the nearest 1 microsecond.\r
+\r
+  @param  NanoSeconds The minimum number of nanoseconds to delay.\r
+\r
+  @return The value of NanoSeconds inputted.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+NanoSecondDelay (\r
+  IN  UINTN NanoSeconds\r
+  )\r
+{\r
+  UINTN  MicroSeconds;\r
+\r
+  // Round up to 1us Tick Number\r
+  MicroSeconds = NanoSeconds / 1000;\r
+  MicroSeconds += ((NanoSeconds % 1000) == 0) ? 0 : 1;\r
+\r
+  MicroSecondDelay (MicroSeconds);\r
+\r
+  return NanoSeconds;\r
+}\r
+\r
+/**\r
+  Retrieves the current value of a 64-bit free running performance counter.\r
+\r
+  The counter can either count up by 1 or count down by 1. If the physical\r
+  performance counter counts by a larger increment, then the counter values\r
+  must be translated. The properties of the counter can be retrieved from\r
+  GetPerformanceCounterProperties().\r
+\r
+  @return The current value of the free running performance counter.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+GetPerformanceCounter (\r
+  VOID\r
+  )\r
+{ \r
+  // Free running 64-bit/32-bit counter is needed here.\r
+  // Don't think we need this to boot, just to do performance profile\r
+  UINT64 Value;\r
+  Value = MmioRead32 (SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CURRENT_REG);\r
+  return Value;\r
+}\r
+\r
+\r
+/**\r
+  Retrieves the 64-bit frequency in Hz and the range of performance counter\r
+  values.\r
+\r
+  If StartValue is not NULL, then the value that the performance counter starts\r
+  with immediately after is it rolls over is returned in StartValue. If\r
+  EndValue is not NULL, then the value that the performance counter end with\r
+  immediately before it rolls over is returned in EndValue. The 64-bit\r
+  frequency of the performance counter in Hz is always returned. If StartValue\r
+  is less than EndValue, then the performance counter counts up. If StartValue\r
+  is greater than EndValue, then the performance counter counts down. For\r
+  example, a 64-bit free running counter that counts up would have a StartValue\r
+  of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter\r
+  that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.\r
+\r
+  @param  StartValue  The value the performance counter starts with when it\r
+                      rolls over.\r
+  @param  EndValue    The value that the performance counter ends with before\r
+                      it rolls over.\r
+\r
+  @return The frequency in Hz.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+GetPerformanceCounterProperties (\r
+  OUT UINT64  *StartValue,  OPTIONAL\r
+  OUT UINT64  *EndValue     OPTIONAL\r
+  )\r
+{\r
+  if (StartValue != NULL) {\r
+    // Timer starts with the reload value\r
+    *StartValue = 0xFFFFFFFF;\r
+  }\r
+  \r
+  if (EndValue != NULL) {\r
+    // Timer counts down to 0x0\r
+    *EndValue = (UINT64)0ULL;\r
+  }\r
+  \r
+  return PcdGet64 (PcdEmbeddedPerformanceCounterFrequencyInHz);\r
+}\r
index 0928cae53ba3ccf1491d15728f4a3ecb51adcd52..d9bce48b9382f0035a642158ed08eb9be6f7686f 100644 (file)
@@ -1,44 +1,44 @@
-#/** @file
-# Timer library implementation
-#  
-#  
-#  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>
-#  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                      = SP804TimerLib
-  FILE_GUID                      = 09cefa99-0d07-487f-a651-fb44f094b1c7 
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = TimerLib
-  
-  CONSTRUCTOR                    = TimerConstructor
-
-[Sources.common]
-  SP804TimerLib.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  ArmPkg/ArmPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-
-[LibraryClasses]
-  DebugLib
-  IoLib
-  BaseLib
-
-[Pcd]
-  gArmPlatformTokenSpaceGuid.PcdSP804TimerFrequencyInMHz
-  gArmPlatformTokenSpaceGuid.PcdSP804TimerPerformanceBase
-  gArmPlatformTokenSpaceGuid.PcdSP804TimerMetronomeBase
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterFrequencyInHz
+#/** @file\r
+# Timer library implementation\r
+#  \r
+#  \r
+#  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = SP804TimerLib\r
+  FILE_GUID                      = 09cefa99-0d07-487f-a651-fb44f094b1c7 \r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = TimerLib\r
+  \r
+  CONSTRUCTOR                    = TimerConstructor\r
+\r
+[Sources.common]\r
+  SP804TimerLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  IoLib\r
+  BaseLib\r
+\r
+[Pcd]\r
+  gArmPlatformTokenSpaceGuid.PcdSP804TimerFrequencyInMHz\r
+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPerformanceBase\r
+  gArmPlatformTokenSpaceGuid.PcdSP804TimerMetronomeBase\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterFrequencyInHz\r
index 8c8d6108831fcda2628bcbfcccaa080bd44843a7..fb77e4db5d2303727a58426d95f7637f2b1f0cb9 100755 (executable)
@@ -1,66 +1,66 @@
-#/** @file
-#  
-#  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>
-#  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                      = ArmMemoryInitPeiLib
-  FILE_GUID                      = 55ddb6e0-70b5-11e0-b33e-0002a5d5c51b
-  MODULE_TYPE                    = SEC
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = PlatformPeiLib
-
-[Sources]
-  MemoryInitPeiLib.c
-
-
-[Packages]
-  MdePkg/MdePkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  ArmPkg/ArmPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-  
-[LibraryClasses]
-  DebugLib
-  HobLib
-  ArmLib
-  ArmPlatformLib
-
-[Guids]
-  gEfiMemoryTypeInformationGuid
-
-[Ppis]
-
-[FeaturePcd]
-  gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob
-
-[FixedPcd]
-  gArmTokenSpaceGuid.PcdFdBaseAddress
-  gArmTokenSpaceGuid.PcdFdSize
-
-  gArmTokenSpaceGuid.PcdSystemMemoryBase
-  gArmTokenSpaceGuid.PcdSystemMemorySize
-  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize
-  
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData
-   
-[depex]
-  TRUE
+#/** @file\r
+#  \r
+#  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = ArmMemoryInitPeiLib\r
+  FILE_GUID                      = 55ddb6e0-70b5-11e0-b33e-0002a5d5c51b\r
+  MODULE_TYPE                    = SEC\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PlatformPeiLib\r
+\r
+[Sources]\r
+  MemoryInitPeiLib.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+  \r
+[LibraryClasses]\r
+  DebugLib\r
+  HobLib\r
+  ArmLib\r
+  ArmPlatformLib\r
+\r
+[Guids]\r
+  gEfiMemoryTypeInformationGuid\r
+\r
+[Ppis]\r
+\r
+[FeaturePcd]\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob\r
+\r
+[FixedPcd]\r
+  gArmTokenSpaceGuid.PcdFdBaseAddress\r
+  gArmTokenSpaceGuid.PcdFdSize\r
+\r
+  gArmTokenSpaceGuid.PcdSystemMemoryBase\r
+  gArmTokenSpaceGuid.PcdSystemMemorySize\r
+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize\r
+  \r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData\r
+   \r
+[depex]\r
+  TRUE\r
index 01f9359522c57c29139c718debef6c8378a8e0bb..5cddeccb68a6565353f327870b45c4a74b214fa7 100755 (executable)
@@ -1,53 +1,53 @@
-#/** @file
-#
-#  Copyright (c) 2011-2012, ARM Limited. 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                      = ArmPlatformPeiLib
-  FILE_GUID                      = 49d37060-70b5-11e0-aa2d-0002a5d5c51b
-  MODULE_TYPE                    = SEC
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = PlatformPeiLib
-
-[Sources]
-  PlatformPeiLib.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  ArmPkg/ArmPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-
-[LibraryClasses]
-  DebugLib
-  HobLib
-  ArmPlatformLib
-
-[Ppis]
-  gEfiPeiMasterBootModePpiGuid                  # PPI ALWAYS_PRODUCED
-  gEfiPeiBootInRecoveryModePpiGuid              # PPI SOMETIMES_PRODUCED
-
-[FixedPcd]
-  gArmTokenSpaceGuid.PcdFdBaseAddress
-  gArmTokenSpaceGuid.PcdFdSize
-  
-  gArmTokenSpaceGuid.PcdFvBaseAddress
-  gArmTokenSpaceGuid.PcdFvSize
-  
-  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
-  gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize
-  
-[depex]
-  TRUE
+#/** @file\r
+#\r
+#  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = ArmPlatformPeiLib\r
+  FILE_GUID                      = 49d37060-70b5-11e0-aa2d-0002a5d5c51b\r
+  MODULE_TYPE                    = SEC\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PlatformPeiLib\r
+\r
+[Sources]\r
+  PlatformPeiLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  HobLib\r
+  ArmPlatformLib\r
+\r
+[Ppis]\r
+  gEfiPeiMasterBootModePpiGuid                  # PPI ALWAYS_PRODUCED\r
+  gEfiPeiBootInRecoveryModePpiGuid              # PPI SOMETIMES_PRODUCED\r
+\r
+[FixedPcd]\r
+  gArmTokenSpaceGuid.PcdFdBaseAddress\r
+  gArmTokenSpaceGuid.PcdFdSize\r
+  \r
+  gArmTokenSpaceGuid.PcdFvBaseAddress\r
+  gArmTokenSpaceGuid.PcdFvSize\r
+  \r
+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize\r
+  \r
+[depex]\r
+  TRUE\r
index 3805c0b43bd25134a7c50409245571efd1b4ffa2..e59230090fb2d771c713bc6455cc96b135b9fa78 100644 (file)
@@ -1,54 +1,54 @@
-#
-#  Copyright (c) 2011-2012, ARM Limited. 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.             
-#
-
-import re
-
-class BuildReport:
-    PCDs = {}
-    
-    def parse_platform_summary(self, file):
-        pass
-    
-    def parse_pcd_report(self, report_file):
-        pcd_reg = re.compile(" (\*P|\*F|\*M|  ) (\w+)(\ +)\: (.*) \((\w+)\) = (.*)\n")
-        
-        for line in report_file.xreadlines():
-            stripped_line = line.strip()
-            if re.match("\<=+\>", stripped_line):
-                return
-            elif re.match("g.*Guid", stripped_line):
-                guid = stripped_line
-                self.PCDs[guid] = {}
-            else:
-                m = pcd_reg.match(line)
-                if m:
-                    self.PCDs[guid][m.group(2)] = (m.group(6).strip(),m.group(5))
-                
-    def parse_firmware_device(self, file):
-        pass
-        
-    def parse_module_summary(self, file):
-        #print "Module Summary"
-        pass
-    
-    CONST_SECTION_HEADERS = [('Platform Summary', parse_platform_summary),
-                             ('Platform Configuration Database Report',parse_pcd_report),
-                             ('Firmware Device (FD)',parse_firmware_device),
-                             ('Module Summary',parse_module_summary)]
-    
-    def __init__(self, filename = 'report.log'):
-        report_file = open(filename, 'r')
-        for line in report_file.xreadlines():
-            for section_header in BuildReport.CONST_SECTION_HEADERS:
-                if line.strip() == section_header[0]:
-                    section_header[1](self, report_file)
-        #print self.PCDs
+#\r
+#  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+\r
+import re\r
+\r
+class BuildReport:\r
+    PCDs = {}\r
+    \r
+    def parse_platform_summary(self, file):\r
+        pass\r
+    \r
+    def parse_pcd_report(self, report_file):\r
+        pcd_reg = re.compile(" (\*P|\*F|\*M|  ) (\w+)(\ +)\: (.*) \((\w+)\) = (.*)\n")\r
+        \r
+        for line in report_file.xreadlines():\r
+            stripped_line = line.strip()\r
+            if re.match("\<=+\>", stripped_line):\r
+                return\r
+            elif re.match("g.*Guid", stripped_line):\r
+                guid = stripped_line\r
+                self.PCDs[guid] = {}\r
+            else:\r
+                m = pcd_reg.match(line)\r
+                if m:\r
+                    self.PCDs[guid][m.group(2)] = (m.group(6).strip(),m.group(5))\r
+                \r
+    def parse_firmware_device(self, file):\r
+        pass\r
+        \r
+    def parse_module_summary(self, file):\r
+        #print "Module Summary"\r
+        pass\r
+    \r
+    CONST_SECTION_HEADERS = [('Platform Summary', parse_platform_summary),\r
+                             ('Platform Configuration Database Report',parse_pcd_report),\r
+                             ('Firmware Device (FD)',parse_firmware_device),\r
+                             ('Module Summary',parse_module_summary)]\r
+    \r
+    def __init__(self, filename = 'report.log'):\r
+        report_file = open(filename, 'r')\r
+        for line in report_file.xreadlines():\r
+            for section_header in BuildReport.CONST_SECTION_HEADERS:\r
+                if line.strip() == section_header[0]:\r
+                    section_header[1](self, report_file)\r
+        #print self.PCDs\r
index 71e5a3ccd5d55cdf76afb8e9df4b844495a070a6..87e82b68d6c28470c6dacca6a7f2b96b93ca9420 100644 (file)
-#
-#  Copyright (c) 2011-2012, ARM Limited. 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.             
-#
-
-import os
-
-import firmware_volume
-import build_report
-import system_table
-
-# Reload external classes
-reload(firmware_volume)
-reload(build_report)
-reload(system_table)
-
-def readMem32(executionContext, address):
-    bytes = executionContext.getMemoryService().read(address, 4, 32)
-    return struct.unpack('<I',bytes)[0]
-
-def dump_fv(ec, fv_base, fv_size):
-    fv = firmware_volume.FirmwareVolume(ec,
-                                        int(build.PCDs['gArmTokenSpaceGuid']['PcdFvBaseAddress'][0],16),
-                                        int(build.PCDs['gArmTokenSpaceGuid']['PcdFvSize'][0],16))
-    
-    ffs = fv.get_next_ffs()
-    while ffs != None:    
-        print "# %s" % ffs
-    
-        section = ffs.get_next_section()
-        while section != None:
-            print "\t%s" % section
-            try:
-                print "\t\t- %s" % section.get_debug_filepath()
-            except Exception:
-                pass
-            section = ffs.get_next_section(section)
-            
-        ffs = fv.get_next_ffs(ffs)
-
-def dump_system_table(ec, mem_base, mem_size):
-    st = system_table.SystemTable(ec, mem_base, mem_size)
-    
-    debug_info_table_base = st.get_configuration_table(system_table.DebugInfoTable.CONST_DEBUG_INFO_TABLE_GUID)
-    
-    debug_info_table = system_table.DebugInfoTable(ec, debug_info_table_base)
-    debug_info_table.dump()
-
-def load_symbol_from_file(ec, filename, address):
-    try:
-        ec.getImageService().addSymbols(filename, address)
-    except:
-        try:
-            # We could get an exception if the symbols are already loaded
-            ec.getImageService().unloadSymbols(filename)
-            ec.getImageService().addSymbols(filename, address)
-        except:
-            print "Warning: not possible to load symbols from %s" % filename
-            pass
-
-class ArmPlatform:
-    def __init__(self, sysmembase=None, sysmemsize=None, fvs={}):
-        self.sysmembase = sysmembase
-        self.sysmemsize = sysmemsize
-        self.fvs = fvs
-        
-class ArmPlatformDebugger:
-    system_table = None
-    firmware_volumes = {}
-    
-    REGION_TYPE_SYSMEM = 1
-    REGION_TYPE_ROM    = 2
-    REGION_TYPE_FV     = 3
-    
-    def __init__(self, ec, report_log, regions):
-        self.ec = ec
-        fvs = []
-        sysmem_base = None
-        sysmem_size = None
-        
-        if report_log and os.path.isfile(report_log):
-            try:
-                self.build = build_report.BuildReport(report_log)
-            except IOError:
-                raise IOError(2, 'Report \'%s\' isnot valid' % report_log)
-            
-            # Generate list of supported Firmware Volumes
-            if self.build.PCDs['gArmTokenSpaceGuid'].has_key('PcdFvSize') and int(self.build.PCDs['gArmTokenSpaceGuid']['PcdFvSize'][0],16) != 0:
-                fvs.append((int(self.build.PCDs['gArmTokenSpaceGuid']['PcdFvBaseAddress'][0],16),int(self.build.PCDs['gArmTokenSpaceGuid']['PcdFvSize'][0],16)))
-            if self.build.PCDs['gArmTokenSpaceGuid'].has_key('PcdSecureFvSize') and int(self.build.PCDs['gArmTokenSpaceGuid']['PcdSecureFvSize'][0],16) != 0:
-                fvs.append((int(self.build.PCDs['gArmTokenSpaceGuid']['PcdSecureFvBaseAddress'][0],16),int(self.build.PCDs['gArmTokenSpaceGuid']['PcdSecureFvSize'][0],16)))
-            if self.build.PCDs['gArmTokenSpaceGuid'].has_key('PcdHypFvSize') and int(self.build.PCDs['gArmTokenSpaceGuid']['PcdHypFvSize'][0],16) != 0:
-                fvs.append((int(self.build.PCDs['gArmTokenSpaceGuid']['PcdHypFvBaseAddress'][0],16),int(self.build.PCDs['gArmTokenSpaceGuid']['PcdHypFvSize'][0],16)))
-            
-            sysmem_base = int(self.build.PCDs['gArmTokenSpaceGuid']['PcdSystemMemoryBase'][0],16)
-            sysmem_size = int(self.build.PCDs['gArmTokenSpaceGuid']['PcdSystemMemorySize'][0],16)
-        else:
-            for region in regions:
-                if region[0] == ArmPlatformDebugger.REGION_TYPE_SYSMEM:
-                    sysmem_base = region[1]
-                    sysmem_size = region[2]
-                elif region[0] == ArmPlatformDebugger.REGION_TYPE_FV:
-                    fvs.append((region[1],region[2]))
-                elif region[0] == ArmPlatformDebugger.REGION_TYPE_ROM:
-                    for base in xrange(region[1], region[1] + region[2], 0x400000):
-                        signature = struct.unpack("cccc", self.ec.getMemoryService().read(base, 4, 32))
-                        if signature == FirmwareVolume.CONST_FV_SIGNATURE:
-                            fvs.append((base,0))
-                else:
-                    print "Region type '%d' Not Supported" % region[0]
-                    
-        self.platform = ArmPlatform(sysmem_base, sysmem_size, fvs)
-        
-    def in_sysmem(self, addr):
-        return (self.platform.sysmembase is not None) and (self.platform.sysmembase <= addr) and (addr < self.platform.sysmembase + self.platform.sysmemsize)
-
-    def in_fv(self, addr):
-        return (self.get_fv_at(addr) != None)
-
-    def get_fv_at(self, addr):
-        for fv in self.platform.fvs:
-            if (fv[0] <= addr) and (addr < fv[0] + fv[1]):
-                return fv
-        return None
-
-    def load_current_symbols(self):
-        pc = int(self.ec.getRegisterService().getValue('PC')) & 0xFFFFFFFF
-        if self.in_fv(pc):
-            debug_infos = []
-            
-            (fv_base, fv_size) = self.get_fv_at(pc)
-            
-            if self.firmware_volumes.has_key(fv_base) == False:
-                self.firmware_volumes[fv_base] = firmware_volume.FirmwareVolume(self.ec, fv_base, fv_size)
-                
-            stack_frame = self.ec.getTopLevelStackFrame()
-            info = self.firmware_volumes[fv_base].load_symbols_at(int(stack_frame.getRegisterService().getValue('PC')) & 0xFFFFFFFF)
-            debug_infos.append(info)
-            while stack_frame.next() is not None:
-                stack_frame = stack_frame.next()
-                
-                # Stack frame attached to 'PC'
-                pc = int(stack_frame.getRegisterService().getValue('PC')) & 0xFFFFFFFF
-                
-                # Check if the symbols for this stack frame have already been loaded
-                found = False
-                for debug_info in debug_infos:
-                    if (pc >= debug_info[0]) and (pc < debug_info[0] + debug_info[1]):
-                        found = True
-                if found == False:
-                    info = self.firmware_volumes[fv_base].load_symbols_at(pc)
-                    debug_infos.append(info)
-                    
-            #self.firmware_volumes[fv_base].load_symbols_at(pc)
-        elif self.in_sysmem(pc):
-            debug_infos = []
-            
-            if self.system_table is None:
-                # Find the System Table
-                self.system_table = system_table.SystemTable(self.ec, self.platform.sysmembase, self.platform.sysmemsize)
-                
-                # Find the Debug Info Table
-                debug_info_table_base = self.system_table.get_configuration_table(system_table.DebugInfoTable.CONST_DEBUG_INFO_TABLE_GUID)
-                self.debug_info_table = system_table.DebugInfoTable(self.ec, debug_info_table_base)
-                
-            stack_frame = self.ec.getTopLevelStackFrame()
-            info = self.debug_info_table.load_symbols_at(int(stack_frame.getRegisterService().getValue('PC')) & 0xFFFFFFFF)
-            debug_infos.append(info)
-            while stack_frame.next() is not None:
-                stack_frame = stack_frame.next()
-                
-                # Stack frame attached to 'PC'
-                pc = int(stack_frame.getRegisterService().getValue('PC')) & 0xFFFFFFFF
-                
-                # Check if the symbols for this stack frame have already been loaded
-                found = False
-                for debug_info in debug_infos:
-                    if (pc >= debug_info[0]) and (pc < debug_info[0] + debug_info[1]):
-                        found = True
-                if found == False:
-                    info = self.debug_info_table.load_symbols_at(pc)
-                    debug_infos.append(info)
-                
-            #self.debug_info_table.load_symbols_at(pc)
-        else:
-            raise Exception('ArmPlatformDebugger', "Not supported region")
-        
-    def load_all_symbols(self):
-        # Load all the XIP symbols attached to the Firmware Volume
-        for (fv_base, fv_size) in self.platform.fvs:
-            if self.firmware_volumes.has_key(fv_base) == False:
-                self.firmware_volumes[fv_base] = firmware_volume.FirmwareVolume(self.ec, fv_base, fv_size)    
-            self.firmware_volumes[fv_base].load_all_symbols()
-
-        try:
-            # Load all symbols of module loaded into System Memory
-            if self.system_table is None:
-                # Find the System Table
-                self.system_table = system_table.SystemTable(self.ec, self.platform.sysmembase, self.platform.sysmemsize)
-        
-                
-                # Find the Debug Info Table
-                debug_info_table_base = self.system_table.get_configuration_table(system_table.DebugInfoTable.CONST_DEBUG_INFO_TABLE_GUID)
-                self.debug_info_table = system_table.DebugInfoTable(self.ec, debug_info_table_base)
-            
-            self.debug_info_table.load_all_symbols()
-        except:
-            # Debugger exception could be excepted if DRAM has not been initialized or if we have not started to run from DRAM yet
-            print "Note: no symbols have been found in System Memory (possible cause: the UEFI permanent memory has been installed yet)"
-            pass
+#\r
+#  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+\r
+import os\r
+\r
+import firmware_volume\r
+import build_report\r
+import system_table\r
+\r
+# Reload external classes\r
+reload(firmware_volume)\r
+reload(build_report)\r
+reload(system_table)\r
+\r
+def readMem32(executionContext, address):\r
+    bytes = executionContext.getMemoryService().read(address, 4, 32)\r
+    return struct.unpack('<I',bytes)[0]\r
+\r
+def dump_fv(ec, fv_base, fv_size):\r
+    fv = firmware_volume.FirmwareVolume(ec,\r
+                                        int(build.PCDs['gArmTokenSpaceGuid']['PcdFvBaseAddress'][0],16),\r
+                                        int(build.PCDs['gArmTokenSpaceGuid']['PcdFvSize'][0],16))\r
+    \r
+    ffs = fv.get_next_ffs()\r
+    while ffs != None:    \r
+        print "# %s" % ffs\r
+    \r
+        section = ffs.get_next_section()\r
+        while section != None:\r
+            print "\t%s" % section\r
+            try:\r
+                print "\t\t- %s" % section.get_debug_filepath()\r
+            except Exception:\r
+                pass\r
+            section = ffs.get_next_section(section)\r
+            \r
+        ffs = fv.get_next_ffs(ffs)\r
+\r
+def dump_system_table(ec, mem_base, mem_size):\r
+    st = system_table.SystemTable(ec, mem_base, mem_size)\r
+    \r
+    debug_info_table_base = st.get_configuration_table(system_table.DebugInfoTable.CONST_DEBUG_INFO_TABLE_GUID)\r
+    \r
+    debug_info_table = system_table.DebugInfoTable(ec, debug_info_table_base)\r
+    debug_info_table.dump()\r
+\r
+def load_symbol_from_file(ec, filename, address):\r
+    try:\r
+        ec.getImageService().addSymbols(filename, address)\r
+    except:\r
+        try:\r
+            # We could get an exception if the symbols are already loaded\r
+            ec.getImageService().unloadSymbols(filename)\r
+            ec.getImageService().addSymbols(filename, address)\r
+        except:\r
+            print "Warning: not possible to load symbols from %s" % filename\r
+            pass\r
+\r
+class ArmPlatform:\r
+    def __init__(self, sysmembase=None, sysmemsize=None, fvs={}):\r
+        self.sysmembase = sysmembase\r
+        self.sysmemsize = sysmemsize\r
+        self.fvs = fvs\r
+        \r
+class ArmPlatformDebugger:\r
+    system_table = None\r
+    firmware_volumes = {}\r
+    \r
+    REGION_TYPE_SYSMEM = 1\r
+    REGION_TYPE_ROM    = 2\r
+    REGION_TYPE_FV     = 3\r
+    \r
+    def __init__(self, ec, report_log, regions):\r
+        self.ec = ec\r
+        fvs = []\r
+        sysmem_base = None\r
+        sysmem_size = None\r
+        \r
+        if report_log and os.path.isfile(report_log):\r
+            try:\r
+                self.build = build_report.BuildReport(report_log)\r
+            except IOError:\r
+                raise IOError(2, 'Report \'%s\' isnot valid' % report_log)\r
+            \r
+            # Generate list of supported Firmware Volumes\r
+            if self.build.PCDs['gArmTokenSpaceGuid'].has_key('PcdFvSize') and int(self.build.PCDs['gArmTokenSpaceGuid']['PcdFvSize'][0],16) != 0:\r
+                fvs.append((int(self.build.PCDs['gArmTokenSpaceGuid']['PcdFvBaseAddress'][0],16),int(self.build.PCDs['gArmTokenSpaceGuid']['PcdFvSize'][0],16)))\r
+            if self.build.PCDs['gArmTokenSpaceGuid'].has_key('PcdSecureFvSize') and int(self.build.PCDs['gArmTokenSpaceGuid']['PcdSecureFvSize'][0],16) != 0:\r
+                fvs.append((int(self.build.PCDs['gArmTokenSpaceGuid']['PcdSecureFvBaseAddress'][0],16),int(self.build.PCDs['gArmTokenSpaceGuid']['PcdSecureFvSize'][0],16)))\r
+            if self.build.PCDs['gArmTokenSpaceGuid'].has_key('PcdHypFvSize') and int(self.build.PCDs['gArmTokenSpaceGuid']['PcdHypFvSize'][0],16) != 0:\r
+                fvs.append((int(self.build.PCDs['gArmTokenSpaceGuid']['PcdHypFvBaseAddress'][0],16),int(self.build.PCDs['gArmTokenSpaceGuid']['PcdHypFvSize'][0],16)))\r
+            \r
+            sysmem_base = int(self.build.PCDs['gArmTokenSpaceGuid']['PcdSystemMemoryBase'][0],16)\r
+            sysmem_size = int(self.build.PCDs['gArmTokenSpaceGuid']['PcdSystemMemorySize'][0],16)\r
+        else:\r
+            for region in regions:\r
+                if region[0] == ArmPlatformDebugger.REGION_TYPE_SYSMEM:\r
+                    sysmem_base = region[1]\r
+                    sysmem_size = region[2]\r
+                elif region[0] == ArmPlatformDebugger.REGION_TYPE_FV:\r
+                    fvs.append((region[1],region[2]))\r
+                elif region[0] == ArmPlatformDebugger.REGION_TYPE_ROM:\r
+                    for base in xrange(region[1], region[1] + region[2], 0x400000):\r
+                        signature = struct.unpack("cccc", self.ec.getMemoryService().read(base, 4, 32))\r
+                        if signature == FirmwareVolume.CONST_FV_SIGNATURE:\r
+                            fvs.append((base,0))\r
+                else:\r
+                    print "Region type '%d' Not Supported" % region[0]\r
+                    \r
+        self.platform = ArmPlatform(sysmem_base, sysmem_size, fvs)\r
+        \r
+    def in_sysmem(self, addr):\r
+        return (self.platform.sysmembase is not None) and (self.platform.sysmembase <= addr) and (addr < self.platform.sysmembase + self.platform.sysmemsize)\r
+\r
+    def in_fv(self, addr):\r
+        return (self.get_fv_at(addr) != None)\r
+\r
+    def get_fv_at(self, addr):\r
+        for fv in self.platform.fvs:\r
+            if (fv[0] <= addr) and (addr < fv[0] + fv[1]):\r
+                return fv\r
+        return None\r
+\r
+    def load_current_symbols(self):\r
+        pc = int(self.ec.getRegisterService().getValue('PC')) & 0xFFFFFFFF\r
+        if self.in_fv(pc):\r
+            debug_infos = []\r
+            \r
+            (fv_base, fv_size) = self.get_fv_at(pc)\r
+            \r
+            if self.firmware_volumes.has_key(fv_base) == False:\r
+                self.firmware_volumes[fv_base] = firmware_volume.FirmwareVolume(self.ec, fv_base, fv_size)\r
+                \r
+            stack_frame = self.ec.getTopLevelStackFrame()\r
+            info = self.firmware_volumes[fv_base].load_symbols_at(int(stack_frame.getRegisterService().getValue('PC')) & 0xFFFFFFFF)\r
+            debug_infos.append(info)\r
+            while stack_frame.next() is not None:\r
+                stack_frame = stack_frame.next()\r
+                \r
+                # Stack frame attached to 'PC'\r
+                pc = int(stack_frame.getRegisterService().getValue('PC')) & 0xFFFFFFFF\r
+                \r
+                # Check if the symbols for this stack frame have already been loaded\r
+                found = False\r
+                for debug_info in debug_infos:\r
+                    if (pc >= debug_info[0]) and (pc < debug_info[0] + debug_info[1]):\r
+                        found = True\r
+                if found == False:\r
+                    info = self.firmware_volumes[fv_base].load_symbols_at(pc)\r
+                    debug_infos.append(info)\r
+                    \r
+            #self.firmware_volumes[fv_base].load_symbols_at(pc)\r
+        elif self.in_sysmem(pc):\r
+            debug_infos = []\r
+            \r
+            if self.system_table is None:\r
+                # Find the System Table\r
+                self.system_table = system_table.SystemTable(self.ec, self.platform.sysmembase, self.platform.sysmemsize)\r
+                \r
+                # Find the Debug Info Table\r
+                debug_info_table_base = self.system_table.get_configuration_table(system_table.DebugInfoTable.CONST_DEBUG_INFO_TABLE_GUID)\r
+                self.debug_info_table = system_table.DebugInfoTable(self.ec, debug_info_table_base)\r
+                \r
+            stack_frame = self.ec.getTopLevelStackFrame()\r
+            info = self.debug_info_table.load_symbols_at(int(stack_frame.getRegisterService().getValue('PC')) & 0xFFFFFFFF)\r
+            debug_infos.append(info)\r
+            while stack_frame.next() is not None:\r
+                stack_frame = stack_frame.next()\r
+                \r
+                # Stack frame attached to 'PC'\r
+                pc = int(stack_frame.getRegisterService().getValue('PC')) & 0xFFFFFFFF\r
+                \r
+                # Check if the symbols for this stack frame have already been loaded\r
+                found = False\r
+                for debug_info in debug_infos:\r
+                    if (pc >= debug_info[0]) and (pc < debug_info[0] + debug_info[1]):\r
+                        found = True\r
+                if found == False:\r
+                    info = self.debug_info_table.load_symbols_at(pc)\r
+                    debug_infos.append(info)\r
+                \r
+            #self.debug_info_table.load_symbols_at(pc)\r
+        else:\r
+            raise Exception('ArmPlatformDebugger', "Not supported region")\r
+        \r
+    def load_all_symbols(self):\r
+        # Load all the XIP symbols attached to the Firmware Volume\r
+        for (fv_base, fv_size) in self.platform.fvs:\r
+            if self.firmware_volumes.has_key(fv_base) == False:\r
+                self.firmware_volumes[fv_base] = firmware_volume.FirmwareVolume(self.ec, fv_base, fv_size)    \r
+            self.firmware_volumes[fv_base].load_all_symbols()\r
+\r
+        try:\r
+            # Load all symbols of module loaded into System Memory\r
+            if self.system_table is None:\r
+                # Find the System Table\r
+                self.system_table = system_table.SystemTable(self.ec, self.platform.sysmembase, self.platform.sysmemsize)\r
+        \r
+                \r
+                # Find the Debug Info Table\r
+                debug_info_table_base = self.system_table.get_configuration_table(system_table.DebugInfoTable.CONST_DEBUG_INFO_TABLE_GUID)\r
+                self.debug_info_table = system_table.DebugInfoTable(self.ec, debug_info_table_base)\r
+            \r
+            self.debug_info_table.load_all_symbols()\r
+        except:\r
+            # Debugger exception could be excepted if DRAM has not been initialized or if we have not started to run from DRAM yet\r
+            print "Note: no symbols have been found in System Memory (possible cause: the UEFI permanent memory has been installed yet)"\r
+            pass\r
index c4e02ece248587a0a0c342b665e223e41328bc12..a13d1433eb447823acb46d9d7dce37fcced238b4 100644 (file)
-#
-#  Copyright (c) 2011-2012, ARM Limited. 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.             
-#
-
-from arm_ds.debugger_v1 import DebugException
-
-import struct
-import string
-
-import edk2_debugger
-    
-class EfiFileSection(object):
-    EFI_SECTION_PE32                  = 0x10
-    EFI_SECTION_PIC                   = 0x11
-    EFI_SECTION_TE                    = 0x12
-    
-    EFI_IMAGE_DEBUG_TYPE_CODEVIEW     = 0x2
-    
-    SIZEOF_EFI_FFS_FILE_HEADER        = 0x28
-
-    def __init__(self, ec, base):
-        self.base = base
-        self.ec = ec
-        
-    def __str__(self):
-        return "FileSection(type:0x%X, size:0x%x)" % (self.get_type(), self.get_size())
-        
-    def get_base(self):
-        return self.base
-    def get_type(self):
-        return struct.unpack("B", self.ec.getMemoryService().read(self.base + 0x3, 1, 8))[0]
-       
-    def get_size(self):
-        return (struct.unpack("<I", self.ec.getMemoryService().read(self.base, 4, 32))[0] & 0x00ffffff)
-
-    def get_debug_filepath(self):
-        type = self.get_type()
-        if type == EfiFileSection.EFI_SECTION_TE:
-            section = EfiSectionTE(self, ec, self.base + 0x4)
-        elif type == EfiFileSection.EFI_SECTION_PE32:
-            section = EfiSectionPE32(self, ec, self.base + 0x4)
-        else:
-            raise Exception("EfiFileSection", "No debug section")
-        return section.get_debug_filepath()
-
-class EfiSectionTE:
-    SIZEOF_EFI_TE_IMAGE_HEADER        = 0x28
-    EFI_TE_IMAGE_SIGNATURE            = ('V','Z')
-    
-    def __init__(self, ec, base_te):
-        self.ec = ec
-        self.base_te = int(base_te)
-        te_sig = struct.unpack("cc", self.ec.getMemoryService().read(self.base_te, 2, 32))
-        if te_sig != EfiSectionTE.EFI_TE_IMAGE_SIGNATURE:
-            raise Exception("EfiFileSectionTE","TE Signature incorrect")
-        
-    def get_debug_filepath(self):
-        stripped_size = struct.unpack("<H", self.ec.getMemoryService().read(self.base_te + 0x6, 2, 32))[0]
-        stripped_size -= EfiSectionTE.SIZEOF_EFI_TE_IMAGE_HEADER
-        
-        debug_dir_entry_rva = self.ec.getMemoryService().readMemory32(self.base_te + 0x20)
-        if debug_dir_entry_rva == 0:
-            raise Exception("EfiFileSectionTE","No debug directory for image")
-        debug_dir_entry_rva -= stripped_size
-        
-        debug_type = self.ec.getMemoryService().readMemory32(self.base_te + debug_dir_entry_rva + 0xC)
-        if (debug_type != 0xdf) and (debug_type != EfiFileSection.EFI_IMAGE_DEBUG_TYPE_CODEVIEW):
-            raise Exception("EfiFileSectionTE","Debug type is not dwarf")
-
-        debug_rva = self.ec.getMemoryService().readMemory32(self.base_te + debug_dir_entry_rva + 0x14)
-        debug_rva -= stripped_size
-
-        dwarf_sig = struct.unpack("cccc", self.ec.getMemoryService().read(self.base_te + debug_rva, 4, 32))
-        if (dwarf_sig != 0x66727764) and (dwarf_sig != FirmwareFile.CONST_NB10_SIGNATURE):
-            raise Exception("EfiFileSectionTE","Dwarf debug signature not found")
-        
-        if dwarf_sig == 0x66727764:
-            filename = self.base_te + debug_rva + 0xc
-        else:
-            filename = self.base_te + debug_rva + 0x10
-        filename = struct.unpack("200s", self.ec.getMemoryService().read(filename, 200, 32))[0]
-        return filename[0:string.find(filename,'\0')]
-        
-    def get_debug_elfbase(self):
-        stripped_size = struct.unpack("<H", self.ec.getMemoryService().read(self.base_te + 0x6, 2, 32))[0]
-        stripped_size -= EfiSectionTE.SIZEOF_EFI_TE_IMAGE_HEADER
-        
-        base_of_code = self.ec.getMemoryService().readMemory32(self.base_te + 0xC)
-        
-        return self.base_te + base_of_code - stripped_size
-
-class EfiSectionPE32:
-    def __init__(self, ec, base_pe32):
-        self.ec = ec
-        self.base_pe32 = base_pe32
-
-    def get_debug_filepath(self):
-        # Offset from dos hdr to PE file hdr
-        file_header_offset = self.ec.getMemoryService().readMemory32(self.base_pe32 + 0x3C)
-
-        # Offset to debug dir in PE hdrs
-        debug_dir_entry_rva = self.ec.getMemoryService().readMemory32(self.base_pe32 + file_header_offset + 0xA8)
-        if debug_dir_entry_rva == 0:
-            raise Exception("EfiFileSectionPE32","No Debug Directory")
-
-        debug_type = self.ec.getMemoryService().readMemory32(self.base_pe32 + debug_dir_entry_rva + 0xC)
-        if (debug_type != 0xdf) and (debug_type != EfiFileSection.EFI_IMAGE_DEBUG_TYPE_CODEVIEW):
-            raise Exception("EfiFileSectionPE32","Debug type is not dwarf")
-        
-        
-        debug_rva = self.ec.getMemoryService().readMemory32(self.base_pe32 + debug_dir_entry_rva + 0x14)
-        
-        dwarf_sig = struct.unpack("cccc", self.ec.getMemoryService().read(str(self.base_pe32 + debug_rva), 4, 32))
-        if (dwarf_sig != 0x66727764) and (dwarf_sig != FirmwareFile.CONST_NB10_SIGNATURE):
-            raise Exception("EfiFileSectionPE32","Dwarf debug signature not found")
-    
-        if dwarf_sig == 0x66727764:
-            filename = self.base_pe32 + debug_rva + 0xc
-        else:
-            filename = self.base_pe32 + debug_rva + 0x10
-        filename = struct.unpack("200s", self.ec.getMemoryService().read(str(filename), 200, 32))[0]
-        return filename[0:string.find(filename,'\0')]
-    
-    def get_debug_elfbase(self):
-        # Offset from dos hdr to PE file hdr
-        pe_file_header = self.base_pe32 + self.ec.getMemoryService().readMemory32(self.base_pe32 + 0x3C)
-        
-        base_of_code = self.base_pe32 + self.ec.getMemoryService().readMemory32(pe_file_header + 0x28)
-        base_of_data = self.base_pe32 + self.ec.getMemoryService().readMemory32(pe_file_header + 0x2C)
-        
-        if (base_of_code < base_of_data) and (base_of_code != 0):
-            return base_of_code
-        else:
-            return base_of_data       
-    
-class FirmwareFile:
-    EFI_FV_FILETYPE_RAW                   = 0x01
-    EFI_FV_FILETYPE_FREEFORM              = 0x02
-    EFI_FV_FILETYPE_SECURITY_CORE         = 0x03
-    EFI_FV_FILETYPE_PEI_CORE              = 0x04
-    EFI_FV_FILETYPE_DXE_CORE              = 0x05
-    EFI_FV_FILETYPE_PEIM                  = 0x06
-    EFI_FV_FILETYPE_DRIVER                = 0x07
-    EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER  = 0x08
-    EFI_FV_FILETYPE_APPLICATION           = 0x09
-    EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE = 0x0B
-    EFI_FV_FILETYPE_FFS_MIN               = 0xF0
-    
-    CONST_NB10_SIGNATURE = ('N','B','1','0')
-    
-    def __init__(self, fv, base, ec):
-        self.fv = fv
-        self.base = base
-        self.ec = ec
-        
-    def __str__(self):
-        return "FFS(state:0x%x, type:0x%X, size:0x%x)" % (self.get_state(), self.get_type(), self.get_size())
-    
-    def get_base(self):
-        return self.base
-    
-    def get_size(self):
-        size = (self.ec.getMemoryService().readMemory32(self.base + 0x14) & 0x00ffffff)
-
-        # Occupied size is the size considering the alignment
-        return size + ((0x8 - (size & 0x7)) & 0x7)
-    
-    def get_type(self):
-        return self.ec.getMemoryService().readMemory8(self.base + 0x12)
-     
-    def get_state(self):
-        state = self.ec.getMemoryService().readMemory8(self.base + 0x17)
-        
-        polarity = self.fv.get_polarity()
-        if polarity:
-            state = ~state
-            
-        highest_bit = 0x80;
-        while (highest_bit != 0) and ((highest_bit & state) == 0):
-            highest_bit >>= 1
-            
-        return highest_bit
-    
-    def get_next_section(self, section=None):
-        if section == None:
-            if self.get_type() != FirmwareFile.EFI_FV_FILETYPE_FFS_MIN:
-                section_base = self.get_base() + 0x18;
-            else:
-                return None
-        else:
-            section_base = int(section.get_base() + section.get_size())
-            
-            # Align to next 4 byte boundary
-            if (section_base & 0x3) != 0:
-                section_base = section_base + 0x4 - (section_base & 0x3)
-
-        if section_base < self.get_base() + self.get_size():
-            return EfiFileSection(self.ec, section_base)
-        else:
-            return None
-    
-class FirmwareVolume:
-    CONST_FV_SIGNATURE = ('_','F','V','H')
-    EFI_FVB2_ERASE_POLARITY = 0x800
-    
-    DebugInfos = []
-    
-    def __init__(self, ec, fv_base, fv_size):
-        self.ec = ec
-        self.fv_base = fv_base
-        self.fv_size = fv_size
-        
-        try:
-            signature = struct.unpack("cccc", self.ec.getMemoryService().read(fv_base + 0x28, 4, 32))
-        except DebugException:
-            raise Exception("FirmwareVolume", "Not possible to access the defined firmware volume at [0x%X,0x%X]. Could be the used build report does not correspond to your current debugging context." % (int(fv_base),int(fv_base+fv_size)))
-        if signature != FirmwareVolume.CONST_FV_SIGNATURE:
-            raise Exception("FirmwareVolume", "This is not a valid firmware volume")
-      
-    def get_size(self):
-        return self.ec.getMemoryService().readMemory32(self.fv_base + 0x20)
-    
-    def get_attributes(self):
-        return self.ec.getMemoryService().readMemory32(self.fv_base + 0x2C)
-    
-    def get_polarity(self):
-        attributes = self.get_attributes()
-        if attributes & FirmwareVolume.EFI_FVB2_ERASE_POLARITY:
-            return 1
-        else:
-            return 0
-    
-    def get_next_ffs(self, ffs=None):
-        if ffs == None:
-            # Get the offset of the first FFS file from the FV header
-            ffs_base = self.fv_base +  self.ec.getMemoryService().readMemory16(self.fv_base + 0x30)
-        else:
-            # Goto the next FFS file
-            ffs_base = int(ffs.get_base() + ffs.get_size())
-            
-            # Align to next 8 byte boundary
-            if (ffs_base & 0x7) != 0:
-                ffs_base = ffs_base + 0x8 - (ffs_base & 0x7)
-                
-        if ffs_base < self.fv_base + self.get_size():
-            return FirmwareFile(self, ffs_base, self.ec)
-        else:
-            return None
-        
-    def get_debug_info(self):        
-        self.DebugInfos = []
-        
-        ffs = self.get_next_ffs()
-        while ffs != None:            
-            section = ffs.get_next_section()
-            while section != None:
-                type = section.get_type()
-                if (type == EfiFileSection.EFI_SECTION_TE) or (type == EfiFileSection.EFI_SECTION_PE32):
-                    self.DebugInfos.append((section.get_base(), section.get_size(), section.get_type()))
-                section = ffs.get_next_section(section)
-            ffs = self.get_next_ffs(ffs)
-
-    def load_symbols_at(self, addr):
-        if self.DebugInfos == []:
-            self.get_debug_info()
-        
-        for debug_info in self.DebugInfos:
-            if (addr >= debug_info[0]) and (addr < debug_info[0] + debug_info[1]):
-                if debug_info[2] == EfiFileSection.EFI_SECTION_TE:
-                    section = EfiSectionTE(self.ec, debug_info[0] + 0x4)
-                elif debug_info[2] == EfiFileSection.EFI_SECTION_PE32:
-                    section = EfiSectionPE32(self.ec, debug_info[0] + 0x4)
-                else:
-                    raise Exception('FirmwareVolume','Section Type not supported')
-                
-                edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase())
-
-                return debug_info
-
-    def load_all_symbols(self):
-        if self.DebugInfos == []:
-            self.get_debug_info()
-        
-        for debug_info in self.DebugInfos:
-            if debug_info[2] == EfiFileSection.EFI_SECTION_TE:
-                section = EfiSectionTE(self.ec, debug_info[0] + 0x4)
-            elif debug_info[2] == EfiFileSection.EFI_SECTION_PE32:
-                section = EfiSectionPE32(self.ec, debug_info[0] + 0x4)
-            else:
-                continue
-            
-            edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase())
+#\r
+#  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+\r
+from arm_ds.debugger_v1 import DebugException\r
+\r
+import struct\r
+import string\r
+\r
+import edk2_debugger\r
+    \r
+class EfiFileSection(object):\r
+    EFI_SECTION_PE32                  = 0x10\r
+    EFI_SECTION_PIC                   = 0x11\r
+    EFI_SECTION_TE                    = 0x12\r
+    \r
+    EFI_IMAGE_DEBUG_TYPE_CODEVIEW     = 0x2\r
+    \r
+    SIZEOF_EFI_FFS_FILE_HEADER        = 0x28\r
+\r
+    def __init__(self, ec, base):\r
+        self.base = base\r
+        self.ec = ec\r
+        \r
+    def __str__(self):\r
+        return "FileSection(type:0x%X, size:0x%x)" % (self.get_type(), self.get_size())\r
+        \r
+    def get_base(self):\r
+        return self.base\r
\r
+    def get_type(self):\r
+        return struct.unpack("B", self.ec.getMemoryService().read(self.base + 0x3, 1, 8))[0]\r
+       \r
+    def get_size(self):\r
+        return (struct.unpack("<I", self.ec.getMemoryService().read(self.base, 4, 32))[0] & 0x00ffffff)\r
+\r
+    def get_debug_filepath(self):\r
+        type = self.get_type()\r
+        if type == EfiFileSection.EFI_SECTION_TE:\r
+            section = EfiSectionTE(self, ec, self.base + 0x4)\r
+        elif type == EfiFileSection.EFI_SECTION_PE32:\r
+            section = EfiSectionPE32(self, ec, self.base + 0x4)\r
+        else:\r
+            raise Exception("EfiFileSection", "No debug section")\r
+        return section.get_debug_filepath()\r
+\r
+class EfiSectionTE:\r
+    SIZEOF_EFI_TE_IMAGE_HEADER        = 0x28\r
+    EFI_TE_IMAGE_SIGNATURE            = ('V','Z')\r
+    \r
+    def __init__(self, ec, base_te):\r
+        self.ec = ec\r
+        self.base_te = int(base_te)\r
+        te_sig = struct.unpack("cc", self.ec.getMemoryService().read(self.base_te, 2, 32))\r
+        if te_sig != EfiSectionTE.EFI_TE_IMAGE_SIGNATURE:\r
+            raise Exception("EfiFileSectionTE","TE Signature incorrect")\r
+        \r
+    def get_debug_filepath(self):\r
+        stripped_size = struct.unpack("<H", self.ec.getMemoryService().read(self.base_te + 0x6, 2, 32))[0]\r
+        stripped_size -= EfiSectionTE.SIZEOF_EFI_TE_IMAGE_HEADER\r
+        \r
+        debug_dir_entry_rva = self.ec.getMemoryService().readMemory32(self.base_te + 0x20)\r
+        if debug_dir_entry_rva == 0:\r
+            raise Exception("EfiFileSectionTE","No debug directory for image")\r
+        debug_dir_entry_rva -= stripped_size\r
+        \r
+        debug_type = self.ec.getMemoryService().readMemory32(self.base_te + debug_dir_entry_rva + 0xC)\r
+        if (debug_type != 0xdf) and (debug_type != EfiFileSection.EFI_IMAGE_DEBUG_TYPE_CODEVIEW):\r
+            raise Exception("EfiFileSectionTE","Debug type is not dwarf")\r
+\r
+        debug_rva = self.ec.getMemoryService().readMemory32(self.base_te + debug_dir_entry_rva + 0x14)\r
+        debug_rva -= stripped_size\r
+\r
+        dwarf_sig = struct.unpack("cccc", self.ec.getMemoryService().read(self.base_te + debug_rva, 4, 32))\r
+        if (dwarf_sig != 0x66727764) and (dwarf_sig != FirmwareFile.CONST_NB10_SIGNATURE):\r
+            raise Exception("EfiFileSectionTE","Dwarf debug signature not found")\r
+        \r
+        if dwarf_sig == 0x66727764:\r
+            filename = self.base_te + debug_rva + 0xc\r
+        else:\r
+            filename = self.base_te + debug_rva + 0x10\r
+        filename = struct.unpack("200s", self.ec.getMemoryService().read(filename, 200, 32))[0]\r
+        return filename[0:string.find(filename,'\0')]\r
+        \r
+    def get_debug_elfbase(self):\r
+        stripped_size = struct.unpack("<H", self.ec.getMemoryService().read(self.base_te + 0x6, 2, 32))[0]\r
+        stripped_size -= EfiSectionTE.SIZEOF_EFI_TE_IMAGE_HEADER\r
+        \r
+        base_of_code = self.ec.getMemoryService().readMemory32(self.base_te + 0xC)\r
+        \r
+        return self.base_te + base_of_code - stripped_size\r
+\r
+class EfiSectionPE32:\r
+    def __init__(self, ec, base_pe32):\r
+        self.ec = ec\r
+        self.base_pe32 = base_pe32\r
+\r
+    def get_debug_filepath(self):\r
+        # Offset from dos hdr to PE file hdr\r
+        file_header_offset = self.ec.getMemoryService().readMemory32(self.base_pe32 + 0x3C)\r
+\r
+        # Offset to debug dir in PE hdrs\r
+        debug_dir_entry_rva = self.ec.getMemoryService().readMemory32(self.base_pe32 + file_header_offset + 0xA8)\r
+        if debug_dir_entry_rva == 0:\r
+            raise Exception("EfiFileSectionPE32","No Debug Directory")\r
+\r
+        debug_type = self.ec.getMemoryService().readMemory32(self.base_pe32 + debug_dir_entry_rva + 0xC)\r
+        if (debug_type != 0xdf) and (debug_type != EfiFileSection.EFI_IMAGE_DEBUG_TYPE_CODEVIEW):\r
+            raise Exception("EfiFileSectionPE32","Debug type is not dwarf")\r
+        \r
+        \r
+        debug_rva = self.ec.getMemoryService().readMemory32(self.base_pe32 + debug_dir_entry_rva + 0x14)\r
+        \r
+        dwarf_sig = struct.unpack("cccc", self.ec.getMemoryService().read(str(self.base_pe32 + debug_rva), 4, 32))\r
+        if (dwarf_sig != 0x66727764) and (dwarf_sig != FirmwareFile.CONST_NB10_SIGNATURE):\r
+            raise Exception("EfiFileSectionPE32","Dwarf debug signature not found")\r
+    \r
+        if dwarf_sig == 0x66727764:\r
+            filename = self.base_pe32 + debug_rva + 0xc\r
+        else:\r
+            filename = self.base_pe32 + debug_rva + 0x10\r
+        filename = struct.unpack("200s", self.ec.getMemoryService().read(str(filename), 200, 32))[0]\r
+        return filename[0:string.find(filename,'\0')]\r
+    \r
+    def get_debug_elfbase(self):\r
+        # Offset from dos hdr to PE file hdr\r
+        pe_file_header = self.base_pe32 + self.ec.getMemoryService().readMemory32(self.base_pe32 + 0x3C)\r
+        \r
+        base_of_code = self.base_pe32 + self.ec.getMemoryService().readMemory32(pe_file_header + 0x28)\r
+        base_of_data = self.base_pe32 + self.ec.getMemoryService().readMemory32(pe_file_header + 0x2C)\r
+        \r
+        if (base_of_code < base_of_data) and (base_of_code != 0):\r
+            return base_of_code\r
+        else:\r
+            return base_of_data       \r
+    \r
+class FirmwareFile:\r
+    EFI_FV_FILETYPE_RAW                   = 0x01\r
+    EFI_FV_FILETYPE_FREEFORM              = 0x02\r
+    EFI_FV_FILETYPE_SECURITY_CORE         = 0x03\r
+    EFI_FV_FILETYPE_PEI_CORE              = 0x04\r
+    EFI_FV_FILETYPE_DXE_CORE              = 0x05\r
+    EFI_FV_FILETYPE_PEIM                  = 0x06\r
+    EFI_FV_FILETYPE_DRIVER                = 0x07\r
+    EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER  = 0x08\r
+    EFI_FV_FILETYPE_APPLICATION           = 0x09\r
+    EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE = 0x0B\r
+    EFI_FV_FILETYPE_FFS_MIN               = 0xF0\r
+    \r
+    CONST_NB10_SIGNATURE = ('N','B','1','0')\r
+    \r
+    def __init__(self, fv, base, ec):\r
+        self.fv = fv\r
+        self.base = base\r
+        self.ec = ec\r
+        \r
+    def __str__(self):\r
+        return "FFS(state:0x%x, type:0x%X, size:0x%x)" % (self.get_state(), self.get_type(), self.get_size())\r
+    \r
+    def get_base(self):\r
+        return self.base\r
+    \r
+    def get_size(self):\r
+        size = (self.ec.getMemoryService().readMemory32(self.base + 0x14) & 0x00ffffff)\r
+\r
+        # Occupied size is the size considering the alignment\r
+        return size + ((0x8 - (size & 0x7)) & 0x7)\r
+    \r
+    def get_type(self):\r
+        return self.ec.getMemoryService().readMemory8(self.base + 0x12)\r
+     \r
+    def get_state(self):\r
+        state = self.ec.getMemoryService().readMemory8(self.base + 0x17)\r
+        \r
+        polarity = self.fv.get_polarity()\r
+        if polarity:\r
+            state = ~state\r
+            \r
+        highest_bit = 0x80;\r
+        while (highest_bit != 0) and ((highest_bit & state) == 0):\r
+            highest_bit >>= 1\r
+            \r
+        return highest_bit\r
+    \r
+    def get_next_section(self, section=None):\r
+        if section == None:\r
+            if self.get_type() != FirmwareFile.EFI_FV_FILETYPE_FFS_MIN:\r
+                section_base = self.get_base() + 0x18;\r
+            else:\r
+                return None\r
+        else:\r
+            section_base = int(section.get_base() + section.get_size())\r
+            \r
+            # Align to next 4 byte boundary\r
+            if (section_base & 0x3) != 0:\r
+                section_base = section_base + 0x4 - (section_base & 0x3)\r
+\r
+        if section_base < self.get_base() + self.get_size():\r
+            return EfiFileSection(self.ec, section_base)\r
+        else:\r
+            return None\r
+    \r
+class FirmwareVolume:\r
+    CONST_FV_SIGNATURE = ('_','F','V','H')\r
+    EFI_FVB2_ERASE_POLARITY = 0x800\r
+    \r
+    DebugInfos = []\r
+    \r
+    def __init__(self, ec, fv_base, fv_size):\r
+        self.ec = ec\r
+        self.fv_base = fv_base\r
+        self.fv_size = fv_size\r
+        \r
+        try:\r
+            signature = struct.unpack("cccc", self.ec.getMemoryService().read(fv_base + 0x28, 4, 32))\r
+        except DebugException:\r
+            raise Exception("FirmwareVolume", "Not possible to access the defined firmware volume at [0x%X,0x%X]. Could be the used build report does not correspond to your current debugging context." % (int(fv_base),int(fv_base+fv_size)))\r
+        if signature != FirmwareVolume.CONST_FV_SIGNATURE:\r
+            raise Exception("FirmwareVolume", "This is not a valid firmware volume")\r
+      \r
+    def get_size(self):\r
+        return self.ec.getMemoryService().readMemory32(self.fv_base + 0x20)\r
+    \r
+    def get_attributes(self):\r
+        return self.ec.getMemoryService().readMemory32(self.fv_base + 0x2C)\r
+    \r
+    def get_polarity(self):\r
+        attributes = self.get_attributes()\r
+        if attributes & FirmwareVolume.EFI_FVB2_ERASE_POLARITY:\r
+            return 1\r
+        else:\r
+            return 0\r
+    \r
+    def get_next_ffs(self, ffs=None):\r
+        if ffs == None:\r
+            # Get the offset of the first FFS file from the FV header\r
+            ffs_base = self.fv_base +  self.ec.getMemoryService().readMemory16(self.fv_base + 0x30)\r
+        else:\r
+            # Goto the next FFS file\r
+            ffs_base = int(ffs.get_base() + ffs.get_size())\r
+            \r
+            # Align to next 8 byte boundary\r
+            if (ffs_base & 0x7) != 0:\r
+                ffs_base = ffs_base + 0x8 - (ffs_base & 0x7)\r
+                \r
+        if ffs_base < self.fv_base + self.get_size():\r
+            return FirmwareFile(self, ffs_base, self.ec)\r
+        else:\r
+            return None\r
+        \r
+    def get_debug_info(self):        \r
+        self.DebugInfos = []\r
+        \r
+        ffs = self.get_next_ffs()\r
+        while ffs != None:            \r
+            section = ffs.get_next_section()\r
+            while section != None:\r
+                type = section.get_type()\r
+                if (type == EfiFileSection.EFI_SECTION_TE) or (type == EfiFileSection.EFI_SECTION_PE32):\r
+                    self.DebugInfos.append((section.get_base(), section.get_size(), section.get_type()))\r
+                section = ffs.get_next_section(section)\r
+            ffs = self.get_next_ffs(ffs)\r
+\r
+    def load_symbols_at(self, addr):\r
+        if self.DebugInfos == []:\r
+            self.get_debug_info()\r
+        \r
+        for debug_info in self.DebugInfos:\r
+            if (addr >= debug_info[0]) and (addr < debug_info[0] + debug_info[1]):\r
+                if debug_info[2] == EfiFileSection.EFI_SECTION_TE:\r
+                    section = EfiSectionTE(self.ec, debug_info[0] + 0x4)\r
+                elif debug_info[2] == EfiFileSection.EFI_SECTION_PE32:\r
+                    section = EfiSectionPE32(self.ec, debug_info[0] + 0x4)\r
+                else:\r
+                    raise Exception('FirmwareVolume','Section Type not supported')\r
+                \r
+                edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase())\r
+\r
+                return debug_info\r
+\r
+    def load_all_symbols(self):\r
+        if self.DebugInfos == []:\r
+            self.get_debug_info()\r
+        \r
+        for debug_info in self.DebugInfos:\r
+            if debug_info[2] == EfiFileSection.EFI_SECTION_TE:\r
+                section = EfiSectionTE(self.ec, debug_info[0] + 0x4)\r
+            elif debug_info[2] == EfiFileSection.EFI_SECTION_PE32:\r
+                section = EfiSectionPE32(self.ec, debug_info[0] + 0x4)\r
+            else:\r
+                continue\r
+            \r
+            edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase())\r
index f489e466ad00f85d21f0cbfa62dabe1aad4361b4..8dec591e63cc7cd1ddf6a7bf1ad5389ebc30c5d1 100644 (file)
-#
-#  Copyright (c) 2011-2012, ARM Limited. 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.             
-#
-
-from arm_ds.debugger_v1 import DebugException
-
-import struct
-
-import edk2_debugger
-import firmware_volume
-
-class DebugInfoTable:
-    CONST_DEBUG_INFO_TABLE_GUID = ( 0x49152E77L, 0x47641ADAL, 0xFE7AA2B7L, 0x8B5ED9FEL)
-    
-    DebugInfos = []
-    
-    def __init__(self, ec, debug_info_table_header_offset):
-        self.ec = ec
-        self.base = debug_info_table_header_offset
-        
-    def get_debug_info(self):
-        count = self.ec.getMemoryService().readMemory32(self.base + 0x4)
-        debug_info_table_base = self.ec.getMemoryService().readMemory32(self.base + 0x8)
-        
-        self.DebugInfos = []
-        
-        for i in range(0, count):
-            # Get the address of the structure EFI_DEBUG_IMAGE_INFO
-            debug_info = self.ec.getMemoryService().readMemory32(debug_info_table_base + (i * 4))
-            if debug_info:
-                debug_info_type = self.ec.getMemoryService().readMemory32(debug_info)
-                # Normal Debug Info Type
-                if debug_info_type == 1:
-                    # Get the base address of the structure EFI_LOADED_IMAGE_PROTOCOL
-                    loaded_image_protocol = self.ec.getMemoryService().readMemory32(debug_info + 0x4)
-                    
-                    image_base = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x20)
-                    image_size = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x28)
-                    
-                    self.DebugInfos.append((image_base,image_size))
-    
-    # Return (base, size)
-    def load_symbols_at(self, addr):
-        if self.DebugInfos == []:
-            self.get_debug_info()
-        
-        found = False
-        for debug_info in self.DebugInfos:
-            if (addr >= debug_info[0]) and (addr < debug_info[0] + debug_info[1]):
-                section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0])
-                
-                edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase())
-
-                found = True
-                return debug_info
-
-        if found == False:
-            raise Exception('DebugInfoTable','No symbol found at 0x%x' % addr)
-
-    def load_all_symbols(self):
-        if self.DebugInfos == []:
-            self.get_debug_info()
-        
-        for debug_info in self.DebugInfos:
-            section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0])
-           
-            edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase())
-
-    def dump(self):
-        self.get_debug_info()
-        for debug_info in self.DebugInfos:
-            base_pe32 = debug_info[0]
-            section = firmware_volume.EfiSectionPE32(self.ec, base_pe32)
-            print section.get_debug_filepath()
-        
-class SystemTable:
-    CONST_ST_SIGNATURE = ('I','B','I',' ','S','Y','S','T')
-    
-    def __init__(self, ec, membase, memsize):
-        self.membase = membase
-        self.memsize = memsize
-        self.ec = ec
-        
-        found = False
-        
-        # Start from the top of the memory
-        offset = self.membase + self.memsize
-        # Align to highest 4MB boundary
-        offset = offset & ~0x3FFFFF
-        # We should not have a System Table at the top of the System Memory
-        offset = offset - 0x400000
-        
-        # Start at top and look on 4MB boundaries for system table ptr structure
-        while offset > self.membase:
-            try:
-                signature = struct.unpack("cccccccc", self.ec.getMemoryService().read(str(offset), 8, 32))
-            except DebugException:
-                raise Exception('SystemTable','Fail to access System Memory. Ensure all the memory in the region [0x%x;0x%X] is accessible.' % (membase,membase+memsize))
-            if signature == SystemTable.CONST_ST_SIGNATURE:
-                found = True
-                self.system_table_base = self.ec.getMemoryService().readMemory32(offset + 0x8)
-                break
-            offset = offset - 0x400000
-            
-        if not found:
-            raise Exception('SystemTable','System Table not found in System Memory [0x%x;0x%X]' % (membase,membase+memsize))
-        
-    def get_configuration_table(self, conf_table_guid):
-        # Number of configuration Table entry
-        conf_table_entry_count = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x40)
-        
-        # Get location of the Configuration Table entries
-        conf_table_offset = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x44)
-        
-        for i in range(0, conf_table_entry_count):
-            offset = conf_table_offset + (i * 0x14)
-            guid = struct.unpack("<IIII", self.ec.getMemoryService().read(str(offset), 16, 32))
-            if guid == conf_table_guid:
-                return self.ec.getMemoryService().readMemory32(offset + 0x10)
-            
-        raise Exception('SystemTable','Configuration Table not found')
+#\r
+#  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+\r
+from arm_ds.debugger_v1 import DebugException\r
+\r
+import struct\r
+\r
+import edk2_debugger\r
+import firmware_volume\r
+\r
+class DebugInfoTable:\r
+    CONST_DEBUG_INFO_TABLE_GUID = ( 0x49152E77L, 0x47641ADAL, 0xFE7AA2B7L, 0x8B5ED9FEL)\r
+    \r
+    DebugInfos = []\r
+    \r
+    def __init__(self, ec, debug_info_table_header_offset):\r
+        self.ec = ec\r
+        self.base = debug_info_table_header_offset\r
+        \r
+    def get_debug_info(self):\r
+        count = self.ec.getMemoryService().readMemory32(self.base + 0x4)\r
+        debug_info_table_base = self.ec.getMemoryService().readMemory32(self.base + 0x8)\r
+        \r
+        self.DebugInfos = []\r
+        \r
+        for i in range(0, count):\r
+            # Get the address of the structure EFI_DEBUG_IMAGE_INFO\r
+            debug_info = self.ec.getMemoryService().readMemory32(debug_info_table_base + (i * 4))\r
+            if debug_info:\r
+                debug_info_type = self.ec.getMemoryService().readMemory32(debug_info)\r
+                # Normal Debug Info Type\r
+                if debug_info_type == 1:\r
+                    # Get the base address of the structure EFI_LOADED_IMAGE_PROTOCOL\r
+                    loaded_image_protocol = self.ec.getMemoryService().readMemory32(debug_info + 0x4)\r
+                    \r
+                    image_base = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x20)\r
+                    image_size = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x28)\r
+                    \r
+                    self.DebugInfos.append((image_base,image_size))\r
+    \r
+    # Return (base, size)\r
+    def load_symbols_at(self, addr):\r
+        if self.DebugInfos == []:\r
+            self.get_debug_info()\r
+        \r
+        found = False\r
+        for debug_info in self.DebugInfos:\r
+            if (addr >= debug_info[0]) and (addr < debug_info[0] + debug_info[1]):\r
+                section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0])\r
+                \r
+                edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase())\r
+\r
+                found = True\r
+                return debug_info\r
+\r
+        if found == False:\r
+            raise Exception('DebugInfoTable','No symbol found at 0x%x' % addr)\r
+\r
+    def load_all_symbols(self):\r
+        if self.DebugInfos == []:\r
+            self.get_debug_info()\r
+        \r
+        for debug_info in self.DebugInfos:\r
+            section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0])\r
+           \r
+            edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase())\r
+\r
+    def dump(self):\r
+        self.get_debug_info()\r
+        for debug_info in self.DebugInfos:\r
+            base_pe32 = debug_info[0]\r
+            section = firmware_volume.EfiSectionPE32(self.ec, base_pe32)\r
+            print section.get_debug_filepath()\r
+        \r
+class SystemTable:\r
+    CONST_ST_SIGNATURE = ('I','B','I',' ','S','Y','S','T')\r
+    \r
+    def __init__(self, ec, membase, memsize):\r
+        self.membase = membase\r
+        self.memsize = memsize\r
+        self.ec = ec\r
+        \r
+        found = False\r
+        \r
+        # Start from the top of the memory\r
+        offset = self.membase + self.memsize\r
+        # Align to highest 4MB boundary\r
+        offset = offset & ~0x3FFFFF\r
+        # We should not have a System Table at the top of the System Memory\r
+        offset = offset - 0x400000\r
+        \r
+        # Start at top and look on 4MB boundaries for system table ptr structure\r
+        while offset > self.membase:\r
+            try:\r
+                signature = struct.unpack("cccccccc", self.ec.getMemoryService().read(str(offset), 8, 32))\r
+            except DebugException:\r
+                raise Exception('SystemTable','Fail to access System Memory. Ensure all the memory in the region [0x%x;0x%X] is accessible.' % (membase,membase+memsize))\r
+            if signature == SystemTable.CONST_ST_SIGNATURE:\r
+                found = True\r
+                self.system_table_base = self.ec.getMemoryService().readMemory32(offset + 0x8)\r
+                break\r
+            offset = offset - 0x400000\r
+            \r
+        if not found:\r
+            raise Exception('SystemTable','System Table not found in System Memory [0x%x;0x%X]' % (membase,membase+memsize))\r
+        \r
+    def get_configuration_table(self, conf_table_guid):\r
+        # Number of configuration Table entry\r
+        conf_table_entry_count = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x40)\r
+        \r
+        # Get location of the Configuration Table entries\r
+        conf_table_offset = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x44)\r
+        \r
+        for i in range(0, conf_table_entry_count):\r
+            offset = conf_table_offset + (i * 0x14)\r
+            guid = struct.unpack("<IIII", self.ec.getMemoryService().read(str(offset), 16, 32))\r
+            if guid == conf_table_guid:\r
+                return self.ec.getMemoryService().readMemory32(offset + 0x10)\r
+            \r
+        raise Exception('SystemTable','Configuration Table not found')\r
index 55807ec9d9dbb77e0c53e02063af22223bd24fc0..be165442bfaf72975e3d11b2299486571e89d783 100644 (file)
-/** @file
-*  Main file supporting the SEC Phase on ARM Platforms
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 <Library/ArmTrustedMonitorLib.h>
-#include <Library/DebugAgentLib.h>
-#include <Library/PrintLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/SerialPortLib.h>
-#include <Library/ArmGicLib.h>
-
-#include "SecInternal.h"
-
-#define SerialPrint(txt)  SerialPortWrite ((UINT8*)txt, AsciiStrLen(txt)+1);
-
-VOID
-CEntryPoint (
-  IN  UINTN                     MpId,
-  IN  UINTN                     SecBootMode
-  )
-{
-  CHAR8           Buffer[100];
-  UINTN           CharCount;
-  UINTN           JumpAddress;
-
-  // Invalidate the data cache. Doesn't have to do the Data cache clean.
-  ArmInvalidateDataCache();
-
-  // Invalidate Instruction Cache
-  ArmInvalidateInstructionCache();
-
-  // Invalidate I & D TLBs
-  ArmInvalidateInstructionAndDataTlb();
-
-  // CPU specific settings
-  ArmCpuSetup (MpId);
-
-  // Enable Floating Point Coprocessor if supported by the platform
-  if (FixedPcdGet32 (PcdVFPEnabled)) {
-    ArmEnableVFP();
-  }
-
-  // Initialize peripherals that must be done at the early stage
-  // Example: Some L2 controller, interconnect, clock, DMC, etc
-  ArmPlatformSecInitialize (MpId);
-
-  // Primary CPU clears out the SCU tag RAMs, secondaries wait
-  if (IS_PRIMARY_CORE(MpId) && (SecBootMode == ARM_SEC_COLD_BOOT)) {
-    if (ArmIsMpCore()) {
-      // Signal for the initial memory is configured (event: BOOT_MEM_INIT)
-      ArmCallSEV ();
-    }
-
-    // SEC phase needs to run library constructors by hand. This assumes we are linked against the SerialLib
-    // In non SEC modules the init call is in autogenerated code.
-    SerialPortInitialize ();
-
-    // Start talking
-    if (FixedPcdGetBool (PcdTrustzoneSupport)) {
-      CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Secure firmware (version %s built at %a on %a)\n\r",
-          (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);
-    } else {
-      CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Boot firmware (version %s built at %a on %a)\n\r",
-          (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);
-    }
-    SerialPortWrite ((UINT8 *) Buffer, CharCount);
-
-    // Initialize the Debug Agent for Source Level Debugging
-    InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC, NULL, NULL);
-    SaveAndSetDebugTimerInterrupt (TRUE);
-
-    // Enable the GIC distributor and CPU Interface
-    // - no other Interrupts are enabled,  doesn't have to worry about the priority.
-    // - all the cores are in secure state, use secure SGI's
-    ArmGicEnableDistributor (PcdGet32(PcdGicDistributorBase));
-    ArmGicEnableInterruptInterface (PcdGet32(PcdGicInterruptInterfaceBase));
-  } else {
-    // Enable the GIC CPU Interface
-    ArmGicEnableInterruptInterface (PcdGet32(PcdGicInterruptInterfaceBase));
-  }
-
-  // Enable Full Access to CoProcessors
-  ArmWriteCpacr (CPACR_CP_FULL_ACCESS);
-
-  // Test if Trustzone is supported on this platform
-  if (FixedPcdGetBool (PcdTrustzoneSupport)) {
-    if (ArmIsMpCore()) {
-      // Setup SMP in Non Secure world
-      ArmCpuSetupSmpNonSecure (GET_CORE_ID(MpId));
-    }
-
-    // Either we use the Secure Stacks for Secure Monitor (in this case (Base == 0) && (Size == 0))
-    // Or we use separate Secure Monitor stacks (but (Base != 0) && (Size != 0))
-    ASSERT (((PcdGet32(PcdCPUCoresSecMonStackBase) == 0) && (PcdGet32(PcdCPUCoreSecMonStackSize) == 0)) ||
-            ((PcdGet32(PcdCPUCoresSecMonStackBase) != 0) && (PcdGet32(PcdCPUCoreSecMonStackSize) != 0)));
-
-    // Enter Monitor Mode
-    enter_monitor_mode ((UINTN)TrustedWorldInitialization, MpId, SecBootMode, (VOID*)(PcdGet32(PcdCPUCoresSecMonStackBase) + (PcdGet32(PcdCPUCoreSecMonStackSize) * (GET_CORE_POS(MpId) + 1))));
-  } else {
-    if (IS_PRIMARY_CORE(MpId)) {
-      SerialPrint ("Trust Zone Configuration is disabled\n\r");
-    }
-
-    // With Trustzone support the transition from Sec to Normal world is done by return_from_exception().
-    // If we want to keep this function call we need to ensure the SVC's SPSR point to the same Program
-    // Status Register as the the current one (CPSR).
-    copy_cpsr_into_spsr ();
-
-    // Call the Platform specific function to execute additional actions if required
-    JumpAddress = PcdGet32 (PcdFvBaseAddress);
-    ArmPlatformSecExtraAction (MpId, &JumpAddress);
-
-    NonTrustedWorldTransition (MpId, JumpAddress);
-  }
-  ASSERT (0); // We must never return from the above function
-}
-
-VOID
-TrustedWorldInitialization (
-  IN  UINTN                     MpId,
-  IN  UINTN                     SecBootMode
-  )
-{
-  UINTN   JumpAddress;
-
-  //-------------------- Monitor Mode ---------------------
-
-  // Set up Monitor World (Vector Table, etc)
-  ArmSecureMonitorWorldInitialize ();
-
-  // Transfer the interrupt to Non-secure World
-  ArmGicSetupNonSecure (MpId, PcdGet32(PcdGicDistributorBase), PcdGet32(PcdGicInterruptInterfaceBase));
-
-  // Initialize platform specific security policy
-  ArmPlatformSecTrustzoneInit (MpId);
-
-  // Setup the Trustzone Chipsets
-  if (SecBootMode == ARM_SEC_COLD_BOOT) {
-    if (IS_PRIMARY_CORE(MpId)) {
-      if (ArmIsMpCore()) {
-        // Signal the secondary core the Security settings is done (event: EVENT_SECURE_INIT)
-        ArmCallSEV ();
-      }
-    } else {
-      // The secondary cores need to wait until the Trustzone chipsets configuration is done
-      // before switching to Non Secure World
-
-      // Wait for the Primary Core to finish the initialization of the Secure World (event: EVENT_SECURE_INIT)
-      ArmCallWFE ();
-    }
-  }
-
-  // Call the Platform specific function to execute additional actions if required
-  JumpAddress = PcdGet32 (PcdFvBaseAddress);
-  ArmPlatformSecExtraAction (MpId, &JumpAddress);
-
-  // Write to CP15 Non-secure Access Control Register
-  ArmWriteNsacr (PcdGet32 (PcdArmNsacr));
-
-  // CP15 Secure Configuration Register
-  ArmWriteScr (PcdGet32 (PcdArmScr));
-
-  NonTrustedWorldTransition (MpId, JumpAddress);
-}
-
-VOID
-NonTrustedWorldTransition (
-  IN  UINTN                     MpId,
-  IN  UINTN                     JumpAddress
-  )
-{
-  // If PcdArmNonSecModeTransition is defined then set this specific mode to CPSR before the transition
-  // By not set, the mode for Non Secure World is SVC
-  if (PcdGet32 (PcdArmNonSecModeTransition) != 0) {
-    set_non_secure_mode ((ARM_PROCESSOR_MODE)PcdGet32 (PcdArmNonSecModeTransition));
-  }
-
-  return_from_exception (JumpAddress);
-  //-------------------- Non Secure Mode ---------------------
-
-  // PEI Core should always load and never return
-  ASSERT (FALSE);
-}
-
+/** @file\r
+*  Main file supporting the SEC Phase on ARM Platforms\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include <Library/ArmTrustedMonitorLib.h>\r
+#include <Library/DebugAgentLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/SerialPortLib.h>\r
+#include <Library/ArmGicLib.h>\r
+\r
+#include "SecInternal.h"\r
+\r
+#define SerialPrint(txt)  SerialPortWrite ((UINT8*)txt, AsciiStrLen(txt)+1);\r
+\r
+VOID\r
+CEntryPoint (\r
+  IN  UINTN                     MpId,\r
+  IN  UINTN                     SecBootMode\r
+  )\r
+{\r
+  CHAR8           Buffer[100];\r
+  UINTN           CharCount;\r
+  UINTN           JumpAddress;\r
+\r
+  // Invalidate the data cache. Doesn't have to do the Data cache clean.\r
+  ArmInvalidateDataCache();\r
+\r
+  // Invalidate Instruction Cache\r
+  ArmInvalidateInstructionCache();\r
+\r
+  // Invalidate I & D TLBs\r
+  ArmInvalidateInstructionAndDataTlb();\r
+\r
+  // CPU specific settings\r
+  ArmCpuSetup (MpId);\r
+\r
+  // Enable Floating Point Coprocessor if supported by the platform\r
+  if (FixedPcdGet32 (PcdVFPEnabled)) {\r
+    ArmEnableVFP();\r
+  }\r
+\r
+  // Initialize peripherals that must be done at the early stage\r
+  // Example: Some L2 controller, interconnect, clock, DMC, etc\r
+  ArmPlatformSecInitialize (MpId);\r
+\r
+  // Primary CPU clears out the SCU tag RAMs, secondaries wait\r
+  if (IS_PRIMARY_CORE(MpId) && (SecBootMode == ARM_SEC_COLD_BOOT)) {\r
+    if (ArmIsMpCore()) {\r
+      // Signal for the initial memory is configured (event: BOOT_MEM_INIT)\r
+      ArmCallSEV ();\r
+    }\r
+\r
+    // SEC phase needs to run library constructors by hand. This assumes we are linked against the SerialLib\r
+    // In non SEC modules the init call is in autogenerated code.\r
+    SerialPortInitialize ();\r
+\r
+    // Start talking\r
+    if (FixedPcdGetBool (PcdTrustzoneSupport)) {\r
+      CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Secure firmware (version %s built at %a on %a)\n\r",\r
+          (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);\r
+    } else {\r
+      CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Boot firmware (version %s built at %a on %a)\n\r",\r
+          (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);\r
+    }\r
+    SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
+\r
+    // Initialize the Debug Agent for Source Level Debugging\r
+    InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC, NULL, NULL);\r
+    SaveAndSetDebugTimerInterrupt (TRUE);\r
+\r
+    // Enable the GIC distributor and CPU Interface\r
+    // - no other Interrupts are enabled,  doesn't have to worry about the priority.\r
+    // - all the cores are in secure state, use secure SGI's\r
+    ArmGicEnableDistributor (PcdGet32(PcdGicDistributorBase));\r
+    ArmGicEnableInterruptInterface (PcdGet32(PcdGicInterruptInterfaceBase));\r
+  } else {\r
+    // Enable the GIC CPU Interface\r
+    ArmGicEnableInterruptInterface (PcdGet32(PcdGicInterruptInterfaceBase));\r
+  }\r
+\r
+  // Enable Full Access to CoProcessors\r
+  ArmWriteCpacr (CPACR_CP_FULL_ACCESS);\r
+\r
+  // Test if Trustzone is supported on this platform\r
+  if (FixedPcdGetBool (PcdTrustzoneSupport)) {\r
+    if (ArmIsMpCore()) {\r
+      // Setup SMP in Non Secure world\r
+      ArmCpuSetupSmpNonSecure (GET_CORE_ID(MpId));\r
+    }\r
+\r
+    // Either we use the Secure Stacks for Secure Monitor (in this case (Base == 0) && (Size == 0))\r
+    // Or we use separate Secure Monitor stacks (but (Base != 0) && (Size != 0))\r
+    ASSERT (((PcdGet32(PcdCPUCoresSecMonStackBase) == 0) && (PcdGet32(PcdCPUCoreSecMonStackSize) == 0)) ||\r
+            ((PcdGet32(PcdCPUCoresSecMonStackBase) != 0) && (PcdGet32(PcdCPUCoreSecMonStackSize) != 0)));\r
+\r
+    // Enter Monitor Mode\r
+    enter_monitor_mode ((UINTN)TrustedWorldInitialization, MpId, SecBootMode, (VOID*)(PcdGet32(PcdCPUCoresSecMonStackBase) + (PcdGet32(PcdCPUCoreSecMonStackSize) * (GET_CORE_POS(MpId) + 1))));\r
+  } else {\r
+    if (IS_PRIMARY_CORE(MpId)) {\r
+      SerialPrint ("Trust Zone Configuration is disabled\n\r");\r
+    }\r
+\r
+    // With Trustzone support the transition from Sec to Normal world is done by return_from_exception().\r
+    // If we want to keep this function call we need to ensure the SVC's SPSR point to the same Program\r
+    // Status Register as the the current one (CPSR).\r
+    copy_cpsr_into_spsr ();\r
+\r
+    // Call the Platform specific function to execute additional actions if required\r
+    JumpAddress = PcdGet32 (PcdFvBaseAddress);\r
+    ArmPlatformSecExtraAction (MpId, &JumpAddress);\r
+\r
+    NonTrustedWorldTransition (MpId, JumpAddress);\r
+  }\r
+  ASSERT (0); // We must never return from the above function\r
+}\r
+\r
+VOID\r
+TrustedWorldInitialization (\r
+  IN  UINTN                     MpId,\r
+  IN  UINTN                     SecBootMode\r
+  )\r
+{\r
+  UINTN   JumpAddress;\r
+\r
+  //-------------------- Monitor Mode ---------------------\r
+\r
+  // Set up Monitor World (Vector Table, etc)\r
+  ArmSecureMonitorWorldInitialize ();\r
+\r
+  // Transfer the interrupt to Non-secure World\r
+  ArmGicSetupNonSecure (MpId, PcdGet32(PcdGicDistributorBase), PcdGet32(PcdGicInterruptInterfaceBase));\r
+\r
+  // Initialize platform specific security policy\r
+  ArmPlatformSecTrustzoneInit (MpId);\r
+\r
+  // Setup the Trustzone Chipsets\r
+  if (SecBootMode == ARM_SEC_COLD_BOOT) {\r
+    if (IS_PRIMARY_CORE(MpId)) {\r
+      if (ArmIsMpCore()) {\r
+        // Signal the secondary core the Security settings is done (event: EVENT_SECURE_INIT)\r
+        ArmCallSEV ();\r
+      }\r
+    } else {\r
+      // The secondary cores need to wait until the Trustzone chipsets configuration is done\r
+      // before switching to Non Secure World\r
+\r
+      // Wait for the Primary Core to finish the initialization of the Secure World (event: EVENT_SECURE_INIT)\r
+      ArmCallWFE ();\r
+    }\r
+  }\r
+\r
+  // Call the Platform specific function to execute additional actions if required\r
+  JumpAddress = PcdGet32 (PcdFvBaseAddress);\r
+  ArmPlatformSecExtraAction (MpId, &JumpAddress);\r
+\r
+  // Write to CP15 Non-secure Access Control Register\r
+  ArmWriteNsacr (PcdGet32 (PcdArmNsacr));\r
+\r
+  // CP15 Secure Configuration Register\r
+  ArmWriteScr (PcdGet32 (PcdArmScr));\r
+\r
+  NonTrustedWorldTransition (MpId, JumpAddress);\r
+}\r
+\r
+VOID\r
+NonTrustedWorldTransition (\r
+  IN  UINTN                     MpId,\r
+  IN  UINTN                     JumpAddress\r
+  )\r
+{\r
+  // If PcdArmNonSecModeTransition is defined then set this specific mode to CPSR before the transition\r
+  // By not set, the mode for Non Secure World is SVC\r
+  if (PcdGet32 (PcdArmNonSecModeTransition) != 0) {\r
+    set_non_secure_mode ((ARM_PROCESSOR_MODE)PcdGet32 (PcdArmNonSecModeTransition));\r
+  }\r
+\r
+  return_from_exception (JumpAddress);\r
+  //-------------------- Non Secure Mode ---------------------\r
+\r
+  // PEI Core should always load and never return\r
+  ASSERT (FALSE);\r
+}\r
+\r
index a6ee2740bbe043c06ca98e3db6c8f6aea408bca1..496442a627e8e42c2b202bf172ed9ebce404f82f 100644 (file)
@@ -1,36 +1,36 @@
-#/** @file
-# Beagle board package.
-#
-# Copyright (c) 2009, Apple Inc. All rights reserved.<BR>
-#
-#    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_SPECIFICATION              = 0x00010005
-  PACKAGE_NAME                   = BeagleBoardPkg
-  PACKAGE_GUID                   = 6eba6648-d853-4eb3-9761-528b82d5ab04
-  PACKAGE_VERSION                = 0.1
-
-################################################################################
-#
-# Include Section - list of Include Paths that are provided by this package.
-#                   Comments are used for Keywords and Module Types.
-#
-# Supported Module Types:
-#  BASE SEC PEI_CORE PEIM DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER DXE_SAL_DRIVER UEFI_DRIVER UEFI_APPLICATION
-#
-################################################################################
-[Includes.common]
-  Include                        # Root include for the package
-
-[Guids.common]
-  gBeagleBoardTokenSpaceGuid    =  { 0x6834fe45, 0x4aee, 0x4fc6, { 0xbc, 0xb5, 0xff, 0x45, 0xb7, 0xa8, 0x71, 0xe2 } }
-
+#/** @file\r
+# Beagle board package.\r
+#\r
+# Copyright (c) 2009, Apple Inc. All rights reserved.<BR>\r
+#\r
+#    This program and the accompanying materials are licensed and made available under\r
+#    the terms and conditions of the BSD License which accompanies this distribution.\r
+#    The full text of the license may be found at\r
+#    http://opensource.org/licenses/bsd-license.php\r
+#\r
+#    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  DEC_SPECIFICATION              = 0x00010005\r
+  PACKAGE_NAME                   = BeagleBoardPkg\r
+  PACKAGE_GUID                   = 6eba6648-d853-4eb3-9761-528b82d5ab04\r
+  PACKAGE_VERSION                = 0.1\r
+\r
+################################################################################\r
+#\r
+# Include Section - list of Include Paths that are provided by this package.\r
+#                   Comments are used for Keywords and Module Types.\r
+#\r
+# Supported Module Types:\r
+#  BASE SEC PEI_CORE PEIM DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER DXE_SAL_DRIVER UEFI_DRIVER UEFI_APPLICATION\r
+#\r
+################################################################################\r
+[Includes.common]\r
+  Include                        # Root include for the package\r
+\r
+[Guids.common]\r
+  gBeagleBoardTokenSpaceGuid    =  { 0x6834fe45, 0x4aee, 0x4fc6, { 0xbc, 0xb5, 0xff, 0x45, 0xb7, 0xa8, 0x71, 0xe2 } }\r
+\r
index ff4c5568725bfc7d295dd05780ab7e16028acfce..4e58f36042e4fda127a7b0bc5912a6a310af1c16 100755 (executable)
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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 <Library/IoLib.h>
-#include <Library/ArmPlatformLib.h>
-#include <Library/DebugLib.h>
-#include <Library/PcdLib.h>
-
-#include <Omap3530/Omap3530.h>
-#include <BeagleBoard.h>
-
-VOID
-PadConfiguration (
-  BEAGLEBOARD_REVISION Revision
-  );
-
-VOID
-ClockInit (
-  VOID
-  );
-
-/**
-  Detect board revision
-
-  @return Board revision
-**/
-BEAGLEBOARD_REVISION
-BeagleBoardGetRevision (
-  VOID
-  )
-{
-  UINT32 OldPinDir;
-  UINT32 Revision;
-
-  // Read GPIO 171, 172, 173
-  OldPinDir = MmioRead32 (GPIO6_BASE + GPIO_OE);
-  MmioWrite32(GPIO6_BASE + GPIO_OE, (OldPinDir | BIT11 | BIT12 | BIT13));
-  Revision = MmioRead32 (GPIO6_BASE + GPIO_DATAIN);
-  
-  // Restore I/O settings
-  MmioWrite32 (GPIO6_BASE + GPIO_OE, OldPinDir);
-  
-  return (BEAGLEBOARD_REVISION)((Revision >> 11) & 0x7);
-}
-
-/**
-  Return the current Boot Mode
-
-  This function returns the boot reason on the platform
-
-**/
-EFI_BOOT_MODE
-ArmPlatformGetBootMode (
-  VOID
-  )
-{
-  return BOOT_WITH_FULL_CONFIGURATION;
-}
-
-/**
-  Initialize controllers that must setup at the early stage
-
-  Some peripherals must be initialized in Secure World.
-  For example, some L2x0 requires to be initialized in Secure World
-
-**/
-RETURN_STATUS
-ArmPlatformInitialize (
-  IN  UINTN                     MpId
-  )
-{
-  BEAGLEBOARD_REVISION Revision;
-
-  Revision = BeagleBoardGetRevision();
-
-  // Set up Pin muxing.
-  PadConfiguration (Revision);
-
-  // Set up system clocking
-  ClockInit ();
-
-  // Turn off the functional clock for Timer 3
-  MmioAnd32 (CM_FCLKEN_PER, 0xFFFFFFFF ^ CM_ICLKEN_PER_EN_GPT3_ENABLE );
-  ArmDataSyncronizationBarrier ();
-
-  // Clear IRQs
-  MmioWrite32 (INTCPS_CONTROL, INTCPS_CONTROL_NEWIRQAGR);
-  ArmDataSyncronizationBarrier ();
-
-  return RETURN_SUCCESS;
-}
-
-/**
-  Initialize the system (or sometimes called permanent) memory
-
-  This memory is generally represented by the DRAM.
-
-**/
-VOID
-ArmPlatformInitializeSystemMemory (
-  VOID
-  )
-{
-  // We do not need to initialize the System Memory on RTSM
-}
-
-VOID
-ArmPlatformGetPlatformPpiList (
-  OUT UINTN                   *PpiListSize,
-  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList
-  )
-{
-  *PpiListSize = 0;
-  *PpiList = NULL;
-}
-
-UINTN
-ArmPlatformGetCorePosition (
-  IN UINTN MpId
-  )
-{
-  return 1;
-}
-
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include <Library/IoLib.h>\r
+#include <Library/ArmPlatformLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+#include <Omap3530/Omap3530.h>\r
+#include <BeagleBoard.h>\r
+\r
+VOID\r
+PadConfiguration (\r
+  BEAGLEBOARD_REVISION Revision\r
+  );\r
+\r
+VOID\r
+ClockInit (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Detect board revision\r
+\r
+  @return Board revision\r
+**/\r
+BEAGLEBOARD_REVISION\r
+BeagleBoardGetRevision (\r
+  VOID\r
+  )\r
+{\r
+  UINT32 OldPinDir;\r
+  UINT32 Revision;\r
+\r
+  // Read GPIO 171, 172, 173\r
+  OldPinDir = MmioRead32 (GPIO6_BASE + GPIO_OE);\r
+  MmioWrite32(GPIO6_BASE + GPIO_OE, (OldPinDir | BIT11 | BIT12 | BIT13));\r
+  Revision = MmioRead32 (GPIO6_BASE + GPIO_DATAIN);\r
+  \r
+  // Restore I/O settings\r
+  MmioWrite32 (GPIO6_BASE + GPIO_OE, OldPinDir);\r
+  \r
+  return (BEAGLEBOARD_REVISION)((Revision >> 11) & 0x7);\r
+}\r
+\r
+/**\r
+  Return the current Boot Mode\r
+\r
+  This function returns the boot reason on the platform\r
+\r
+**/\r
+EFI_BOOT_MODE\r
+ArmPlatformGetBootMode (\r
+  VOID\r
+  )\r
+{\r
+  return BOOT_WITH_FULL_CONFIGURATION;\r
+}\r
+\r
+/**\r
+  Initialize controllers that must setup at the early stage\r
+\r
+  Some peripherals must be initialized in Secure World.\r
+  For example, some L2x0 requires to be initialized in Secure World\r
+\r
+**/\r
+RETURN_STATUS\r
+ArmPlatformInitialize (\r
+  IN  UINTN                     MpId\r
+  )\r
+{\r
+  BEAGLEBOARD_REVISION Revision;\r
+\r
+  Revision = BeagleBoardGetRevision();\r
+\r
+  // Set up Pin muxing.\r
+  PadConfiguration (Revision);\r
+\r
+  // Set up system clocking\r
+  ClockInit ();\r
+\r
+  // Turn off the functional clock for Timer 3\r
+  MmioAnd32 (CM_FCLKEN_PER, 0xFFFFFFFF ^ CM_ICLKEN_PER_EN_GPT3_ENABLE );\r
+  ArmDataSyncronizationBarrier ();\r
+\r
+  // Clear IRQs\r
+  MmioWrite32 (INTCPS_CONTROL, INTCPS_CONTROL_NEWIRQAGR);\r
+  ArmDataSyncronizationBarrier ();\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Initialize the system (or sometimes called permanent) memory\r
+\r
+  This memory is generally represented by the DRAM.\r
+\r
+**/\r
+VOID\r
+ArmPlatformInitializeSystemMemory (\r
+  VOID\r
+  )\r
+{\r
+  // We do not need to initialize the System Memory on RTSM\r
+}\r
+\r
+VOID\r
+ArmPlatformGetPlatformPpiList (\r
+  OUT UINTN                   *PpiListSize,\r
+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList\r
+  )\r
+{\r
+  *PpiListSize = 0;\r
+  *PpiList = NULL;\r
+}\r
+\r
+UINTN\r
+ArmPlatformGetCorePosition (\r
+  IN UINTN MpId\r
+  )\r
+{\r
+  return 1;\r
+}\r
+\r
index e076500b8143c82f724d8514dc84325f79d29cb5..7ca98c2bbb1260f90c850c336429b9f0a08be7fa 100755 (executable)
@@ -1,53 +1,53 @@
-#/* @file
-#  Copyright (c) 2011-2012, ARM Limited. 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                      = BeagleBoardLib
-  FILE_GUID                      = 736343a0-1d96-11e0-aaaa-0002a5d5c51b
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = ArmPlatformLib
-
-[Packages]
-  MdePkg/MdePkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  ArmPkg/ArmPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-  Omap35xxPkg/Omap35xxPkg.dec
-  BeagleBoardPkg/BeagleBoardPkg.dec
-
-[LibraryClasses]
-  IoLib
-  ArmLib
-#  OmapLib
-  MemoryAllocationLib
-
-[Sources.common]
-  BeagleBoard.c
-  BeagleBoardMem.c
-  PadConfiguration.c
-  Clock.c
-
-[Protocols]
-
-[FeaturePcd]
-  gEmbeddedTokenSpaceGuid.PcdCacheEnable
-
-[FixedPcd]
-  gArmTokenSpaceGuid.PcdFdBaseAddress
-  gArmTokenSpaceGuid.PcdFdSize
-
-  gArmTokenSpaceGuid.PcdSystemMemoryBase
-  gArmTokenSpaceGuid.PcdSystemMemorySize
+#/* @file\r
+#  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+#*/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = BeagleBoardLib\r
+  FILE_GUID                      = 736343a0-1d96-11e0-aaaa-0002a5d5c51b\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ArmPlatformLib\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+  Omap35xxPkg/Omap35xxPkg.dec\r
+  BeagleBoardPkg/BeagleBoardPkg.dec\r
+\r
+[LibraryClasses]\r
+  IoLib\r
+  ArmLib\r
+#  OmapLib\r
+  MemoryAllocationLib\r
+\r
+[Sources.common]\r
+  BeagleBoard.c\r
+  BeagleBoardMem.c\r
+  PadConfiguration.c\r
+  Clock.c\r
+\r
+[Protocols]\r
+\r
+[FeaturePcd]\r
+  gEmbeddedTokenSpaceGuid.PcdCacheEnable\r
+\r
+[FixedPcd]\r
+  gArmTokenSpaceGuid.PcdFdBaseAddress\r
+  gArmTokenSpaceGuid.PcdFdSize\r
+\r
+  gArmTokenSpaceGuid.PcdSystemMemoryBase\r
+  gArmTokenSpaceGuid.PcdSystemMemorySize\r
index 2f9a3202e32587928eb38391d8fe68994b380919..7634ee174cfed45446fe6512f3d55ee19a3bceae 100644 (file)
-/** @file
-  Basic serial IO abstaction for GDB
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <Uefi.h>
-#include <Library/GdbSerialLib.h>
-#include <Library/PcdLib.h>
-#include <Library/IoLib.h>
-#include <Library/DebugLib.h>
-#include <Library/OmapLib.h>
-#include <Omap3530/Omap3530.h>
-
-RETURN_STATUS
-EFIAPI
-GdbSerialLibConstructor (
-  IN EFI_HANDLE        ImageHandle,
-  IN EFI_SYSTEM_TABLE  *SystemTable
-  )
-{
-  return RETURN_SUCCESS;
-}
-
-RETURN_STATUS
-EFIAPI
-GdbSerialInit (
-  IN UINT64     BaudRate, 
-  IN UINT8      Parity, 
-  IN UINT8      DataBits, 
-  IN UINT8      StopBits 
-  )
-{
-  return RETURN_SUCCESS;
-}
-
-BOOLEAN
-EFIAPI
-GdbIsCharAvailable (
-  VOID
-  )  
-{
-  UINT32 LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;
-
-  if ((MmioRead8(LSR) & UART_LSR_RX_FIFO_E_MASK) == UART_LSR_RX_FIFO_E_NOT_EMPTY) {
-    return TRUE;
-  } else {
-    return FALSE;
-  }
-}
-
-CHAR8
-EFIAPI
-GdbGetChar (
-  VOID
-  )
-{
-  UINT32  LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;
-  UINT32  RBR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_RBR_REG;
-  CHAR8   Char;
-    
-  while ((MmioRead8(LSR) & UART_LSR_RX_FIFO_E_MASK) == UART_LSR_RX_FIFO_E_EMPTY);
-  Char = MmioRead8(RBR);
-
-  return Char;
-}
-
-VOID
-EFIAPI
-GdbPutChar (
-  IN  CHAR8   Char
-  )
-{
-  UINT32  LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;
-  UINT32  THR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_THR_REG;
-    
-  while ((MmioRead8(LSR) & UART_LSR_TX_FIFO_E_MASK) == UART_LSR_TX_FIFO_E_NOT_EMPTY);
-  MmioWrite8(THR, Char);
-}
-
-VOID
-GdbPutString (
-  IN CHAR8  *String
-  )
-{
-  while (*String != '\0') {
-    GdbPutChar (*String);
-    String++;
-  }
-}
-
-
-
-
+/** @file\r
+  Basic serial IO abstaction for GDB\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+#include <Library/GdbSerialLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/OmapLib.h>\r
+#include <Omap3530/Omap3530.h>\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+GdbSerialLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+GdbSerialInit (\r
+  IN UINT64     BaudRate, \r
+  IN UINT8      Parity, \r
+  IN UINT8      DataBits, \r
+  IN UINT8      StopBits \r
+  )\r
+{\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+BOOLEAN\r
+EFIAPI\r
+GdbIsCharAvailable (\r
+  VOID\r
+  )  \r
+{\r
+  UINT32 LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;\r
+\r
+  if ((MmioRead8(LSR) & UART_LSR_RX_FIFO_E_MASK) == UART_LSR_RX_FIFO_E_NOT_EMPTY) {\r
+    return TRUE;\r
+  } else {\r
+    return FALSE;\r
+  }\r
+}\r
+\r
+CHAR8\r
+EFIAPI\r
+GdbGetChar (\r
+  VOID\r
+  )\r
+{\r
+  UINT32  LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;\r
+  UINT32  RBR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_RBR_REG;\r
+  CHAR8   Char;\r
+    \r
+  while ((MmioRead8(LSR) & UART_LSR_RX_FIFO_E_MASK) == UART_LSR_RX_FIFO_E_EMPTY);\r
+  Char = MmioRead8(RBR);\r
+\r
+  return Char;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+GdbPutChar (\r
+  IN  CHAR8   Char\r
+  )\r
+{\r
+  UINT32  LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;\r
+  UINT32  THR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_THR_REG;\r
+    \r
+  while ((MmioRead8(LSR) & UART_LSR_TX_FIFO_E_MASK) == UART_LSR_TX_FIFO_E_NOT_EMPTY);\r
+  MmioWrite8(THR, Char);\r
+}\r
+\r
+VOID\r
+GdbPutString (\r
+  IN CHAR8  *String\r
+  )\r
+{\r
+  while (*String != '\0') {\r
+    GdbPutChar (*String);\r
+    String++;\r
+  }\r
+}\r
+\r
+\r
+\r
+\r
index 8627442eeae57b89d4dfb0f5abeca32cd3d6a9f6..df96e8b7563a15ef2c25ce763cadc26e18160cc0 100644 (file)
@@ -1,41 +1,41 @@
-#/** @file
-#  
-#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-#  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                      = GdbSerialLib
-  FILE_GUID                      = E2423349-EF5D-439B-95F5-8B8D8E3B443F
-  MODULE_TYPE                    = UEFI_DRIVER
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = GdbSerialLib
-
-  CONSTRUCTOR                    = GdbSerialLibConstructor
-
-
-[Sources.common]
-  GdbSerialLib.c
-
-
-[Packages]
-  MdePkg/MdePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  Omap35xxPkg/Omap35xxPkg.dec
-
-[LibraryClasses]
-  DebugLib
-  IoLib
-  OmapLib    
-
-[FixedPcd]
-  gOmap35xxTokenSpaceGuid.PcdOmap35xxConsoleUart
-
+#/** @file\r
+#  \r
+#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = GdbSerialLib\r
+  FILE_GUID                      = E2423349-EF5D-439B-95F5-8B8D8E3B443F\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = GdbSerialLib\r
+\r
+  CONSTRUCTOR                    = GdbSerialLibConstructor\r
+\r
+\r
+[Sources.common]\r
+  GdbSerialLib.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  Omap35xxPkg/Omap35xxPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  IoLib\r
+  OmapLib    \r
+\r
+[FixedPcd]\r
+  gOmap35xxTokenSpaceGuid.PcdOmap35xxConsoleUart\r
+\r
index 4256b0e99b37e50e48dc4cf1205397ed7b3044ac..193004a8e84c5eca3d6a6eb0bff5cb85d37a7e42 100644 (file)
@@ -75,5 +75,5 @@ InitCache (
   \r
   ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r
   \r
   \r
   ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r
   \r
-  BuildMemoryAllocationHob((EFI_PHYSICAL_ADDRESS)(UINTN)TranslationTableBase, TranslationTableSize, EfiBootServicesData);
+  BuildMemoryAllocationHob((EFI_PHYSICAL_ADDRESS)(UINTN)TranslationTableBase, TranslationTableSize, EfiBootServicesData);\r
 }\r
 }\r
index a3fc192c2fa1c6e558eefe05507f6ae05a091340..7fc4ec12d488b6e3cfcc41c2d21e789e3bafcb5f 100644 (file)
@@ -1,73 +1,73 @@
-
-#/** @file
-#  SEC - Reset vector code that jumps to C and loads DXE core
-#  
-#  Copyright (c) 2008, Apple Inc. All rights reserved.<BR>
-#  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                      = BeagleBoardSec
-  FILE_GUID                      = d959e387-7b91-452c-90e0-a1dbac90ddb8
-  MODULE_TYPE                    = SEC
-  VERSION_STRING                 = 1.0
-
-
-[Sources.ARM]
-  Arm/ModuleEntryPoint.S   | GCC
-  Arm/ModuleEntryPoint.asm | RVCT
-
-[Sources.ARM]
-  Sec.c
-  Cache.c
-  PadConfiguration.c
-  Clock.c
-  
-[Packages]
-  MdePkg/MdePkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  ArmPkg/ArmPkg.dec
-  Omap35xxPkg/Omap35xxPkg.dec
-  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
-
-[LibraryClasses]
-  BaseLib
-  DebugLib
-  ArmLib
-  IoLib
-  ExtractGuidedSectionLib
-  LzmaDecompressLib
-  OmapLib
-  PeCoffGetEntryPointLib
-  DebugAgentLib
-  MemoryAllocationLib
-  PrePiHobListPointerLib
-
-[FeaturePcd]  
-  gEmbeddedTokenSpaceGuid.PcdCacheEnable
-
-[FixedPcd]
-  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedFdBaseAddress
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedFdSize
-  gEmbeddedTokenSpaceGuid.PcdFlashFvMainBase
-  gEmbeddedTokenSpaceGuid.PcdFlashFvMainSize
-  gEmbeddedTokenSpaceGuid.PcdPrePiStackSize
-  gEmbeddedTokenSpaceGuid.PcdPrePiStackBase
-  gEmbeddedTokenSpaceGuid.PcdMemoryBase
-  gEmbeddedTokenSpaceGuid.PcdMemorySize
-  
-  gOmap35xxTokenSpaceGuid.PcdOmap35xxConsoleUart
-  gOmap35xxTokenSpaceGuid.PcdOmap35xxFreeTimer
-  
-  gArmTokenSpaceGuid.PcdCpuVectorBaseAddress
-
+\r
+#/** @file\r
+#  SEC - Reset vector code that jumps to C and loads DXE core\r
+#  \r
+#  Copyright (c) 2008, Apple Inc. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = BeagleBoardSec\r
+  FILE_GUID                      = d959e387-7b91-452c-90e0-a1dbac90ddb8\r
+  MODULE_TYPE                    = SEC\r
+  VERSION_STRING                 = 1.0\r
+\r
+\r
+[Sources.ARM]\r
+  Arm/ModuleEntryPoint.S   | GCC\r
+  Arm/ModuleEntryPoint.asm | RVCT\r
+\r
+[Sources.ARM]\r
+  Sec.c\r
+  Cache.c\r
+  PadConfiguration.c\r
+  Clock.c\r
+  \r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  Omap35xxPkg/Omap35xxPkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  ArmLib\r
+  IoLib\r
+  ExtractGuidedSectionLib\r
+  LzmaDecompressLib\r
+  OmapLib\r
+  PeCoffGetEntryPointLib\r
+  DebugAgentLib\r
+  MemoryAllocationLib\r
+  PrePiHobListPointerLib\r
+\r
+[FeaturePcd]  \r
+  gEmbeddedTokenSpaceGuid.PcdCacheEnable\r
+\r
+[FixedPcd]\r
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedFdBaseAddress\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedFdSize\r
+  gEmbeddedTokenSpaceGuid.PcdFlashFvMainBase\r
+  gEmbeddedTokenSpaceGuid.PcdFlashFvMainSize\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiStackSize\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiStackBase\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryBase\r
+  gEmbeddedTokenSpaceGuid.PcdMemorySize\r
+  \r
+  gOmap35xxTokenSpaceGuid.PcdOmap35xxConsoleUart\r
+  gOmap35xxTokenSpaceGuid.PcdOmap35xxFreeTimer\r
+  \r
+  gArmTokenSpaceGuid.PcdCpuVectorBaseAddress\r
+\r
index fa4cdcc497eedb1f4684362a6b8573dee579edbb..9426ca333761a1f3be36ce38fd90781cedc1a2f3 100644 (file)
-/** @file
- The data structures in this code come from:
- OMAP35x Applications Processor Technical Reference Manual chapter 25
- OMAP34xx Multimedia Device Technical Reference Manual chapter 26.4.8.
- You should use the OMAP35x manual when possible. Some things, like SectionKey, 
- are not defined in the OMAP35x manual and you have to use the OMAP34xx manual
- to find the data. 
-
-  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-  
-  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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-
-
-//TOC structure as defined by OMAP35XX TRM.
-typedef struct {
-  unsigned int  Start;
-  unsigned int  Size;
-  unsigned int  Reserved1;
-  unsigned int  Reserved2;
-  unsigned int  Reserved3;
-  unsigned char Filename[12];
-} TOC_DATA;
-
-//NOTE: OMAP3430 TRM has CHSETTINGS and CHRAM structures.
-typedef struct {
-  unsigned int   SectionKey;
-  unsigned char  Valid;
-  unsigned char  Version;
-  unsigned short Reserved;
-  unsigned int   Flags;
-  unsigned int   PRM_CLKSRC_CTRL; 
-  unsigned int   PRM_CLKSEL; 
-  unsigned int   CM_CLKSEL1_EMU;
-  unsigned int   CM_CLKSEL_CORE;
-  unsigned int   CM_CLKSEL_WKUP;
-  unsigned int   CM_CLKEN_PLL_DPLL3;
-  unsigned int   CM_AUTOIDLE_PLL_DPLL3; 
-  unsigned int   CM_CLKSEL1_PLL; 
-  unsigned int   CM_CLKEN_PLL_DPLL4;
-  unsigned int   CM_AUTOIDLE_PLL_DPLL4;
-  unsigned int   CM_CLKSEL2_PLL;
-  unsigned int   CM_CLKSEL3_PLL; 
-  unsigned int   CM_CLKEN_PLL_MPU; 
-  unsigned int   CM_AUTOIDLE_PLL_MPU; 
-  unsigned int   CM_CLKSEL1_PLL_MPU; 
-  unsigned int   CM_CLKSEL2_PLL_MPU; 
-  unsigned int   CM_CLKSTCTRL_MPU;
-} CHSETTINGS_DATA;
-
-typedef struct {
-  unsigned int   SectionKey;
-  unsigned char  Valid;
-  unsigned char  Reserved1;
-  unsigned char  Reserved2;
-  unsigned char  Reserved3;
-  unsigned short SDRC_SYSCONFIG_LSB;
-  unsigned short SDRC_CS_CFG_LSB;
-  unsigned short SDRC_SHARING_LSB;
-  unsigned short SDRC_ERR_TYPE_LSB;
-  unsigned int   SDRC_DLLA_CTRL;
-  unsigned short Reserved4;
-  unsigned short Reserved5;
-  unsigned int   SDRC_POWER;
-  unsigned short MEMORY_TYPE_CS0;
-  unsigned short Reserved6;
-  unsigned int   SDRC_MCFG_0;
-  unsigned short SDRC_MR_0_LSB;
-  unsigned short SDRC_EMR1_0_LSB;
-  unsigned short SDRC_EMR2_0_LSB;
-  unsigned short SDRC_EMR3_0_LSB;
-  unsigned int   SDRC_ACTIM_CTRLA_0;
-  unsigned int   SDRC_ACTIM_CTRLB_0;
-  unsigned int   SDRC_RFRCTRL_0;
-  unsigned short MEMORY_TYPE_CS1;
-  unsigned short Reserved7;
-  unsigned int   SDRC_MCFG_1;
-  unsigned short SDRC_MR_1_LSB;
-  unsigned short SDRC_EMR1_1_LSB;
-  unsigned short SDRC_EMR2_1_LSB;
-  unsigned short SDRC_EMR3_1_LSB;
-  unsigned int   SDRC_ACTIM_CTRLA_1;
-  unsigned int   SDRC_ACTIM_CTRLB_1;
-  unsigned int   SDRC_RFRCTRL_1;
-  unsigned int   Reserved8;
-  unsigned short Flags;
-  unsigned short Reserved9;
-} CHRAM_DATA;
-
-#define CHSETTINGS_START      0xA0
-#define CHSETTINGS_SIZE       0x50
-#define CHRAM_START           0xF0
-#define CHRAM_SIZE            0x5C
-#define CLOSING_TOC_ITEM_SIZE 4
-
-unsigned char gConfigurationHeader[512];
-unsigned int  gImageExecutionAddress;
-char          *gInputImageFile = NULL;
-char          *gOutputImageFile = NULL;
-char          *gDataFile = NULL;
-
-static
-void
-PrintUsage (
-  void
-  )
-{
-  printf("Usage..\n");
-}
-
-static
-void
-PopulateCHSETTINGSData (
-  FILE            *DataFile,
-  CHSETTINGS_DATA *CHSETTINGSData
-  )
-{
-  unsigned int Value;
-  
-  CHSETTINGSData->SectionKey            = 0xC0C0C0C1;
-  CHSETTINGSData->Valid                 = 0x1;
-  CHSETTINGSData->Version               = 0x1;
-  CHSETTINGSData->Reserved              = 0x00;
-  CHSETTINGSData->Flags                 = 0x050001FD;
-
-  //General clock settings.
-  fscanf(DataFile, "PRM_CLKSRC_CTRL=0x%08x\n", &Value);
-  CHSETTINGSData->PRM_CLKSRC_CTRL = Value;
-  fscanf(DataFile, "PRM_CLKSEL=0x%08x\n", &Value);
-  CHSETTINGSData->PRM_CLKSEL = Value;
-  fscanf(DataFile, "CM_CLKSEL1_EMU=0x%08x\n", &Value);
-  CHSETTINGSData->CM_CLKSEL1_EMU = Value;
-
-  //Clock configuration
-  fscanf(DataFile, "CM_CLKSEL_CORE=0x%08x\n", &Value);
-  CHSETTINGSData->CM_CLKSEL_CORE = Value;
-  fscanf(DataFile, "CM_CLKSEL_WKUP=0x%08x\n", &Value);
-  CHSETTINGSData->CM_CLKSEL_WKUP = Value;
-
-  //DPLL3 (Core) settings
-  fscanf(DataFile, "CM_CLKEN_PLL_DPLL3=0x%08x\n", &Value);
-  CHSETTINGSData->CM_CLKEN_PLL_DPLL3 = Value;
-  fscanf(DataFile, "CM_AUTOIDLE_PLL_DPLL3=0x%08x\n", &Value);
-  CHSETTINGSData->CM_AUTOIDLE_PLL_DPLL3 = Value;
-  fscanf(DataFile, "CM_CLKSEL1_PLL=0x%08x\n", &Value);
-  CHSETTINGSData->CM_CLKSEL1_PLL = Value;
-
-  //DPLL4 (Peripheral) settings
-  fscanf(DataFile, "CM_CLKEN_PLL_DPLL4=0x%08x\n", &Value);
-  CHSETTINGSData->CM_CLKEN_PLL_DPLL4 = Value;
-  fscanf(DataFile, "CM_AUTOIDLE_PLL_DPLL4=0x%08x\n", &Value);
-  CHSETTINGSData->CM_AUTOIDLE_PLL_DPLL4 = Value;
-  fscanf(DataFile, "CM_CLKSEL2_PLL=0x%08x\n", &Value);
-  CHSETTINGSData->CM_CLKSEL2_PLL = Value;
-  fscanf(DataFile, "CM_CLKSEL3_PLL=0x%08x\n", &Value);
-  CHSETTINGSData->CM_CLKSEL3_PLL = Value;
-
-  //DPLL1 (MPU) settings
-  fscanf(DataFile, "CM_CLKEN_PLL_MPU=0x%08x\n", &Value);
-  CHSETTINGSData->CM_CLKEN_PLL_MPU = Value;
-  fscanf(DataFile, "CM_AUTOIDLE_PLL_MPU=0x%08x\n", &Value);
-  CHSETTINGSData->CM_AUTOIDLE_PLL_MPU = Value;
-  fscanf(DataFile, "CM_CLKSEL1_PLL_MPU=0x%08x\n", &Value);
-  CHSETTINGSData->CM_CLKSEL1_PLL_MPU = Value;
-  fscanf(DataFile, "CM_CLKSEL2_PLL_MPU=0x%08x\n", &Value);
-  CHSETTINGSData->CM_CLKSEL2_PLL_MPU = Value;
-  fscanf(DataFile, "CM_CLKSTCTRL_MPU=0x%08x\n", &Value);
-  CHSETTINGSData->CM_CLKSTCTRL_MPU = Value;
-}
-
-static
-void
-PopulateCHRAMData (
-  FILE       *DataFile,
-  CHRAM_DATA *CHRAMData
-  )
-{
-  unsigned int Value;
-  
-  CHRAMData->SectionKey         = 0xC0C0C0C2;
-  CHRAMData->Valid              = 0x1;
-  
-  fscanf(DataFile, "SDRC_SYSCONFIG_LSB=0x%04x\n", &Value);
-  CHRAMData->SDRC_SYSCONFIG_LSB = Value;
-  fscanf(DataFile, "SDRC_CS_CFG_LSB=0x%04x\n", &Value);
-  CHRAMData->SDRC_CS_CFG_LSB    = Value;
-  fscanf(DataFile, "SDRC_SHARING_LSB=0x%04x\n", &Value);
-  CHRAMData->SDRC_SHARING_LSB   = Value;
-  fscanf(DataFile, "SDRC_ERR_TYPE_LSB=0x%04x\n", &Value);
-  CHRAMData->SDRC_ERR_TYPE_LSB  = Value;
-  fscanf(DataFile, "SDRC_DLLA_CTRL=0x%08x\n", &Value);
-  CHRAMData->SDRC_DLLA_CTRL     = Value;
-  fscanf(DataFile, "SDRC_POWER=0x%08x\n", &Value);
-  CHRAMData->SDRC_POWER         = Value;
-  fscanf(DataFile, "MEMORY_TYPE_CS0=0x%04x\n", &Value);
-  CHRAMData->MEMORY_TYPE_CS0    = Value;
-  fscanf(DataFile, "SDRC_MCFG_0=0x%08x\n", &Value);
-  CHRAMData->SDRC_MCFG_0        = Value;
-  fscanf(DataFile, "SDRC_MR_0_LSB=0x%04x\n", &Value);
-  CHRAMData->SDRC_MR_0_LSB      = Value;
-  fscanf(DataFile, "SDRC_EMR1_0_LSB=0x%04x\n", &Value);
-  CHRAMData->SDRC_EMR1_0_LSB    = Value;
-  fscanf(DataFile, "SDRC_EMR2_0_LSB=0x%04x\n", &Value);
-  CHRAMData->SDRC_EMR2_0_LSB    = Value;
-  fscanf(DataFile, "SDRC_EMR3_0_LSB=0x%04x\n", &Value);
-  CHRAMData->SDRC_EMR3_0_LSB    = Value;
-  fscanf(DataFile, "SDRC_ACTIM_CTRLA_0=0x%08x\n", &Value);
-  CHRAMData->SDRC_ACTIM_CTRLA_0 = Value;
-  fscanf(DataFile, "SDRC_ACTIM_CTRLB_0=0x%08x\n", &Value);
-  CHRAMData->SDRC_ACTIM_CTRLB_0 = Value;
-  fscanf(DataFile, "SDRC_RFRCTRL_0=0x%08x\n", &Value);
-  CHRAMData->SDRC_RFRCTRL_0     = Value;
-  fscanf(DataFile, "MEMORY_TYPE_CS1=0x%04x\n", &Value);
-  CHRAMData->MEMORY_TYPE_CS1    = Value;
-  fscanf(DataFile, "SDRC_MCFG_1=0x%08x\n", &Value);
-  CHRAMData->SDRC_MCFG_1        = Value;
-  fscanf(DataFile, "SDRC_MR_1_LSB=0x%04x\n", &Value);
-  CHRAMData->SDRC_MR_1_LSB      = Value;
-  fscanf(DataFile, "SDRC_EMR1_1_LSB=0x%04x\n", &Value);
-  CHRAMData->SDRC_EMR1_1_LSB    = Value;
-  fscanf(DataFile, "SDRC_EMR2_1_LSB=0x%04x\n", &Value);
-  CHRAMData->SDRC_EMR2_1_LSB    = Value;
-  fscanf(DataFile, "SDRC_EMR3_1_LSB=0x%04x\n", &Value);
-  CHRAMData->SDRC_EMR3_1_LSB    = Value;
-  fscanf(DataFile, "SDRC_ACTIM_CTRLA_1=0x%08x\n", &Value);
-  CHRAMData->SDRC_ACTIM_CTRLA_1 = Value;
-  fscanf(DataFile, "SDRC_ACTIM_CTRLB_1=0x%08x\n", &Value);
-  CHRAMData->SDRC_ACTIM_CTRLB_1 = Value;
-  fscanf(DataFile, "SDRC_RFRCTRL_1=0x%08x\n", &Value);
-  CHRAMData->SDRC_RFRCTRL_1     = Value;
-
-  CHRAMData->Flags              = 0x0003;
-}
-
-static 
-void 
-PrepareConfigurationHeader (
-  void
-  )
-{
-  TOC_DATA        Toc;
-  CHSETTINGS_DATA CHSETTINGSData;
-  CHRAM_DATA      CHRAMData;
-  unsigned int    ConfigurationHdrOffset = 0;
-  FILE            *DataFile;
-  
-  // Open data file
-  DataFile = fopen(gDataFile, "rb");
-  if (DataFile == NULL) {
-    fprintf(stderr, "Can't open data file %s.\n", gDataFile);
-    exit(1);
-  }
-  
-  //Initialize configuration header.
-  memset(gConfigurationHeader, 0x00, sizeof(gConfigurationHeader));
-
-  //CHSETTINGS TOC
-  memset(&Toc, 0x00, sizeof(TOC_DATA));
-  Toc.Start = CHSETTINGS_START;
-  Toc.Size = CHSETTINGS_SIZE;
-  strcpy((char *)Toc.Filename, (const char *)"CHSETTINGS");
-  memcpy(gConfigurationHeader + ConfigurationHdrOffset, &Toc, sizeof(TOC_DATA));
-
-  //Populate CHSETTINGS Data
-  memset(&CHSETTINGSData, 0x00, sizeof(CHSETTINGS_DATA));
-  PopulateCHSETTINGSData(DataFile, &CHSETTINGSData);
-  memcpy(gConfigurationHeader + Toc.Start, &CHSETTINGSData, Toc.Size);
-
-  //Adjust ConfigurationHdrOffset to point to next TOC
-  ConfigurationHdrOffset += sizeof(TOC_DATA);
-
-  //CHRAM TOC
-  memset(&Toc, 0x00, sizeof(TOC_DATA));
-  Toc.Start = CHRAM_START;
-  Toc.Size = CHRAM_SIZE;
-  strcpy((char *)Toc.Filename, (const char *)"CHRAM");
-  memcpy(gConfigurationHeader + ConfigurationHdrOffset, &Toc, sizeof(TOC_DATA));
-
-  //Populate CHRAM Data
-  memset(&CHRAMData, 0x00, sizeof(CHRAM_DATA));
-  PopulateCHRAMData(DataFile, &CHRAMData);
-  memcpy(gConfigurationHeader + Toc.Start, &CHRAMData, Toc.Size);
-  
-  //Adjust ConfigurationHdrOffset to point to next TOC
-  ConfigurationHdrOffset += sizeof(TOC_DATA);
-
-  //Closing TOC item
-  memset(gConfigurationHeader + ConfigurationHdrOffset, 0xFF, CLOSING_TOC_ITEM_SIZE);
-  ConfigurationHdrOffset += CLOSING_TOC_ITEM_SIZE;
-  
-  // Close data file
-  fclose(DataFile);
-}
-
-static 
-void
-ConstructImage (
-  void
-  )
-{
-  FILE         *InputFile;
-  FILE         *OutputFile;
-  unsigned int InputImageFileSize;
-  struct       stat FileStat;
-  char         Ch;
-  unsigned int i;
-
-  InputFile = fopen(gInputImageFile, "rb");
-  if (InputFile == NULL) {
-    fprintf(stderr, "Can't open input file.\n");
-    exit(0);
-  } 
-
-  // Get the size of the input image.
-  fstat(fileno(InputFile), &FileStat);
-  InputImageFileSize = FileStat.st_size;
-  
-  OutputFile = fopen(gOutputImageFile, "wb");
-  if (OutputFile == NULL) {
-    fprintf(stderr, "Can't open output file %s.\n", gOutputImageFile);
-    exit(0);
-  }
-
-  // Write Configuration header 
-  fwrite(gConfigurationHeader, 1, sizeof(gConfigurationHeader), OutputFile);
-
-  // Write image header (Input image size, execution address)
-  fwrite(&InputImageFileSize, 1, 4, OutputFile);
-  fwrite(&gImageExecutionAddress, 1, 4, OutputFile);
-
-  // Copy input image to the output file.
-  for (i = 0; i < InputImageFileSize; i++) {
-    fread(&Ch, 1, 1, InputFile);
-    fwrite(&Ch, 1, 1, OutputFile);
-  }
-
-  fclose(InputFile);
-  fclose(OutputFile);
-}
-
-
-int 
-main (
-  int    argc, 
-  char** argv
-  )
-{
-  char          Ch;
-  unsigned char *ptr;
-  int           i;
-  int           TwoArg;  
-
-  if (argc == 1) {
-    PrintUsage ();
-    exit(1);
-  }
-
-  for (i=1; i < argc; i++) {
-    if (argv[i][0] == '-') {
-      // TwoArg TRUE -E 0x123, FALSE -E0x1234
-      TwoArg = (argv[i][2] != ' ');
-      switch (argv[i][1]) {
-        case 'E': /* Image execution address */
-          gImageExecutionAddress = strtoul (TwoArg ? argv[i+1] : &argv[i][2], (char **)&ptr, 16);
-          break;
-        
-        case 'I': /* Input image file */
-          gInputImageFile = TwoArg ? argv[i+1] : &argv[i][2];
-          break;
-
-        case 'O': /* Output image file */
-          gOutputImageFile = TwoArg ? argv[i+1] : &argv[i][2];
-          break;
-        
-        case 'D': /* Data file */
-          gDataFile = TwoArg ? argv[i+1] : &argv[i][2];
-          break;
-
-        default:
-          abort ();
-      }
-    }
-  }
-
-  //Prepare configuration header
-  PrepareConfigurationHeader ();
-
-  //Build image with configuration header + image header + image
-  ConstructImage ();
-
-  return 0;
-}
+/** @file\r
+ The data structures in this code come from:\r
+ OMAP35x Applications Processor Technical Reference Manual chapter 25\r
+ OMAP34xx Multimedia Device Technical Reference Manual chapter 26.4.8.\r
\r
+ You should use the OMAP35x manual when possible. Some things, like SectionKey, \r
+ are not defined in the OMAP35x manual and you have to use the OMAP34xx manual\r
+ to find the data. \r
+\r
+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <errno.h>\r
+#include <sys/types.h>\r
+#include <sys/stat.h>\r
+\r
+\r
+\r
+//TOC structure as defined by OMAP35XX TRM.\r
+typedef struct {\r
+  unsigned int  Start;\r
+  unsigned int  Size;\r
+  unsigned int  Reserved1;\r
+  unsigned int  Reserved2;\r
+  unsigned int  Reserved3;\r
+  unsigned char Filename[12];\r
+} TOC_DATA;\r
+\r
+//NOTE: OMAP3430 TRM has CHSETTINGS and CHRAM structures.\r
+typedef struct {\r
+  unsigned int   SectionKey;\r
+  unsigned char  Valid;\r
+  unsigned char  Version;\r
+  unsigned short Reserved;\r
+  unsigned int   Flags;\r
+  unsigned int   PRM_CLKSRC_CTRL; \r
+  unsigned int   PRM_CLKSEL; \r
+  unsigned int   CM_CLKSEL1_EMU;\r
+  unsigned int   CM_CLKSEL_CORE;\r
+  unsigned int   CM_CLKSEL_WKUP;\r
+  unsigned int   CM_CLKEN_PLL_DPLL3;\r
+  unsigned int   CM_AUTOIDLE_PLL_DPLL3; \r
+  unsigned int   CM_CLKSEL1_PLL; \r
+  unsigned int   CM_CLKEN_PLL_DPLL4;\r
+  unsigned int   CM_AUTOIDLE_PLL_DPLL4;\r
+  unsigned int   CM_CLKSEL2_PLL;\r
+  unsigned int   CM_CLKSEL3_PLL; \r
+  unsigned int   CM_CLKEN_PLL_MPU; \r
+  unsigned int   CM_AUTOIDLE_PLL_MPU; \r
+  unsigned int   CM_CLKSEL1_PLL_MPU; \r
+  unsigned int   CM_CLKSEL2_PLL_MPU; \r
+  unsigned int   CM_CLKSTCTRL_MPU;\r
+} CHSETTINGS_DATA;\r
+\r
+typedef struct {\r
+  unsigned int   SectionKey;\r
+  unsigned char  Valid;\r
+  unsigned char  Reserved1;\r
+  unsigned char  Reserved2;\r
+  unsigned char  Reserved3;\r
+  unsigned short SDRC_SYSCONFIG_LSB;\r
+  unsigned short SDRC_CS_CFG_LSB;\r
+  unsigned short SDRC_SHARING_LSB;\r
+  unsigned short SDRC_ERR_TYPE_LSB;\r
+  unsigned int   SDRC_DLLA_CTRL;\r
+  unsigned short Reserved4;\r
+  unsigned short Reserved5;\r
+  unsigned int   SDRC_POWER;\r
+  unsigned short MEMORY_TYPE_CS0;\r
+  unsigned short Reserved6;\r
+  unsigned int   SDRC_MCFG_0;\r
+  unsigned short SDRC_MR_0_LSB;\r
+  unsigned short SDRC_EMR1_0_LSB;\r
+  unsigned short SDRC_EMR2_0_LSB;\r
+  unsigned short SDRC_EMR3_0_LSB;\r
+  unsigned int   SDRC_ACTIM_CTRLA_0;\r
+  unsigned int   SDRC_ACTIM_CTRLB_0;\r
+  unsigned int   SDRC_RFRCTRL_0;\r
+  unsigned short MEMORY_TYPE_CS1;\r
+  unsigned short Reserved7;\r
+  unsigned int   SDRC_MCFG_1;\r
+  unsigned short SDRC_MR_1_LSB;\r
+  unsigned short SDRC_EMR1_1_LSB;\r
+  unsigned short SDRC_EMR2_1_LSB;\r
+  unsigned short SDRC_EMR3_1_LSB;\r
+  unsigned int   SDRC_ACTIM_CTRLA_1;\r
+  unsigned int   SDRC_ACTIM_CTRLB_1;\r
+  unsigned int   SDRC_RFRCTRL_1;\r
+  unsigned int   Reserved8;\r
+  unsigned short Flags;\r
+  unsigned short Reserved9;\r
+} CHRAM_DATA;\r
+\r
+#define CHSETTINGS_START      0xA0\r
+#define CHSETTINGS_SIZE       0x50\r
+#define CHRAM_START           0xF0\r
+#define CHRAM_SIZE            0x5C\r
+#define CLOSING_TOC_ITEM_SIZE 4\r
+\r
+unsigned char gConfigurationHeader[512];\r
+unsigned int  gImageExecutionAddress;\r
+char          *gInputImageFile = NULL;\r
+char          *gOutputImageFile = NULL;\r
+char          *gDataFile = NULL;\r
+\r
+static\r
+void\r
+PrintUsage (\r
+  void\r
+  )\r
+{\r
+  printf("Usage..\n");\r
+}\r
+\r
+static\r
+void\r
+PopulateCHSETTINGSData (\r
+  FILE            *DataFile,\r
+  CHSETTINGS_DATA *CHSETTINGSData\r
+  )\r
+{\r
+  unsigned int Value;\r
+  \r
+  CHSETTINGSData->SectionKey            = 0xC0C0C0C1;\r
+  CHSETTINGSData->Valid                 = 0x1;\r
+  CHSETTINGSData->Version               = 0x1;\r
+  CHSETTINGSData->Reserved              = 0x00;\r
+  CHSETTINGSData->Flags                 = 0x050001FD;\r
+\r
+  //General clock settings.\r
+  fscanf(DataFile, "PRM_CLKSRC_CTRL=0x%08x\n", &Value);\r
+  CHSETTINGSData->PRM_CLKSRC_CTRL = Value;\r
+  fscanf(DataFile, "PRM_CLKSEL=0x%08x\n", &Value);\r
+  CHSETTINGSData->PRM_CLKSEL = Value;\r
+  fscanf(DataFile, "CM_CLKSEL1_EMU=0x%08x\n", &Value);\r
+  CHSETTINGSData->CM_CLKSEL1_EMU = Value;\r
+\r
+  //Clock configuration\r
+  fscanf(DataFile, "CM_CLKSEL_CORE=0x%08x\n", &Value);\r
+  CHSETTINGSData->CM_CLKSEL_CORE = Value;\r
+  fscanf(DataFile, "CM_CLKSEL_WKUP=0x%08x\n", &Value);\r
+  CHSETTINGSData->CM_CLKSEL_WKUP = Value;\r
+\r
+  //DPLL3 (Core) settings\r
+  fscanf(DataFile, "CM_CLKEN_PLL_DPLL3=0x%08x\n", &Value);\r
+  CHSETTINGSData->CM_CLKEN_PLL_DPLL3 = Value;\r
+  fscanf(DataFile, "CM_AUTOIDLE_PLL_DPLL3=0x%08x\n", &Value);\r
+  CHSETTINGSData->CM_AUTOIDLE_PLL_DPLL3 = Value;\r
+  fscanf(DataFile, "CM_CLKSEL1_PLL=0x%08x\n", &Value);\r
+  CHSETTINGSData->CM_CLKSEL1_PLL = Value;\r
+\r
+  //DPLL4 (Peripheral) settings\r
+  fscanf(DataFile, "CM_CLKEN_PLL_DPLL4=0x%08x\n", &Value);\r
+  CHSETTINGSData->CM_CLKEN_PLL_DPLL4 = Value;\r
+  fscanf(DataFile, "CM_AUTOIDLE_PLL_DPLL4=0x%08x\n", &Value);\r
+  CHSETTINGSData->CM_AUTOIDLE_PLL_DPLL4 = Value;\r
+  fscanf(DataFile, "CM_CLKSEL2_PLL=0x%08x\n", &Value);\r
+  CHSETTINGSData->CM_CLKSEL2_PLL = Value;\r
+  fscanf(DataFile, "CM_CLKSEL3_PLL=0x%08x\n", &Value);\r
+  CHSETTINGSData->CM_CLKSEL3_PLL = Value;\r
+\r
+  //DPLL1 (MPU) settings\r
+  fscanf(DataFile, "CM_CLKEN_PLL_MPU=0x%08x\n", &Value);\r
+  CHSETTINGSData->CM_CLKEN_PLL_MPU = Value;\r
+  fscanf(DataFile, "CM_AUTOIDLE_PLL_MPU=0x%08x\n", &Value);\r
+  CHSETTINGSData->CM_AUTOIDLE_PLL_MPU = Value;\r
+  fscanf(DataFile, "CM_CLKSEL1_PLL_MPU=0x%08x\n", &Value);\r
+  CHSETTINGSData->CM_CLKSEL1_PLL_MPU = Value;\r
+  fscanf(DataFile, "CM_CLKSEL2_PLL_MPU=0x%08x\n", &Value);\r
+  CHSETTINGSData->CM_CLKSEL2_PLL_MPU = Value;\r
+  fscanf(DataFile, "CM_CLKSTCTRL_MPU=0x%08x\n", &Value);\r
+  CHSETTINGSData->CM_CLKSTCTRL_MPU = Value;\r
+}\r
+\r
+static\r
+void\r
+PopulateCHRAMData (\r
+  FILE       *DataFile,\r
+  CHRAM_DATA *CHRAMData\r
+  )\r
+{\r
+  unsigned int Value;\r
+  \r
+  CHRAMData->SectionKey         = 0xC0C0C0C2;\r
+  CHRAMData->Valid              = 0x1;\r
+  \r
+  fscanf(DataFile, "SDRC_SYSCONFIG_LSB=0x%04x\n", &Value);\r
+  CHRAMData->SDRC_SYSCONFIG_LSB = Value;\r
+  fscanf(DataFile, "SDRC_CS_CFG_LSB=0x%04x\n", &Value);\r
+  CHRAMData->SDRC_CS_CFG_LSB    = Value;\r
+  fscanf(DataFile, "SDRC_SHARING_LSB=0x%04x\n", &Value);\r
+  CHRAMData->SDRC_SHARING_LSB   = Value;\r
+  fscanf(DataFile, "SDRC_ERR_TYPE_LSB=0x%04x\n", &Value);\r
+  CHRAMData->SDRC_ERR_TYPE_LSB  = Value;\r
+  fscanf(DataFile, "SDRC_DLLA_CTRL=0x%08x\n", &Value);\r
+  CHRAMData->SDRC_DLLA_CTRL     = Value;\r
+  fscanf(DataFile, "SDRC_POWER=0x%08x\n", &Value);\r
+  CHRAMData->SDRC_POWER         = Value;\r
+  fscanf(DataFile, "MEMORY_TYPE_CS0=0x%04x\n", &Value);\r
+  CHRAMData->MEMORY_TYPE_CS0    = Value;\r
+  fscanf(DataFile, "SDRC_MCFG_0=0x%08x\n", &Value);\r
+  CHRAMData->SDRC_MCFG_0        = Value;\r
+  fscanf(DataFile, "SDRC_MR_0_LSB=0x%04x\n", &Value);\r
+  CHRAMData->SDRC_MR_0_LSB      = Value;\r
+  fscanf(DataFile, "SDRC_EMR1_0_LSB=0x%04x\n", &Value);\r
+  CHRAMData->SDRC_EMR1_0_LSB    = Value;\r
+  fscanf(DataFile, "SDRC_EMR2_0_LSB=0x%04x\n", &Value);\r
+  CHRAMData->SDRC_EMR2_0_LSB    = Value;\r
+  fscanf(DataFile, "SDRC_EMR3_0_LSB=0x%04x\n", &Value);\r
+  CHRAMData->SDRC_EMR3_0_LSB    = Value;\r
+  fscanf(DataFile, "SDRC_ACTIM_CTRLA_0=0x%08x\n", &Value);\r
+  CHRAMData->SDRC_ACTIM_CTRLA_0 = Value;\r
+  fscanf(DataFile, "SDRC_ACTIM_CTRLB_0=0x%08x\n", &Value);\r
+  CHRAMData->SDRC_ACTIM_CTRLB_0 = Value;\r
+  fscanf(DataFile, "SDRC_RFRCTRL_0=0x%08x\n", &Value);\r
+  CHRAMData->SDRC_RFRCTRL_0     = Value;\r
+  fscanf(DataFile, "MEMORY_TYPE_CS1=0x%04x\n", &Value);\r
+  CHRAMData->MEMORY_TYPE_CS1    = Value;\r
+  fscanf(DataFile, "SDRC_MCFG_1=0x%08x\n", &Value);\r
+  CHRAMData->SDRC_MCFG_1        = Value;\r
+  fscanf(DataFile, "SDRC_MR_1_LSB=0x%04x\n", &Value);\r
+  CHRAMData->SDRC_MR_1_LSB      = Value;\r
+  fscanf(DataFile, "SDRC_EMR1_1_LSB=0x%04x\n", &Value);\r
+  CHRAMData->SDRC_EMR1_1_LSB    = Value;\r
+  fscanf(DataFile, "SDRC_EMR2_1_LSB=0x%04x\n", &Value);\r
+  CHRAMData->SDRC_EMR2_1_LSB    = Value;\r
+  fscanf(DataFile, "SDRC_EMR3_1_LSB=0x%04x\n", &Value);\r
+  CHRAMData->SDRC_EMR3_1_LSB    = Value;\r
+  fscanf(DataFile, "SDRC_ACTIM_CTRLA_1=0x%08x\n", &Value);\r
+  CHRAMData->SDRC_ACTIM_CTRLA_1 = Value;\r
+  fscanf(DataFile, "SDRC_ACTIM_CTRLB_1=0x%08x\n", &Value);\r
+  CHRAMData->SDRC_ACTIM_CTRLB_1 = Value;\r
+  fscanf(DataFile, "SDRC_RFRCTRL_1=0x%08x\n", &Value);\r
+  CHRAMData->SDRC_RFRCTRL_1     = Value;\r
+\r
+  CHRAMData->Flags              = 0x0003;\r
+}\r
+\r
+static \r
+void \r
+PrepareConfigurationHeader (\r
+  void\r
+  )\r
+{\r
+  TOC_DATA        Toc;\r
+  CHSETTINGS_DATA CHSETTINGSData;\r
+  CHRAM_DATA      CHRAMData;\r
+  unsigned int    ConfigurationHdrOffset = 0;\r
+  FILE            *DataFile;\r
+  \r
+  // Open data file\r
+  DataFile = fopen(gDataFile, "rb");\r
+  if (DataFile == NULL) {\r
+    fprintf(stderr, "Can't open data file %s.\n", gDataFile);\r
+    exit(1);\r
+  }\r
+  \r
+  //Initialize configuration header.\r
+  memset(gConfigurationHeader, 0x00, sizeof(gConfigurationHeader));\r
+\r
+  //CHSETTINGS TOC\r
+  memset(&Toc, 0x00, sizeof(TOC_DATA));\r
+  Toc.Start = CHSETTINGS_START;\r
+  Toc.Size = CHSETTINGS_SIZE;\r
+  strcpy((char *)Toc.Filename, (const char *)"CHSETTINGS");\r
+  memcpy(gConfigurationHeader + ConfigurationHdrOffset, &Toc, sizeof(TOC_DATA));\r
+\r
+  //Populate CHSETTINGS Data\r
+  memset(&CHSETTINGSData, 0x00, sizeof(CHSETTINGS_DATA));\r
+  PopulateCHSETTINGSData(DataFile, &CHSETTINGSData);\r
+  memcpy(gConfigurationHeader + Toc.Start, &CHSETTINGSData, Toc.Size);\r
+\r
+  //Adjust ConfigurationHdrOffset to point to next TOC\r
+  ConfigurationHdrOffset += sizeof(TOC_DATA);\r
+\r
+  //CHRAM TOC\r
+  memset(&Toc, 0x00, sizeof(TOC_DATA));\r
+  Toc.Start = CHRAM_START;\r
+  Toc.Size = CHRAM_SIZE;\r
+  strcpy((char *)Toc.Filename, (const char *)"CHRAM");\r
+  memcpy(gConfigurationHeader + ConfigurationHdrOffset, &Toc, sizeof(TOC_DATA));\r
+\r
+  //Populate CHRAM Data\r
+  memset(&CHRAMData, 0x00, sizeof(CHRAM_DATA));\r
+  PopulateCHRAMData(DataFile, &CHRAMData);\r
+  memcpy(gConfigurationHeader + Toc.Start, &CHRAMData, Toc.Size);\r
+  \r
+  //Adjust ConfigurationHdrOffset to point to next TOC\r
+  ConfigurationHdrOffset += sizeof(TOC_DATA);\r
+\r
+  //Closing TOC item\r
+  memset(gConfigurationHeader + ConfigurationHdrOffset, 0xFF, CLOSING_TOC_ITEM_SIZE);\r
+  ConfigurationHdrOffset += CLOSING_TOC_ITEM_SIZE;\r
+  \r
+  // Close data file\r
+  fclose(DataFile);\r
+}\r
+\r
+static \r
+void\r
+ConstructImage (\r
+  void\r
+  )\r
+{\r
+  FILE         *InputFile;\r
+  FILE         *OutputFile;\r
+  unsigned int InputImageFileSize;\r
+  struct       stat FileStat;\r
+  char         Ch;\r
+  unsigned int i;\r
+\r
+  InputFile = fopen(gInputImageFile, "rb");\r
+  if (InputFile == NULL) {\r
+    fprintf(stderr, "Can't open input file.\n");\r
+    exit(0);\r
+  } \r
+\r
+  // Get the size of the input image.\r
+  fstat(fileno(InputFile), &FileStat);\r
+  InputImageFileSize = FileStat.st_size;\r
+  \r
+  OutputFile = fopen(gOutputImageFile, "wb");\r
+  if (OutputFile == NULL) {\r
+    fprintf(stderr, "Can't open output file %s.\n", gOutputImageFile);\r
+    exit(0);\r
+  }\r
+\r
+  // Write Configuration header \r
+  fwrite(gConfigurationHeader, 1, sizeof(gConfigurationHeader), OutputFile);\r
+\r
+  // Write image header (Input image size, execution address)\r
+  fwrite(&InputImageFileSize, 1, 4, OutputFile);\r
+  fwrite(&gImageExecutionAddress, 1, 4, OutputFile);\r
+\r
+  // Copy input image to the output file.\r
+  for (i = 0; i < InputImageFileSize; i++) {\r
+    fread(&Ch, 1, 1, InputFile);\r
+    fwrite(&Ch, 1, 1, OutputFile);\r
+  }\r
+\r
+  fclose(InputFile);\r
+  fclose(OutputFile);\r
+}\r
+\r
+\r
+int \r
+main (\r
+  int    argc, \r
+  char** argv\r
+  )\r
+{\r
+  char          Ch;\r
+  unsigned char *ptr;\r
+  int           i;\r
+  int           TwoArg;  \r
+\r
+  if (argc == 1) {\r
+    PrintUsage ();\r
+    exit(1);\r
+  }\r
+\r
+  for (i=1; i < argc; i++) {\r
+    if (argv[i][0] == '-') {\r
+      // TwoArg TRUE -E 0x123, FALSE -E0x1234\r
+      TwoArg = (argv[i][2] != ' ');\r
+      switch (argv[i][1]) {\r
+        case 'E': /* Image execution address */\r
+          gImageExecutionAddress = strtoul (TwoArg ? argv[i+1] : &argv[i][2], (char **)&ptr, 16);\r
+          break;\r
+        \r
+        case 'I': /* Input image file */\r
+          gInputImageFile = TwoArg ? argv[i+1] : &argv[i][2];\r
+          break;\r
+\r
+        case 'O': /* Output image file */\r
+          gOutputImageFile = TwoArg ? argv[i+1] : &argv[i][2];\r
+          break;\r
+        \r
+        case 'D': /* Data file */\r
+          gDataFile = TwoArg ? argv[i+1] : &argv[i][2];\r
+          break;\r
+\r
+        default:\r
+          abort ();\r
+      }\r
+    }\r
+  }\r
+\r
\r
+  //Prepare configuration header\r
+  PrepareConfigurationHeader ();\r
+\r
+  //Build image with configuration header + image header + image\r
+  ConstructImage ();\r
+\r
+  return 0;\r
+}\r
index 03b4ba29fb4b1727d9c1af06a0ad4412aaf02e10..44c44fb0fc33526f58722f5a50194cbc3af66127 100644 (file)
-/** @file
-  Include file for basic command line parser for EBL (Embedded Boot Loader)
-
-  Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
-  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __EBL_H__
-#define __EBL_H__
-
-#include <PiDxe.h>
-#include <Protocol/BlockIo.h>             
-#include <Protocol/SimpleFileSystem.h>      
-#include <Protocol/FirmwareVolume2.h>        
-#include <Protocol/LoadFile.h>              
-#include <Protocol/FirmwareVolumeBlock.h> 
-#include <Protocol/PxeBaseCode.h> 
-#include <Protocol/LoadedImage.h> 
-#include <Protocol/EblAddCommand.h>
-#include <Protocol/PciIo.h>
-#include <Protocol/DevicePath.h>
-
-#include <Guid/FileInfo.h>
-#include <Guid/DxeServices.h>
-#include <Guid/MemoryTypeInformation.h>
-#include <Guid/MemoryAllocationHob.h>
-#include <Library/BaseLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/DevicePathLib.h>
-#include <Library/PrintLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/UefiLib.h>   
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/DebugLib.h>
-#include <Library/EfiFileLib.h>
-#include <Library/HobLib.h>
-#include <Library/DebugLib.h>
-#include <Library/IoLib.h>
-#include <Library/PcdLib.h>
-#include <Library/EblCmdLib.h>
-#include <Library/DevicePathLib.h>
-#include <Library/UefiLib.h>
-#include <Library/EblNetworkLib.h>
-#include <Library/TimerLib.h>
-
-#include <IndustryStandard/Pci.h>
-
-//
-// Prompt for the command line
-//
-#define CMD_SEPARATOR             ';'
-#define EBL_MAX_COMMAND_COUNT     0x100
-#define MAX_CMD_HISTORY           16
-#define MAX_CMD_LINE              256
-#define MAX_ARGS                  32
-
-#define EBL_CR                    0x0a
-#define EBL_LF                    0x0d
-
-#define EFI_SET_TIMER_TO_SECOND   10000000
-
-
-
-EBL_COMMAND_TABLE *
-EblGetCommand (
-  IN CHAR8                        *CommandName
-  );
-
-
-EFI_STATUS
-EblPathToDevice (
-  IN  CHAR8                       *Path,
-  OUT EFI_HANDLE                  *DeviceHandle,
-  OUT EFI_DEVICE_PATH_PROTOCOL    **PathDevicePath,
-  OUT VOID                        **Buffer,
-  OUT UINTN                       *BufferSize
-  );
-
-BOOLEAN
-EblAnyKeyToContinueQtoQuit (
-  IN  UINTN                       *CurrentRow,
-  IN  BOOLEAN                     PrefixNewline
-  );
-
-VOID
-EblUpdateDeviceLists (
-  VOID
-  );
-
-VOID
-EblInitializeCmdTable (
-  VOID
-  );
-
-VOID
-EblShutdownExternalCmdTable (
-  VOID
-  );
-
-VOID
-EblSetTextColor (
-  UINTN                           Attribute
-  );
-
-
-EFI_STATUS
-EblGetCharKey (
-  IN OUT EFI_INPUT_KEY            *Key,
-  IN     UINTN                    TimoutInSec,
-  IN     EBL_GET_CHAR_CALL_BACK   CallBack   OPTIONAL
-  );
-
-// BugBug: Move me to a library
-INTN
-EFIAPI
-AsciiStrniCmp (
-  IN      CONST CHAR8             *FirstString,
-  IN      CONST CHAR8             *SecondString,
-  IN      UINTN                   Length
-  );
-
-
-VOID
-EblInitializeDeviceCmd (
-  VOID
-  );
-
-VOID
-EblInitializemdHwDebugCmds (
-  VOID
-  );
-
-VOID
-EblInitializeDirCmd (
-  VOID
-  );
-
-VOID
-EblInitializeHobCmd (
-  VOID
-  );
-
-VOID
-EblInitializemdHwIoDebugCmds (
-  VOID
-  );
-
-VOID
-EblInitializeScriptCmd (
-  VOID
-  );
-
-VOID
-EblInitializeNetworkCmd (
-  VOID
-  );
-
-VOID
-EblInitializeVariableCmds (
-  VOID
-  );
-
-CHAR8 *
-ParseArguments (
-  IN  CHAR8                       *CmdLine,
-  OUT UINTN                       *Argc,
-  OUT CHAR8                       **Argv
-  );
-
-EFI_STATUS
-ProcessCmdLine (
-  IN CHAR8                        *CmdLine,
-  IN UINTN                        MaxCmdLineSize
-  );
-
-EFI_STATUS
-OutputData (
-  IN UINT8                        *Address,
-  IN UINTN                        Length,
-  IN UINTN                         Width,
-  IN UINTN                        Offset
-  );
-  
-UINTN
-WidthFromCommandName (
-  IN CHAR8                        *Argv,
-  IN UINTN                        Default
-  );
-
-
-extern UINTN                      gScreenColumns;
-extern UINTN                      gScreenRows;
-extern BOOLEAN                    gPageBreak;
-extern CHAR8                      *gMemMapType[];
-
-#endif
-
+/** @file\r
+  Include file for basic command line parser for EBL (Embedded Boot Loader)\r
+\r
+  Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
+  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __EBL_H__\r
+#define __EBL_H__\r
+\r
+#include <PiDxe.h>\r
+#include <Protocol/BlockIo.h>             \r
+#include <Protocol/SimpleFileSystem.h>      \r
+#include <Protocol/FirmwareVolume2.h>        \r
+#include <Protocol/LoadFile.h>              \r
+#include <Protocol/FirmwareVolumeBlock.h> \r
+#include <Protocol/PxeBaseCode.h> \r
+#include <Protocol/LoadedImage.h> \r
+#include <Protocol/EblAddCommand.h>\r
+#include <Protocol/PciIo.h>\r
+#include <Protocol/DevicePath.h>\r
+\r
+#include <Guid/FileInfo.h>\r
+#include <Guid/DxeServices.h>\r
+#include <Guid/MemoryTypeInformation.h>\r
+#include <Guid/MemoryAllocationHob.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiLib.h>   \r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/EfiFileLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/EblCmdLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/EblNetworkLib.h>\r
+#include <Library/TimerLib.h>\r
+\r
+#include <IndustryStandard/Pci.h>\r
+\r
+//\r
+// Prompt for the command line\r
+//\r
+#define CMD_SEPARATOR             ';'\r
+#define EBL_MAX_COMMAND_COUNT     0x100\r
+#define MAX_CMD_HISTORY           16\r
+#define MAX_CMD_LINE              256\r
+#define MAX_ARGS                  32\r
+\r
+#define EBL_CR                    0x0a\r
+#define EBL_LF                    0x0d\r
+\r
+#define EFI_SET_TIMER_TO_SECOND   10000000\r
+\r
+\r
+\r
+EBL_COMMAND_TABLE *\r
+EblGetCommand (\r
+  IN CHAR8                        *CommandName\r
+  );\r
+\r
+\r
+EFI_STATUS\r
+EblPathToDevice (\r
+  IN  CHAR8                       *Path,\r
+  OUT EFI_HANDLE                  *DeviceHandle,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL    **PathDevicePath,\r
+  OUT VOID                        **Buffer,\r
+  OUT UINTN                       *BufferSize\r
+  );\r
+\r
+BOOLEAN\r
+EblAnyKeyToContinueQtoQuit (\r
+  IN  UINTN                       *CurrentRow,\r
+  IN  BOOLEAN                     PrefixNewline\r
+  );\r
+\r
+VOID\r
+EblUpdateDeviceLists (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EblInitializeCmdTable (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EblShutdownExternalCmdTable (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EblSetTextColor (\r
+  UINTN                           Attribute\r
+  );\r
+\r
+\r
+EFI_STATUS\r
+EblGetCharKey (\r
+  IN OUT EFI_INPUT_KEY            *Key,\r
+  IN     UINTN                    TimoutInSec,\r
+  IN     EBL_GET_CHAR_CALL_BACK   CallBack   OPTIONAL\r
+  );\r
+\r
+// BugBug: Move me to a library\r
+INTN\r
+EFIAPI\r
+AsciiStrniCmp (\r
+  IN      CONST CHAR8             *FirstString,\r
+  IN      CONST CHAR8             *SecondString,\r
+  IN      UINTN                   Length\r
+  );\r
+\r
+\r
+VOID\r
+EblInitializeDeviceCmd (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EblInitializemdHwDebugCmds (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EblInitializeDirCmd (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EblInitializeHobCmd (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EblInitializemdHwIoDebugCmds (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EblInitializeScriptCmd (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EblInitializeNetworkCmd (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EblInitializeVariableCmds (\r
+  VOID\r
+  );\r
+\r
+CHAR8 *\r
+ParseArguments (\r
+  IN  CHAR8                       *CmdLine,\r
+  OUT UINTN                       *Argc,\r
+  OUT CHAR8                       **Argv\r
+  );\r
+\r
+EFI_STATUS\r
+ProcessCmdLine (\r
+  IN CHAR8                        *CmdLine,\r
+  IN UINTN                        MaxCmdLineSize\r
+  );\r
+\r
+EFI_STATUS\r
+OutputData (\r
+  IN UINT8                        *Address,\r
+  IN UINTN                        Length,\r
+  IN UINTN                         Width,\r
+  IN UINTN                        Offset\r
+  );\r
+  \r
+UINTN\r
+WidthFromCommandName (\r
+  IN CHAR8                        *Argv,\r
+  IN UINTN                        Default\r
+  );\r
+\r
+\r
+extern UINTN                      gScreenColumns;\r
+extern UINTN                      gScreenRows;\r
+extern BOOLEAN                    gPageBreak;\r
+extern CHAR8                      *gMemMapType[];\r
+\r
+#endif\r
+\r
index 8862f3d1ec913ff126cd329aafd9427ea576e81e..e1a4c225e61541b4836bfb90d1cb14695b8a95d6 100644 (file)
-#/** @file
-# Embedded Package
-#
-#
-# Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
-#
-#    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                  = Embedded
-  PLATFORM_GUID                  = 8DBB580B-CF89-4D57-95C6-DFE96C44686E
-  PLATFORM_VERSION               = 0.1
-  DSC_SPECIFICATION              = 0x00010005
-  OUTPUT_DIRECTORY               = Build/Embedded
-  SUPPORTED_ARCHITECTURES        = IA32|X64|IPF|ARM
-  BUILD_TARGETS                  = DEBUG|RELEASE
-  SKUID_IDENTIFIER               = DEFAULT
-  FLASH_DEFINITION               = EmbeddedPkg/EmbeddedPkg.fdf
-
-
-################################################################################
-#
-# SKU Identification section - list of all SKU IDs supported by this
-#                              Platform.
-#
-################################################################################
-[SkuIds]
-  0|DEFAULT              # The entry: 0|DEFAULT is reserved and always required.
-
-################################################################################
-#
-# Library Class section - list of all Library Classes needed by this Platform.
-#
-################################################################################
-[LibraryClasses.common]
-#  DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
-  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
-
-  
-  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
-  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
-  PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf
-  PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf
-  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
-  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf
-  EfiFileLib|EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf
-  
-  TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
-  
-  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
-  
-  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
-  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
-  PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf
-  CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf
-  PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf
-  
-  SerialPortLib|EmbeddedPkg/Library/TemplateSerialPortLib/TemplateSerialPortLib.inf
-  RealTimeClockLib|EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf
-  EfiResetSystemLib|EmbeddedPkg/Library/TemplateResetSystemLib/TemplateResetSystemLib.inf
-  GdbSerialLib|EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.inf
-
-
- #
- # Need to change this for IPF
- #
-  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
-  
-  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
-  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
-  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
-  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
-  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
-  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
-  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
-
-  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
-  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
-  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
-
-
-  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
-  EblCmdLib|EmbeddedPkg/Library/EblCmdLibNull/EblCmdLibNull.inf
-  
-  EblNetworkLib|EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.inf
-  
-
-[LibraryClasses.common.DXE_DRIVER]
-  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
-  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
-
-
-[LibraryClasses.common.UEFI_APPLICATION]
-  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
-  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
-
-[LibraryClasses.common.UEFI_DRIVER]
-  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
-  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
-  
-[LibraryClasses.common.SEC]
-  ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf
-
-[LibraryClasses.ARM]
-  SemihostLib|ArmPkg/Library/SemihostLib/SemihostLib.inf
-
-[LibraryClasses.ARM]
-  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
-
-
-################################################################################
-#
-# Pcd Section - list of all PCD Entries defined by this Platform
-#
-################################################################################
-
-[PcdsFeatureFlag.common]
-  gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|FALSE
-  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable|FALSE
-  gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable|FALSE
-  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable|FALSE
-  
-  #
-  # Control what commands are supported from the UI
-  # Turn these on and off to add features or save size
-  #  
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedMacBoot|TRUE
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedDirCmd|TRUE
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedHobCmd|TRUE
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedHwDebugCmd|TRUE
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedIoEnable|FALSE
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedScriptCmd|FALSE
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedPciDebugCmd|TRUE
-  
-  gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob|FALSE
-
-
-[PcdsFixedAtBuild.common]
-  gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000
-  gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|1000000
-  gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000
-  gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000
-  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x0f
-  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000000
-  gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x06
-  gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue|0xAF
-  gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|0
-  gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0
-  gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xE0000000
-  gEfiMdePkgTokenSpaceGuid.PcdFSBClock|200000000
-  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320
-  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000000
-  gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xE0000000
-  gEfiMdePkgTokenSpaceGuid.PcdFSBClock|200000000
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedAutomaticBootCommand|L""|VOID*|2
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedDefaultTextColor|0x07
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedMemVariableStoreSize|0x10000
-  
-  gEmbeddedTokenSpaceGuid.PcdPrePiHobBase|0
-  gEmbeddedTokenSpaceGuid.PcdPrePiStackBase|0
-  gEmbeddedTokenSpaceGuid.PcdPrePiStackSize|0
-
-#
-# Optinal feature to help prevent EFI memory map fragments
-# Turned on and off via: PcdPrePiProduceMemoryTypeInformationHob
-# Values are in EFI Pages (4K). DXE Core will make sure that 
-# at least this much of each type of memory can be allocated 
-# from a single memory range. This way you only end up with
-# maximum of two fragements for each type in the memory map
-# (the memory used, and the free memory that was prereserved
-# but not used).
-#
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory|0
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS|0
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType|0
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData|0
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode|0
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode|0
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData|0
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode|0
-  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData|0
-
-#
-# Timer config for this platform
-#
-  gEmbeddedTokenSpaceGuid.PcdTimerBaseAddress|0x3c700000
-  gEmbeddedTokenSpaceGuid.PcdTimerVector|7
-  gEmbeddedTokenSpaceGuid.PcdTimerPeriod|100000
-
-
-[PcdsFixedAtBuild.ARM]
-  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize|32
-  gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|0
-
-[PcdsFixedAtBuild.IA32]
-  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize|36
-  gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|16
-
-[PcdsFixedAtBuild.X64]
-  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize|52
-  gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|16
-
-
-
-[PcdsFixedAtBuild.IPF]
-  gEfiMdePkgTokenSpaceGuid.PcdIoBlockBaseAddressForIpf|0x0ffffc000000
-
-#
-# This makes it so you can source level debug with NT32. VC++ debugger limitiation!
-#
-#[BuildOptions]
-#  DEBUG_*_IA32_DLINK_FLAGS = /EXPORT:InitializeDriver=$(IMAGE_ENTRY_POINT) /ALIGN:4096 /SUBSYSTEM:CONSOLE
-#  RELEASE_*_IA32_DLINK_FLAGS = /ALIGN:4096
-#  *_*_IA32_CC_FLAGS = /D EFI_SPECIFICATION_VERSION=0x0002000A /D TIANO_RELEASE_VERSION=0x00080006
-
-
-################################################################################
-#
-# Components Section - list of all Modules needed by this Platform
-#
-################################################################################
-[Components.common]
-  EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.inf 
-  EmbeddedPkg/Library/EblCmdLibNull/EblCmdLibNull.inf
-  EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf
-  EmbeddedPkg/Library/GdbSerialDebugPortLib/GdbSerialDebugPortLib.inf  
-  EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.inf                    
-  EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf
-  EmbeddedPkg/Library/PrePiLib/PrePiLib.inf
-  EmbeddedPkg/Library/TemplateSerialPortLib/TemplateSerialPortLib.inf
-  EmbeddedPkg/Library/TemplateResetSystemLib/TemplateResetSystemLib.inf
-  EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf
-  EmbeddedPkg/Library/LzmaHobCustomDecompressLib/LzmaHobCustomDecompressLib.inf
-  EmbeddedPkg/Library/NullDmaLib/NullDmaLib.inf
-
-  EmbeddedPkg/Ebl/Ebl.inf
-####  EmbeddedPkg/EblExternCmd/EblExternCmd.inf
-  EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf
-  EmbeddedPkg/GdbStub/GdbStub.inf
-  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
-  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf
-  EmbeddedPkg/SerialDxe/SerialDxe.inf
-  EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf
-  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
-
-  EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf
-  
-  
-
+#/** @file\r
+# Embedded Package\r
+#\r
+#\r
+# Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#    This program and the accompanying materials\r
+#    are licensed and made available under the terms and conditions of the BSD License\r
+#    which accompanies this distribution. The full text of the license may be found at\r
+#    http://opensource.org/licenses/bsd-license.php\r
+#\r
+#    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  PLATFORM_NAME                  = Embedded\r
+  PLATFORM_GUID                  = 8DBB580B-CF89-4D57-95C6-DFE96C44686E\r
+  PLATFORM_VERSION               = 0.1\r
+  DSC_SPECIFICATION              = 0x00010005\r
+  OUTPUT_DIRECTORY               = Build/Embedded\r
+  SUPPORTED_ARCHITECTURES        = IA32|X64|IPF|ARM\r
+  BUILD_TARGETS                  = DEBUG|RELEASE\r
+  SKUID_IDENTIFIER               = DEFAULT\r
+  FLASH_DEFINITION               = EmbeddedPkg/EmbeddedPkg.fdf\r
+\r
+\r
+################################################################################\r
+#\r
+# SKU Identification section - list of all SKU IDs supported by this\r
+#                              Platform.\r
+#\r
+################################################################################\r
+[SkuIds]\r
+  0|DEFAULT              # The entry: 0|DEFAULT is reserved and always required.\r
+\r
+################################################################################\r
+#\r
+# Library Class section - list of all Library Classes needed by this Platform.\r
+#\r
+################################################################################\r
+[LibraryClasses.common]\r
+#  DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf\r
+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
+\r
+  \r
+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf\r
+  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf\r
+  PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf\r
+  PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf\r
+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf\r
+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf\r
+  EfiFileLib|EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf\r
+  \r
+  TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf\r
+  \r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
+  \r
+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf\r
+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf\r
+  PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf\r
+  CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf\r
+  PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf\r
+  \r
+  SerialPortLib|EmbeddedPkg/Library/TemplateSerialPortLib/TemplateSerialPortLib.inf\r
+  RealTimeClockLib|EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf\r
+  EfiResetSystemLib|EmbeddedPkg/Library/TemplateResetSystemLib/TemplateResetSystemLib.inf\r
+  GdbSerialLib|EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.inf\r
+\r
+\r
+ #\r
+ # Need to change this for IPF\r
+ #\r
+  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf\r
+  \r
+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
+  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf\r
+\r
+  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
+  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf\r
+  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf\r
+\r
+\r
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  EblCmdLib|EmbeddedPkg/Library/EblCmdLibNull/EblCmdLibNull.inf\r
+  \r
+  EblNetworkLib|EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.inf\r
+  \r
+\r
+[LibraryClasses.common.DXE_DRIVER]\r
+  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+\r
+\r
+[LibraryClasses.common.UEFI_APPLICATION]\r
+  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+\r
+[LibraryClasses.common.UEFI_DRIVER]\r
+  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+  \r
+[LibraryClasses.common.SEC]\r
+  ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf\r
+\r
+[LibraryClasses.ARM]\r
+  SemihostLib|ArmPkg/Library/SemihostLib/SemihostLib.inf\r
+\r
+[LibraryClasses.ARM]\r
+  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf\r
+\r
+\r
+################################################################################\r
+#\r
+# Pcd Section - list of all PCD Entries defined by this Platform\r
+#\r
+################################################################################\r
+\r
+[PcdsFeatureFlag.common]\r
+  gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|FALSE\r
+  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable|FALSE\r
+  gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable|FALSE\r
+  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable|FALSE\r
+  \r
+  #\r
+  # Control what commands are supported from the UI\r
+  # Turn these on and off to add features or save size\r
+  #  \r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedMacBoot|TRUE\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedDirCmd|TRUE\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedHobCmd|TRUE\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedHwDebugCmd|TRUE\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedIoEnable|FALSE\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedScriptCmd|FALSE\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPciDebugCmd|TRUE\r
+  \r
+  gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob|FALSE\r
+\r
+\r
+[PcdsFixedAtBuild.common]\r
+  gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|1000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x0f\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x06\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue|0xAF\r
+  gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|0\r
+  gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0\r
+  gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xE0000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdFSBClock|200000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xE0000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdFSBClock|200000000\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedAutomaticBootCommand|L""|VOID*|2\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedDefaultTextColor|0x07\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedMemVariableStoreSize|0x10000\r
+  \r
+  gEmbeddedTokenSpaceGuid.PcdPrePiHobBase|0\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiStackBase|0\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiStackSize|0\r
+\r
+#\r
+# Optinal feature to help prevent EFI memory map fragments\r
+# Turned on and off via: PcdPrePiProduceMemoryTypeInformationHob\r
+# Values are in EFI Pages (4K). DXE Core will make sure that \r
+# at least this much of each type of memory can be allocated \r
+# from a single memory range. This way you only end up with\r
+# maximum of two fragements for each type in the memory map\r
+# (the memory used, and the free memory that was prereserved\r
+# but not used).\r
+#\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory|0\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS|0\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType|0\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData|0\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode|0\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode|0\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData|0\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode|0\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData|0\r
+\r
+#\r
+# Timer config for this platform\r
+#\r
+  gEmbeddedTokenSpaceGuid.PcdTimerBaseAddress|0x3c700000\r
+  gEmbeddedTokenSpaceGuid.PcdTimerVector|7\r
+  gEmbeddedTokenSpaceGuid.PcdTimerPeriod|100000\r
+\r
+\r
+[PcdsFixedAtBuild.ARM]\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize|32\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|0\r
+\r
+[PcdsFixedAtBuild.IA32]\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize|36\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|16\r
+\r
+[PcdsFixedAtBuild.X64]\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize|52\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|16\r
+\r
+\r
+\r
+[PcdsFixedAtBuild.IPF]\r
+  gEfiMdePkgTokenSpaceGuid.PcdIoBlockBaseAddressForIpf|0x0ffffc000000\r
+\r
+#\r
+# This makes it so you can source level debug with NT32. VC++ debugger limitiation!\r
+#\r
+#[BuildOptions]\r
+#  DEBUG_*_IA32_DLINK_FLAGS = /EXPORT:InitializeDriver=$(IMAGE_ENTRY_POINT) /ALIGN:4096 /SUBSYSTEM:CONSOLE\r
+#  RELEASE_*_IA32_DLINK_FLAGS = /ALIGN:4096\r
+#  *_*_IA32_CC_FLAGS = /D EFI_SPECIFICATION_VERSION=0x0002000A /D TIANO_RELEASE_VERSION=0x00080006\r
+\r
+\r
+################################################################################\r
+#\r
+# Components Section - list of all Modules needed by this Platform\r
+#\r
+################################################################################\r
+[Components.common]\r
+  EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.inf \r
+  EmbeddedPkg/Library/EblCmdLibNull/EblCmdLibNull.inf\r
+  EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf\r
+  EmbeddedPkg/Library/GdbSerialDebugPortLib/GdbSerialDebugPortLib.inf  \r
+  EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.inf                    \r
+  EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf\r
+  EmbeddedPkg/Library/PrePiLib/PrePiLib.inf\r
+  EmbeddedPkg/Library/TemplateSerialPortLib/TemplateSerialPortLib.inf\r
+  EmbeddedPkg/Library/TemplateResetSystemLib/TemplateResetSystemLib.inf\r
+  EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf\r
+  EmbeddedPkg/Library/LzmaHobCustomDecompressLib/LzmaHobCustomDecompressLib.inf\r
+  EmbeddedPkg/Library/NullDmaLib/NullDmaLib.inf\r
+\r
+  EmbeddedPkg/Ebl/Ebl.inf\r
+####  EmbeddedPkg/EblExternCmd/EblExternCmd.inf\r
+  EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf\r
+  EmbeddedPkg/GdbStub/GdbStub.inf\r
+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf\r
+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf\r
+  EmbeddedPkg/SerialDxe/SerialDxe.inf\r
+  EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf\r
+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf\r
+\r
+  EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf\r
+  \r
+  \r
+\r
index 742de505cad5127544320d3d5e7005b43c0f1c81..8a13cc8a193d11894a84fce610fc4ee32c150fb4 100644 (file)
-/** @file
-  UEFI driver that implements a GDB stub
-  
-  Note: Any code in the path of the Serial IO output can not call DEBUG as will
-  will blow out the stack. Serial IO calls DEBUG, debug calls Serail IO, ...
-  
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <GdbStubInternal.h>
-#include <Protocol/DebugPort.h>
-
-
-UINTN     gMaxProcessorIndex = 0;
-
-//
-// Buffers for basic gdb communication
-//
-CHAR8 gInBuffer[MAX_BUF_SIZE];
-CHAR8 gOutBuffer[MAX_BUF_SIZE];
-
-// Assume gdb does a "qXfer:libraries:read::offset,length" when it connects so we can default 
-// this value to FALSE. Since gdb can reconnect its self a global default is not good enough
-BOOLEAN   gSymbolTableUpdate = FALSE;
-EFI_EVENT gEvent;
-VOID      *gGdbSymbolEventHandlerRegistration = NULL;
-
-//
-// Globals for returning XML from qXfer:libraries:read packet
-//
-UINTN                             gPacketqXferLibraryOffset = 0;
-UINTN                             gEfiDebugImageTableEntry = 0;
-EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *gDebugImageTableHeader = NULL;
-EFI_DEBUG_IMAGE_INFO              *gDebugTable = NULL;
-CHAR8                             gXferLibraryBuffer[2000];
-
-GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexToStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
-
-
-VOID
-EFIAPI
-GdbSymbolEventHandler (
-  IN  EFI_EVENT       Event,
-  IN  VOID            *Context
-  )
-{
-}
-
-
-/**
-  The user Entry Point for Application. The user code starts with this function
-  as the real entry point for the image goes into a library that calls 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
-GdbStubEntry (
-  IN EFI_HANDLE        ImageHandle,
-  IN EFI_SYSTEM_TABLE  *SystemTable
-  )
-
-{
-  EFI_STATUS                  Status;  
-  EFI_DEBUG_SUPPORT_PROTOCOL  *DebugSupport;
-  UINTN                       HandleCount;
-  EFI_HANDLE                  *Handles;
-  UINTN                       Index;
-  UINTN                       Processor;
-  BOOLEAN                     IsaSupported;
-   
-  Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&gDebugImageTableHeader);
-  if (EFI_ERROR (Status)) {
-    gDebugImageTableHeader = NULL;
-  }
-
-  Status = gBS->LocateHandleBuffer (
-                  ByProtocol,
-                  &gEfiDebugSupportProtocolGuid,
-                  NULL,
-                  &HandleCount,
-                  &Handles
-                  );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((EFI_D_ERROR, "Debug Support Protocol not found\n"));
-
-    return Status;
-  }
-  
-  DebugSupport = NULL;
-  IsaSupported = FALSE;
-  do {
-    HandleCount--;
-    Status = gBS->HandleProtocol (
-                    Handles[HandleCount],
-                    &gEfiDebugSupportProtocolGuid,
-                    (VOID **) &DebugSupport
-                    );
-    if (!EFI_ERROR (Status)) {
-      if (CheckIsa (DebugSupport->Isa)) {
-        // We found what we are looking for so break out of the loop
-        IsaSupported = TRUE;
-        break;
-      }
-    }
-  } while (HandleCount > 0);
-  FreePool (Handles);
-  
-  if (!IsaSupported) {
-    DEBUG ((EFI_D_ERROR, "Debug Support Protocol does not support our ISA\n"));
-
-    return EFI_NOT_FOUND;
-  }
-  
-  Status = DebugSupport->GetMaximumProcessorIndex (DebugSupport, &gMaxProcessorIndex);
-  ASSERT_EFI_ERROR (Status);
-  
-  DEBUG ((EFI_D_INFO, "Debug Support Protocol ISA %x\n", DebugSupport->Isa));
-  DEBUG ((EFI_D_INFO, "Debug Support Protocol Processor Index %d\n", gMaxProcessorIndex));
-  
-  // Call processor-specific init routine
-  InitializeProcessor();
-
-  for (Processor = 0; Processor <= gMaxProcessorIndex; Processor++) {
-    
-    for (Index = 0; Index < MaxEfiException (); Index++) {
-      Status = DebugSupport->RegisterExceptionCallback (DebugSupport, Processor,  GdbExceptionHandler, gExceptionType[Index].Exception);
-      ASSERT_EFI_ERROR (Status);
-    }
-    //
-    // Current edk2 DebugPort is not interrupt context safe so we can not use it
-    //
-    Status = DebugSupport->RegisterPeriodicCallback (DebugSupport, Processor, GdbPeriodicCallBack);
-    ASSERT_EFI_ERROR (Status);
-  }
-  //
-  // This even fires every time an image is added. This allows the stub to know when gdb needs
-  // to update the symbol table. 
-  //
-  Status = gBS->CreateEvent (
-                  EVT_NOTIFY_SIGNAL,
-                  TPL_CALLBACK,
-                  GdbSymbolEventHandler,
-                  NULL,
-                  &gEvent
-                  );
-  ASSERT_EFI_ERROR (Status);
-
-  //
-  // Register for protocol notifactions on this event
-  //
-  Status = gBS->RegisterProtocolNotify (
-                  &gEfiLoadedImageProtocolGuid,
-                  gEvent,
-                  &gGdbSymbolEventHandlerRegistration
-                  );
-  ASSERT_EFI_ERROR (Status);
-
- if (PcdGetBool (PcdGdbSerial)) {
-   GdbInitializeSerialConsole ();
- }
-   
-  return EFI_SUCCESS;
-}
-
-
-
-/**
- Transfer length bytes of input buffer, starting at Address, to memory.
-
- @param     length                  the number of the bytes to be transferred/written
- @param     *address                the start address of the transferring/writing the memory
- @param     *new_data               the new data to be written to memory
- **/
-
-VOID
-TransferFromInBufToMem (
-  IN    UINTN                       Length,
-  IN    unsigned char               *Address,
-  IN    CHAR8                       *NewData
-  )
-{
-  CHAR8 c1;
-  CHAR8 c2;
-   
-  while (Length-- > 0) {
-    c1 = (CHAR8)HexCharToInt (*NewData++);
-    c2 = (CHAR8)HexCharToInt (*NewData++);
-
-    if ((c1 < 0) || (c2 < 0)) {
-      Print ((CHAR16 *)L"Bad message from write to memory..\n");
-      SendError (GDB_EBADMEMDATA); 
-      return;
-    }
-    *Address++ = (UINT8)((c1 << 4) + c2);
-  }
-
-  SendSuccess();
-}
-
-
-/**
- Transfer Length bytes of memory starting at Address to an output buffer, OutBuffer. This function will finally send the buffer
- as a packet.
-
- @param     Length                  the number of the bytes to be transferred/read
- @param     *address                pointer to the start address of the transferring/reading the memory
- **/
-
-VOID
-TransferFromMemToOutBufAndSend (
-  IN    UINTN                       Length,
-  IN    unsigned char               *Address
-  )
-{
-  // there are Length bytes and every byte is represented as 2 hex chars
-  CHAR8   OutBuffer[MAX_BUF_SIZE];
-  CHAR8   *OutBufPtr;             // pointer to the output buffer
-  CHAR8   Char;
-
-  if (ValidateAddress(Address) == FALSE) {
-    SendError(14);
-    return;
-  }
-
-  OutBufPtr = OutBuffer;
-  while (Length > 0) {
-    
-    Char = mHexToStr[*Address >> 4];
-    if ((Char >= 'A') && (Char <= 'F')) {
-      Char = Char - 'A' + 'a';
-    }
-    *OutBufPtr++ = Char;
-
-    Char = mHexToStr[*Address & 0x0f];
-    if ((Char >= 'A') && (Char <= 'F')) {
-      Char = Char - 'A' + 'a';
-    }
-    *OutBufPtr++ = Char;
-
-    Address++;
-    Length--;
-  }
-
-  *OutBufPtr = '\0' ;  // the end of the buffer
-  SendPacket (OutBuffer);
-}
-
-
-
-/**
-  Send a GDB Remote Serial Protocol Packet
-  
-  $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', 
-  the packet teminating character '#' and the two digit checksum.
-  
-  If an ack '+' is not sent resend the packet, but timeout eventually so we don't end up 
-  in an infinit loop. This is so if you unplug the debugger code just keeps running
-
-  @param PacketData   Payload data for the packet  
-
-  
-  @retval             Number of bytes of packet data sent.
-
-**/
-UINTN
-SendPacket (
-  IN  CHAR8 *PacketData
-  )
-{
-  UINT8 CheckSum;
-  UINTN Timeout;
-  CHAR8 *Ptr;
-  CHAR8 TestChar;
-  UINTN Count;
-  
-  Timeout = PcdGet32 (PcdGdbMaxPacketRetryCount);
-
-  Count = 0;
-  do {
-
-    Ptr = PacketData;
-
-    if (Timeout-- == 0) {
-      // Only try a finite number of times so we don't get stuck in the loop
-      return Count;
-    }
-  
-    // Packet prefix
-    GdbPutChar ('$');
-  
-    for (CheckSum = 0, Count =0 ; *Ptr != '\0'; Ptr++, Count++) {
-      GdbPutChar (*Ptr);
-      CheckSum = CheckSum + *Ptr;
-    }
-  
-    // Packet terminating character and checksum 
-    GdbPutChar ('#');
-    GdbPutChar (mHexToStr[CheckSum >> 4]);
-    GdbPutChar (mHexToStr[CheckSum & 0x0F]);
-    
-    TestChar =  GdbGetChar ();
-  } while (TestChar != '+');
-  
-  return Count;
-}
-
-/**
-  Receive a GDB Remote Serial Protocol Packet
-  
-  $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', 
-  the packet teminating character '#' and the two digit checksum.
-  If host re-starts sending a packet without ending the previous packet, only the last valid packet is proccessed.
-  (In other words, if received packet is '$12345$12345$123456#checksum', only '$123456#checksum' will be processed.)
-  If an ack '+' is not sent resend the packet
-
-  @param PacketData   Payload data for the packet  
-
-  @retval             Number of bytes of packet data received.
-
-**/
-UINTN
-ReceivePacket (
-  OUT  CHAR8 *PacketData,
-  IN   UINTN PacketDataSize
- )
-{
-  UINT8 CheckSum;
-  UINTN Index;
-  CHAR8 Char;
-  CHAR8 SumString[3];
-  CHAR8 TestChar;
-  
-  ZeroMem (PacketData, PacketDataSize);
-  
-  for (;;) {
-      // wait for the start of a packet
-    TestChar = GdbGetChar ();
-    while (TestChar != '$') {
-      TestChar = GdbGetChar ();
-    };
-    
-  retry:
-    for (Index = 0, CheckSum = 0; Index < (PacketDataSize - 1); Index++) {
-      Char = GdbGetChar ();
-      if (Char == '$') {
-        goto retry;
-      }
-      if (Char == '#') {
-        break;
-      }
-
-      PacketData[Index] = Char;
-      CheckSum = CheckSum + Char;
-    }
-    PacketData[Index] = '\0';
-
-    if (Index == PacketDataSize) {
-      continue;
-    }
-
-    SumString[0] = GdbGetChar ();  
-    SumString[1] = GdbGetChar ();
-    SumString[2] = '\0';
-    
-    if (AsciiStrHexToUintn (SumString) == CheckSum) {
-      // Ack: Success
-      GdbPutChar ('+');
-  
-      // Null terminate the callers string
-      PacketData[Index] = '\0';
-      return Index;
-    } else {
-      // Ack: Failure
-      GdbPutChar ('-');
-    }
-  }
-  
-  //return 0;
-}
-
-
-/**
- Empties the given buffer 
- @param   Buf          pointer to the first element in buffer to be emptied
- **/
-VOID
-EmptyBuffer ( 
-  IN  CHAR8           *Buf
-  )
-{ 
-  *Buf = '\0';
-}
-
-
-/**
- Converts an 8-bit Hex Char into a INTN.
- @param   Char the hex character to be converted into UINTN
- @retval  a INTN, from 0 to 15, that corressponds to Char
- -1 if Char is not a hex character
- **/
-INTN
-HexCharToInt (
-  IN  CHAR8           Char
-  )
-{
-  if ((Char >= 'A') && (Char <= 'F')) {
-    return Char - 'A' + 10;
-  } else if ((Char >= 'a') && (Char <= 'f')) {
-    return Char - 'a' + 10;
-  } else if ((Char >= '0') && (Char <= '9')) {
-    return Char - '0';
-  } else { // if not a hex value, return a negative value
-    return -1; 
-  }
-}
-
-  // 'E' + the biggest error number is 255, so its 2 hex digits + buffer end
-CHAR8 *gError = "E__";
-
-/** 'E NN'
- Send an error with the given error number after converting to hex.
- The error number is put into the buffer in hex. '255' is the biggest errno we can send.
- ex: 162 will be sent as A2.
- @param   errno           the error number that will be sent
- **/
-VOID
-EFIAPI
-SendError (
-  IN  UINT8              ErrorNum
-  )
-{
-  //
-  // Replace _, or old data, with current errno
-  //
-  gError[1] = mHexToStr [ErrorNum >> 4];
-  gError[2] = mHexToStr [ErrorNum & 0x0f];
-    
-  SendPacket (gError); // send buffer
-}
-
-
-
-/**
- Send 'OK' when the function is done executing successfully.
- **/
-VOID
-EFIAPI
-SendSuccess (
-  VOID
-  ) 
-{
-  SendPacket ("OK"); // send buffer
-}
-
-
-/**
- Send empty packet to specify that particular command/functionality is not supported.
- **/
-VOID        
-EFIAPI      
-SendNotSupported (
-  VOID          
-  )             
-{       
-  SendPacket ("");
-}
-
-
-
-/**
- Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints
- @param  SystemContext        Register content at time of the exception
- @param  GdbExceptionType     GDB exception type
- **/
-VOID
-GdbSendTSignal (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINT8               GdbExceptionType
-  )
-{
-  CHAR8 TSignalBuffer[128];
-  CHAR8 *TSignalPtr;
-  UINTN BreakpointDetected;
-  BREAK_TYPE BreakType;
-  UINTN DataAddress;
-  CHAR8 *WatchStrPtr = NULL;
-  UINTN RegSize;
-
-  TSignalPtr = &TSignalBuffer[0];
-
-  //Construct TSignal packet
-  *TSignalPtr++ = 'T';
-
-  //
-  // replace _, or previous value, with Exception type
-  //
-  *TSignalPtr++ = mHexToStr [GdbExceptionType >> 4]; 
-  *TSignalPtr++ = mHexToStr [GdbExceptionType & 0x0f];
-  
-  if (GdbExceptionType == GDB_SIGTRAP) {
-    if (gSymbolTableUpdate) {
-      //
-      // We can only send back on reason code. So if the flag is set it means the breakpoint is from our event handler
-      //
-      WatchStrPtr = "library:;";
-      while (*WatchStrPtr != '\0') {
-        *TSignalPtr++ = *WatchStrPtr++;
-      }
-      gSymbolTableUpdate = FALSE;
-    } else {
-
-
-      //
-      // possible n:r pairs
-      // 
-
-      //Retrieve the breakpoint number
-      BreakpointDetected = GetBreakpointDetected (SystemContext);
-
-      //Figure out if the exception is happend due to watch, rwatch or awatch.
-      BreakType = GetBreakpointType (SystemContext, BreakpointDetected); 
-
-      //INFO: rwatch is not supported due to the way IA32 debug registers work
-      if ((BreakType == DataWrite) || (BreakType == DataRead) || (BreakType == DataReadWrite)) {
-        
-        //Construct n:r pair
-        DataAddress = GetBreakpointDataAddress (SystemContext, BreakpointDetected);
-
-        //Assign appropriate buffer to print particular watchpoint type
-        if (BreakType == DataWrite) {
-          WatchStrPtr = "watch";
-        } else if (BreakType == DataRead) {
-          WatchStrPtr = "rwatch";
-        } else if (BreakType == DataReadWrite) {
-          WatchStrPtr = "awatch";
-        }
-
-        while (*WatchStrPtr != '\0') {
-          *TSignalPtr++ = *WatchStrPtr++;
-        }
-
-        *TSignalPtr++ = ':';
-        
-        //Set up series of bytes in big-endian byte order. "awatch" won't work with little-endian byte order.
-        RegSize = REG_SIZE;
-        while (RegSize > 0) {
-          RegSize = RegSize-4;
-          *TSignalPtr++ = mHexToStr[(UINT8)(DataAddress >> RegSize) & 0xf];
-        }
-
-        //Always end n:r pair with ';'
-        *TSignalPtr++ = ';';
-      }
-    }
-  }
-
-  *TSignalPtr = '\0';
-
-  SendPacket (TSignalBuffer); 
-}
-
-
-/**
- Translates the EFI mapping to GDB mapping
- @param   EFIExceptionType    EFI Exception that is being processed
- @retval  UINTN that corresponds to EFIExceptionType's GDB exception type number
- **/
-UINT8
-ConvertEFItoGDBtype ( 
-  IN  EFI_EXCEPTION_TYPE      EFIExceptionType
-  )
-{ 
-  UINTN i;
-  
-  for (i=0; i < MaxEfiException() ; i++) {
-    if (gExceptionType[i].Exception == EFIExceptionType) {
-      return gExceptionType[i].SignalNo;
-    }
-  }
-  return GDB_SIGTRAP; // this is a GDB trap
-}
-
-
-/** "m addr,length"
- Find the Length of the area to read and the start addres. Finally, pass them to 
- another function, TransferFromMemToOutBufAndSend, that will read from that memory space and 
- send it as a packet.
- **/
-
-VOID
-EFIAPI
-ReadFromMemory (
-  CHAR8 *PacketData
-  )
-{
-  UINTN Address;
-  UINTN Length;
-  CHAR8 AddressBuffer[MAX_ADDR_SIZE]; // the buffer that will hold the address in hex chars
-  CHAR8 *AddrBufPtr; // pointer to the address buffer
-  CHAR8 *InBufPtr; /// pointer to the input buffer
-  
-  AddrBufPtr = AddressBuffer;
-  InBufPtr = &PacketData[1];
-  while (*InBufPtr != ',') {
-    *AddrBufPtr++ = *InBufPtr++;
-  }
-  *AddrBufPtr = '\0';
-  
-  InBufPtr++; // this skips ',' in the buffer
-  
-  /* Error checking */
-  if (AsciiStrLen(AddressBuffer) >= MAX_ADDR_SIZE) {
-    Print((CHAR16 *)L"Address is too long\n");
-    SendError (GDB_EBADMEMADDRBUFSIZE); 
-    return;
-  }
-  
-  // 2 = 'm' + ','
-  if (AsciiStrLen(PacketData) - AsciiStrLen(AddressBuffer) - 2 >= MAX_LENGTH_SIZE) {
-    Print((CHAR16 *)L"Length is too long\n");
-    SendError (GDB_EBADMEMLENGTH); 
-    return;
-  }
-  
-  Address = AsciiStrHexToUintn (AddressBuffer);
-  Length = AsciiStrHexToUintn (InBufPtr);
-  
-  TransferFromMemToOutBufAndSend (Length, (unsigned char *)Address);
-}
-
-
-/** "M addr,length :XX..."
- Find the Length of the area in bytes to write and the start addres. Finally, pass them to 
- another function, TransferFromInBufToMem, that will write to that memory space the info in
- the input buffer.
- **/
-VOID
-EFIAPI
-WriteToMemory (
-  IN CHAR8 *PacketData
-  )
-{
-  UINTN Address;
-  UINTN Length;
-  UINTN MessageLength;
-  CHAR8 AddressBuffer[MAX_ADDR_SIZE]; // the buffer that will hold the Address in hex chars
-  CHAR8 LengthBuffer[MAX_LENGTH_SIZE]; // the buffer that will hold the Length in hex chars
-  CHAR8 *AddrBufPtr; // pointer to the Address buffer
-  CHAR8 *LengthBufPtr; // pointer to the Length buffer
-  CHAR8 *InBufPtr; /// pointer to the input buffer
-  
-  AddrBufPtr = AddressBuffer;
-  LengthBufPtr = LengthBuffer;
-  InBufPtr = &PacketData[1];
-  
-  while (*InBufPtr != ',') {
-    *AddrBufPtr++ = *InBufPtr++;
-  }
-  *AddrBufPtr = '\0';
-  
-  InBufPtr++; // this skips ',' in the buffer
-  
-  while (*InBufPtr != ':') {
-    *LengthBufPtr++ = *InBufPtr++;
-  }
-  *LengthBufPtr = '\0';
-  
-  InBufPtr++; // this skips ':' in the buffer
-  
-  Address = AsciiStrHexToUintn (AddressBuffer);
-  Length = AsciiStrHexToUintn (LengthBuffer);
-  
-  /* Error checking */
-  
-  //Check if Address is not too long.
-  if (AsciiStrLen(AddressBuffer) >= MAX_ADDR_SIZE) {
-    Print ((CHAR16 *)L"Address too long..\n");
-    SendError (GDB_EBADMEMADDRBUFSIZE); 
-    return;
-  }
-  
-  //Check if message length is not too long
-  if (AsciiStrLen(LengthBuffer) >= MAX_LENGTH_SIZE) {
-    Print ((CHAR16 *)L"Length too long..\n");
-    SendError (GDB_EBADMEMLENGBUFSIZE); 
-    return;
-  }
-  
-  // Check if Message is not too long/short.
-  // 3 = 'M' + ',' + ':'
-  MessageLength = (AsciiStrLen(PacketData) - AsciiStrLen(AddressBuffer) - AsciiStrLen(LengthBuffer) - 3);
-  if (MessageLength != (2*Length)) {
-    //Message too long/short. New data is not the right size.
-    SendError (GDB_EBADMEMDATASIZE);   
-    return;
-  }
-  TransferFromInBufToMem (Length, (unsigned char *)Address, InBufPtr);
-}
-
-/**
-  Parses breakpoint packet data and captures Breakpoint type, Address and length.
-  In case of an error, function returns particular error code. Returning 0 meaning
-  no error.
-
-  @param  PacketData  Pointer to the payload data for the packet.
-  @param  Type        Breakpoint type
-  @param  Address     Breakpoint address
-  @param  Length      Breakpoint length in Bytes (1 byte, 2 byte, 4 byte)
-
-  @retval 1           Success
-  @retval {other}     Particular error code
-
-**/
-UINTN
-ParseBreakpointPacket (
-  IN  CHAR8 *PacketData,
-  OUT UINTN *Type,
-  OUT UINTN *Address,
-  OUT UINTN *Length
-  )
-{
-  CHAR8 AddressBuffer[MAX_ADDR_SIZE];
-  CHAR8 *AddressBufferPtr;
-  CHAR8 *PacketDataPtr;
-
-  PacketDataPtr = &PacketData[1];
-  AddressBufferPtr = AddressBuffer;
-
-  *Type = AsciiStrHexToUintn (PacketDataPtr);
-
-  //Breakpoint/watchpoint type should be between 0 to 4
-  if (*Type > 4) {
-    Print ((CHAR16 *)L"Type is invalid\n");
-    return 22; //EINVAL: Invalid argument.
-  }
-
-  //Skip ',' in the buffer.
-  while (*PacketDataPtr++ != ',');
-
-  //Parse Address information
-  while (*PacketDataPtr != ',') {
-    *AddressBufferPtr++ = *PacketDataPtr++;
-  }
-  *AddressBufferPtr = '\0';
-
-  //Check if Address is not too long.
-  if (AsciiStrLen(AddressBuffer) >= MAX_ADDR_SIZE) {
-    Print ((CHAR16 *)L"Address too long..\n");
-    return 40; //EMSGSIZE: Message size too long.
-  }
-
-  *Address = AsciiStrHexToUintn (AddressBuffer);
-
-  PacketDataPtr++; //This skips , in the buffer
-
-  //Parse Length information
-  *Length = AsciiStrHexToUintn (PacketDataPtr);
-
-  //Length should be 1, 2 or 4 bytes
-  if (*Length > 4) {
-    Print ((CHAR16 *)L"Length is invalid\n");
-    return 22; //EINVAL: Invalid argument
-  }
-
-  return 0; //0 = No error
-}
-
-UINTN
-gXferObjectReadResponse (
-  IN  CHAR8         Type,
-  IN  CHAR8         *Str
-  )
-{
-  CHAR8   *OutBufPtr;             // pointer to the output buffer
-  CHAR8   Char;
-  UINTN   Count;
-
-  // responce starts with 'm' or 'l' if it is the end
-  OutBufPtr = gOutBuffer;
-  *OutBufPtr++ = Type;
-  Count = 1;
-
-  // Binary data encoding 
-  OutBufPtr = gOutBuffer;
-  while (*Str != '\0') {
-    Char = *Str++;
-    if ((Char == 0x7d) || (Char == 0x23) || (Char == 0x24) || (Char == 0x2a)) {
-      // escape character
-      *OutBufPtr++ = 0x7d;
-
-      Char ^= 0x20;
-    }
-    *OutBufPtr++ = Char;
-    Count++;
-  }
-
-  *OutBufPtr = '\0' ;  // the end of the buffer
-  SendPacket (gOutBuffer);
-  
-  return Count;
-}
-
-
-/**
-  Note: This should be a library function.  In the Apple case you have to add 
-  the size of the PE/COFF header into the starting address to make things work 
-  right as there is no way to pad the Mach-O for the size of the PE/COFF header.
-  
-  
-  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.
-  @param  DebugBase  Address that the debugger would use as the base of the image
-
-  @return The PDB file name for the PE/COFF image specified by Pe32Data or NULL
-          if it cannot be retrieved. DebugBase is only valid if PDB file name is
-          valid. 
-
-**/
-VOID *
-EFIAPI
-PeCoffLoaderGetDebuggerInfo (
-  IN VOID     *Pe32Data,
-  OUT VOID    **DebugBase
-  )
-{
-  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;
-  UINTN                                 SizeOfHeaders;
-
-  ASSERT (Pe32Data   != NULL);
-
-  TEImageAdjust       = 0;
-  DirectoryEntry      = NULL;
-  DebugEntry          = NULL;
-  NumberOfRvaAndSizes = 0;
-  SizeOfHeaders       = 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);
-    }
-    SizeOfHeaders = sizeof (EFI_TE_IMAGE_HEADER) + (UINTN)Hdr.Te->BaseOfCode - (UINTN)Hdr.Te->StrippedSize;
-    
-    // __APPLE__ check this math...
-    *DebugBase = ((CHAR8 *)Pe32Data) -  TEImageAdjust;
-  } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
-    
-    *DebugBase = Pe32Data;
-    
-    
-    //
-    // 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_IA64:
-      //
-      // 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
-      //
-      SizeOfHeaders = Hdr.Pe32->OptionalHeader.SizeOfHeaders;
-      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 (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
-      //
-      // Use PE32+ offset get Debug Directory Entry
-      //
-      SizeOfHeaders = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders;
-      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));
-        case CODEVIEW_SIGNATURE_MTOC:
-          *DebugBase = (VOID *)(UINTN)((UINTN)DebugBase - SizeOfHeaders);
-          return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY));
-        default:
-          break;
-        }
-      }
-    }
-  }
-
-  (void)SizeOfHeaders;
-  return NULL;
-}
-
-
-
-/** 
-  Process "qXfer:object:read:annex:offset,length" request.
-  
-  Returns an XML document that contains loaded libraries. In our case it is 
-  infomration in the EFI Debug Inmage Table converted into an XML document.
-  
-  GDB will call with an arbitrary length (it can't know the real length and 
-  will reply with chunks of XML that are easy for us to deal with. Gdb will 
-  keep calling until we say we are done. XML doc looks like:
-  
-  <library-list>
-    <library name="/a/a/c/d.dSYM"><segment address="0x10000000"/></library>
-    <library name="/a/m/e/e.pdb"><segment address="0x20000000"/></library>
-    <library name="/a/l/f/f.dll"><segment address="0x30000000"/></library>
-  </library-list>
-  
-  Since we can not allocate memory in interupt context this module has 
-  assumptions about how it will get called:
-  1) Length will generally be max remote packet size (big enough)
-  2) First Offset of an XML document read needs to be 0
-  3) This code will return back small chunks of the XML document on every read.
-     Each subseqent call will ask for the next availble part of the document.
-     
-  Note: The only variable size element in the XML is:
-  "  <library name=\"%s\"><segment address=\"%p\"/></library>\n" and it is 
-  based on the file path and name of the symbol file. If the symbol file name
-  is bigger than the max gdb remote packet size we could update this code
-  to respond back in chunks.
-
- @param Offset  offset into special data area
- @param Length  number of bytes to read starting at Offset  
-  
- **/
-VOID
-QxferLibrary (
-  IN  UINTN   Offset,
-  IN  UINTN   Length
-  )
-{
-  VOID                              *LoadAddress;
-  CHAR8                             *Pdb;
-  UINTN                             Size;
-
-  if (Offset != gPacketqXferLibraryOffset) {
-    SendError (GDB_EINVALIDARG);
-    Print (L"\nqXferLibrary (%d, %d) != %d\n", Offset, Length, gPacketqXferLibraryOffset);
-    
-    // Force a retry from the beginning 
-    gPacketqXferLibraryOffset = 0;
-    return;
-  }
-
-  if (Offset == 0) {
-    gPacketqXferLibraryOffset += gXferObjectReadResponse ('m', "<library-list>\n");
-    
-    // The owner of the table may have had to ralloc it so grab a fresh copy every time
-    // we assume qXferLibrary will get called over and over again until the entire XML table is 
-    // returned in a tight loop. Since we are in the debugger the table should not get updated
-    gDebugTable = gDebugImageTableHeader->EfiDebugImageInfoTable;
-    gEfiDebugImageTableEntry = 0;
-    return;
-  }
-  
-  if (gDebugTable != NULL) {
-    for (; gEfiDebugImageTableEntry < gDebugImageTableHeader->TableSize; gEfiDebugImageTableEntry++, gDebugTable++) {
-      if (gDebugTable->NormalImage != NULL) {
-        if ((gDebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) && 
-            (gDebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) {
-          Pdb = PeCoffLoaderGetDebuggerInfo (
-                 gDebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase, 
-                 &LoadAddress
-                 );
-          if (Pdb != NULL) {
-            Size = AsciiSPrint (
-                    gXferLibraryBuffer, 
-                    sizeof (gXferLibraryBuffer), 
-                    "  <library name=\"%a\"><segment address=\"0x%p\"/></library>\n", 
-                    Pdb,
-                    LoadAddress
-                    );
-            if ((Size != 0) && (Size != (sizeof (gXferLibraryBuffer) - 1))) {
-              gPacketqXferLibraryOffset += gXferObjectReadResponse ('m', gXferLibraryBuffer);
-              
-              // Update loop variables so we are in the right place when we get back
-              gEfiDebugImageTableEntry++;
-              gDebugTable++;
-              return;
-            } else {
-              // We could handle <library> entires larger than sizeof (gXferLibraryBuffer) here if 
-              // needed by breaking up into N packets
-              // "<library name=\"%s
-              // the rest of the string (as many packets as required
-              // \"><segment address=\"%d\"/></library> (fixed size)
-              //
-              // But right now we just skip any entry that is too big
-            }
-          }           
-        }
-      }  
-    }
-  }
-  
-  
-  gXferObjectReadResponse ('l', "</library-list>\n");
-  gPacketqXferLibraryOffset = 0;
-  return;
-}
-
-
-/**
- Exception Hanldler for GDB. It will be called for all exceptions
- registered via the gExceptionType[] array.
- @param ExceptionType     Exception that is being processed
- @param SystemContext     Register content at time of the exception  
- **/
-VOID
-EFIAPI
-GdbExceptionHandler ( 
-  IN  EFI_EXCEPTION_TYPE        ExceptionType, 
-  IN OUT EFI_SYSTEM_CONTEXT     SystemContext 
-  )
-{
-  UINT8   GdbExceptionType;
-  CHAR8   *Ptr;
-      
-  
-  if (ValidateException(ExceptionType, SystemContext) == FALSE) {
-    return;
-  }
-
-  RemoveSingleStep (SystemContext);
-  
-  GdbExceptionType = ConvertEFItoGDBtype (ExceptionType);
-  GdbSendTSignal (SystemContext, GdbExceptionType);
-  
-  for( ; ; ) {
-    ReceivePacket (gInBuffer, MAX_BUF_SIZE);
-    
-    switch (gInBuffer[0]) {
-      case '?':
-        GdbSendTSignal (SystemContext, GdbExceptionType);
-        break;
-          
-      case 'c':
-        ContinueAtAddress (SystemContext, gInBuffer);          
-        return;
-
-      case 'g':
-        ReadGeneralRegisters (SystemContext);
-        break;
-          
-      case 'G':
-        WriteGeneralRegisters (SystemContext, gInBuffer);
-        break;
-          
-      case 'H':
-        //Return "OK" packet since we don't have more than one thread. 
-        SendSuccess ();
-        break;
-          
-      case 'm':
-        ReadFromMemory (gInBuffer);
-        break;
-
-      case 'M':
-        WriteToMemory (gInBuffer);
-        break;
-
-      case 'P':
-        WriteNthRegister (SystemContext, gInBuffer);
-        break;
-
-      //
-      // Still debugging this code. Not used in Darwin
-      //
-      case 'q': 
-        // General Query Packets
-        if (AsciiStrnCmp (gInBuffer, "qSupported", 10) == 0) {
-          // return what we currently support, we don't parse what gdb suports
-          AsciiSPrint (gOutBuffer, MAX_BUF_SIZE, "qXfer:libraries:read+;PacketSize=%d", MAX_BUF_SIZE);
-          SendPacket (gOutBuffer);
-        } else if (AsciiStrnCmp (gInBuffer, "qXfer:libraries:read::", 22) == 0) {
-          // â€˜qXfer:libraries:read::offset,length
-          // gInBuffer[22] is offset string, ++Ptr is length string’
-          for (Ptr = &gInBuffer[22]; *Ptr != ','; Ptr++);
-        
-          // Not sure if multi-radix support is required. Currently only support decimal
-          QxferLibrary (AsciiStrHexToUintn (&gInBuffer[22]), AsciiStrHexToUintn (++Ptr));
-        } if (AsciiStrnCmp (gInBuffer, "qOffsets", 10) == 0) {
-          AsciiSPrint (gOutBuffer, MAX_BUF_SIZE, "Text=1000;Data=f000;Bss=f000");
-          SendPacket (gOutBuffer);
-        } else {
-          //Send empty packet
-          SendNotSupported ();
-        }
-        break;
-
-      case 's':
-        SingleStep (SystemContext, gInBuffer);          
-        return;
-          
-      case 'z':
-        RemoveBreakPoint (SystemContext, gInBuffer);
-        break;
-  
-      case 'Z':
-        InsertBreakPoint (SystemContext, gInBuffer);
-        break;
-                  
-      default:  
-        //Send empty packet
-        SendNotSupported ();
-        break;
-    }
-  }
-}
-
-
-/**
- Periodic callback for GDB. This function is used to catch a ctrl-c or other 
- break in type command from GDB.
- @param SystemContext     Register content at time of the call  
- **/
-VOID
-EFIAPI
-GdbPeriodicCallBack ( 
-  IN OUT EFI_SYSTEM_CONTEXT     SystemContext 
-  )
-{
-  //
-  // gCtrlCBreakFlag may have been set from a previous F response package 
-  // and we set the global as we need to process it at a point where we 
-  // can update the system context. If we are in the middle of processing
-  // a F Packet it is not safe to read the GDB serial stream so we need
-  // to skip it on this check
-  //
-  if (!gCtrlCBreakFlag && !gProcessingFPacket) {
-    //
-    // Ctrl-C was not pending so grab any pending characters and see if they 
-    // are a Ctrl-c (0x03). If so set the Ctrl-C global. 
-    //
-    while (TRUE) {
-      if (!GdbIsCharAvailable ()) {
-        //
-        // No characters are pending so exit the loop
-        //
-        break;
-      }
-      
-      if (GdbGetChar () == 0x03) {
-        gCtrlCBreakFlag = TRUE;
-        //
-        // We have a ctrl-c so exit the loop
-        //
-        break;
-      }
-    }
-  }
-  
-  if (gCtrlCBreakFlag) {
-    //
-    // Update the context to force a single step trap when we exit the GDB
-    // stub. This will trasfer control to GdbExceptionHandler () and let
-    // us break into the program. We don't want to break into the GDB stub.
-    //
-    AddSingleStep (SystemContext);
-    gCtrlCBreakFlag = FALSE;
-  }
-}
+/** @file\r
+  UEFI driver that implements a GDB stub\r
+  \r
+  Note: Any code in the path of the Serial IO output can not call DEBUG as will\r
+  will blow out the stack. Serial IO calls DEBUG, debug calls Serail IO, ...\r
+  \r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <GdbStubInternal.h>\r
+#include <Protocol/DebugPort.h>\r
+\r
+\r
+UINTN     gMaxProcessorIndex = 0;\r
+\r
+//\r
+// Buffers for basic gdb communication\r
+//\r
+CHAR8 gInBuffer[MAX_BUF_SIZE];\r
+CHAR8 gOutBuffer[MAX_BUF_SIZE];\r
+\r
+// Assume gdb does a "qXfer:libraries:read::offset,length" when it connects so we can default \r
+// this value to FALSE. Since gdb can reconnect its self a global default is not good enough\r
+BOOLEAN   gSymbolTableUpdate = FALSE;\r
+EFI_EVENT gEvent;\r
+VOID      *gGdbSymbolEventHandlerRegistration = NULL;\r
+\r
+//\r
+// Globals for returning XML from qXfer:libraries:read packet\r
+//\r
+UINTN                             gPacketqXferLibraryOffset = 0;\r
+UINTN                             gEfiDebugImageTableEntry = 0;\r
+EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *gDebugImageTableHeader = NULL;\r
+EFI_DEBUG_IMAGE_INFO              *gDebugTable = NULL;\r
+CHAR8                             gXferLibraryBuffer[2000];\r
+\r
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexToStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};\r
+\r
+\r
+VOID\r
+EFIAPI\r
+GdbSymbolEventHandler (\r
+  IN  EFI_EVENT       Event,\r
+  IN  VOID            *Context\r
+  )\r
+{\r
+}\r
+\r
+\r
+/**\r
+  The user Entry Point for Application. The user code starts with this function\r
+  as the real entry point for the image goes into a library that calls this \r
+  function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GdbStubEntry (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+\r
+{\r
+  EFI_STATUS                  Status;  \r
+  EFI_DEBUG_SUPPORT_PROTOCOL  *DebugSupport;\r
+  UINTN                       HandleCount;\r
+  EFI_HANDLE                  *Handles;\r
+  UINTN                       Index;\r
+  UINTN                       Processor;\r
+  BOOLEAN                     IsaSupported;\r
\r
+   \r
+  Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&gDebugImageTableHeader);\r
+  if (EFI_ERROR (Status)) {\r
+    gDebugImageTableHeader = NULL;\r
+  }\r
+\r
+  Status = gBS->LocateHandleBuffer (\r
+                  ByProtocol,\r
+                  &gEfiDebugSupportProtocolGuid,\r
+                  NULL,\r
+                  &HandleCount,\r
+                  &Handles\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "Debug Support Protocol not found\n"));\r
+\r
+    return Status;\r
+  }\r
+  \r
+  DebugSupport = NULL;\r
+  IsaSupported = FALSE;\r
+  do {\r
+    HandleCount--;\r
+    Status = gBS->HandleProtocol (\r
+                    Handles[HandleCount],\r
+                    &gEfiDebugSupportProtocolGuid,\r
+                    (VOID **) &DebugSupport\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      if (CheckIsa (DebugSupport->Isa)) {\r
+        // We found what we are looking for so break out of the loop\r
+        IsaSupported = TRUE;\r
+        break;\r
+      }\r
+    }\r
+  } while (HandleCount > 0);\r
+  FreePool (Handles);\r
+  \r
+  if (!IsaSupported) {\r
+    DEBUG ((EFI_D_ERROR, "Debug Support Protocol does not support our ISA\n"));\r
+\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  \r
+  Status = DebugSupport->GetMaximumProcessorIndex (DebugSupport, &gMaxProcessorIndex);\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  DEBUG ((EFI_D_INFO, "Debug Support Protocol ISA %x\n", DebugSupport->Isa));\r
+  DEBUG ((EFI_D_INFO, "Debug Support Protocol Processor Index %d\n", gMaxProcessorIndex));\r
+  \r
+  // Call processor-specific init routine\r
+  InitializeProcessor();\r
+\r
+  for (Processor = 0; Processor <= gMaxProcessorIndex; Processor++) {\r
+    \r
+    for (Index = 0; Index < MaxEfiException (); Index++) {\r
+      Status = DebugSupport->RegisterExceptionCallback (DebugSupport, Processor,  GdbExceptionHandler, gExceptionType[Index].Exception);\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+    //\r
+    // Current edk2 DebugPort is not interrupt context safe so we can not use it\r
+    //\r
+    Status = DebugSupport->RegisterPeriodicCallback (DebugSupport, Processor, GdbPeriodicCallBack);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
\r
+  //\r
+  // This even fires every time an image is added. This allows the stub to know when gdb needs\r
+  // to update the symbol table. \r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  GdbSymbolEventHandler,\r
+                  NULL,\r
+                  &gEvent\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Register for protocol notifactions on this event\r
+  //\r
+  Status = gBS->RegisterProtocolNotify (\r
+                  &gEfiLoadedImageProtocolGuid,\r
+                  gEvent,\r
+                  &gGdbSymbolEventHandlerRegistration\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
\r
+ if (PcdGetBool (PcdGdbSerial)) {\r
+   GdbInitializeSerialConsole ();\r
+ }\r
+   \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+\r
+/**\r
+ Transfer length bytes of input buffer, starting at Address, to memory.\r
+\r
+ @param     length                  the number of the bytes to be transferred/written\r
+ @param     *address                the start address of the transferring/writing the memory\r
+ @param     *new_data               the new data to be written to memory\r
+ **/\r
+\r
+VOID\r
+TransferFromInBufToMem (\r
+  IN    UINTN                       Length,\r
+  IN    unsigned char               *Address,\r
+  IN    CHAR8                       *NewData\r
+  )\r
+{\r
+  CHAR8 c1;\r
+  CHAR8 c2;\r
+   \r
+  while (Length-- > 0) {\r
+    c1 = (CHAR8)HexCharToInt (*NewData++);\r
+    c2 = (CHAR8)HexCharToInt (*NewData++);\r
+\r
+    if ((c1 < 0) || (c2 < 0)) {\r
+      Print ((CHAR16 *)L"Bad message from write to memory..\n");\r
+      SendError (GDB_EBADMEMDATA); \r
+      return;\r
+    }\r
+    *Address++ = (UINT8)((c1 << 4) + c2);\r
+  }\r
+\r
+  SendSuccess();\r
+}\r
+\r
+\r
+/**\r
+ Transfer Length bytes of memory starting at Address to an output buffer, OutBuffer. This function will finally send the buffer\r
+ as a packet.\r
+\r
+ @param     Length                  the number of the bytes to be transferred/read\r
+ @param     *address                pointer to the start address of the transferring/reading the memory\r
+ **/\r
+\r
+VOID\r
+TransferFromMemToOutBufAndSend (\r
+  IN    UINTN                       Length,\r
+  IN    unsigned char               *Address\r
+  )\r
+{\r
+  // there are Length bytes and every byte is represented as 2 hex chars\r
+  CHAR8   OutBuffer[MAX_BUF_SIZE];\r
+  CHAR8   *OutBufPtr;             // pointer to the output buffer\r
+  CHAR8   Char;\r
+\r
+  if (ValidateAddress(Address) == FALSE) {\r
+    SendError(14);\r
+    return;\r
+  }\r
+\r
+  OutBufPtr = OutBuffer;\r
+  while (Length > 0) {\r
+    \r
+    Char = mHexToStr[*Address >> 4];\r
+    if ((Char >= 'A') && (Char <= 'F')) {\r
+      Char = Char - 'A' + 'a';\r
+    }\r
+    *OutBufPtr++ = Char;\r
+\r
+    Char = mHexToStr[*Address & 0x0f];\r
+    if ((Char >= 'A') && (Char <= 'F')) {\r
+      Char = Char - 'A' + 'a';\r
+    }\r
+    *OutBufPtr++ = Char;\r
+\r
+    Address++;\r
+    Length--;\r
+  }\r
+\r
+  *OutBufPtr = '\0' ;  // the end of the buffer\r
+  SendPacket (OutBuffer);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Send a GDB Remote Serial Protocol Packet\r
+  \r
+  $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', \r
+  the packet teminating character '#' and the two digit checksum.\r
+  \r
+  If an ack '+' is not sent resend the packet, but timeout eventually so we don't end up \r
+  in an infinit loop. This is so if you unplug the debugger code just keeps running\r
+\r
+  @param PacketData   Payload data for the packet  \r
+\r
+  \r
+  @retval             Number of bytes of packet data sent.\r
+\r
+**/\r
+UINTN\r
+SendPacket (\r
+  IN  CHAR8 *PacketData\r
+  )\r
+{\r
+  UINT8 CheckSum;\r
+  UINTN Timeout;\r
+  CHAR8 *Ptr;\r
+  CHAR8 TestChar;\r
+  UINTN Count;\r
+  \r
+  Timeout = PcdGet32 (PcdGdbMaxPacketRetryCount);\r
+\r
+  Count = 0;\r
+  do {\r
+\r
+    Ptr = PacketData;\r
+\r
+    if (Timeout-- == 0) {\r
+      // Only try a finite number of times so we don't get stuck in the loop\r
+      return Count;\r
+    }\r
+  \r
+    // Packet prefix\r
+    GdbPutChar ('$');\r
+  \r
+    for (CheckSum = 0, Count =0 ; *Ptr != '\0'; Ptr++, Count++) {\r
+      GdbPutChar (*Ptr);\r
+      CheckSum = CheckSum + *Ptr;\r
+    }\r
+  \r
+    // Packet terminating character and checksum \r
+    GdbPutChar ('#');\r
+    GdbPutChar (mHexToStr[CheckSum >> 4]);\r
+    GdbPutChar (mHexToStr[CheckSum & 0x0F]);\r
+    \r
+    TestChar =  GdbGetChar ();\r
+  } while (TestChar != '+');\r
+  \r
+  return Count;\r
+}\r
+\r
+/**\r
+  Receive a GDB Remote Serial Protocol Packet\r
+  \r
+  $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', \r
+  the packet teminating character '#' and the two digit checksum.\r
\r
+  If host re-starts sending a packet without ending the previous packet, only the last valid packet is proccessed.\r
+  (In other words, if received packet is '$12345$12345$123456#checksum', only '$123456#checksum' will be processed.)\r
\r
+  If an ack '+' is not sent resend the packet\r
+\r
+  @param PacketData   Payload data for the packet  \r
+\r
+  @retval             Number of bytes of packet data received.\r
+\r
+**/\r
+UINTN\r
+ReceivePacket (\r
+  OUT  CHAR8 *PacketData,\r
+  IN   UINTN PacketDataSize\r
+ )\r
+{\r
+  UINT8 CheckSum;\r
+  UINTN Index;\r
+  CHAR8 Char;\r
+  CHAR8 SumString[3];\r
+  CHAR8 TestChar;\r
+  \r
+  ZeroMem (PacketData, PacketDataSize);\r
+  \r
+  for (;;) {\r
+      // wait for the start of a packet\r
+    TestChar = GdbGetChar ();\r
+    while (TestChar != '$') {\r
+      TestChar = GdbGetChar ();\r
+    };\r
+    \r
+  retry:\r
+    for (Index = 0, CheckSum = 0; Index < (PacketDataSize - 1); Index++) {\r
+      Char = GdbGetChar ();\r
+      if (Char == '$') {\r
+        goto retry;\r
+      }\r
+      if (Char == '#') {\r
+        break;\r
+      }\r
+\r
+      PacketData[Index] = Char;\r
+      CheckSum = CheckSum + Char;\r
+    }\r
+    PacketData[Index] = '\0';\r
+\r
+    if (Index == PacketDataSize) {\r
+      continue;\r
+    }\r
+\r
+    SumString[0] = GdbGetChar ();  \r
+    SumString[1] = GdbGetChar ();\r
+    SumString[2] = '\0';\r
+    \r
+    if (AsciiStrHexToUintn (SumString) == CheckSum) {\r
+      // Ack: Success\r
+      GdbPutChar ('+');\r
+  \r
+      // Null terminate the callers string\r
+      PacketData[Index] = '\0';\r
+      return Index;\r
+    } else {\r
+      // Ack: Failure\r
+      GdbPutChar ('-');\r
+    }\r
+  }\r
+  \r
+  //return 0;\r
+}\r
+\r
+\r
+/**\r
+ Empties the given buffer \r
+ @param   Buf          pointer to the first element in buffer to be emptied\r
+ **/\r
+VOID\r
+EmptyBuffer ( \r
+  IN  CHAR8           *Buf\r
+  )\r
+{ \r
+  *Buf = '\0';\r
+}\r
+\r
+\r
+/**\r
+ Converts an 8-bit Hex Char into a INTN.\r
\r
+ @param   Char the hex character to be converted into UINTN\r
+ @retval  a INTN, from 0 to 15, that corressponds to Char\r
+ -1 if Char is not a hex character\r
+ **/\r
+INTN\r
+HexCharToInt (\r
+  IN  CHAR8           Char\r
+  )\r
+{\r
+  if ((Char >= 'A') && (Char <= 'F')) {\r
+    return Char - 'A' + 10;\r
+  } else if ((Char >= 'a') && (Char <= 'f')) {\r
+    return Char - 'a' + 10;\r
+  } else if ((Char >= '0') && (Char <= '9')) {\r
+    return Char - '0';\r
+  } else { // if not a hex value, return a negative value\r
+    return -1; \r
+  }\r
+}\r
+\r
+  // 'E' + the biggest error number is 255, so its 2 hex digits + buffer end\r
+CHAR8 *gError = "E__";\r
+\r
+/** 'E NN'\r
+ Send an error with the given error number after converting to hex.\r
+ The error number is put into the buffer in hex. '255' is the biggest errno we can send.\r
+ ex: 162 will be sent as A2.\r
\r
+ @param   errno           the error number that will be sent\r
+ **/\r
+VOID\r
+EFIAPI\r
+SendError (\r
+  IN  UINT8              ErrorNum\r
+  )\r
+{\r
+  //\r
+  // Replace _, or old data, with current errno\r
+  //\r
+  gError[1] = mHexToStr [ErrorNum >> 4];\r
+  gError[2] = mHexToStr [ErrorNum & 0x0f];\r
+    \r
+  SendPacket (gError); // send buffer\r
+}\r
+\r
+\r
+\r
+/**\r
+ Send 'OK' when the function is done executing successfully.\r
+ **/\r
+VOID\r
+EFIAPI\r
+SendSuccess (\r
+  VOID\r
+  ) \r
+{\r
+  SendPacket ("OK"); // send buffer\r
+}\r
+\r
+\r
+/**\r
+ Send empty packet to specify that particular command/functionality is not supported.\r
+ **/\r
+VOID        \r
+EFIAPI      \r
+SendNotSupported (\r
+  VOID          \r
+  )             \r
+{       \r
+  SendPacket ("");\r
+}\r
+\r
+\r
+\r
+/**\r
+ Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints\r
\r
+ @param  SystemContext        Register content at time of the exception\r
+ @param  GdbExceptionType     GDB exception type\r
+ **/\r
+VOID\r
+GdbSendTSignal (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINT8               GdbExceptionType\r
+  )\r
+{\r
+  CHAR8 TSignalBuffer[128];\r
+  CHAR8 *TSignalPtr;\r
+  UINTN BreakpointDetected;\r
+  BREAK_TYPE BreakType;\r
+  UINTN DataAddress;\r
+  CHAR8 *WatchStrPtr = NULL;\r
+  UINTN RegSize;\r
+\r
+  TSignalPtr = &TSignalBuffer[0];\r
+\r
+  //Construct TSignal packet\r
+  *TSignalPtr++ = 'T';\r
+\r
+  //\r
+  // replace _, or previous value, with Exception type\r
+  //\r
+  *TSignalPtr++ = mHexToStr [GdbExceptionType >> 4]; \r
+  *TSignalPtr++ = mHexToStr [GdbExceptionType & 0x0f];\r
+  \r
+  if (GdbExceptionType == GDB_SIGTRAP) {\r
+    if (gSymbolTableUpdate) {\r
+      //\r
+      // We can only send back on reason code. So if the flag is set it means the breakpoint is from our event handler\r
+      //\r
+      WatchStrPtr = "library:;";\r
+      while (*WatchStrPtr != '\0') {\r
+        *TSignalPtr++ = *WatchStrPtr++;\r
+      }\r
+      gSymbolTableUpdate = FALSE;\r
+    } else {\r
+\r
+\r
+      //\r
+      // possible n:r pairs\r
+      // \r
+\r
+      //Retrieve the breakpoint number\r
+      BreakpointDetected = GetBreakpointDetected (SystemContext);\r
+\r
+      //Figure out if the exception is happend due to watch, rwatch or awatch.\r
+      BreakType = GetBreakpointType (SystemContext, BreakpointDetected); \r
+\r
+      //INFO: rwatch is not supported due to the way IA32 debug registers work\r
+      if ((BreakType == DataWrite) || (BreakType == DataRead) || (BreakType == DataReadWrite)) {\r
+        \r
+        //Construct n:r pair\r
+        DataAddress = GetBreakpointDataAddress (SystemContext, BreakpointDetected);\r
+\r
+        //Assign appropriate buffer to print particular watchpoint type\r
+        if (BreakType == DataWrite) {\r
+          WatchStrPtr = "watch";\r
+        } else if (BreakType == DataRead) {\r
+          WatchStrPtr = "rwatch";\r
+        } else if (BreakType == DataReadWrite) {\r
+          WatchStrPtr = "awatch";\r
+        }\r
+\r
+        while (*WatchStrPtr != '\0') {\r
+          *TSignalPtr++ = *WatchStrPtr++;\r
+        }\r
+\r
+        *TSignalPtr++ = ':';\r
+        \r
+        //Set up series of bytes in big-endian byte order. "awatch" won't work with little-endian byte order.\r
+        RegSize = REG_SIZE;\r
+        while (RegSize > 0) {\r
+          RegSize = RegSize-4;\r
+          *TSignalPtr++ = mHexToStr[(UINT8)(DataAddress >> RegSize) & 0xf];\r
+        }\r
+\r
+        //Always end n:r pair with ';'\r
+        *TSignalPtr++ = ';';\r
+      }\r
+    }\r
+  }\r
+\r
+  *TSignalPtr = '\0';\r
+\r
+  SendPacket (TSignalBuffer); \r
+}\r
+\r
+\r
+/**\r
+ Translates the EFI mapping to GDB mapping\r
\r
+ @param   EFIExceptionType    EFI Exception that is being processed\r
+ @retval  UINTN that corresponds to EFIExceptionType's GDB exception type number\r
+ **/\r
+UINT8\r
+ConvertEFItoGDBtype ( \r
+  IN  EFI_EXCEPTION_TYPE      EFIExceptionType\r
+  )\r
+{ \r
+  UINTN i;\r
+  \r
+  for (i=0; i < MaxEfiException() ; i++) {\r
+    if (gExceptionType[i].Exception == EFIExceptionType) {\r
+      return gExceptionType[i].SignalNo;\r
+    }\r
+  }\r
+  return GDB_SIGTRAP; // this is a GDB trap\r
+}\r
+\r
+\r
+/** "m addr,length"\r
+ Find the Length of the area to read and the start addres. Finally, pass them to \r
+ another function, TransferFromMemToOutBufAndSend, that will read from that memory space and \r
+ send it as a packet.\r
+ **/\r
+\r
+VOID\r
+EFIAPI\r
+ReadFromMemory (\r
+  CHAR8 *PacketData\r
+  )\r
+{\r
+  UINTN Address;\r
+  UINTN Length;\r
+  CHAR8 AddressBuffer[MAX_ADDR_SIZE]; // the buffer that will hold the address in hex chars\r
+  CHAR8 *AddrBufPtr; // pointer to the address buffer\r
+  CHAR8 *InBufPtr; /// pointer to the input buffer\r
+  \r
+  AddrBufPtr = AddressBuffer;\r
+  InBufPtr = &PacketData[1];\r
+  while (*InBufPtr != ',') {\r
+    *AddrBufPtr++ = *InBufPtr++;\r
+  }\r
+  *AddrBufPtr = '\0';\r
+  \r
+  InBufPtr++; // this skips ',' in the buffer\r
+  \r
+  /* Error checking */\r
+  if (AsciiStrLen(AddressBuffer) >= MAX_ADDR_SIZE) {\r
+    Print((CHAR16 *)L"Address is too long\n");\r
+    SendError (GDB_EBADMEMADDRBUFSIZE); \r
+    return;\r
+  }\r
+  \r
+  // 2 = 'm' + ','\r
+  if (AsciiStrLen(PacketData) - AsciiStrLen(AddressBuffer) - 2 >= MAX_LENGTH_SIZE) {\r
+    Print((CHAR16 *)L"Length is too long\n");\r
+    SendError (GDB_EBADMEMLENGTH); \r
+    return;\r
+  }\r
+  \r
+  Address = AsciiStrHexToUintn (AddressBuffer);\r
+  Length = AsciiStrHexToUintn (InBufPtr);\r
+  \r
+  TransferFromMemToOutBufAndSend (Length, (unsigned char *)Address);\r
+}\r
+\r
+\r
+/** "M addr,length :XX..."\r
+ Find the Length of the area in bytes to write and the start addres. Finally, pass them to \r
+ another function, TransferFromInBufToMem, that will write to that memory space the info in\r
+ the input buffer.\r
+ **/\r
+VOID\r
+EFIAPI\r
+WriteToMemory (\r
+  IN CHAR8 *PacketData\r
+  )\r
+{\r
+  UINTN Address;\r
+  UINTN Length;\r
+  UINTN MessageLength;\r
+  CHAR8 AddressBuffer[MAX_ADDR_SIZE]; // the buffer that will hold the Address in hex chars\r
+  CHAR8 LengthBuffer[MAX_LENGTH_SIZE]; // the buffer that will hold the Length in hex chars\r
+  CHAR8 *AddrBufPtr; // pointer to the Address buffer\r
+  CHAR8 *LengthBufPtr; // pointer to the Length buffer\r
+  CHAR8 *InBufPtr; /// pointer to the input buffer\r
+  \r
+  AddrBufPtr = AddressBuffer;\r
+  LengthBufPtr = LengthBuffer;\r
+  InBufPtr = &PacketData[1];\r
+  \r
+  while (*InBufPtr != ',') {\r
+    *AddrBufPtr++ = *InBufPtr++;\r
+  }\r
+  *AddrBufPtr = '\0';\r
+  \r
+  InBufPtr++; // this skips ',' in the buffer\r
+  \r
+  while (*InBufPtr != ':') {\r
+    *LengthBufPtr++ = *InBufPtr++;\r
+  }\r
+  *LengthBufPtr = '\0';\r
+  \r
+  InBufPtr++; // this skips ':' in the buffer\r
+  \r
+  Address = AsciiStrHexToUintn (AddressBuffer);\r
+  Length = AsciiStrHexToUintn (LengthBuffer);\r
+  \r
+  /* Error checking */\r
+  \r
+  //Check if Address is not too long.\r
+  if (AsciiStrLen(AddressBuffer) >= MAX_ADDR_SIZE) {\r
+    Print ((CHAR16 *)L"Address too long..\n");\r
+    SendError (GDB_EBADMEMADDRBUFSIZE); \r
+    return;\r
+  }\r
+  \r
+  //Check if message length is not too long\r
+  if (AsciiStrLen(LengthBuffer) >= MAX_LENGTH_SIZE) {\r
+    Print ((CHAR16 *)L"Length too long..\n");\r
+    SendError (GDB_EBADMEMLENGBUFSIZE); \r
+    return;\r
+  }\r
+  \r
+  // Check if Message is not too long/short.\r
+  // 3 = 'M' + ',' + ':'\r
+  MessageLength = (AsciiStrLen(PacketData) - AsciiStrLen(AddressBuffer) - AsciiStrLen(LengthBuffer) - 3);\r
+  if (MessageLength != (2*Length)) {\r
+    //Message too long/short. New data is not the right size.\r
+    SendError (GDB_EBADMEMDATASIZE);   \r
+    return;\r
+  }\r
+  TransferFromInBufToMem (Length, (unsigned char *)Address, InBufPtr);\r
+}\r
+\r
+/**\r
+  Parses breakpoint packet data and captures Breakpoint type, Address and length.\r
+  In case of an error, function returns particular error code. Returning 0 meaning\r
+  no error.\r
+\r
+  @param  PacketData  Pointer to the payload data for the packet.\r
+  @param  Type        Breakpoint type\r
+  @param  Address     Breakpoint address\r
+  @param  Length      Breakpoint length in Bytes (1 byte, 2 byte, 4 byte)\r
+\r
+  @retval 1           Success\r
+  @retval {other}     Particular error code\r
+\r
+**/\r
+UINTN\r
+ParseBreakpointPacket (\r
+  IN  CHAR8 *PacketData,\r
+  OUT UINTN *Type,\r
+  OUT UINTN *Address,\r
+  OUT UINTN *Length\r
+  )\r
+{\r
+  CHAR8 AddressBuffer[MAX_ADDR_SIZE];\r
+  CHAR8 *AddressBufferPtr;\r
+  CHAR8 *PacketDataPtr;\r
+\r
+  PacketDataPtr = &PacketData[1];\r
+  AddressBufferPtr = AddressBuffer;\r
+\r
+  *Type = AsciiStrHexToUintn (PacketDataPtr);\r
+\r
+  //Breakpoint/watchpoint type should be between 0 to 4\r
+  if (*Type > 4) {\r
+    Print ((CHAR16 *)L"Type is invalid\n");\r
+    return 22; //EINVAL: Invalid argument.\r
+  }\r
+\r
+  //Skip ',' in the buffer.\r
+  while (*PacketDataPtr++ != ',');\r
+\r
+  //Parse Address information\r
+  while (*PacketDataPtr != ',') {\r
+    *AddressBufferPtr++ = *PacketDataPtr++;\r
+  }\r
+  *AddressBufferPtr = '\0';\r
+\r
+  //Check if Address is not too long.\r
+  if (AsciiStrLen(AddressBuffer) >= MAX_ADDR_SIZE) {\r
+    Print ((CHAR16 *)L"Address too long..\n");\r
+    return 40; //EMSGSIZE: Message size too long.\r
+  }\r
+\r
+  *Address = AsciiStrHexToUintn (AddressBuffer);\r
+\r
+  PacketDataPtr++; //This skips , in the buffer\r
+\r
+  //Parse Length information\r
+  *Length = AsciiStrHexToUintn (PacketDataPtr);\r
+\r
+  //Length should be 1, 2 or 4 bytes\r
+  if (*Length > 4) {\r
+    Print ((CHAR16 *)L"Length is invalid\n");\r
+    return 22; //EINVAL: Invalid argument\r
+  }\r
+\r
+  return 0; //0 = No error\r
+}\r
+\r
+UINTN\r
+gXferObjectReadResponse (\r
+  IN  CHAR8         Type,\r
+  IN  CHAR8         *Str\r
+  )\r
+{\r
+  CHAR8   *OutBufPtr;             // pointer to the output buffer\r
+  CHAR8   Char;\r
+  UINTN   Count;\r
+\r
+  // responce starts with 'm' or 'l' if it is the end\r
+  OutBufPtr = gOutBuffer;\r
+  *OutBufPtr++ = Type;\r
+  Count = 1;\r
+\r
+  // Binary data encoding \r
+  OutBufPtr = gOutBuffer;\r
+  while (*Str != '\0') {\r
+    Char = *Str++;\r
+    if ((Char == 0x7d) || (Char == 0x23) || (Char == 0x24) || (Char == 0x2a)) {\r
+      // escape character\r
+      *OutBufPtr++ = 0x7d;\r
+\r
+      Char ^= 0x20;\r
+    }\r
+    *OutBufPtr++ = Char;\r
+    Count++;\r
+  }\r
+\r
+  *OutBufPtr = '\0' ;  // the end of the buffer\r
+  SendPacket (gOutBuffer);\r
+  \r
+  return Count;\r
+}\r
+\r
+\r
+/**\r
+  Note: This should be a library function.  In the Apple case you have to add \r
+  the size of the PE/COFF header into the starting address to make things work \r
+  right as there is no way to pad the Mach-O for the size of the PE/COFF header.\r
+  \r
+  \r
+  Returns a pointer to the PDB file name for a PE/COFF image that has been\r
+  loaded into system memory with the PE/COFF Loader Library functions.\r
+\r
+  Returns the PDB file name for the PE/COFF image specified by Pe32Data.  If\r
+  the PE/COFF image specified by Pe32Data is not a valid, then NULL is\r
+  returned.  If the PE/COFF image specified by Pe32Data does not contain a\r
+  debug directory entry, then NULL is returned.  If the debug directory entry\r
+  in the PE/COFF image specified by Pe32Data does not contain a PDB file name,\r
+  then NULL is returned.\r
+  If Pe32Data is NULL, then ASSERT().\r
+\r
+  @param  Pe32Data   Pointer to the PE/COFF image that is loaded in system\r
+                     memory.\r
+  @param  DebugBase  Address that the debugger would use as the base of the image\r
+\r
+  @return The PDB file name for the PE/COFF image specified by Pe32Data or NULL\r
+          if it cannot be retrieved. DebugBase is only valid if PDB file name is\r
+          valid. \r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+PeCoffLoaderGetDebuggerInfo (\r
+  IN VOID     *Pe32Data,\r
+  OUT VOID    **DebugBase\r
+  )\r
+{\r
+  EFI_IMAGE_DOS_HEADER                  *DosHdr;\r
+  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION   Hdr;\r
+  EFI_IMAGE_DATA_DIRECTORY              *DirectoryEntry;\r
+  EFI_IMAGE_DEBUG_DIRECTORY_ENTRY       *DebugEntry;\r
+  UINTN                                 DirCount;\r
+  VOID                                  *CodeViewEntryPointer;\r
+  INTN                                  TEImageAdjust;\r
+  UINT32                                NumberOfRvaAndSizes;\r
+  UINT16                                Magic;\r
+  UINTN                                 SizeOfHeaders;\r
+\r
+  ASSERT (Pe32Data   != NULL);\r
+\r
+  TEImageAdjust       = 0;\r
+  DirectoryEntry      = NULL;\r
+  DebugEntry          = NULL;\r
+  NumberOfRvaAndSizes = 0;\r
+  SizeOfHeaders       = 0;\r
+\r
+  DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
+  if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
+    //\r
+    // DOS image header is present, so read the PE header after the DOS image header.\r
+    //\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
+  } else {\r
+    //\r
+    // DOS image header is not present, so PE header is at the image base.\r
+    //\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
+  }\r
+\r
+  if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
+    if (Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress != 0) {\r
+      DirectoryEntry  = &Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG];\r
+      TEImageAdjust   = sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize;\r
+      DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN) Hdr.Te +\r
+                    Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +\r
+                    TEImageAdjust);\r
+    }\r
+    SizeOfHeaders = sizeof (EFI_TE_IMAGE_HEADER) + (UINTN)Hdr.Te->BaseOfCode - (UINTN)Hdr.Te->StrippedSize;\r
+    \r
+    // __APPLE__ check this math...\r
+    *DebugBase = ((CHAR8 *)Pe32Data) -  TEImageAdjust;\r
+  } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
+    \r
+    *DebugBase = Pe32Data;\r
+    \r
+    \r
+    //\r
+    // NOTE: We use Machine field to identify PE32/PE32+, instead of Magic.\r
+    //       It is due to backward-compatibility, for some system might\r
+    //       generate PE32+ image with PE32 Magic.\r
+    //\r
+    switch (Hdr.Pe32->FileHeader.Machine) {\r
+    case EFI_IMAGE_MACHINE_IA32:\r
+      //\r
+      // Assume PE32 image with IA32 Machine field.\r
+      //\r
+      Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;\r
+      break;\r
+    case EFI_IMAGE_MACHINE_X64:\r
+    case EFI_IMAGE_MACHINE_IA64:\r
+      //\r
+      // Assume PE32+ image with X64 or IPF Machine field\r
+      //\r
+      Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;\r
+      break;\r
+    default:\r
+      //\r
+      // For unknow Machine field, use Magic in optional Header\r
+      //\r
+      Magic = Hdr.Pe32->OptionalHeader.Magic;\r
+    }\r
+\r
+    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+      //\r
+      // Use PE32 offset get Debug Directory Entry\r
+      //\r
+      SizeOfHeaders = Hdr.Pe32->OptionalHeader.SizeOfHeaders;\r
+      NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;\r
+      DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
+      DebugEntry     = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);\r
+    } else if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
+      //\r
+      // Use PE32+ offset get Debug Directory Entry\r
+      //\r
+      SizeOfHeaders = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders;\r
+      NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;\r
+      DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
+      DebugEntry     = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);\r
+    }\r
+\r
+    if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {\r
+      DirectoryEntry = NULL;\r
+      DebugEntry = NULL;\r
+    }\r
+  } else {\r
+    return NULL;\r
+  }\r
+\r
+  if (DebugEntry == NULL || DirectoryEntry == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY), DebugEntry++) {\r
+    if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {\r
+      if (DebugEntry->SizeOfData > 0) {\r
+        CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + ((UINTN)Pe32Data) + (UINTN)TEImageAdjust);\r
+        switch (* (UINT32 *) CodeViewEntryPointer) {\r
+        case CODEVIEW_SIGNATURE_NB10:\r
+          return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY));\r
+        case CODEVIEW_SIGNATURE_RSDS:\r
+          return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY));\r
+        case CODEVIEW_SIGNATURE_MTOC:\r
+          *DebugBase = (VOID *)(UINTN)((UINTN)DebugBase - SizeOfHeaders);\r
+          return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY));\r
+        default:\r
+          break;\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  (void)SizeOfHeaders;\r
+  return NULL;\r
+}\r
+\r
+\r
+\r
+/** \r
+  Process "qXfer:object:read:annex:offset,length" request.\r
+  \r
+  Returns an XML document that contains loaded libraries. In our case it is \r
+  infomration in the EFI Debug Inmage Table converted into an XML document.\r
+  \r
+  GDB will call with an arbitrary length (it can't know the real length and \r
+  will reply with chunks of XML that are easy for us to deal with. Gdb will \r
+  keep calling until we say we are done. XML doc looks like:\r
+  \r
+  <library-list>\r
+    <library name="/a/a/c/d.dSYM"><segment address="0x10000000"/></library>\r
+    <library name="/a/m/e/e.pdb"><segment address="0x20000000"/></library>\r
+    <library name="/a/l/f/f.dll"><segment address="0x30000000"/></library>\r
+  </library-list>\r
+  \r
+  Since we can not allocate memory in interupt context this module has \r
+  assumptions about how it will get called:\r
+  1) Length will generally be max remote packet size (big enough)\r
+  2) First Offset of an XML document read needs to be 0\r
+  3) This code will return back small chunks of the XML document on every read.\r
+     Each subseqent call will ask for the next availble part of the document.\r
+     \r
+  Note: The only variable size element in the XML is:\r
+  "  <library name=\"%s\"><segment address=\"%p\"/></library>\n" and it is \r
+  based on the file path and name of the symbol file. If the symbol file name\r
+  is bigger than the max gdb remote packet size we could update this code\r
+  to respond back in chunks.\r
+\r
+ @param Offset  offset into special data area\r
+ @param Length  number of bytes to read starting at Offset  \r
+  \r
+ **/\r
+VOID\r
+QxferLibrary (\r
+  IN  UINTN   Offset,\r
+  IN  UINTN   Length\r
+  )\r
+{\r
+  VOID                              *LoadAddress;\r
+  CHAR8                             *Pdb;\r
+  UINTN                             Size;\r
+\r
+  if (Offset != gPacketqXferLibraryOffset) {\r
+    SendError (GDB_EINVALIDARG);\r
+    Print (L"\nqXferLibrary (%d, %d) != %d\n", Offset, Length, gPacketqXferLibraryOffset);\r
+    \r
+    // Force a retry from the beginning \r
+    gPacketqXferLibraryOffset = 0;\r
+    return;\r
+  }\r
+\r
+  if (Offset == 0) {\r
+    gPacketqXferLibraryOffset += gXferObjectReadResponse ('m', "<library-list>\n");\r
+    \r
+    // The owner of the table may have had to ralloc it so grab a fresh copy every time\r
+    // we assume qXferLibrary will get called over and over again until the entire XML table is \r
+    // returned in a tight loop. Since we are in the debugger the table should not get updated\r
+    gDebugTable = gDebugImageTableHeader->EfiDebugImageInfoTable;\r
+    gEfiDebugImageTableEntry = 0;\r
+    return;\r
+  }\r
+  \r
+  if (gDebugTable != NULL) {\r
+    for (; gEfiDebugImageTableEntry < gDebugImageTableHeader->TableSize; gEfiDebugImageTableEntry++, gDebugTable++) {\r
+      if (gDebugTable->NormalImage != NULL) {\r
+        if ((gDebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) && \r
+            (gDebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) {\r
+          Pdb = PeCoffLoaderGetDebuggerInfo (\r
+                 gDebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase, \r
+                 &LoadAddress\r
+                 );\r
+          if (Pdb != NULL) {\r
+            Size = AsciiSPrint (\r
+                    gXferLibraryBuffer, \r
+                    sizeof (gXferLibraryBuffer), \r
+                    "  <library name=\"%a\"><segment address=\"0x%p\"/></library>\n", \r
+                    Pdb,\r
+                    LoadAddress\r
+                    );\r
+            if ((Size != 0) && (Size != (sizeof (gXferLibraryBuffer) - 1))) {\r
+              gPacketqXferLibraryOffset += gXferObjectReadResponse ('m', gXferLibraryBuffer);\r
+              \r
+              // Update loop variables so we are in the right place when we get back\r
+              gEfiDebugImageTableEntry++;\r
+              gDebugTable++;\r
+              return;\r
+            } else {\r
+              // We could handle <library> entires larger than sizeof (gXferLibraryBuffer) here if \r
+              // needed by breaking up into N packets\r
+              // "<library name=\"%s\r
+              // the rest of the string (as many packets as required\r
+              // \"><segment address=\"%d\"/></library> (fixed size)\r
+              //\r
+              // But right now we just skip any entry that is too big\r
+            }\r
+          }           \r
+        }\r
+      }  \r
+    }\r
+  }\r
+  \r
+  \r
+  gXferObjectReadResponse ('l', "</library-list>\n");\r
+  gPacketqXferLibraryOffset = 0;\r
+  return;\r
+}\r
+\r
+\r
+/**\r
+ Exception Hanldler for GDB. It will be called for all exceptions\r
+ registered via the gExceptionType[] array.\r
\r
+ @param ExceptionType     Exception that is being processed\r
+ @param SystemContext     Register content at time of the exception  \r
+ **/\r
+VOID\r
+EFIAPI\r
+GdbExceptionHandler ( \r
+  IN  EFI_EXCEPTION_TYPE        ExceptionType, \r
+  IN OUT EFI_SYSTEM_CONTEXT     SystemContext \r
+  )\r
+{\r
+  UINT8   GdbExceptionType;\r
+  CHAR8   *Ptr;\r
+      \r
+  \r
+  if (ValidateException(ExceptionType, SystemContext) == FALSE) {\r
+    return;\r
+  }\r
+\r
+  RemoveSingleStep (SystemContext);\r
+  \r
+  GdbExceptionType = ConvertEFItoGDBtype (ExceptionType);\r
+  GdbSendTSignal (SystemContext, GdbExceptionType);\r
+  \r
+  for( ; ; ) {\r
+    ReceivePacket (gInBuffer, MAX_BUF_SIZE);\r
+    \r
+    switch (gInBuffer[0]) {\r
+      case '?':\r
+        GdbSendTSignal (SystemContext, GdbExceptionType);\r
+        break;\r
+          \r
+      case 'c':\r
+        ContinueAtAddress (SystemContext, gInBuffer);          \r
+        return;\r
+\r
+      case 'g':\r
+        ReadGeneralRegisters (SystemContext);\r
+        break;\r
+          \r
+      case 'G':\r
+        WriteGeneralRegisters (SystemContext, gInBuffer);\r
+        break;\r
+          \r
+      case 'H':\r
+        //Return "OK" packet since we don't have more than one thread. \r
+        SendSuccess ();\r
+        break;\r
+          \r
+      case 'm':\r
+        ReadFromMemory (gInBuffer);\r
+        break;\r
+\r
+      case 'M':\r
+        WriteToMemory (gInBuffer);\r
+        break;\r
+\r
+      case 'P':\r
+        WriteNthRegister (SystemContext, gInBuffer);\r
+        break;\r
+\r
+      //\r
+      // Still debugging this code. Not used in Darwin\r
+      //\r
+      case 'q': \r
+        // General Query Packets\r
+        if (AsciiStrnCmp (gInBuffer, "qSupported", 10) == 0) {\r
+          // return what we currently support, we don't parse what gdb suports\r
+          AsciiSPrint (gOutBuffer, MAX_BUF_SIZE, "qXfer:libraries:read+;PacketSize=%d", MAX_BUF_SIZE);\r
+          SendPacket (gOutBuffer);\r
+        } else if (AsciiStrnCmp (gInBuffer, "qXfer:libraries:read::", 22) == 0) {\r
+          // â€˜qXfer:libraries:read::offset,length\r
+          // gInBuffer[22] is offset string, ++Ptr is length string’\r
+          for (Ptr = &gInBuffer[22]; *Ptr != ','; Ptr++);\r
+        \r
+          // Not sure if multi-radix support is required. Currently only support decimal\r
+          QxferLibrary (AsciiStrHexToUintn (&gInBuffer[22]), AsciiStrHexToUintn (++Ptr));\r
+        } if (AsciiStrnCmp (gInBuffer, "qOffsets", 10) == 0) {\r
+          AsciiSPrint (gOutBuffer, MAX_BUF_SIZE, "Text=1000;Data=f000;Bss=f000");\r
+          SendPacket (gOutBuffer);\r
+        } else {\r
+          //Send empty packet\r
+          SendNotSupported ();\r
+        }\r
+        break;\r
+\r
+      case 's':\r
+        SingleStep (SystemContext, gInBuffer);          \r
+        return;\r
+          \r
+      case 'z':\r
+        RemoveBreakPoint (SystemContext, gInBuffer);\r
+        break;\r
+  \r
+      case 'Z':\r
+        InsertBreakPoint (SystemContext, gInBuffer);\r
+        break;\r
+                  \r
+      default:  \r
+        //Send empty packet\r
+        SendNotSupported ();\r
+        break;\r
+    }\r
+  }\r
+}\r
+\r
+\r
+/**\r
+ Periodic callback for GDB. This function is used to catch a ctrl-c or other \r
+ break in type command from GDB.\r
\r
+ @param SystemContext     Register content at time of the call  \r
+ **/\r
+VOID\r
+EFIAPI\r
+GdbPeriodicCallBack ( \r
+  IN OUT EFI_SYSTEM_CONTEXT     SystemContext \r
+  )\r
+{\r
+  //\r
+  // gCtrlCBreakFlag may have been set from a previous F response package \r
+  // and we set the global as we need to process it at a point where we \r
+  // can update the system context. If we are in the middle of processing\r
+  // a F Packet it is not safe to read the GDB serial stream so we need\r
+  // to skip it on this check\r
+  //\r
+  if (!gCtrlCBreakFlag && !gProcessingFPacket) {\r
+    //\r
+    // Ctrl-C was not pending so grab any pending characters and see if they \r
+    // are a Ctrl-c (0x03). If so set the Ctrl-C global. \r
+    //\r
+    while (TRUE) {\r
+      if (!GdbIsCharAvailable ()) {\r
+        //\r
+        // No characters are pending so exit the loop\r
+        //\r
+        break;\r
+      }\r
+      \r
+      if (GdbGetChar () == 0x03) {\r
+        gCtrlCBreakFlag = TRUE;\r
+        //\r
+        // We have a ctrl-c so exit the loop\r
+        //\r
+        break;\r
+      }\r
+    }\r
+  }\r
+  \r
+  if (gCtrlCBreakFlag) {\r
+    //\r
+    // Update the context to force a single step trap when we exit the GDB\r
+    // stub. This will trasfer control to GdbExceptionHandler () and let\r
+    // us break into the program. We don't want to break into the GDB stub.\r
+    //\r
+    AddSingleStep (SystemContext);\r
+    gCtrlCBreakFlag = FALSE;\r
+  }\r
+}\r
index ac04d7b9a53bd9e6f66e475168a9fda3f6b0334d..5f15420f02e8852aef2c4d21d7c2e7c96a42bd92 100644 (file)
-/** @file
-  Private include file for GDB stub
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __GDB_STUB_INTERNAL__
-#define __GDB_STUB_INTERNAL__
-
-#include <Uefi.h>
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/DebugLib.h>
-#include <Library/UefiLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/PcdLib.h>
-#include <Library/GdbSerialLib.h>
-#include <Library/PrintLib.h>
-
-#include <Protocol/DebugSupport.h>
-#include <Protocol/SerialIo.h>
-#include <Protocol/LoadedImage.h>
-#include <Protocol/LoadedImage.h>
-#include <Guid/DebugImageInfoTable.h>
-#include <IndustryStandard/PeImage.h>
-
-extern CONST CHAR8 mHexToStr[];
-
-// maximum size of input and output buffers
-// This value came from the show remote command of the gdb we tested against 
-#define MAX_BUF_SIZE 2000
-
-// maximum size of address buffer
-#define MAX_ADDR_SIZE 32
-
-// maximum size of register number buffer
-#define MAX_REG_NUM_BUF_SIZE 32
-
-// maximum size of length buffer
-#define MAX_LENGTH_SIZE 32
-
-// maximum size of T signal members
-#define MAX_T_SIGNAL_SIZE 64
-
-// the mask used to clear all the cache
-#define TF_BIT 0x00000100
-
-
-//
-// GDB Signal definitions - generic names for interrupts
-//
-#define GDB_SIGILL      4  // Illegal instruction       
-#define GDB_SIGTRAP     5  // Trace Trap (Breakpoint and SingleStep)
-#define GDB_SIGEMT      7  // Emulator Trap
-#define GDB_SIGFPE      8  // Floating point exception
-#define GDB_SIGSEGV     11 // Setgment violation, page fault 
-
-
-//
-// GDB File I/O Error values, zero means no error
-// Includes all general GDB Unix like error values
-//
-#define GDB_EBADMEMADDRBUFSIZE   11  // the buffer that stores memory Address to be read from/written to is not the right size
-#define GDB_EBADMEMLENGBUFSIZE   12  // the buffer that stores Length is not the right size 
-#define GDB_EBADMEMLENGTH        13  // Length, the given number of bytes to read or write, is not the right size
-#define GDB_EBADMEMDATA          14  // one of the bytes or nibbles of the memory is leess than 0 
-#define GDB_EBADMEMDATASIZE      15  // the memory data, 'XX..', is too short or too long
-#define GDB_EBADBUFSIZE          21  // the buffer created is not the correct size
-#define GDB_EINVALIDARG          31  // argument is invalid
-#define GDB_ENOSPACE             41  //
-#define GDB_EINVALIDBRKPOINTTYPE 51  // the breakpoint type is not recognized
-#define GDB_EINVALIDREGNUM       61  // given register number is not valid: either <0 or >=Number of Registers
-#define GDB_EUNKNOWN             255 // unknown
-
-
-//
-// These devices are open by GDB so we can just read and write to them
-//
-#define GDB_STDIN   0x00
-#define GDB_STDOUT  0x01
-#define GDB_STDERR  0x02
-
-//
-//Define Register size for different architectures
-//
-#if defined (MDE_CPU_IA32) 
-#define REG_SIZE  32
-#elif defined (MDE_CPU_X64)
-#define REG_SIZE  64
-#elif defined (MDE_CPU_ARM)
-#define REG_SIZE  32
-#endif
-
-#define GDB_SERIAL_DEV_SIGNATURE    SIGNATURE_32 ('g', 'd', 'b', 's')
-
-typedef struct {
-  VENDOR_DEVICE_PATH                     VendorDevice;
-  UINT32                                 Index;         // Suport more than one
-  EFI_DEVICE_PATH_PROTOCOL               End;
-} GDB_SERIAL_DEVICE_PATH;
-
-//
-//  Name:   SERIAL_DEV
-//  Purpose:  To provide device specific information
-//  Fields:
-//      Signature UINTN: The identity of the serial device
-//      SerialIo  SERIAL_IO_PROTOCOL: Serial I/O protocol interface
-//      SerialMode  SERIAL_IO_MODE:
-//      DevicePath  EFI_DEVICE_PATH_PROTOCOL *: Device path of the serial device
-//
-typedef struct {
-  UINTN                                  Signature;
-  EFI_HANDLE                             Handle;
-  EFI_SERIAL_IO_PROTOCOL                 SerialIo;
-  EFI_SERIAL_IO_MODE                     SerialMode;
-  GDB_SERIAL_DEVICE_PATH                 DevicePath;
-  INTN                                   InFileDescriptor;
-  INTN                                   OutFileDescriptor;
-} GDB_SERIAL_DEV;
-
-
-#define GDB_SERIAL_DEV_FROM_THIS(a) CR (a, GDB_SERIAL_DEV, SerialIo, GDB_SERIAL_DEV_SIGNATURE)
-
-
-typedef struct {
-    EFI_EXCEPTION_TYPE  Exception;
-    UINT8               SignalNo;
-} EFI_EXCEPTION_TYPE_ENTRY;
-
-
-#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
-
-//
-// Byte packed structure for DR6
-// 32-bits on IA-32
-// 64-bits on X64.  The upper 32-bits on X64 are reserved
-//
-typedef union {
-  struct {
-    UINT32  B0:1;           // Breakpoint condition detected
-    UINT32  B1:1;           // Breakpoint condition detected
-    UINT32  B2:1;           // Breakpoint condition detected
-    UINT32  B3:1;           // Breakpoint condition detected
-    UINT32  Reserved_1:9;   // Reserved 
-    UINT32  BD:1;           // Debug register access detected
-    UINT32  BS:1;           // Single step
-    UINT32  BT:1;           // Task switch
-    UINT32  Reserved_2:16;  // Reserved
-  } Bits;
-  UINTN     UintN;
-} IA32_DR6;
-
-//
-// Byte packed structure for DR7
-// 32-bits on IA-32
-// 64-bits on X64.  The upper 32-bits on X64 are reserved
-//
-typedef union {
-  struct {
-    UINT32  L0:1;           // Local breakpoint enable
-    UINT32  G0:1;           // Global breakpoint enable
-    UINT32  L1:1;           // Local breakpoint enable
-    UINT32  G1:1;           // Global breakpoint enable
-    UINT32  L2:1;           // Local breakpoint enable
-    UINT32  G2:1;           // Global breakpoint enable
-    UINT32  L3:1;           // Local breakpoint enable
-    UINT32  G3:1;           // Global breakpoint enable
-    UINT32  LE:1;           // Local exact breakpoint enable
-    UINT32  GE:1;           // Global exact breakpoint enable
-    UINT32  Reserved_1:3;   // Reserved
-    UINT32  GD:1;           // Global detect enable
-    UINT32  Reserved_2:2;   // Reserved
-    UINT32  RW0:2;          // Read/Write field
-    UINT32  LEN0:2;         // Length field
-    UINT32  RW1:2;          // Read/Write field
-    UINT32  LEN1:2;         // Length field
-    UINT32  RW2:2;          // Read/Write field
-    UINT32  LEN2:2;         // Length field
-    UINT32  RW3:2;          // Read/Write field
-    UINT32  LEN3:2;         // Length field
-  } Bits;
-  UINTN     UintN;
-} IA32_DR7;
-
-#endif /* if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) */
-
-typedef enum {
-  InstructionExecution,   //Hardware breakpoint
-  DataWrite,              //watch
-  DataRead,               //rwatch
-  DataReadWrite,          //awatch
-  SoftwareBreakpoint,     //Software breakpoint
-  NotSupported
-} BREAK_TYPE;
-
-//
-// Array of exception types that need to be hooked by the debugger
-//
-extern EFI_EXCEPTION_TYPE_ENTRY gExceptionType[];
-
-//
-// Set TRUE if F Reply package signals a ctrl-c. We can not process the Ctrl-c
-// here we need to wait for the periodic callback to do this. 
-//
-extern BOOLEAN gCtrlCBreakFlag;
-
-//
-// If the periodic callback is called while we are processing an F packet we need
-// to let the callback know to not read from the serail stream as it could steal
-// characters from the F reponse packet
-//
-extern BOOLEAN gProcessingFPacket;
-
-
-// The offsets of registers SystemContext.
-// The fields in the array are in the gdb ordering.
-//
-extern UINTN    gRegisterOffsets[];
-
-/**
- Return the number of entries in the gExceptionType[]
- @retval    UINTN, the number of entries in the gExceptionType[] array.    
- **/
-UINTN
-MaxEfiException (
-  VOID
-  );
-
-
-/**
- Return the number of entries in the gRegisters[]
- @retval    UINTN, the number of entries (registers) in the gRegisters[] array.    
- **/
-UINTN
-MaxRegisterCount (
-  VOID
-  );
-
-
-/**
- Check to see if the ISA is supported. 
- ISA = Instruction Set Architecture
- @retval    TRUE if Isa is supported,
- FALSE otherwise.
- **/
-BOOLEAN
-CheckIsa (
-  IN    EFI_INSTRUCTION_SET_ARCHITECTURE    Isa
-  );
-
-
-/**
- Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints
- @param  SystemContext        Register content at time of the exception
- @param  GdbExceptionType     GDB exception type
- **/
-
-VOID
-GdbSendTSignal (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINT8                  GdbExceptionType
-  );
-
-
-/**
- Translates the EFI mapping to GDB mapping
- @param     EFIExceptionType        EFI Exception that is being processed
- @retval    UINTN that corresponds to EFIExceptionType's GDB exception type number
- **/
-UINT8
-ConvertEFItoGDBtype ( 
-  IN  EFI_EXCEPTION_TYPE EFIExceptionType
-  );
-
-
-/**
- Empties the given buffer 
- @param *Buf pointer to the first element in buffer to be emptied
- **/
-VOID
-EmptyBuffer ( 
-  IN CHAR8  *Buf
-  );
-
-
-/**
- Converts an 8-bit Hex Char into a INTN.
- @param     Char  - the hex character to be converted into UINTN
- @retval    a INTN, from 0 to 15, that corressponds to Char
- -1 if Char is not a hex character
- **/
-INTN
-HexCharToInt (
-  IN  CHAR8 Char
-  );
-
-
-/** 'E NN'
- Send an error with the given error number after converting to hex.
- The error number is put into the buffer in hex. '255' is the biggest errno we can send.
- ex: 162 will be sent as A2.
- @param   errno    the error number that will be sent
- **/
-VOID
-EFIAPI
-SendError (
-  IN  UINT8     ErrorNum
-  );
-
-
-/**
- Send 'OK' when the function is done executing successfully.
- **/
-VOID
-SendSuccess (
-  VOID
-  );
-
-
-/**
- Send empty packet to specify that particular command/functionality is not supported.
- **/
-VOID
-SendNotSupported (
-  VOID
-  );
-
-/** â€˜p n’ 
- Reads the n-th register's value into an output buffer and sends it as a packet 
- @param     SystemContext       Register content at time of the exception
- @param     InBuffer            This is the input buffer received from gdb server
- **/
-VOID
-ReadNthRegister (
-  IN    EFI_SYSTEM_CONTEXT  SystemContext,
-  IN    CHAR8               *InBuffer
-  );
-
-
-/** â€˜g’ 
- Reads the general registers into an output buffer  and sends it as a packet 
- @param     SystemContext           Register content at time of the exception
- **/
-VOID
-ReadGeneralRegisters (  
-  IN    EFI_SYSTEM_CONTEXT  SystemContext
-  );
-
-
-/** â€˜P n...=r...’
- Writes the new value of n-th register received into the input buffer to the n-th register
- @param     SystemContext       Register content at time of the exception
- @param     InBuffer            This is the input buffer received from gdb server
- **/
-VOID
-WriteNthRegister (
-  IN    EFI_SYSTEM_CONTEXT  SystemContext,
-  IN    CHAR8               *InBuffer
-  );
-
-
-/** â€˜G XX...’
- Writes the new values received into the input buffer to the general registers
- @param     SystemContext               Register content at time of the exception
- @param     InBuffer                    Pointer to the input buffer received from gdb server
- **/
-
-VOID
-WriteGeneralRegisters (
-  IN    EFI_SYSTEM_CONTEXT  SystemContext,
-  IN    CHAR8               *InBuffer
-  );
-
-
-/** â€˜m addr,length â€™
- Find the Length of the area to read and the start addres. Finally, pass them to 
- another function, TransferFromMemToOutBufAndSend, that will read from that memory space and 
- send it as a packet.
- @param  *PacketData  Pointer to Payload data for the packet
- **/
-VOID
-ReadFromMemory (
-  IN  CHAR8  *PacketData
-  );
-
-
-/** â€˜M addr,length :XX...’
- Find the Length of the area in bytes to write and the start addres. Finally, pass them to 
- another function, TransferFromInBufToMem, that will write to that memory space the info in
- the input buffer.
- @param   PacketData     Pointer to Payload data for the packet
- **/
-VOID
-WriteToMemory (
-  IN CHAR8 *PacketData
-  );
-
-
-/** â€˜c [addr ]’ 
- Continue. addr is Address to resume. If addr is omitted, resume at current 
- Address.
- @param SystemContext Register content at time of the exception  
- @param *PacketData   Pointer to PacketData
- **/
-
-VOID
-ContinueAtAddress (
-  IN  EFI_SYSTEM_CONTEXT   SystemContext,
-  IN  CHAR8                *PacketData
-  );
-
-
-/** â€˜s [addr ]’
- Single step. addr is the Address at which to resume. If addr is omitted, resume 
- at same Address.
- @param SystemContext   Register content at time of the exception
- @param PacketData      Pointer to Payload data for the packet
- **/
-VOID
-SingleStep (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  CHAR8               *PacketData
-  );
-
-/** 
- Insert Single Step in the SystemContext
- @param SystemContext   Register content at time of the exception
- **/
-VOID
-AddSingleStep (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext
-  );
-  
-/** 
- Remove Single Step in the SystemContext
- @param SystemContext   Register content at time of the exception
- **/
-VOID
-RemoveSingleStep (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext
-  );
-  
-  
-/**
-  â€˜Z1, [addr], [length]’
-  â€˜Z2, [addr], [length]’
-  â€˜Z3, [addr], [length]’
-  â€˜Z4, [addr], [length]’
-
-  Insert hardware breakpoint/watchpoint at address addr of size length
-
-  @param SystemContext  Register content at time of the exception
-  @param *PacketData    Pointer to the Payload data for the packet
-
-**/
-VOID
-EFIAPI
-InsertBreakPoint(
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  CHAR8               *PacketData
-  );
-
-
-/**
-  â€˜z1, [addr], [length]’
-  â€˜z2, [addr], [length]’
-  â€˜z3, [addr], [length]’
-  â€˜z4, [addr], [length]’
-
-  Remove hardware breakpoint/watchpoint at address addr of size length
-
-  @param SystemContext  Register content at time of the exception
-  @param *PacketData    Pointer to the Payload data for the packet
-
-**/
-VOID
-EFIAPI
-RemoveBreakPoint(
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  CHAR8               *PacketData
-  );
-
-
-/**
- Exception Hanldler for GDB. It will be called for all exceptions
- registered via the gExceptionType[] array.
- @param ExceptionType   Exception that is being processed
- @param SystemContext   Register content at time of the exception  
- **/
-VOID
-EFIAPI
-GdbExceptionHandler ( 
-  IN     EFI_EXCEPTION_TYPE  ExceptionType, 
-  IN OUT EFI_SYSTEM_CONTEXT  SystemContext 
-  );
-
-
-/**
- Periodic callback for GDB. This function is used to catch a ctrl-c or other 
- break in type command from GDB.
- @param SystemContext           Register content at time of the call
- **/
-VOID
-EFIAPI
-GdbPeriodicCallBack ( 
-  IN OUT EFI_SYSTEM_CONTEXT  SystemContext 
-  );
-
-
-/**
-  Make two serail consoles: 1) StdIn and StdOut via GDB. 2) StdErr via GDB.
-  
-  These console show up on the remote system running GDB
-
-**/
-
-VOID
-GdbInitializeSerialConsole (
-  VOID
-  );
-
-
-/**
-  Send a GDB Remote Serial Protocol Packet
-  
-  $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', 
-  the packet teminating character '#' and the two digit checksum.
-  
-  If an ack '+' is not sent resend the packet, but timeout eventually so we don't end up 
-  in an infinit loop. This is so if you unplug the debugger code just keeps running
-
-  @param PacketData   Payload data for the packet  
-  
-  @retval             Number of bytes of packet data sent.
-
-**/
-UINTN
-SendPacket (
-  IN  CHAR8 *PacketData
-  );
-  
-
-/**
- Receive a GDB Remote Serial Protocol Packet
- $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', 
- the packet teminating character '#' and the two digit checksum.
- If host re-starts sending a packet without ending the previous packet, only the last valid packet is proccessed.
- (In other words, if received packet is '$12345$12345$123456#checksum', only '$123456#checksum' will be processed.)
- If an ack '+' is not sent resend the packet
- @param PacketData   Payload data for the packet  
- @retval             Number of bytes of packet data received.
-
- **/
-UINTN
-ReceivePacket (
- OUT  CHAR8 *PacketData,
- IN   UINTN PacketDataSize
- );
-  
-
-/**
-  Read data from a FileDescriptor. On success number of bytes read is returned. Zero indicates 
-  the end of a file. On error -1 is returned. If count is zero, GdbRead returns zero.
-
-  @param  FileDescriptor   Device to talk to.
-  @param  Buffer           Buffer to hold Count bytes that were read
-  @param  Count            Number of bytes to transfer. 
-
-  @retval -1               Error
-  @retval {other}          Number of bytes read.
-
-**/
-INTN
-GdbRead (
-  IN  INTN    FileDescriptor,
-  OUT VOID    *Buffer,
-  IN  UINTN   Count
-  );
-  
-
-/**
-  Write data to a FileDescriptor. On success number of bytes written is returned. Zero indicates 
-  nothing was written. On error -1 is returned. 
-
-  @param  FileDescriptor   Device to talk to.
-  @param  Buffer           Buffer to hold Count bytes that are to be written
-  @param  Count            Number of bytes to transfer. 
-
-  @retval -1               Error
-  @retval {other}          Number of bytes written.
-
-**/
-INTN
-GdbWrite (
-  IN  INTN          FileDescriptor,
-  OUT CONST VOID    *Buffer,
-  IN  UINTN         Count
-  );
-
-UINTN *  
-FindPointerToRegister (
-  IN  EFI_SYSTEM_CONTEXT    SystemContext,
-  IN  UINTN                 RegNumber  
-  );
-
-CHAR8 * 
-BasicReadRegister (
-  IN  EFI_SYSTEM_CONTEXT      SystemContext,
-  IN  UINTN                   RegNumber,
-  IN  CHAR8                   *OutBufPtr
-  );
-
-VOID
-TransferFromInBufToMem (
-  IN  UINTN   Length,
-  IN  UINT8   *Address,
-  IN  CHAR8   *NewData
-  );
-
-VOID
-TransferFromMemToOutBufAndSend (
-  IN  UINTN  Length,
-  IN  UINT8  *Address
-  );
-
-CHAR8 *
-BasicWriteRegister (
-  IN  EFI_SYSTEM_CONTEXT    SystemContext,
-  IN  UINTN                 RegNumber,
-  IN  CHAR8                 *InBufPtr
-  );
-
-VOID  
-PrintReg (
-  EFI_SYSTEM_CONTEXT SystemContext
-  );
-
-UINTN
-ParseBreakpointPacket (
-  IN  CHAR8 *PacketData,
-  OUT UINTN *Type,
-  OUT UINTN *Address,
-  OUT UINTN *Length
-  );
-
-UINTN
-GetBreakpointDataAddress (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINTN               BreakpointNumber 
-  );
-
-UINTN
-GetBreakpointDetected (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext
-  );
-
-BREAK_TYPE
-GetBreakpointType (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINTN               BreakpointNumber  
-  );
-
-UINTN
-ConvertLengthData (
-  IN  UINTN  Length
-  );
-
-EFI_STATUS
-FindNextFreeDebugRegister (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  OUT UINTN               *Register
-  );
-
-EFI_STATUS
-EnableDebugRegister (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINTN               Register,
-  IN  UINTN               Address,
-  IN  UINTN               Length,
-  IN  UINTN               Type
-  );
-
-EFI_STATUS
-FindMatchingDebugRegister (
- IN  EFI_SYSTEM_CONTEXT  SystemContext,
- IN  UINTN               Address,
- IN  UINTN               Length,
- IN  UINTN               Type,
- OUT UINTN               *Register
- );
-
-EFI_STATUS
-DisableDebugRegister (
- IN  EFI_SYSTEM_CONTEXT  SystemContext,
- IN  UINTN               Register
- );
-
-VOID
-InitializeProcessor (
-  VOID
-  );
-
-BOOLEAN
-ValidateAddress (
-  IN  VOID  *Address
-  );
-
-BOOLEAN
-ValidateException (
-  IN  EFI_EXCEPTION_TYPE    ExceptionType, 
-  IN OUT EFI_SYSTEM_CONTEXT SystemContext 
-  );
-
-#endif
+/** @file\r
+  Private include file for GDB stub\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __GDB_STUB_INTERNAL__\r
+#define __GDB_STUB_INTERNAL__\r
+\r
+#include <Uefi.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/GdbSerialLib.h>\r
+#include <Library/PrintLib.h>\r
+\r
+#include <Protocol/DebugSupport.h>\r
+#include <Protocol/SerialIo.h>\r
+#include <Protocol/LoadedImage.h>\r
+#include <Protocol/LoadedImage.h>\r
+#include <Guid/DebugImageInfoTable.h>\r
+#include <IndustryStandard/PeImage.h>\r
+\r
+extern CONST CHAR8 mHexToStr[];\r
+\r
+// maximum size of input and output buffers\r
+// This value came from the show remote command of the gdb we tested against \r
+#define MAX_BUF_SIZE 2000\r
+\r
+// maximum size of address buffer\r
+#define MAX_ADDR_SIZE 32\r
+\r
+// maximum size of register number buffer\r
+#define MAX_REG_NUM_BUF_SIZE 32\r
+\r
+// maximum size of length buffer\r
+#define MAX_LENGTH_SIZE 32\r
+\r
+// maximum size of T signal members\r
+#define MAX_T_SIGNAL_SIZE 64\r
+\r
+// the mask used to clear all the cache\r
+#define TF_BIT 0x00000100\r
+\r
+\r
+//\r
+// GDB Signal definitions - generic names for interrupts\r
+//\r
+#define GDB_SIGILL      4  // Illegal instruction       \r
+#define GDB_SIGTRAP     5  // Trace Trap (Breakpoint and SingleStep)\r
+#define GDB_SIGEMT      7  // Emulator Trap\r
+#define GDB_SIGFPE      8  // Floating point exception\r
+#define GDB_SIGSEGV     11 // Setgment violation, page fault \r
+\r
+\r
+//\r
+// GDB File I/O Error values, zero means no error\r
+// Includes all general GDB Unix like error values\r
+//\r
+#define GDB_EBADMEMADDRBUFSIZE   11  // the buffer that stores memory Address to be read from/written to is not the right size\r
+#define GDB_EBADMEMLENGBUFSIZE   12  // the buffer that stores Length is not the right size \r
+#define GDB_EBADMEMLENGTH        13  // Length, the given number of bytes to read or write, is not the right size\r
+#define GDB_EBADMEMDATA          14  // one of the bytes or nibbles of the memory is leess than 0 \r
+#define GDB_EBADMEMDATASIZE      15  // the memory data, 'XX..', is too short or too long\r
+#define GDB_EBADBUFSIZE          21  // the buffer created is not the correct size\r
+#define GDB_EINVALIDARG          31  // argument is invalid\r
+#define GDB_ENOSPACE             41  //\r
+#define GDB_EINVALIDBRKPOINTTYPE 51  // the breakpoint type is not recognized\r
+#define GDB_EINVALIDREGNUM       61  // given register number is not valid: either <0 or >=Number of Registers\r
+#define GDB_EUNKNOWN             255 // unknown\r
+\r
+\r
+//\r
+// These devices are open by GDB so we can just read and write to them\r
+//\r
+#define GDB_STDIN   0x00\r
+#define GDB_STDOUT  0x01\r
+#define GDB_STDERR  0x02\r
+\r
+//\r
+//Define Register size for different architectures\r
+//\r
+#if defined (MDE_CPU_IA32) \r
+#define REG_SIZE  32\r
+#elif defined (MDE_CPU_X64)\r
+#define REG_SIZE  64\r
+#elif defined (MDE_CPU_ARM)\r
+#define REG_SIZE  32\r
+#endif\r
+\r
+#define GDB_SERIAL_DEV_SIGNATURE    SIGNATURE_32 ('g', 'd', 'b', 's')\r
+\r
+typedef struct {\r
+  VENDOR_DEVICE_PATH                     VendorDevice;\r
+  UINT32                                 Index;         // Suport more than one\r
+  EFI_DEVICE_PATH_PROTOCOL               End;\r
+} GDB_SERIAL_DEVICE_PATH;\r
+\r
+//\r
+//  Name:   SERIAL_DEV\r
+//  Purpose:  To provide device specific information\r
+//  Fields:\r
+//      Signature UINTN: The identity of the serial device\r
+//      SerialIo  SERIAL_IO_PROTOCOL: Serial I/O protocol interface\r
+//      SerialMode  SERIAL_IO_MODE:\r
+//      DevicePath  EFI_DEVICE_PATH_PROTOCOL *: Device path of the serial device\r
+//\r
+typedef struct {\r
+  UINTN                                  Signature;\r
+  EFI_HANDLE                             Handle;\r
+  EFI_SERIAL_IO_PROTOCOL                 SerialIo;\r
+  EFI_SERIAL_IO_MODE                     SerialMode;\r
+  GDB_SERIAL_DEVICE_PATH                 DevicePath;\r
+  INTN                                   InFileDescriptor;\r
+  INTN                                   OutFileDescriptor;\r
+} GDB_SERIAL_DEV;\r
+\r
+\r
+#define GDB_SERIAL_DEV_FROM_THIS(a) CR (a, GDB_SERIAL_DEV, SerialIo, GDB_SERIAL_DEV_SIGNATURE)\r
+\r
+\r
+typedef struct {\r
+    EFI_EXCEPTION_TYPE  Exception;\r
+    UINT8               SignalNo;\r
+} EFI_EXCEPTION_TYPE_ENTRY;\r
+\r
+\r
+#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r
+\r
+//\r
+// Byte packed structure for DR6\r
+// 32-bits on IA-32\r
+// 64-bits on X64.  The upper 32-bits on X64 are reserved\r
+//\r
+typedef union {\r
+  struct {\r
+    UINT32  B0:1;           // Breakpoint condition detected\r
+    UINT32  B1:1;           // Breakpoint condition detected\r
+    UINT32  B2:1;           // Breakpoint condition detected\r
+    UINT32  B3:1;           // Breakpoint condition detected\r
+    UINT32  Reserved_1:9;   // Reserved \r
+    UINT32  BD:1;           // Debug register access detected\r
+    UINT32  BS:1;           // Single step\r
+    UINT32  BT:1;           // Task switch\r
+    UINT32  Reserved_2:16;  // Reserved\r
+  } Bits;\r
+  UINTN     UintN;\r
+} IA32_DR6;\r
+\r
+//\r
+// Byte packed structure for DR7\r
+// 32-bits on IA-32\r
+// 64-bits on X64.  The upper 32-bits on X64 are reserved\r
+//\r
+typedef union {\r
+  struct {\r
+    UINT32  L0:1;           // Local breakpoint enable\r
+    UINT32  G0:1;           // Global breakpoint enable\r
+    UINT32  L1:1;           // Local breakpoint enable\r
+    UINT32  G1:1;           // Global breakpoint enable\r
+    UINT32  L2:1;           // Local breakpoint enable\r
+    UINT32  G2:1;           // Global breakpoint enable\r
+    UINT32  L3:1;           // Local breakpoint enable\r
+    UINT32  G3:1;           // Global breakpoint enable\r
+    UINT32  LE:1;           // Local exact breakpoint enable\r
+    UINT32  GE:1;           // Global exact breakpoint enable\r
+    UINT32  Reserved_1:3;   // Reserved\r
+    UINT32  GD:1;           // Global detect enable\r
+    UINT32  Reserved_2:2;   // Reserved\r
+    UINT32  RW0:2;          // Read/Write field\r
+    UINT32  LEN0:2;         // Length field\r
+    UINT32  RW1:2;          // Read/Write field\r
+    UINT32  LEN1:2;         // Length field\r
+    UINT32  RW2:2;          // Read/Write field\r
+    UINT32  LEN2:2;         // Length field\r
+    UINT32  RW3:2;          // Read/Write field\r
+    UINT32  LEN3:2;         // Length field\r
+  } Bits;\r
+  UINTN     UintN;\r
+} IA32_DR7;\r
+\r
+#endif /* if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) */\r
+\r
+typedef enum {\r
+  InstructionExecution,   //Hardware breakpoint\r
+  DataWrite,              //watch\r
+  DataRead,               //rwatch\r
+  DataReadWrite,          //awatch\r
+  SoftwareBreakpoint,     //Software breakpoint\r
+  NotSupported\r
+} BREAK_TYPE;\r
+\r
+//\r
+// Array of exception types that need to be hooked by the debugger\r
+//\r
+extern EFI_EXCEPTION_TYPE_ENTRY gExceptionType[];\r
+\r
+//\r
+// Set TRUE if F Reply package signals a ctrl-c. We can not process the Ctrl-c\r
+// here we need to wait for the periodic callback to do this. \r
+//\r
+extern BOOLEAN gCtrlCBreakFlag;\r
+\r
+//\r
+// If the periodic callback is called while we are processing an F packet we need\r
+// to let the callback know to not read from the serail stream as it could steal\r
+// characters from the F reponse packet\r
+//\r
+extern BOOLEAN gProcessingFPacket;\r
+\r
+\r
+// The offsets of registers SystemContext.\r
+// The fields in the array are in the gdb ordering.\r
+//\r
+extern UINTN    gRegisterOffsets[];\r
+\r
+/**\r
+ Return the number of entries in the gExceptionType[]\r
\r
+ @retval    UINTN, the number of entries in the gExceptionType[] array.    \r
+ **/\r
+UINTN\r
+MaxEfiException (\r
+  VOID\r
+  );\r
+\r
+\r
+/**\r
+ Return the number of entries in the gRegisters[]\r
\r
+ @retval    UINTN, the number of entries (registers) in the gRegisters[] array.    \r
+ **/\r
+UINTN\r
+MaxRegisterCount (\r
+  VOID\r
+  );\r
+\r
+\r
+/**\r
+ Check to see if the ISA is supported. \r
+ ISA = Instruction Set Architecture\r
\r
+ @retval    TRUE if Isa is supported,\r
+ FALSE otherwise.\r
+ **/\r
+BOOLEAN\r
+CheckIsa (\r
+  IN    EFI_INSTRUCTION_SET_ARCHITECTURE    Isa\r
+  );\r
+\r
+\r
+/**\r
+ Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints\r
\r
+ @param  SystemContext        Register content at time of the exception\r
+ @param  GdbExceptionType     GDB exception type\r
+ **/\r
+\r
+VOID\r
+GdbSendTSignal (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINT8                  GdbExceptionType\r
+  );\r
+\r
+\r
+/**\r
+ Translates the EFI mapping to GDB mapping\r
\r
+ @param     EFIExceptionType        EFI Exception that is being processed\r
+ @retval    UINTN that corresponds to EFIExceptionType's GDB exception type number\r
+ **/\r
+UINT8\r
+ConvertEFItoGDBtype ( \r
+  IN  EFI_EXCEPTION_TYPE EFIExceptionType\r
+  );\r
+\r
+\r
+/**\r
+ Empties the given buffer \r
+ @param *Buf pointer to the first element in buffer to be emptied\r
+ **/\r
+VOID\r
+EmptyBuffer ( \r
+  IN CHAR8  *Buf\r
+  );\r
+\r
+\r
+/**\r
+ Converts an 8-bit Hex Char into a INTN.\r
\r
+ @param     Char  - the hex character to be converted into UINTN\r
+ @retval    a INTN, from 0 to 15, that corressponds to Char\r
+ -1 if Char is not a hex character\r
+ **/\r
+INTN\r
+HexCharToInt (\r
+  IN  CHAR8 Char\r
+  );\r
+\r
+\r
+/** 'E NN'\r
+ Send an error with the given error number after converting to hex.\r
+ The error number is put into the buffer in hex. '255' is the biggest errno we can send.\r
+ ex: 162 will be sent as A2.\r
\r
+ @param   errno    the error number that will be sent\r
+ **/\r
+VOID\r
+EFIAPI\r
+SendError (\r
+  IN  UINT8     ErrorNum\r
+  );\r
+\r
+\r
+/**\r
+ Send 'OK' when the function is done executing successfully.\r
+ **/\r
+VOID\r
+SendSuccess (\r
+  VOID\r
+  );\r
+\r
+\r
+/**\r
+ Send empty packet to specify that particular command/functionality is not supported.\r
+ **/\r
+VOID\r
+SendNotSupported (\r
+  VOID\r
+  );\r
+\r
+/** â€˜p n’ \r
+ Reads the n-th register's value into an output buffer and sends it as a packet \r
+ @param     SystemContext       Register content at time of the exception\r
+ @param     InBuffer            This is the input buffer received from gdb server\r
+ **/\r
+VOID\r
+ReadNthRegister (\r
+  IN    EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN    CHAR8               *InBuffer\r
+  );\r
+\r
+\r
+/** â€˜g’ \r
+ Reads the general registers into an output buffer  and sends it as a packet \r
+ @param     SystemContext           Register content at time of the exception\r
+ **/\r
+VOID\r
+ReadGeneralRegisters (  \r
+  IN    EFI_SYSTEM_CONTEXT  SystemContext\r
+  );\r
+\r
+\r
+/** â€˜P n...=r...’\r
+ Writes the new value of n-th register received into the input buffer to the n-th register\r
+ @param     SystemContext       Register content at time of the exception\r
+ @param     InBuffer            This is the input buffer received from gdb server\r
+ **/\r
+VOID\r
+WriteNthRegister (\r
+  IN    EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN    CHAR8               *InBuffer\r
+  );\r
+\r
+\r
+/** â€˜G XX...’\r
+ Writes the new values received into the input buffer to the general registers\r
+ @param     SystemContext               Register content at time of the exception\r
+ @param     InBuffer                    Pointer to the input buffer received from gdb server\r
+ **/\r
+\r
+VOID\r
+WriteGeneralRegisters (\r
+  IN    EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN    CHAR8               *InBuffer\r
+  );\r
+\r
+\r
+/** â€˜m addr,length â€™\r
+ Find the Length of the area to read and the start addres. Finally, pass them to \r
+ another function, TransferFromMemToOutBufAndSend, that will read from that memory space and \r
+ send it as a packet.\r
\r
+ @param  *PacketData  Pointer to Payload data for the packet\r
+ **/\r
+VOID\r
+ReadFromMemory (\r
+  IN  CHAR8  *PacketData\r
+  );\r
+\r
+\r
+/** â€˜M addr,length :XX...’\r
+ Find the Length of the area in bytes to write and the start addres. Finally, pass them to \r
+ another function, TransferFromInBufToMem, that will write to that memory space the info in\r
+ the input buffer.\r
\r
+ @param   PacketData     Pointer to Payload data for the packet\r
+ **/\r
+VOID\r
+WriteToMemory (\r
+  IN CHAR8 *PacketData\r
+  );\r
+\r
+\r
+/** â€˜c [addr ]’ \r
+ Continue. addr is Address to resume. If addr is omitted, resume at current \r
+ Address.\r
\r
+ @param SystemContext Register content at time of the exception  \r
+ @param *PacketData   Pointer to PacketData\r
+ **/\r
+\r
+VOID\r
+ContinueAtAddress (\r
+  IN  EFI_SYSTEM_CONTEXT   SystemContext,\r
+  IN  CHAR8                *PacketData\r
+  );\r
+\r
+\r
+/** â€˜s [addr ]’\r
+ Single step. addr is the Address at which to resume. If addr is omitted, resume \r
+ at same Address.\r
\r
+ @param SystemContext   Register content at time of the exception\r
+ @param PacketData      Pointer to Payload data for the packet\r
+ **/\r
+VOID\r
+SingleStep (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  CHAR8               *PacketData\r
+  );\r
+\r
+/** \r
+ Insert Single Step in the SystemContext\r
\r
+ @param SystemContext   Register content at time of the exception\r
+ **/\r
+VOID\r
+AddSingleStep (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext\r
+  );\r
+  \r
+/** \r
+ Remove Single Step in the SystemContext\r
\r
+ @param SystemContext   Register content at time of the exception\r
+ **/\r
+VOID\r
+RemoveSingleStep (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext\r
+  );\r
+  \r
+  \r
+/**\r
+  â€˜Z1, [addr], [length]’\r
+  â€˜Z2, [addr], [length]’\r
+  â€˜Z3, [addr], [length]’\r
+  â€˜Z4, [addr], [length]’\r
+\r
+  Insert hardware breakpoint/watchpoint at address addr of size length\r
+\r
+  @param SystemContext  Register content at time of the exception\r
+  @param *PacketData    Pointer to the Payload data for the packet\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+InsertBreakPoint(\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  CHAR8               *PacketData\r
+  );\r
+\r
+\r
+/**\r
+  â€˜z1, [addr], [length]’\r
+  â€˜z2, [addr], [length]’\r
+  â€˜z3, [addr], [length]’\r
+  â€˜z4, [addr], [length]’\r
+\r
+  Remove hardware breakpoint/watchpoint at address addr of size length\r
+\r
+  @param SystemContext  Register content at time of the exception\r
+  @param *PacketData    Pointer to the Payload data for the packet\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+RemoveBreakPoint(\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  CHAR8               *PacketData\r
+  );\r
+\r
+\r
+/**\r
+ Exception Hanldler for GDB. It will be called for all exceptions\r
+ registered via the gExceptionType[] array.\r
\r
+ @param ExceptionType   Exception that is being processed\r
+ @param SystemContext   Register content at time of the exception  \r
\r
+ **/\r
+VOID\r
+EFIAPI\r
+GdbExceptionHandler ( \r
+  IN     EFI_EXCEPTION_TYPE  ExceptionType, \r
+  IN OUT EFI_SYSTEM_CONTEXT  SystemContext \r
+  );\r
+\r
+\r
+/**\r
+ Periodic callback for GDB. This function is used to catch a ctrl-c or other \r
+ break in type command from GDB.\r
\r
+ @param SystemContext           Register content at time of the call\r
\r
+ **/\r
+VOID\r
+EFIAPI\r
+GdbPeriodicCallBack ( \r
+  IN OUT EFI_SYSTEM_CONTEXT  SystemContext \r
+  );\r
+\r
+\r
+/**\r
+  Make two serail consoles: 1) StdIn and StdOut via GDB. 2) StdErr via GDB.\r
+  \r
+  These console show up on the remote system running GDB\r
+\r
+**/\r
+\r
+VOID\r
+GdbInitializeSerialConsole (\r
+  VOID\r
+  );\r
+\r
+\r
+/**\r
+  Send a GDB Remote Serial Protocol Packet\r
+  \r
+  $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', \r
+  the packet teminating character '#' and the two digit checksum.\r
+  \r
+  If an ack '+' is not sent resend the packet, but timeout eventually so we don't end up \r
+  in an infinit loop. This is so if you unplug the debugger code just keeps running\r
+\r
+  @param PacketData   Payload data for the packet  \r
+  \r
+  @retval             Number of bytes of packet data sent.\r
+\r
+**/\r
+UINTN\r
+SendPacket (\r
+  IN  CHAR8 *PacketData\r
+  );\r
+  \r
+\r
+/**\r
+ Receive a GDB Remote Serial Protocol Packet\r
\r
+ $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', \r
+ the packet teminating character '#' and the two digit checksum.\r
\r
+ If host re-starts sending a packet without ending the previous packet, only the last valid packet is proccessed.\r
+ (In other words, if received packet is '$12345$12345$123456#checksum', only '$123456#checksum' will be processed.)\r
\r
+ If an ack '+' is not sent resend the packet\r
\r
+ @param PacketData   Payload data for the packet  \r
\r
+ @retval             Number of bytes of packet data received.\r
+\r
+ **/\r
+UINTN\r
+ReceivePacket (\r
+ OUT  CHAR8 *PacketData,\r
+ IN   UINTN PacketDataSize\r
+ );\r
+  \r
+\r
+/**\r
+  Read data from a FileDescriptor. On success number of bytes read is returned. Zero indicates \r
+  the end of a file. On error -1 is returned. If count is zero, GdbRead returns zero.\r
+\r
+  @param  FileDescriptor   Device to talk to.\r
+  @param  Buffer           Buffer to hold Count bytes that were read\r
+  @param  Count            Number of bytes to transfer. \r
+\r
+  @retval -1               Error\r
+  @retval {other}          Number of bytes read.\r
+\r
+**/\r
+INTN\r
+GdbRead (\r
+  IN  INTN    FileDescriptor,\r
+  OUT VOID    *Buffer,\r
+  IN  UINTN   Count\r
+  );\r
+  \r
+\r
+/**\r
+  Write data to a FileDescriptor. On success number of bytes written is returned. Zero indicates \r
+  nothing was written. On error -1 is returned. \r
+\r
+  @param  FileDescriptor   Device to talk to.\r
+  @param  Buffer           Buffer to hold Count bytes that are to be written\r
+  @param  Count            Number of bytes to transfer. \r
+\r
+  @retval -1               Error\r
+  @retval {other}          Number of bytes written.\r
+\r
+**/\r
+INTN\r
+GdbWrite (\r
+  IN  INTN          FileDescriptor,\r
+  OUT CONST VOID    *Buffer,\r
+  IN  UINTN         Count\r
+  );\r
+\r
+UINTN *  \r
+FindPointerToRegister (\r
+  IN  EFI_SYSTEM_CONTEXT    SystemContext,\r
+  IN  UINTN                 RegNumber  \r
+  );\r
+\r
+CHAR8 * \r
+BasicReadRegister (\r
+  IN  EFI_SYSTEM_CONTEXT      SystemContext,\r
+  IN  UINTN                   RegNumber,\r
+  IN  CHAR8                   *OutBufPtr\r
+  );\r
+\r
+VOID\r
+TransferFromInBufToMem (\r
+  IN  UINTN   Length,\r
+  IN  UINT8   *Address,\r
+  IN  CHAR8   *NewData\r
+  );\r
+\r
+VOID\r
+TransferFromMemToOutBufAndSend (\r
+  IN  UINTN  Length,\r
+  IN  UINT8  *Address\r
+  );\r
+\r
+CHAR8 *\r
+BasicWriteRegister (\r
+  IN  EFI_SYSTEM_CONTEXT    SystemContext,\r
+  IN  UINTN                 RegNumber,\r
+  IN  CHAR8                 *InBufPtr\r
+  );\r
+\r
+VOID  \r
+PrintReg (\r
+  EFI_SYSTEM_CONTEXT SystemContext\r
+  );\r
+\r
+UINTN\r
+ParseBreakpointPacket (\r
+  IN  CHAR8 *PacketData,\r
+  OUT UINTN *Type,\r
+  OUT UINTN *Address,\r
+  OUT UINTN *Length\r
+  );\r
+\r
+UINTN\r
+GetBreakpointDataAddress (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINTN               BreakpointNumber \r
+  );\r
+\r
+UINTN\r
+GetBreakpointDetected (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext\r
+  );\r
+\r
+BREAK_TYPE\r
+GetBreakpointType (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINTN               BreakpointNumber  \r
+  );\r
+\r
+UINTN\r
+ConvertLengthData (\r
+  IN  UINTN  Length\r
+  );\r
+\r
+EFI_STATUS\r
+FindNextFreeDebugRegister (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  OUT UINTN               *Register\r
+  );\r
+\r
+EFI_STATUS\r
+EnableDebugRegister (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINTN               Register,\r
+  IN  UINTN               Address,\r
+  IN  UINTN               Length,\r
+  IN  UINTN               Type\r
+  );\r
+\r
+EFI_STATUS\r
+FindMatchingDebugRegister (\r
+ IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+ IN  UINTN               Address,\r
+ IN  UINTN               Length,\r
+ IN  UINTN               Type,\r
+ OUT UINTN               *Register\r
+ );\r
+\r
+EFI_STATUS\r
+DisableDebugRegister (\r
+ IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+ IN  UINTN               Register\r
+ );\r
+\r
+VOID\r
+InitializeProcessor (\r
+  VOID\r
+  );\r
+\r
+BOOLEAN\r
+ValidateAddress (\r
+  IN  VOID  *Address\r
+  );\r
+\r
+BOOLEAN\r
+ValidateException (\r
+  IN  EFI_EXCEPTION_TYPE    ExceptionType, \r
+  IN OUT EFI_SYSTEM_CONTEXT SystemContext \r
+  );\r
+\r
+#endif\r
index 442faea023583e76bf26252e7aa1f2a312e1bd22..a6aceaef99a0785d496d0780ff3c316115b57b66 100644 (file)
-/** @file
-  Processor specific parts of the GDB stub
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <GdbStubInternal.h>
-
-//
-// Array of exception types that need to be hooked by the debugger
-// {EFI mapping, GDB mapping}
-//
-EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = {
-  { EXCEPT_IA32_DIVIDE_ERROR,     GDB_SIGFPE  }, 
-  { EXCEPT_IA32_DEBUG,            GDB_SIGTRAP },
-  { EXCEPT_IA32_NMI,              GDB_SIGEMT  },
-  { EXCEPT_IA32_BREAKPOINT,       GDB_SIGTRAP },
-  { EXCEPT_IA32_OVERFLOW,         GDB_SIGSEGV },
-  { EXCEPT_IA32_BOUND,            GDB_SIGSEGV },
-  { EXCEPT_IA32_INVALID_OPCODE,   GDB_SIGILL  },
-  { EXCEPT_IA32_DOUBLE_FAULT,     GDB_SIGEMT  },
-  { EXCEPT_IA32_STACK_FAULT,      GDB_SIGSEGV },
-  { EXCEPT_IA32_GP_FAULT,         GDB_SIGSEGV },
-  { EXCEPT_IA32_PAGE_FAULT,       GDB_SIGSEGV },
-  { EXCEPT_IA32_FP_ERROR,         GDB_SIGEMT  },
-  { EXCEPT_IA32_ALIGNMENT_CHECK,  GDB_SIGEMT  },
-  { EXCEPT_IA32_MACHINE_CHECK,    GDB_SIGEMT  }
-};
-
-
-// The offsets of registers SystemContext.
-// The fields in the array are in the gdb ordering.
-//
-//16 regs
-UINTN gRegisterOffsets[] = {
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eax),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ecx),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Edx),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ebx),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Esp),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ebp),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Esi),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Edi),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eip),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eflags),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Cs),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ss),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ds),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Es),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Fs),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Gs)
-};
-
-
-//Debug only..
-VOID 
-PrintReg (
-  IN EFI_SYSTEM_CONTEXT SystemContext
-  )
-{
-  Print ((CHAR16 *)L"EAX: %x ", SystemContext.SystemContextIa32->Eax);
-  Print ((CHAR16 *)L"ECX: %x ", SystemContext.SystemContextIa32->Ecx);
-  Print ((CHAR16 *)L"EDX: %x ", SystemContext.SystemContextIa32->Edx);
-  Print ((CHAR16 *)L"EBX: %x ", SystemContext.SystemContextIa32->Ebx);
-  Print ((CHAR16 *)L"ESP: %x ", SystemContext.SystemContextIa32->Esp);
-  Print ((CHAR16 *)L"EBP: %x ", SystemContext.SystemContextIa32->Ebp);
-  Print ((CHAR16 *)L"ESI: %x ", SystemContext.SystemContextIa32->Esi);
-  Print ((CHAR16 *)L"EDI: %x ", SystemContext.SystemContextIa32->Edi);
-  Print ((CHAR16 *)L"EIP: %x\n", SystemContext.SystemContextIa32->Eip);
-  Print ((CHAR16 *)L"EFlags: %x\n", SystemContext.SystemContextIa32->Eflags);
-}
-
-//Debug only..
-VOID 
-PrintDRreg (
-  IN EFI_SYSTEM_CONTEXT SystemContext
-  )
-{
-  Print ((CHAR16 *)L"DR0: %x ", SystemContext.SystemContextIa32->Dr0);
-  Print ((CHAR16 *)L"DR1: %x ", SystemContext.SystemContextIa32->Dr1);
-  Print ((CHAR16 *)L"DR2: %x ", SystemContext.SystemContextIa32->Dr2);
-  Print ((CHAR16 *)L"DR3: %x ", SystemContext.SystemContextIa32->Dr3);
-  Print ((CHAR16 *)L"DR6: %x ", SystemContext.SystemContextIa32->Dr6);
-  Print ((CHAR16 *)L"DR7: %x\n", SystemContext.SystemContextIa32->Dr7);
-}
-
-
-/**
- Return the number of entries in the gExceptionType[]
- @retval  UINTN, the number of entries in the gExceptionType[] array.    
- **/
-UINTN
-MaxEfiException (
-  VOID
-  )
-{
-  return sizeof (gExceptionType)/sizeof (EFI_EXCEPTION_TYPE_ENTRY);
-}
-
-
-/**
- Return the number of entries in the gRegisters[]
- @retval  UINTN, the number of entries (registers) in the gRegisters[] array.    
- **/
-UINTN
-MaxRegisterCount (
-  VOID
-  )
-{
-  return sizeof (gRegisterOffsets)/sizeof (UINTN);
-}
-
-
-/**
-  Check to see if the ISA is supported. 
-  ISA = Instruction Set Architecture
-  @retval TRUE if Isa is supported,
-      FALSE otherwise.
-**/
-BOOLEAN
-CheckIsa (
-  IN  EFI_INSTRUCTION_SET_ARCHITECTURE  Isa
-  )
-{
-  return (BOOLEAN)(Isa == IsaIa32);
-}
-
-
-/**
- This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering
- It is, by default, set to find the register pointer of the IA32 member
-
- @param   SystemContext     Register content at time of the exception 
- @param   RegNumber       The register to which we want to find a pointer
- @retval  the pointer to the RegNumber-th pointer
- **/
-UINTN *
-FindPointerToRegister(
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINTN               RegNumber  
-  )
-{
-  UINT8 *TempPtr;
-  TempPtr = ((UINT8 *)SystemContext.SystemContextIa32) + gRegisterOffsets[RegNumber];
-  return (UINTN *)TempPtr;
-}
-
-
-/**
- Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr
-
- @param SystemContext     Register content at time of the exception
- @param   RegNumber       the number of the register that we want to read
- @param   OutBufPtr       pointer to the output buffer's end. the new data will be added from this point on.
- @retval  the pointer to the next character of the output buffer that is available to be written on.
- **/
-CHAR8 *
-BasicReadRegister (
-  IN  EFI_SYSTEM_CONTEXT      SystemContext,
-  IN  UINTN           RegNumber,
-  IN  CHAR8           *OutBufPtr
-  )
-{
-  UINTN RegSize;
-  
-  RegSize = 0;
-  while (RegSize < REG_SIZE) {
-    *OutBufPtr++ = mHexToStr[((*FindPointerToRegister(SystemContext, RegNumber) >> (RegSize+4)) & 0xf)];
-    *OutBufPtr++ = mHexToStr[((*FindPointerToRegister(SystemContext, RegNumber) >> RegSize) & 0xf)];
-    RegSize = RegSize + 8;
-  }
-  return OutBufPtr;
-}
-
-
-/** â€˜p n’ 
- Reads the n-th register's value into an output buffer and sends it as a packet 
-
- @param   SystemContext   Register content at time of the exception
- @param   InBuffer      Pointer to the input buffer received from gdb server
- **/
-VOID
-EFIAPI
-ReadNthRegister (
-  IN  EFI_SYSTEM_CONTEXT   SystemContext,
-  IN  CHAR8                *InBuffer
-  )
-{
-  UINTN RegNumber;
-  CHAR8 OutBuffer[9]; // 1 reg=8 hex chars, and the end '\0' (escape seq)
-  CHAR8 *OutBufPtr;   // pointer to the output buffer
-  
-  RegNumber = AsciiStrHexToUintn (&InBuffer[1]);
-
-  if ((RegNumber < 0) || (RegNumber >= MaxRegisterCount())) {
-    SendError (GDB_EINVALIDREGNUM);
-    return;
-  }
-
-  OutBufPtr = OutBuffer;
-  OutBufPtr = BasicReadRegister(SystemContext, RegNumber, OutBufPtr);
-
-  *OutBufPtr = '\0';  // the end of the buffer
-  SendPacket(OutBuffer);
-}
-
-
-/** â€˜g’ 
- Reads the general registers into an output buffer  and sends it as a packet 
-
- @param   SystemContext     Register content at time of the exception
- **/
-VOID
-EFIAPI
-ReadGeneralRegisters (  
-  IN  EFI_SYSTEM_CONTEXT      SystemContext
-  )
-{
-  UINTN   i;
-  CHAR8 OutBuffer[129]; // 16 regs, 8 hex chars each, and the end '\0' (escape seq)
-  CHAR8 *OutBufPtr;   // pointer to the output buffer
-
-  OutBufPtr = OutBuffer;
-  for(i = 0 ; i < MaxRegisterCount() ; i++) {  // there are only 16 registers to read   
-    OutBufPtr = BasicReadRegister(SystemContext, i, OutBufPtr);
-  }
-
-  *OutBufPtr = '\0';  // the end of the buffer
-  SendPacket(OutBuffer);
-}
-
-
-/**
- Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr
-
- @param   SystemContext       Register content at time of the exception
- @param   RegNumber         the number of the register that we want to write
- @param   InBufPtr          pointer to the output buffer. the new data will be extracted from the input buffer from this point on.
- @retval  the pointer to the next character of the input buffer that can be used
- **/
-CHAR8 *
-BasicWriteRegister (
-  IN  EFI_SYSTEM_CONTEXT      SystemContext,
-  IN  UINTN           RegNumber,
-  IN  CHAR8           *InBufPtr
-  )
-{
-  UINTN RegSize;
-  UINTN TempValue; // the value transferred from a hex char
-  UINT32 NewValue; // the new value of the RegNumber-th Register
-  
-  NewValue = 0;
-  RegSize = 0;
-  while (RegSize < REG_SIZE) {
-    TempValue = HexCharToInt(*InBufPtr++);
-    
-   if (TempValue < 0) {
-      SendError (GDB_EBADMEMDATA); 
-      return NULL;
-    }
-
-    NewValue += (TempValue << (RegSize+4));
-    TempValue = HexCharToInt(*InBufPtr++);
-    
-    if (TempValue < 0) {
-      SendError (GDB_EBADMEMDATA); 
-      return NULL;
-    }
-    
-    NewValue += (TempValue << RegSize); 
-    RegSize = RegSize + 8;
-  }
-  *(FindPointerToRegister(SystemContext, RegNumber)) = NewValue;
-  return InBufPtr;
-}
-
-
-/** â€˜P n...=r...’
- Writes the new value of n-th register received into the input buffer to the n-th register
-
- @param   SystemContext   Register content at time of the exception
- @param   InBuffer      Ponter to the input buffer received from gdb server
- **/
-VOID
-EFIAPI
-WriteNthRegister (
-  IN  EFI_SYSTEM_CONTEXT      SystemContext,
-  IN  CHAR8           *InBuffer
-  )
-{
-  UINTN RegNumber;
-  CHAR8 RegNumBuffer[MAX_REG_NUM_BUF_SIZE];  // put the 'n..' part of the message into this array
-  CHAR8 *RegNumBufPtr;
-  CHAR8 *InBufPtr; // pointer to the input buffer
-  
-  // find the register number to write
-  InBufPtr = &InBuffer[1];
-  RegNumBufPtr = RegNumBuffer;
-  while (*InBufPtr != '=') {
-    *RegNumBufPtr++ = *InBufPtr++;
-  } 
-  *RegNumBufPtr = '\0';
-  RegNumber = AsciiStrHexToUintn (RegNumBuffer); 
-
-  // check if this is a valid Register Number
-  if ((RegNumber < 0) || (RegNumber >= MaxRegisterCount())) {
-       SendError (GDB_EINVALIDREGNUM); 
-    return;
-  }
-  InBufPtr++;  // skips the '=' character
-  BasicWriteRegister (SystemContext, RegNumber, InBufPtr);
-  SendSuccess();
-}
-
-
-/** â€˜G XX...’
- Writes the new values received into the input buffer to the general registers
-
- @param   SystemContext       Register content at time of the exception
- @param   InBuffer          Pointer to the input buffer received from gdb server
- **/
-VOID
-EFIAPI
-WriteGeneralRegisters (
-  IN  EFI_SYSTEM_CONTEXT        SystemContext,
-  IN  CHAR8             *InBuffer
-  )
-{
-  UINTN  i;
-  CHAR8 *InBufPtr; /// pointer to the input buffer
-
-  // check to see if the buffer is the right size which is 
-  // 1 (for 'G') + 16 (for 16 registers) * 8 ( for 8 hex chars each) = 129 
-  if (AsciiStrLen(InBuffer) != 129) { // 16 regs, 8 hex chars each, and the end '\0' (escape seq)
-       //Bad message. Message is not the right length 
-    SendError (GDB_EBADBUFSIZE); 
-    return;
-  }
-
-  InBufPtr = &InBuffer[1];
-  
-  // Read the new values for the registers from the input buffer to an array, NewValueArray.
-  // The values in the array are in the gdb ordering
-  for(i=0; i < MaxRegisterCount(); i++) {  // there are only 16 registers to write
-    InBufPtr = BasicWriteRegister(SystemContext, i, InBufPtr);
-  }
-
-  SendSuccess();
-}
-
-
-/** 
- Insert Single Step in the SystemContext
- @param SystemContext Register content at time of the exception
- **/
-VOID
-AddSingleStep (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext
-  )
-{
-  SystemContext.SystemContextIa32->Eflags |= TF_BIT; //Setting the TF bit.
-}
-
-  
-/** 
- Remove Single Step in the SystemContext
- @param SystemContext Register content at time of the exception
- **/
-VOID
-RemoveSingleStep (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext
-  )
-{
-  SystemContext.SystemContextIa32->Eflags &= ~TF_BIT;  // clearing the TF bit.
-}
-
-
-
-/** â€˜c [addr ]’ 
- Continue. addr is Address to resume. If addr is omitted, resume at current 
- Address.
- @param   SystemContext     Register content at time of the exception  
- **/
-VOID
-EFIAPI
-ContinueAtAddress (
-  IN  EFI_SYSTEM_CONTEXT      SystemContext,
-  IN    CHAR8                 *PacketData
-  )
-{
-  if (PacketData[1] != '\0') {
-    SystemContext.SystemContextIa32->Eip = AsciiStrHexToUintn (&PacketData[1]);
-  } 
-}
-
-
-/** â€˜s [addr ]’
- Single step. addr is the Address at which to resume. If addr is omitted, resume 
- at same Address.
- @param   SystemContext     Register content at time of the exception  
- **/
-VOID
-EFIAPI
-SingleStep (
-  IN  EFI_SYSTEM_CONTEXT      SystemContext,
-  IN    CHAR8                 *PacketData
-  )
-{
-  if (PacketData[1] != '\0') {
-    SystemContext.SystemContextIa32->Eip = AsciiStrHexToUintn (&PacketData[1]);
-  }
-  
-  AddSingleStep (SystemContext);
-}
-
-
-/**
-  Returns breakpoint data address from DR0-DR3 based on the input breakpoint number
-
-  @param  SystemContext      Register content at time of the exception
-  @param  BreakpointNumber   Breakpoint number
-
-  @retval Address            Data address from DR0-DR3 based on the breakpoint number.
-
-**/
-UINTN
-GetBreakpointDataAddress (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINTN               BreakpointNumber
-  )
-{
-  UINTN Address;
-
-  if (BreakpointNumber == 1) {
-    Address = SystemContext.SystemContextIa32->Dr0;
-  } else if (BreakpointNumber == 2) {
-    Address = SystemContext.SystemContextIa32->Dr1;
-  } else if (BreakpointNumber == 3) {
-    Address = SystemContext.SystemContextIa32->Dr2;
-  } else if (BreakpointNumber == 4) {
-    Address = SystemContext.SystemContextIa32->Dr3;
-  } else {
-    Address = 0;
-  }
-
-  return Address;
-}
-
-
-/**
-  Returns currently detected breakpoint value based on the register DR6 B0-B3 field.
-  If no breakpoint is detected then it returns 0.
-
-  @param  SystemContext  Register content at time of the exception
-
-  @retval {1-4}          Currently detected breakpoint value   
-  @retval 0              No breakpoint detected.
-**/
-UINTN
-GetBreakpointDetected (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext
-  )
-{
-  IA32_DR6 Dr6;
-  UINTN BreakpointNumber;
-
-  Dr6.UintN = SystemContext.SystemContextIa32->Dr6;
-
-  if (Dr6.Bits.B0 == 1) {
-    BreakpointNumber = 1;
-  } else if (Dr6.Bits.B1 == 1) {
-    BreakpointNumber = 2;
-  } else if (Dr6.Bits.B2 == 1) {
-    BreakpointNumber = 3;
-  } else if (Dr6.Bits.B3 == 1) {
-    BreakpointNumber = 4;
-  } else {
-    BreakpointNumber = 0;  //No breakpoint detected 
-  }
-
-  return BreakpointNumber;
-}
-
-
-/**
-  Returns Breakpoint type (InstructionExecution, DataWrite, DataRead or DataReadWrite)
-  based on the Breakpoint number
-  
-  @param  SystemContext        Register content at time of the exception
-  @param  BreakpointNumber     Breakpoint number
-  
-  @retval BREAK_TYPE           Breakpoint type value read from register DR7 RWn field
-                               For unknown value, it returns NotSupported.
-  
-**/
-BREAK_TYPE
-GetBreakpointType (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINTN               BreakpointNumber
-  )
-{
-  IA32_DR7 Dr7;
-  BREAK_TYPE Type = NotSupported;  //Default is NotSupported type
-
-  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
-
-  if (BreakpointNumber == 1) {
-    Type = (BREAK_TYPE) Dr7.Bits.RW0;  
-  } else if (BreakpointNumber == 2) {
-    Type = (BREAK_TYPE) Dr7.Bits.RW1;  
-  } else if (BreakpointNumber == 3) {
-    Type = (BREAK_TYPE) Dr7.Bits.RW2;  
-  } else if (BreakpointNumber == 4) {
-    Type = (BREAK_TYPE) Dr7.Bits.RW3;  
-  }
-
-  return Type;
-}
-
-
-/** 
-  Parses Length and returns the length which DR7 LENn field accepts.
-  For example: If we receive 1-Byte length then we should return 0. 
-               Zero gets written to DR7 LENn field.
-
-  @param  Length  Breakpoint length in Bytes (1 byte, 2 byte, 4 byte)
-
-  @retval Length  Appropriate converted values which DR7 LENn field accepts.
-
-**/
-UINTN
-ConvertLengthData (
-  IN     UINTN   Length
-  )
-{
-  if (Length == 1) {         //1-Byte length 
-    return 0;
-  } else if (Length == 2) {  //2-Byte length
-    return 1;
-  } else if (Length == 4) {  //4-Byte length
-    return 3;
-  } else {                   //Undefined or 8-byte length
-    return 2;
-  }
-}
-
-
-/**
-  Finds the next free debug register. If all the registers are occupied then 
-  EFI_OUT_OF_RESOURCES is returned.  
-
-  @param  SystemContext   Register content at time of the exception
-  @param  Register        Register value (0 - 3 for the first free debug register)
-
-  @retval EFI_STATUS      Appropriate status value.
-
-**/
-EFI_STATUS
-FindNextFreeDebugRegister (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  OUT UINTN               *Register
-  )
-{
-  IA32_DR7 Dr7;
-
-  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
-
-  if (Dr7.Bits.G0 == 0) {
-    *Register = 0;
-  } else if (Dr7.Bits.G1 == 0) {
-    *Register = 1;
-  } else if (Dr7.Bits.G2 == 0) {
-    *Register = 2;
-  } else if (Dr7.Bits.G3 == 0) {
-    *Register = 3;
-  } else {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  return EFI_SUCCESS;
-}
-
-
-/**
-  Enables the debug register. Writes Address value to appropriate DR0-3 register.
-  Sets LENn, Gn, RWn bits in DR7 register.
-  @param  SystemContext   Register content at time of the exception
-  @param  Register        Register value (0 - 3) 
-  @param  Address         Breakpoint address value
-  @param  Type            Breakpoint type (Instruction, Data write, Data read 
-                          or write etc.)
-
-  @retval EFI_STATUS      Appropriate status value.
-
-**/
-EFI_STATUS
-EnableDebugRegister (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINTN               Register,
-  IN  UINTN               Address,
-  IN  UINTN               Length,
-  IN  UINTN               Type
-  )
-{
-  IA32_DR7  Dr7;
-
-  //Convert length data
-  Length = ConvertLengthData (Length);
-
-  //For Instruction execution, length should be 0 
-  //(Ref. Intel reference manual 18.2.4)
-  if ((Type == 0) && (Length != 0)) {
-    return EFI_INVALID_PARAMETER;
-  }
-  //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle
-  //software breakpoint. We should send empty packet in both these cases.
-  if ((Type == (BREAK_TYPE)DataRead) || 
-      (Type == (BREAK_TYPE)SoftwareBreakpoint)) {
-    return EFI_UNSUPPORTED;
-  }
-
-  //Read DR7 so appropriate Gn, RWn and LENn bits can be modified.
-  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
-
-  if (Register == 0) {
-    SystemContext.SystemContextIa32->Dr0 = Address;
-    Dr7.Bits.G0 = 1;
-    Dr7.Bits.RW0 = Type;
-    Dr7.Bits.LEN0 = Length;
-  } else if (Register == 1) {
-    SystemContext.SystemContextIa32->Dr1 = Address;
-    Dr7.Bits.G1 = 1;
-    Dr7.Bits.RW1 = Type;
-    Dr7.Bits.LEN1 = Length;
-  } else if (Register == 2) {
-    SystemContext.SystemContextIa32->Dr2 = Address;
-    Dr7.Bits.G2 = 1;
-    Dr7.Bits.RW2 = Type;
-    Dr7.Bits.LEN2 = Length;
-  } else if (Register == 3) {
-    SystemContext.SystemContextIa32->Dr3 = Address;
-    Dr7.Bits.G3 = 1;
-    Dr7.Bits.RW3 = Type;
-    Dr7.Bits.LEN3 = Length;
-  } else {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  //Update Dr7 with appropriate Gn, RWn and LENn bits 
-  SystemContext.SystemContextIa32->Dr7 = Dr7.UintN;
-
-  return EFI_SUCCESS;
-}
-
-
-/**
-  Returns register number 0 - 3 for the maching debug register.
-  This function compares incoming Address, Type, Length and
-  if there is a match then it returns the appropriate register number.
-  In case of mismatch, function returns EFI_NOT_FOUND message.
-
-  @param  SystemContext  Register content at time of the exception
-  @param  Address        Breakpoint address value
-  @param  Length         Breakpoint length value
-  @param  Type           Breakpoint type (Instruction, Data write, 
-                         Data read or write etc.)
-  @param  Register       Register value to be returned
-
-  @retval EFI_STATUS     Appropriate status value.
-
-**/
-EFI_STATUS
-FindMatchingDebugRegister (
- IN  EFI_SYSTEM_CONTEXT  SystemContext,
- IN  UINTN               Address,
- IN  UINTN               Length,
- IN  UINTN               Type,
- OUT UINTN               *Register
- )
-{
-  IA32_DR7 Dr7;
-
-  //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle
-  //software breakpoint. We should send empty packet in both these cases.
-  if ((Type == (BREAK_TYPE)DataRead) || 
-      (Type == (BREAK_TYPE)SoftwareBreakpoint)) {
-    return EFI_UNSUPPORTED;
-  }
-
-  //Convert length data
-  Length = ConvertLengthData(Length);
-
-  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
-
-  if ((Dr7.Bits.G0 == 1) && 
-      (Dr7.Bits.LEN0 == Length) &&
-      (Dr7.Bits.RW0 == Type) && 
-      (Address == SystemContext.SystemContextIa32->Dr0)) {
-    *Register = 0;
-  } else if ((Dr7.Bits.G1 == 1) && 
-             (Dr7.Bits.LEN1 == Length) &&
-             (Dr7.Bits.RW1 == Type) && 
-             (Address == SystemContext.SystemContextIa32->Dr1)) {
-    *Register = 1;
-  } else if ((Dr7.Bits.G2 == 1) && 
-             (Dr7.Bits.LEN2 == Length) &&
-             (Dr7.Bits.RW2 == Type) && 
-             (Address == SystemContext.SystemContextIa32->Dr2)) {
-    *Register = 2;
-  } else if ((Dr7.Bits.G3 == 1) && 
-             (Dr7.Bits.LEN3 == Length) &&
-             (Dr7.Bits.RW3 == Type) && 
-             (Address == SystemContext.SystemContextIa32->Dr3)) {
-    *Register = 3;
-  } else {
-    Print ((CHAR16 *)L"No match found..\n");
-    return EFI_NOT_FOUND;
-  }
-
-  return EFI_SUCCESS;
-}
-
-
-/**
-  Disables the particular debug register.
-
-  @param  SystemContext   Register content at time of the exception
-  @param  Register        Register to be disabled
-
-  @retval EFI_STATUS      Appropriate status value.
-
-**/
-EFI_STATUS
-DisableDebugRegister (
- IN  EFI_SYSTEM_CONTEXT  SystemContext,
- IN  UINTN               Register  
- )
-{
-  IA32_DR7  Dr7;
-  UINTN Address = 0;
-  //Read DR7 register so appropriate Gn, RWn and LENn bits can be turned off.
-  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
-
-  if (Register == 0) {
-    SystemContext.SystemContextIa32->Dr0 = Address;
-    Dr7.Bits.G0 = 0;
-    Dr7.Bits.RW0 = 0;
-    Dr7.Bits.LEN0 = 0;
-  } else if (Register == 1) {
-    SystemContext.SystemContextIa32->Dr1 = Address;
-    Dr7.Bits.G1 = 0;
-    Dr7.Bits.RW1 = 0;
-    Dr7.Bits.LEN1 = 0;
-  } else if (Register == 2) {
-    SystemContext.SystemContextIa32->Dr2 = Address;
-    Dr7.Bits.G2 = 0;
-    Dr7.Bits.RW2 = 0;
-    Dr7.Bits.LEN2 = 0;
-  } else if (Register == 3) {
-    SystemContext.SystemContextIa32->Dr3 = Address;
-    Dr7.Bits.G3 = 0;
-    Dr7.Bits.RW3 = 0;
-    Dr7.Bits.LEN3 = 0;
-  } else {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  //Update DR7 register so appropriate Gn, RWn and LENn bits can be turned off.
-  SystemContext.SystemContextIa32->Dr7 = Dr7.UintN;
-
-  return EFI_SUCCESS;
-}
-
-
-/**
-  â€˜Z1, [addr], [length]’
-  â€˜Z2, [addr], [length]’
-  â€˜Z3, [addr], [length]’
-  â€˜Z4, [addr], [length]’
-
-  Insert hardware breakpoint/watchpoint at address addr of size length
-
-  @param SystemContext  Register content at time of the exception
-  @param *PacketData    Pointer to the Payload data for the packet
-
-**/
-VOID
-EFIAPI
-InsertBreakPoint (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  CHAR8              *PacketData
-  )
-{
-  UINTN Type;
-  UINTN Address;
-  UINTN Length;
-  UINTN Register;
-  EFI_STATUS Status;
-  BREAK_TYPE BreakType = NotSupported;
-  UINTN ErrorCode;
-
-  ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length);
-  if (ErrorCode > 0) {
-    SendError ((UINT8)ErrorCode);
-    return;
-  }
-
-  switch (Type) {
-
-    case    0:   //Software breakpoint
-      BreakType = SoftwareBreakpoint;
-      break;
-
-    case    1:   //Hardware breakpoint
-      BreakType = InstructionExecution;
-      break;
-
-    case    2:   //Write watchpoint
-      BreakType = DataWrite;
-      break;
-
-    case    3:   //Read watchpoint
-      BreakType = DataRead;
-      break;
-
-    case    4:   //Access watchpoint
-      BreakType = DataReadWrite;
-      break;
-
-    default  :
-      Print ((CHAR16 *)L"Insert breakpoint default: %x\n", Type);
-      SendError (GDB_EINVALIDBRKPOINTTYPE);
-      return;
-  }
-
-  // Find next free debug register
-  Status = FindNextFreeDebugRegister (SystemContext, &Register);
-  if (EFI_ERROR(Status)) {
-    Print ((CHAR16 *)L"No space left on device\n");
-    SendError (GDB_ENOSPACE);
-    return;
-  }
-
-  // Write Address, length data at particular DR register
-  Status = EnableDebugRegister (SystemContext, Register, Address, Length, (UINTN)BreakType);
-  if (EFI_ERROR(Status)) {
-
-    if (Status == EFI_UNSUPPORTED) {
-      Print ((CHAR16 *)L"Not supported\n");
-      SendNotSupported();
-      return;
-    }
-
-    Print ((CHAR16 *)L"Invalid argument\n");
-    SendError (GDB_EINVALIDARG);
-    return;
-  }
-
-  SendSuccess ();
-}
-
-
-/**
-  â€˜z1, [addr], [length]’
-  â€˜z2, [addr], [length]’
-  â€˜z3, [addr], [length]’
-  â€˜z4, [addr], [length]’
-
-  Remove hardware breakpoint/watchpoint at address addr of size length
-
-  @param *PacketData    Pointer to the Payload data for the packet
-
-**/
-VOID
-EFIAPI
-RemoveBreakPoint (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  CHAR8               *PacketData
-  )
-{
-  UINTN      Type;
-  UINTN      Address;
-  UINTN      Length;
-  UINTN      Register;
-  BREAK_TYPE BreakType = NotSupported;
-  EFI_STATUS Status;
-  UINTN      ErrorCode;
-
-  //Parse breakpoint packet data
-  ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length);
-  if (ErrorCode > 0) {
-    SendError ((UINT8)ErrorCode);
-    return;
-  }
-
-  switch (Type) {
-  
-    case    0:   //Software breakpoint
-      BreakType = SoftwareBreakpoint;
-      break;
-      
-    case    1:   //Hardware breakpoint
-      BreakType = InstructionExecution;
-      break;
-      
-    case    2:   //Write watchpoint
-      BreakType = DataWrite;
-      break;
-
-    case    3:   //Read watchpoint
-      BreakType = DataRead;
-      break;
-
-    case    4:   //Access watchpoint
-      BreakType = DataReadWrite;
-      break;
-
-    default  :
-      SendError (GDB_EINVALIDBRKPOINTTYPE);
-      return;
-  }
-
-  //Find matching debug register
-  Status = FindMatchingDebugRegister (SystemContext, Address, Length, (UINTN)BreakType, &Register);
-  if (EFI_ERROR(Status)) {
-
-    if (Status == EFI_UNSUPPORTED) {
-      Print ((CHAR16 *)L"Not supported.\n");
-      SendNotSupported();
-      return;
-    }
-
-    Print ((CHAR16 *)L"No matching register found.\n");
-    SendError (GDB_ENOSPACE);
-    return;
-  }
-
-  //Remove breakpoint
-  Status = DisableDebugRegister(SystemContext, Register);
-  if (EFI_ERROR(Status)) {
-    Print ((CHAR16 *)L"Invalid argument.\n");
-    SendError (GDB_EINVALIDARG);
-    return;
-  }
-
-  SendSuccess ();
-}
-
-
-VOID
-InitializeProcessor (
-  VOID
-  )
-{
-}
-
-BOOLEAN
-ValidateAddress (
-  IN  VOID  *Address
-  )
-{
-  return TRUE;
-}
-
-BOOLEAN
-ValidateException (
-  IN  EFI_EXCEPTION_TYPE    ExceptionType, 
-  IN OUT EFI_SYSTEM_CONTEXT SystemContext 
-  )
-{
-  return TRUE;
-}
-
+/** @file\r
+  Processor specific parts of the GDB stub\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <GdbStubInternal.h>\r
+\r
+//\r
+// Array of exception types that need to be hooked by the debugger\r
+// {EFI mapping, GDB mapping}\r
+//\r
+EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = {\r
+  { EXCEPT_IA32_DIVIDE_ERROR,     GDB_SIGFPE  }, \r
+  { EXCEPT_IA32_DEBUG,            GDB_SIGTRAP },\r
+  { EXCEPT_IA32_NMI,              GDB_SIGEMT  },\r
+  { EXCEPT_IA32_BREAKPOINT,       GDB_SIGTRAP },\r
+  { EXCEPT_IA32_OVERFLOW,         GDB_SIGSEGV },\r
+  { EXCEPT_IA32_BOUND,            GDB_SIGSEGV },\r
+  { EXCEPT_IA32_INVALID_OPCODE,   GDB_SIGILL  },\r
+  { EXCEPT_IA32_DOUBLE_FAULT,     GDB_SIGEMT  },\r
+  { EXCEPT_IA32_STACK_FAULT,      GDB_SIGSEGV },\r
+  { EXCEPT_IA32_GP_FAULT,         GDB_SIGSEGV },\r
+  { EXCEPT_IA32_PAGE_FAULT,       GDB_SIGSEGV },\r
+  { EXCEPT_IA32_FP_ERROR,         GDB_SIGEMT  },\r
+  { EXCEPT_IA32_ALIGNMENT_CHECK,  GDB_SIGEMT  },\r
+  { EXCEPT_IA32_MACHINE_CHECK,    GDB_SIGEMT  }\r
+};\r
+\r
+\r
+// The offsets of registers SystemContext.\r
+// The fields in the array are in the gdb ordering.\r
+//\r
+//16 regs\r
+UINTN gRegisterOffsets[] = {\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eax),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ecx),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Edx),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ebx),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Esp),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ebp),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Esi),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Edi),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eip),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eflags),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Cs),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ss),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ds),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Es),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Fs),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Gs)\r
+};\r
+\r
+\r
+//Debug only..\r
+VOID \r
+PrintReg (\r
+  IN EFI_SYSTEM_CONTEXT SystemContext\r
+  )\r
+{\r
+  Print ((CHAR16 *)L"EAX: %x ", SystemContext.SystemContextIa32->Eax);\r
+  Print ((CHAR16 *)L"ECX: %x ", SystemContext.SystemContextIa32->Ecx);\r
+  Print ((CHAR16 *)L"EDX: %x ", SystemContext.SystemContextIa32->Edx);\r
+  Print ((CHAR16 *)L"EBX: %x ", SystemContext.SystemContextIa32->Ebx);\r
+  Print ((CHAR16 *)L"ESP: %x ", SystemContext.SystemContextIa32->Esp);\r
+  Print ((CHAR16 *)L"EBP: %x ", SystemContext.SystemContextIa32->Ebp);\r
+  Print ((CHAR16 *)L"ESI: %x ", SystemContext.SystemContextIa32->Esi);\r
+  Print ((CHAR16 *)L"EDI: %x ", SystemContext.SystemContextIa32->Edi);\r
+  Print ((CHAR16 *)L"EIP: %x\n", SystemContext.SystemContextIa32->Eip);\r
+  Print ((CHAR16 *)L"EFlags: %x\n", SystemContext.SystemContextIa32->Eflags);\r
+}\r
+\r
+//Debug only..\r
+VOID \r
+PrintDRreg (\r
+  IN EFI_SYSTEM_CONTEXT SystemContext\r
+  )\r
+{\r
+  Print ((CHAR16 *)L"DR0: %x ", SystemContext.SystemContextIa32->Dr0);\r
+  Print ((CHAR16 *)L"DR1: %x ", SystemContext.SystemContextIa32->Dr1);\r
+  Print ((CHAR16 *)L"DR2: %x ", SystemContext.SystemContextIa32->Dr2);\r
+  Print ((CHAR16 *)L"DR3: %x ", SystemContext.SystemContextIa32->Dr3);\r
+  Print ((CHAR16 *)L"DR6: %x ", SystemContext.SystemContextIa32->Dr6);\r
+  Print ((CHAR16 *)L"DR7: %x\n", SystemContext.SystemContextIa32->Dr7);\r
+}\r
+\r
+\r
+/**\r
+ Return the number of entries in the gExceptionType[]\r
\r
+ @retval  UINTN, the number of entries in the gExceptionType[] array.    \r
+ **/\r
+UINTN\r
+MaxEfiException (\r
+  VOID\r
+  )\r
+{\r
+  return sizeof (gExceptionType)/sizeof (EFI_EXCEPTION_TYPE_ENTRY);\r
+}\r
+\r
+\r
+/**\r
+ Return the number of entries in the gRegisters[]\r
\r
+ @retval  UINTN, the number of entries (registers) in the gRegisters[] array.    \r
+ **/\r
+UINTN\r
+MaxRegisterCount (\r
+  VOID\r
+  )\r
+{\r
+  return sizeof (gRegisterOffsets)/sizeof (UINTN);\r
+}\r
+\r
+\r
+/**\r
+  Check to see if the ISA is supported. \r
+  ISA = Instruction Set Architecture\r
\r
+  @retval TRUE if Isa is supported,\r
+      FALSE otherwise.\r
+**/\r
+BOOLEAN\r
+CheckIsa (\r
+  IN  EFI_INSTRUCTION_SET_ARCHITECTURE  Isa\r
+  )\r
+{\r
+  return (BOOLEAN)(Isa == IsaIa32);\r
+}\r
+\r
+\r
+/**\r
+ This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering\r
+ It is, by default, set to find the register pointer of the IA32 member\r
+\r
+ @param   SystemContext     Register content at time of the exception \r
+ @param   RegNumber       The register to which we want to find a pointer\r
+ @retval  the pointer to the RegNumber-th pointer\r
+ **/\r
+UINTN *\r
+FindPointerToRegister(\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINTN               RegNumber  \r
+  )\r
+{\r
+  UINT8 *TempPtr;\r
+  TempPtr = ((UINT8 *)SystemContext.SystemContextIa32) + gRegisterOffsets[RegNumber];\r
+  return (UINTN *)TempPtr;\r
+}\r
+\r
+\r
+/**\r
+ Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr\r
+\r
+ @param SystemContext     Register content at time of the exception\r
+ @param   RegNumber       the number of the register that we want to read\r
+ @param   OutBufPtr       pointer to the output buffer's end. the new data will be added from this point on.\r
+ @retval  the pointer to the next character of the output buffer that is available to be written on.\r
+ **/\r
+CHAR8 *\r
+BasicReadRegister (\r
+  IN  EFI_SYSTEM_CONTEXT      SystemContext,\r
+  IN  UINTN           RegNumber,\r
+  IN  CHAR8           *OutBufPtr\r
+  )\r
+{\r
+  UINTN RegSize;\r
+  \r
+  RegSize = 0;\r
+  while (RegSize < REG_SIZE) {\r
+    *OutBufPtr++ = mHexToStr[((*FindPointerToRegister(SystemContext, RegNumber) >> (RegSize+4)) & 0xf)];\r
+    *OutBufPtr++ = mHexToStr[((*FindPointerToRegister(SystemContext, RegNumber) >> RegSize) & 0xf)];\r
+    RegSize = RegSize + 8;\r
+  }\r
+  return OutBufPtr;\r
+}\r
+\r
+\r
+/** â€˜p n’ \r
+ Reads the n-th register's value into an output buffer and sends it as a packet \r
+\r
+ @param   SystemContext   Register content at time of the exception\r
+ @param   InBuffer      Pointer to the input buffer received from gdb server\r
+ **/\r
+VOID\r
+EFIAPI\r
+ReadNthRegister (\r
+  IN  EFI_SYSTEM_CONTEXT   SystemContext,\r
+  IN  CHAR8                *InBuffer\r
+  )\r
+{\r
+  UINTN RegNumber;\r
+  CHAR8 OutBuffer[9]; // 1 reg=8 hex chars, and the end '\0' (escape seq)\r
+  CHAR8 *OutBufPtr;   // pointer to the output buffer\r
+  \r
+  RegNumber = AsciiStrHexToUintn (&InBuffer[1]);\r
+\r
+  if ((RegNumber < 0) || (RegNumber >= MaxRegisterCount())) {\r
+    SendError (GDB_EINVALIDREGNUM);\r
+    return;\r
+  }\r
+\r
+  OutBufPtr = OutBuffer;\r
+  OutBufPtr = BasicReadRegister(SystemContext, RegNumber, OutBufPtr);\r
+\r
+  *OutBufPtr = '\0';  // the end of the buffer\r
+  SendPacket(OutBuffer);\r
+}\r
+\r
+\r
+/** â€˜g’ \r
+ Reads the general registers into an output buffer  and sends it as a packet \r
+\r
+ @param   SystemContext     Register content at time of the exception\r
+ **/\r
+VOID\r
+EFIAPI\r
+ReadGeneralRegisters (  \r
+  IN  EFI_SYSTEM_CONTEXT      SystemContext\r
+  )\r
+{\r
+  UINTN   i;\r
+  CHAR8 OutBuffer[129]; // 16 regs, 8 hex chars each, and the end '\0' (escape seq)\r
+  CHAR8 *OutBufPtr;   // pointer to the output buffer\r
+\r
+  OutBufPtr = OutBuffer;\r
+  for(i = 0 ; i < MaxRegisterCount() ; i++) {  // there are only 16 registers to read   \r
+    OutBufPtr = BasicReadRegister(SystemContext, i, OutBufPtr);\r
+  }\r
+\r
+  *OutBufPtr = '\0';  // the end of the buffer\r
+  SendPacket(OutBuffer);\r
+}\r
+\r
+\r
+/**\r
+ Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr\r
+\r
+ @param   SystemContext       Register content at time of the exception\r
+ @param   RegNumber         the number of the register that we want to write\r
+ @param   InBufPtr          pointer to the output buffer. the new data will be extracted from the input buffer from this point on.\r
+ @retval  the pointer to the next character of the input buffer that can be used\r
+ **/\r
+CHAR8 *\r
+BasicWriteRegister (\r
+  IN  EFI_SYSTEM_CONTEXT      SystemContext,\r
+  IN  UINTN           RegNumber,\r
+  IN  CHAR8           *InBufPtr\r
+  )\r
+{\r
+  UINTN RegSize;\r
+  UINTN TempValue; // the value transferred from a hex char\r
+  UINT32 NewValue; // the new value of the RegNumber-th Register\r
+  \r
+  NewValue = 0;\r
+  RegSize = 0;\r
+  while (RegSize < REG_SIZE) {\r
+    TempValue = HexCharToInt(*InBufPtr++);\r
+    \r
+   if (TempValue < 0) {\r
+      SendError (GDB_EBADMEMDATA); \r
+      return NULL;\r
+    }\r
+\r
+    NewValue += (TempValue << (RegSize+4));\r
+    TempValue = HexCharToInt(*InBufPtr++);\r
+    \r
+    if (TempValue < 0) {\r
+      SendError (GDB_EBADMEMDATA); \r
+      return NULL;\r
+    }\r
+    \r
+    NewValue += (TempValue << RegSize); \r
+    RegSize = RegSize + 8;\r
+  }\r
+  *(FindPointerToRegister(SystemContext, RegNumber)) = NewValue;\r
+  return InBufPtr;\r
+}\r
+\r
+\r
+/** â€˜P n...=r...’\r
+ Writes the new value of n-th register received into the input buffer to the n-th register\r
+\r
+ @param   SystemContext   Register content at time of the exception\r
+ @param   InBuffer      Ponter to the input buffer received from gdb server\r
+ **/\r
+VOID\r
+EFIAPI\r
+WriteNthRegister (\r
+  IN  EFI_SYSTEM_CONTEXT      SystemContext,\r
+  IN  CHAR8           *InBuffer\r
+  )\r
+{\r
+  UINTN RegNumber;\r
+  CHAR8 RegNumBuffer[MAX_REG_NUM_BUF_SIZE];  // put the 'n..' part of the message into this array\r
+  CHAR8 *RegNumBufPtr;\r
+  CHAR8 *InBufPtr; // pointer to the input buffer\r
+  \r
+  // find the register number to write\r
+  InBufPtr = &InBuffer[1];\r
+  RegNumBufPtr = RegNumBuffer;\r
+  while (*InBufPtr != '=') {\r
+    *RegNumBufPtr++ = *InBufPtr++;\r
+  } \r
+  *RegNumBufPtr = '\0';\r
+  RegNumber = AsciiStrHexToUintn (RegNumBuffer); \r
+\r
+  // check if this is a valid Register Number\r
+  if ((RegNumber < 0) || (RegNumber >= MaxRegisterCount())) {\r
+       SendError (GDB_EINVALIDREGNUM); \r
+    return;\r
+  }\r
+  InBufPtr++;  // skips the '=' character\r
+  BasicWriteRegister (SystemContext, RegNumber, InBufPtr);\r
+  SendSuccess();\r
+}\r
+\r
+\r
+/** â€˜G XX...’\r
+ Writes the new values received into the input buffer to the general registers\r
+\r
+ @param   SystemContext       Register content at time of the exception\r
+ @param   InBuffer          Pointer to the input buffer received from gdb server\r
+ **/\r
+VOID\r
+EFIAPI\r
+WriteGeneralRegisters (\r
+  IN  EFI_SYSTEM_CONTEXT        SystemContext,\r
+  IN  CHAR8             *InBuffer\r
+  )\r
+{\r
+  UINTN  i;\r
+  CHAR8 *InBufPtr; /// pointer to the input buffer\r
+\r
+  // check to see if the buffer is the right size which is \r
+  // 1 (for 'G') + 16 (for 16 registers) * 8 ( for 8 hex chars each) = 129 \r
+  if (AsciiStrLen(InBuffer) != 129) { // 16 regs, 8 hex chars each, and the end '\0' (escape seq)\r
+       //Bad message. Message is not the right length \r
+    SendError (GDB_EBADBUFSIZE); \r
+    return;\r
+  }\r
+\r
+  InBufPtr = &InBuffer[1];\r
+  \r
+  // Read the new values for the registers from the input buffer to an array, NewValueArray.\r
+  // The values in the array are in the gdb ordering\r
+  for(i=0; i < MaxRegisterCount(); i++) {  // there are only 16 registers to write\r
+    InBufPtr = BasicWriteRegister(SystemContext, i, InBufPtr);\r
+  }\r
+\r
+  SendSuccess();\r
+}\r
+\r
+\r
+/** \r
+ Insert Single Step in the SystemContext\r
\r
+ @param SystemContext Register content at time of the exception\r
+ **/\r
+VOID\r
+AddSingleStep (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext\r
+  )\r
+{\r
+  SystemContext.SystemContextIa32->Eflags |= TF_BIT; //Setting the TF bit.\r
+}\r
+\r
+  \r
+/** \r
+ Remove Single Step in the SystemContext\r
\r
+ @param SystemContext Register content at time of the exception\r
+ **/\r
+VOID\r
+RemoveSingleStep (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext\r
+  )\r
+{\r
+  SystemContext.SystemContextIa32->Eflags &= ~TF_BIT;  // clearing the TF bit.\r
+}\r
+\r
+\r
+\r
+/** â€˜c [addr ]’ \r
+ Continue. addr is Address to resume. If addr is omitted, resume at current \r
+ Address.\r
\r
+ @param   SystemContext     Register content at time of the exception  \r
+ **/\r
+VOID\r
+EFIAPI\r
+ContinueAtAddress (\r
+  IN  EFI_SYSTEM_CONTEXT      SystemContext,\r
+  IN    CHAR8                 *PacketData\r
+  )\r
+{\r
+  if (PacketData[1] != '\0') {\r
+    SystemContext.SystemContextIa32->Eip = AsciiStrHexToUintn (&PacketData[1]);\r
+  } \r
+}\r
+\r
+\r
+/** â€˜s [addr ]’\r
+ Single step. addr is the Address at which to resume. If addr is omitted, resume \r
+ at same Address.\r
\r
+ @param   SystemContext     Register content at time of the exception  \r
+ **/\r
+VOID\r
+EFIAPI\r
+SingleStep (\r
+  IN  EFI_SYSTEM_CONTEXT      SystemContext,\r
+  IN    CHAR8                 *PacketData\r
+  )\r
+{\r
+  if (PacketData[1] != '\0') {\r
+    SystemContext.SystemContextIa32->Eip = AsciiStrHexToUintn (&PacketData[1]);\r
+  }\r
+  \r
+  AddSingleStep (SystemContext);\r
+}\r
+\r
+\r
+/**\r
+  Returns breakpoint data address from DR0-DR3 based on the input breakpoint number\r
+\r
+  @param  SystemContext      Register content at time of the exception\r
+  @param  BreakpointNumber   Breakpoint number\r
+\r
+  @retval Address            Data address from DR0-DR3 based on the breakpoint number.\r
+\r
+**/\r
+UINTN\r
+GetBreakpointDataAddress (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINTN               BreakpointNumber\r
+  )\r
+{\r
+  UINTN Address;\r
+\r
+  if (BreakpointNumber == 1) {\r
+    Address = SystemContext.SystemContextIa32->Dr0;\r
+  } else if (BreakpointNumber == 2) {\r
+    Address = SystemContext.SystemContextIa32->Dr1;\r
+  } else if (BreakpointNumber == 3) {\r
+    Address = SystemContext.SystemContextIa32->Dr2;\r
+  } else if (BreakpointNumber == 4) {\r
+    Address = SystemContext.SystemContextIa32->Dr3;\r
+  } else {\r
+    Address = 0;\r
+  }\r
+\r
+  return Address;\r
+}\r
+\r
+\r
+/**\r
+  Returns currently detected breakpoint value based on the register DR6 B0-B3 field.\r
+  If no breakpoint is detected then it returns 0.\r
+\r
+  @param  SystemContext  Register content at time of the exception\r
+\r
+  @retval {1-4}          Currently detected breakpoint value   \r
+  @retval 0              No breakpoint detected.\r
\r
+**/\r
+UINTN\r
+GetBreakpointDetected (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext\r
+  )\r
+{\r
+  IA32_DR6 Dr6;\r
+  UINTN BreakpointNumber;\r
+\r
+  Dr6.UintN = SystemContext.SystemContextIa32->Dr6;\r
+\r
+  if (Dr6.Bits.B0 == 1) {\r
+    BreakpointNumber = 1;\r
+  } else if (Dr6.Bits.B1 == 1) {\r
+    BreakpointNumber = 2;\r
+  } else if (Dr6.Bits.B2 == 1) {\r
+    BreakpointNumber = 3;\r
+  } else if (Dr6.Bits.B3 == 1) {\r
+    BreakpointNumber = 4;\r
+  } else {\r
+    BreakpointNumber = 0;  //No breakpoint detected \r
+  }\r
+\r
+  return BreakpointNumber;\r
+}\r
+\r
+\r
+/**\r
+  Returns Breakpoint type (InstructionExecution, DataWrite, DataRead or DataReadWrite)\r
+  based on the Breakpoint number\r
+  \r
+  @param  SystemContext        Register content at time of the exception\r
+  @param  BreakpointNumber     Breakpoint number\r
+  \r
+  @retval BREAK_TYPE           Breakpoint type value read from register DR7 RWn field\r
+                               For unknown value, it returns NotSupported.\r
+  \r
+**/\r
+BREAK_TYPE\r
+GetBreakpointType (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINTN               BreakpointNumber\r
+  )\r
+{\r
+  IA32_DR7 Dr7;\r
+  BREAK_TYPE Type = NotSupported;  //Default is NotSupported type\r
+\r
+  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;\r
+\r
+  if (BreakpointNumber == 1) {\r
+    Type = (BREAK_TYPE) Dr7.Bits.RW0;  \r
+  } else if (BreakpointNumber == 2) {\r
+    Type = (BREAK_TYPE) Dr7.Bits.RW1;  \r
+  } else if (BreakpointNumber == 3) {\r
+    Type = (BREAK_TYPE) Dr7.Bits.RW2;  \r
+  } else if (BreakpointNumber == 4) {\r
+    Type = (BREAK_TYPE) Dr7.Bits.RW3;  \r
+  }\r
+\r
+  return Type;\r
+}\r
+\r
+\r
+/** \r
+  Parses Length and returns the length which DR7 LENn field accepts.\r
+  For example: If we receive 1-Byte length then we should return 0. \r
+               Zero gets written to DR7 LENn field.\r
+\r
+  @param  Length  Breakpoint length in Bytes (1 byte, 2 byte, 4 byte)\r
+\r
+  @retval Length  Appropriate converted values which DR7 LENn field accepts.\r
+\r
+**/\r
+UINTN\r
+ConvertLengthData (\r
+  IN     UINTN   Length\r
+  )\r
+{\r
+  if (Length == 1) {         //1-Byte length \r
+    return 0;\r
+  } else if (Length == 2) {  //2-Byte length\r
+    return 1;\r
+  } else if (Length == 4) {  //4-Byte length\r
+    return 3;\r
+  } else {                   //Undefined or 8-byte length\r
+    return 2;\r
+  }\r
+}\r
+\r
+\r
+/**\r
+  Finds the next free debug register. If all the registers are occupied then \r
+  EFI_OUT_OF_RESOURCES is returned.  \r
+\r
+  @param  SystemContext   Register content at time of the exception\r
+  @param  Register        Register value (0 - 3 for the first free debug register)\r
+\r
+  @retval EFI_STATUS      Appropriate status value.\r
+\r
+**/\r
+EFI_STATUS\r
+FindNextFreeDebugRegister (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  OUT UINTN               *Register\r
+  )\r
+{\r
+  IA32_DR7 Dr7;\r
+\r
+  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;\r
+\r
+  if (Dr7.Bits.G0 == 0) {\r
+    *Register = 0;\r
+  } else if (Dr7.Bits.G1 == 0) {\r
+    *Register = 1;\r
+  } else if (Dr7.Bits.G2 == 0) {\r
+    *Register = 2;\r
+  } else if (Dr7.Bits.G3 == 0) {\r
+    *Register = 3;\r
+  } else {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Enables the debug register. Writes Address value to appropriate DR0-3 register.\r
+  Sets LENn, Gn, RWn bits in DR7 register.\r
\r
+  @param  SystemContext   Register content at time of the exception\r
+  @param  Register        Register value (0 - 3) \r
+  @param  Address         Breakpoint address value\r
+  @param  Type            Breakpoint type (Instruction, Data write, Data read \r
+                          or write etc.)\r
+\r
+  @retval EFI_STATUS      Appropriate status value.\r
+\r
+**/\r
+EFI_STATUS\r
+EnableDebugRegister (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINTN               Register,\r
+  IN  UINTN               Address,\r
+  IN  UINTN               Length,\r
+  IN  UINTN               Type\r
+  )\r
+{\r
+  IA32_DR7  Dr7;\r
+\r
+  //Convert length data\r
+  Length = ConvertLengthData (Length);\r
+\r
+  //For Instruction execution, length should be 0 \r
+  //(Ref. Intel reference manual 18.2.4)\r
+  if ((Type == 0) && (Length != 0)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
\r
+  //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle\r
+  //software breakpoint. We should send empty packet in both these cases.\r
+  if ((Type == (BREAK_TYPE)DataRead) || \r
+      (Type == (BREAK_TYPE)SoftwareBreakpoint)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //Read DR7 so appropriate Gn, RWn and LENn bits can be modified.\r
+  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;\r
+\r
+  if (Register == 0) {\r
+    SystemContext.SystemContextIa32->Dr0 = Address;\r
+    Dr7.Bits.G0 = 1;\r
+    Dr7.Bits.RW0 = Type;\r
+    Dr7.Bits.LEN0 = Length;\r
+  } else if (Register == 1) {\r
+    SystemContext.SystemContextIa32->Dr1 = Address;\r
+    Dr7.Bits.G1 = 1;\r
+    Dr7.Bits.RW1 = Type;\r
+    Dr7.Bits.LEN1 = Length;\r
+  } else if (Register == 2) {\r
+    SystemContext.SystemContextIa32->Dr2 = Address;\r
+    Dr7.Bits.G2 = 1;\r
+    Dr7.Bits.RW2 = Type;\r
+    Dr7.Bits.LEN2 = Length;\r
+  } else if (Register == 3) {\r
+    SystemContext.SystemContextIa32->Dr3 = Address;\r
+    Dr7.Bits.G3 = 1;\r
+    Dr7.Bits.RW3 = Type;\r
+    Dr7.Bits.LEN3 = Length;\r
+  } else {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //Update Dr7 with appropriate Gn, RWn and LENn bits \r
+  SystemContext.SystemContextIa32->Dr7 = Dr7.UintN;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Returns register number 0 - 3 for the maching debug register.\r
+  This function compares incoming Address, Type, Length and\r
+  if there is a match then it returns the appropriate register number.\r
+  In case of mismatch, function returns EFI_NOT_FOUND message.\r
+\r
+  @param  SystemContext  Register content at time of the exception\r
+  @param  Address        Breakpoint address value\r
+  @param  Length         Breakpoint length value\r
+  @param  Type           Breakpoint type (Instruction, Data write, \r
+                         Data read or write etc.)\r
+  @param  Register       Register value to be returned\r
+\r
+  @retval EFI_STATUS     Appropriate status value.\r
+\r
+**/\r
+EFI_STATUS\r
+FindMatchingDebugRegister (\r
+ IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+ IN  UINTN               Address,\r
+ IN  UINTN               Length,\r
+ IN  UINTN               Type,\r
+ OUT UINTN               *Register\r
+ )\r
+{\r
+  IA32_DR7 Dr7;\r
+\r
+  //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle\r
+  //software breakpoint. We should send empty packet in both these cases.\r
+  if ((Type == (BREAK_TYPE)DataRead) || \r
+      (Type == (BREAK_TYPE)SoftwareBreakpoint)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //Convert length data\r
+  Length = ConvertLengthData(Length);\r
+\r
+  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;\r
+\r
+  if ((Dr7.Bits.G0 == 1) && \r
+      (Dr7.Bits.LEN0 == Length) &&\r
+      (Dr7.Bits.RW0 == Type) && \r
+      (Address == SystemContext.SystemContextIa32->Dr0)) {\r
+    *Register = 0;\r
+  } else if ((Dr7.Bits.G1 == 1) && \r
+             (Dr7.Bits.LEN1 == Length) &&\r
+             (Dr7.Bits.RW1 == Type) && \r
+             (Address == SystemContext.SystemContextIa32->Dr1)) {\r
+    *Register = 1;\r
+  } else if ((Dr7.Bits.G2 == 1) && \r
+             (Dr7.Bits.LEN2 == Length) &&\r
+             (Dr7.Bits.RW2 == Type) && \r
+             (Address == SystemContext.SystemContextIa32->Dr2)) {\r
+    *Register = 2;\r
+  } else if ((Dr7.Bits.G3 == 1) && \r
+             (Dr7.Bits.LEN3 == Length) &&\r
+             (Dr7.Bits.RW3 == Type) && \r
+             (Address == SystemContext.SystemContextIa32->Dr3)) {\r
+    *Register = 3;\r
+  } else {\r
+    Print ((CHAR16 *)L"No match found..\n");\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Disables the particular debug register.\r
+\r
+  @param  SystemContext   Register content at time of the exception\r
+  @param  Register        Register to be disabled\r
+\r
+  @retval EFI_STATUS      Appropriate status value.\r
+\r
+**/\r
+EFI_STATUS\r
+DisableDebugRegister (\r
+ IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+ IN  UINTN               Register  \r
+ )\r
+{\r
+  IA32_DR7  Dr7;\r
+  UINTN Address = 0;\r
\r
+  //Read DR7 register so appropriate Gn, RWn and LENn bits can be turned off.\r
+  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;\r
+\r
+  if (Register == 0) {\r
+    SystemContext.SystemContextIa32->Dr0 = Address;\r
+    Dr7.Bits.G0 = 0;\r
+    Dr7.Bits.RW0 = 0;\r
+    Dr7.Bits.LEN0 = 0;\r
+  } else if (Register == 1) {\r
+    SystemContext.SystemContextIa32->Dr1 = Address;\r
+    Dr7.Bits.G1 = 0;\r
+    Dr7.Bits.RW1 = 0;\r
+    Dr7.Bits.LEN1 = 0;\r
+  } else if (Register == 2) {\r
+    SystemContext.SystemContextIa32->Dr2 = Address;\r
+    Dr7.Bits.G2 = 0;\r
+    Dr7.Bits.RW2 = 0;\r
+    Dr7.Bits.LEN2 = 0;\r
+  } else if (Register == 3) {\r
+    SystemContext.SystemContextIa32->Dr3 = Address;\r
+    Dr7.Bits.G3 = 0;\r
+    Dr7.Bits.RW3 = 0;\r
+    Dr7.Bits.LEN3 = 0;\r
+  } else {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //Update DR7 register so appropriate Gn, RWn and LENn bits can be turned off.\r
+  SystemContext.SystemContextIa32->Dr7 = Dr7.UintN;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  â€˜Z1, [addr], [length]’\r
+  â€˜Z2, [addr], [length]’\r
+  â€˜Z3, [addr], [length]’\r
+  â€˜Z4, [addr], [length]’\r
+\r
+  Insert hardware breakpoint/watchpoint at address addr of size length\r
+\r
+  @param SystemContext  Register content at time of the exception\r
+  @param *PacketData    Pointer to the Payload data for the packet\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+InsertBreakPoint (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  CHAR8              *PacketData\r
+  )\r
+{\r
+  UINTN Type;\r
+  UINTN Address;\r
+  UINTN Length;\r
+  UINTN Register;\r
+  EFI_STATUS Status;\r
+  BREAK_TYPE BreakType = NotSupported;\r
+  UINTN ErrorCode;\r
+\r
+  ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length);\r
+  if (ErrorCode > 0) {\r
+    SendError ((UINT8)ErrorCode);\r
+    return;\r
+  }\r
+\r
+  switch (Type) {\r
+\r
+    case    0:   //Software breakpoint\r
+      BreakType = SoftwareBreakpoint;\r
+      break;\r
+\r
+    case    1:   //Hardware breakpoint\r
+      BreakType = InstructionExecution;\r
+      break;\r
+\r
+    case    2:   //Write watchpoint\r
+      BreakType = DataWrite;\r
+      break;\r
+\r
+    case    3:   //Read watchpoint\r
+      BreakType = DataRead;\r
+      break;\r
+\r
+    case    4:   //Access watchpoint\r
+      BreakType = DataReadWrite;\r
+      break;\r
+\r
+    default  :\r
+      Print ((CHAR16 *)L"Insert breakpoint default: %x\n", Type);\r
+      SendError (GDB_EINVALIDBRKPOINTTYPE);\r
+      return;\r
+  }\r
+\r
+  // Find next free debug register\r
+  Status = FindNextFreeDebugRegister (SystemContext, &Register);\r
+  if (EFI_ERROR(Status)) {\r
+    Print ((CHAR16 *)L"No space left on device\n");\r
+    SendError (GDB_ENOSPACE);\r
+    return;\r
+  }\r
+\r
+  // Write Address, length data at particular DR register\r
+  Status = EnableDebugRegister (SystemContext, Register, Address, Length, (UINTN)BreakType);\r
+  if (EFI_ERROR(Status)) {\r
+\r
+    if (Status == EFI_UNSUPPORTED) {\r
+      Print ((CHAR16 *)L"Not supported\n");\r
+      SendNotSupported();\r
+      return;\r
+    }\r
+\r
+    Print ((CHAR16 *)L"Invalid argument\n");\r
+    SendError (GDB_EINVALIDARG);\r
+    return;\r
+  }\r
+\r
+  SendSuccess ();\r
+}\r
+\r
+\r
+/**\r
+  â€˜z1, [addr], [length]’\r
+  â€˜z2, [addr], [length]’\r
+  â€˜z3, [addr], [length]’\r
+  â€˜z4, [addr], [length]’\r
+\r
+  Remove hardware breakpoint/watchpoint at address addr of size length\r
+\r
+  @param *PacketData    Pointer to the Payload data for the packet\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+RemoveBreakPoint (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  CHAR8               *PacketData\r
+  )\r
+{\r
+  UINTN      Type;\r
+  UINTN      Address;\r
+  UINTN      Length;\r
+  UINTN      Register;\r
+  BREAK_TYPE BreakType = NotSupported;\r
+  EFI_STATUS Status;\r
+  UINTN      ErrorCode;\r
+\r
+  //Parse breakpoint packet data\r
+  ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length);\r
+  if (ErrorCode > 0) {\r
+    SendError ((UINT8)ErrorCode);\r
+    return;\r
+  }\r
+\r
+  switch (Type) {\r
+  \r
+    case    0:   //Software breakpoint\r
+      BreakType = SoftwareBreakpoint;\r
+      break;\r
+      \r
+    case    1:   //Hardware breakpoint\r
+      BreakType = InstructionExecution;\r
+      break;\r
+      \r
+    case    2:   //Write watchpoint\r
+      BreakType = DataWrite;\r
+      break;\r
+\r
+    case    3:   //Read watchpoint\r
+      BreakType = DataRead;\r
+      break;\r
+\r
+    case    4:   //Access watchpoint\r
+      BreakType = DataReadWrite;\r
+      break;\r
+\r
+    default  :\r
+      SendError (GDB_EINVALIDBRKPOINTTYPE);\r
+      return;\r
+  }\r
+\r
+  //Find matching debug register\r
+  Status = FindMatchingDebugRegister (SystemContext, Address, Length, (UINTN)BreakType, &Register);\r
+  if (EFI_ERROR(Status)) {\r
+\r
+    if (Status == EFI_UNSUPPORTED) {\r
+      Print ((CHAR16 *)L"Not supported.\n");\r
+      SendNotSupported();\r
+      return;\r
+    }\r
+\r
+    Print ((CHAR16 *)L"No matching register found.\n");\r
+    SendError (GDB_ENOSPACE);\r
+    return;\r
+  }\r
+\r
+  //Remove breakpoint\r
+  Status = DisableDebugRegister(SystemContext, Register);\r
+  if (EFI_ERROR(Status)) {\r
+    Print ((CHAR16 *)L"Invalid argument.\n");\r
+    SendError (GDB_EINVALIDARG);\r
+    return;\r
+  }\r
+\r
+  SendSuccess ();\r
+}\r
+\r
+\r
+VOID\r
+InitializeProcessor (\r
+  VOID\r
+  )\r
+{\r
+}\r
+\r
+BOOLEAN\r
+ValidateAddress (\r
+  IN  VOID  *Address\r
+  )\r
+{\r
+  return TRUE;\r
+}\r
+\r
+BOOLEAN\r
+ValidateException (\r
+  IN  EFI_EXCEPTION_TYPE    ExceptionType, \r
+  IN OUT EFI_SYSTEM_CONTEXT SystemContext \r
+  )\r
+{\r
+  return TRUE;\r
+}\r
+\r
index 8fb8610877429065f03b8fbc3b95b0ed53c237ff..2df967a52a3c4ebbe293430b8c0891bd2c41263e 100644 (file)
-/** @file
-  Serial IO Abstraction for GDB stub. This allows an EFI consoles that shows up on the system 
-  running GDB. One consle for error information and another console for user input/output.
-  
-  Basic packet format is $packet-data#checksum. So every comand has 4 bytes of overhead: $, 
-  #, 0, 0. The 0 and 0 are the ascii characters for the checksum. 
-  
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <GdbStubInternal.h>
-
-//
-// Set TRUE if F Reply package signals a ctrl-c. We can not process the Ctrl-c
-// here we need to wait for the periodic callback to do this. 
-//
-BOOLEAN gCtrlCBreakFlag = FALSE;
-
-//
-// If the periodic callback is called while we are processing an F packet we need
-// to let the callback know to not read from the serail stream as it could steal
-// characters from the F reponse packet
-//
-BOOLEAN gProcessingFPacket = FALSE;
-
-/**
-  Process a control-C break message. 
-  
-  Currently a place holder, remove the ASSERT when it gets implemented. 
-
-  @param  ErrNo   Error infomration from the F reply packet or other source
-
-**/
-
-VOID
-GdbCtrlCBreakMessage (
-  IN  UINTN ErrNo
-  )
-{
-  // See D.10.5 of gdb.pdf
-  // This should look like a break message. Should look like SIGINT
-
-  /* TODO: Make sure if we should do anything with ErrNo */
-  //Turn on the global Ctrl-C flag.
-  gCtrlCBreakFlag = TRUE;
-}
-
-
-/**
-  Parse the F reply packet and extract the return value and an ErrNo if it exists.
-
-  @param  Packet  Packet to parse like an F reply packet
-  @param  ErrNo   Buffer to hold Count bytes that were read
-
-  @retval -1      Error, not a valid F reply packet 
-  @retval other   Return the return code from the F reply packet 
-
-**/
-INTN
-GdbParseFReplyPacket (
-  IN  CHAR8   *Packet,
-  OUT UINTN   *ErrNo   
-  )
-{
-  INTN   RetCode;
-   
-  if (Packet[0] != 'F') {
-    // A valid responce would be an F packet
-    return -1;
-  }
-  
-  RetCode = AsciiStrHexToUintn (&Packet[1]);
-  
-  // Find 1st comma 
-  for (;*Packet != '\0' && *Packet != ',';  Packet++);  
-  if (*Packet == '\0') {
-    *ErrNo = 0;
-    return RetCode;
-  }
-  
-  *ErrNo = AsciiStrHexToUintn (++Packet);
-
-  // Find 2nd comma 
-  for (;*Packet != '\0' && *Packet != ',';  Packet++);  
-  if (*Packet == '\0') {
-    return RetCode;
-  }
-  
-  if (*(++Packet) == 'C') {
-    GdbCtrlCBreakMessage (*ErrNo);  
-  }
-  
-  return RetCode;
-}
-
-
-/**
-  Read data from a FileDescriptor. On success number of bytes read is returned. Zero indicates 
-  the end of a file. On error -1 is returned. If count is zero, GdbRead returns zero.
-
-  @param  FileDescriptor   Device to talk to.
-  @param  Buffer           Buffer to hold Count bytes that were read
-  @param  Count            Number of bytes to transfer. 
-
-  @retval -1               Error
-  @retval {other}          Number of bytes read.
-
-**/
-INTN
-GdbRead (
-  IN  INTN    FileDescriptor,
-  OUT VOID    *Buffer,
-  IN  UINTN   Count
-  )
-{
-  CHAR8   Packet[128];
-  UINTN   Size;
-  INTN    RetCode;
-  UINTN   ErrNo;
-  BOOLEAN ReceiveDone = FALSE;
-   
-  // Send:
-  // "Fread,XX,YYYYYYYY,XX
-  //
-  // XX - FileDescriptor in ASCII
-  // YYYYYYYY - Buffer address in ASCII 
-  // XX - Count in ASCII
-  // SS - check sum
-  //
-  Size = AsciiSPrint (Packet, sizeof (Packet), "Fread,%x,%x,%x", FileDescriptor, Buffer, Count);
-  // Packet array is too small if you got this ASSERT
-  ASSERT (Size < sizeof (Packet));
-  
-  gProcessingFPacket = TRUE;
-  SendPacket (Packet);
-  Print ((CHAR16 *)L"Packet sent..\n");
-
-  do {
-    // Reply:
-    ReceivePacket (Packet, sizeof (Packet));
-    Print ((CHAR16 *)L"Command received..%c\n", Packet[0]);
-
-    // Process GDB commands
-    switch (Packet[0]) {
-      //Write memory command.
-      //M addr,length:XX...
-      case    'M':
-        WriteToMemory (Packet);
-        break;
-
-      //Fretcode, errno, Ctrl-C flag
-      //retcode - Count read
-      case    'F':
-        //Once target receives F reply packet that means the previous
-        //transactions are finished.
-        ReceiveDone = TRUE;
-        break;
-
-      //Send empty buffer
-      default    :
-        SendNotSupported();
-        break;
-    }
-  } while (ReceiveDone == FALSE);
-
-  RetCode = GdbParseFReplyPacket (Packet, &ErrNo);
-  Print ((CHAR16 *)L"RetCode: %x..ErrNo: %x..\n", RetCode, ErrNo);
-  
-  if (ErrNo > 0) {
-    //Send error to the host if there is any.
-    SendError ((UINT8)ErrNo);
-  }
-  
-  gProcessingFPacket = FALSE;
-
-  return RetCode;
-}  
-  
-
-/**
-  Write data to a FileDescriptor. On success number of bytes written is returned. Zero indicates 
-  nothing was written. On error -1 is returned. 
-
-  @param  FileDescriptor   Device to talk to.
-  @param  Buffer           Buffer to hold Count bytes that are to be written
-  @param  Count            Number of bytes to transfer. 
-
-  @retval -1               Error
-  @retval {other}          Number of bytes written.
-
-**/
-INTN
-GdbWrite (
-  IN  INTN          FileDescriptor,
-  OUT CONST VOID    *Buffer,
-  IN  UINTN         Count
-  )
-{
-  CHAR8   Packet[128];
-  UINTN   Size;
-  INTN    RetCode;
-  UINTN   ErrNo;
-  BOOLEAN ReceiveDone = FALSE;
-
-  // Send:
-  // #Fwrite,XX,YYYYYYYY,XX$SS
-  //
-  // XX - FileDescriptor in ASCII
-  // YYYYYYYY - Buffer address in ASCII 
-  // XX - Count in ASCII
-  // SS - check sum
-  //
-  Size = AsciiSPrint (Packet, sizeof (Packet), "Fwrite,%x,%x,%x", FileDescriptor, Buffer, Count);
-  // Packet array is too small if you got this ASSERT
-  ASSERT (Size < sizeof (Packet));
-  
-  SendPacket (Packet);
-  Print ((CHAR16 *)L"Packet sent..\n");
-
-  do {
-    // Reply:
-    ReceivePacket (Packet, sizeof (Packet));
-    Print ((CHAR16 *)L"Command received..%c\n", Packet[0]);
-
-    // Process GDB commands
-    switch (Packet[0]) {
-      //Read memory command.
-      //m addr,length. 
-      case    'm':
-        ReadFromMemory (Packet);
-        break;
-
-      //Fretcode, errno, Ctrl-C flag
-      //retcode - Count read
-      case    'F':
-        //Once target receives F reply packet that means the previous 
-        //transactions are finished.
-        ReceiveDone = TRUE;
-        break;
-      
-      //Send empty buffer
-      default    :  
-        SendNotSupported();
-        break;
-    }
-  } while (ReceiveDone == FALSE);
-
-  RetCode = GdbParseFReplyPacket (Packet, &ErrNo);
-  Print ((CHAR16 *)L"RetCode: %x..ErrNo: %x..\n", RetCode, ErrNo);
-
-  //Send error to the host if there is any.
-  if (ErrNo > 0) {
-    SendError((UINT8)ErrNo);
-  }
-  return RetCode;
-}
-
-
-/**
-  Reset the serial device.
-
-  @param  This              Protocol instance pointer.
-                            
-  @retval EFI_SUCCESS       The device was reset.
-  @retval EFI_DEVICE_ERROR  The serial device could not be reset.
-
-**/
-EFI_STATUS
-EFIAPI
-GdbSerialReset (
-  IN EFI_SERIAL_IO_PROTOCOL  *This
-  )
-{
-  return EFI_SUCCESS;
-}
-
-
-/**
-  Sets the baud rate, receive FIFO depth, transmit/receice time out, parity, 
-  data buts, and stop bits on a serial device.
-
-  @param  This             Protocol instance pointer.
-  @param  BaudRate         The requested baud rate. A BaudRate value of 0 will use the the
-                           device's default interface speed.
-  @param  ReveiveFifoDepth The requested depth of the FIFO on the receive side of the
-                           serial interface. A ReceiveFifoDepth value of 0 will use
-                           the device's dfault FIFO depth.
-  @param  Timeout          The requested time out for a single character in microseconds.
-                           This timeout applies to both the transmit and receive side of the
-                           interface. A Timeout value of 0 will use the device's default time
-                           out value.
-  @param  Parity           The type of parity to use on this serial device. A Parity value of
-                           DefaultParity will use the device's default parity value.
-  @param  DataBits         The number of data bits to use on the serial device. A DataBits
-                           vaule of 0 will use the device's default data bit setting.
-  @param  StopBits         The number of stop bits to use on this serial device. A StopBits
-                           value of DefaultStopBits will use the device's default number of
-                           stop bits.
-
-  @retval EFI_SUCCESS      The device was reset.
-  @retval EFI_DEVICE_ERROR The serial device could not be reset.
-
-**/
-EFI_STATUS
-EFIAPI
-GdbSerialSetAttributes (
-  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
-  )
-{
-  return EFI_UNSUPPORTED;
-}
-
-
-/**
-  Set the control bits on a serial device
-
-  @param  This             Protocol instance pointer.
-  @param  Control          Set the bits of Control that are settable.
-
-  @retval EFI_SUCCESS      The new control bits were set on the serial device.
-  @retval EFI_UNSUPPORTED  The serial device does not support this operation.
-  @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.
-
-**/
-EFI_STATUS
-EFIAPI
-GdbSerialSetControl (
-  IN EFI_SERIAL_IO_PROTOCOL  *This,
-  IN UINT32                  Control
-  )
-{
-  return EFI_UNSUPPORTED;
-}
-
-
-/**
-  Retrieves the status of thecontrol bits on a serial device
-
-  @param  This              Protocol instance pointer.
-  @param  Control           A pointer to return the current Control signals from the serial device.
-                            
-  @retval EFI_SUCCESS       The control bits were read from the serial device.
-  @retval EFI_DEVICE_ERROR  The serial device is not functioning correctly.
-
-**/
-EFI_STATUS
-EFIAPI
-GdbSerialGetControl (
-  IN EFI_SERIAL_IO_PROTOCOL  *This,
-  OUT UINT32                 *Control
-  )
-{
-  return EFI_UNSUPPORTED;
-}
-
-
-/**
-  Writes data to a serial device.
-
-  @param  This              Protocol instance pointer.
-  @param  BufferSize        On input, the size of the Buffer. On output, the amount of
-                            data actually written.
-  @param  Buffer            The buffer of data to write
-
-  @retval EFI_SUCCESS       The data was written.
-  @retval EFI_DEVICE_ERROR  The device reported an error.
-  @retval EFI_TIMEOUT       The data write was stopped due to a timeout.
-
-**/
-EFI_STATUS
-EFIAPI
-GdbSerialWrite (
-  IN EFI_SERIAL_IO_PROTOCOL  *This,
-  IN OUT UINTN               *BufferSize,
-  IN VOID                    *Buffer
-  )
-{
-  GDB_SERIAL_DEV  *SerialDev;
-  UINTN            Return;
-
-  SerialDev = GDB_SERIAL_DEV_FROM_THIS (This);
-  
-  Return = GdbWrite (SerialDev->OutFileDescriptor, Buffer, *BufferSize);
-  if (Return == (UINTN)-1) {
-    return EFI_DEVICE_ERROR;
-  }
-  
-  if (Return != *BufferSize) {
-    *BufferSize = Return;
-  }
-  
-  return EFI_SUCCESS;
-}
-
-/**
-  Writes data to a serial device.
-
-  @param  This              Protocol instance pointer.
-  @param  BufferSize        On input, the size of the Buffer. On output, the amount of
-                            data returned in Buffer.
-  @param  Buffer            The buffer to return the data into.
-
-  @retval EFI_SUCCESS       The data was read.
-  @retval EFI_DEVICE_ERROR  The device reported an error.
-  @retval EFI_TIMEOUT       The data write was stopped due to a timeout.
-
-**/
-
-EFI_STATUS
-EFIAPI
-GdbSerialRead (
-  IN EFI_SERIAL_IO_PROTOCOL  *This,
-  IN OUT UINTN               *BufferSize,
-  OUT VOID                   *Buffer
-  )
-{
-  GDB_SERIAL_DEV  *SerialDev;
-  UINTN            Return;
-
-  SerialDev = GDB_SERIAL_DEV_FROM_THIS (This);
-  
-  Return = GdbRead (SerialDev->InFileDescriptor, Buffer, *BufferSize);
-  if (Return == (UINTN)-1) {
-    return EFI_DEVICE_ERROR;
-  }
-  
-  if (Return != *BufferSize) {
-    *BufferSize = Return;
-  }
-  
-  return EFI_SUCCESS;
-}
-
-
-// 
-// Template used to initailize the GDB Serial IO protocols
-//
-GDB_SERIAL_DEV gdbSerialDevTemplate = {
-  GDB_SERIAL_DEV_SIGNATURE,
-  NULL,
-  
-  { // SerialIo
-    SERIAL_IO_INTERFACE_REVISION,
-    GdbSerialReset,
-    GdbSerialSetAttributes,
-    GdbSerialSetControl,
-    GdbSerialGetControl,
-    GdbSerialWrite,
-    GdbSerialRead,
-    NULL
-  },
-  { // SerialMode
-    0,      // ControlMask
-    0,      // Timeout
-    0,      // BaudRate
-    1,      // RceiveFifoDepth
-    0,      // DataBits
-    0,      // Parity
-    0       // StopBits
-  },
-  { 
-    {
-      HARDWARE_DEVICE_PATH,
-      HW_VENDOR_DP,
-      {
-        (UINT8) (sizeof (VENDOR_DEVICE_PATH) + sizeof (UINT32)),
-        (UINT8) ((sizeof (VENDOR_DEVICE_PATH) + sizeof (UINT32)) >> 8)
-      },
-      EFI_SERIAL_IO_PROTOCOL_GUID,
-    },
-    0,
-    {
-      END_DEVICE_PATH_TYPE,
-      END_ENTIRE_DEVICE_PATH_SUBTYPE,
-      {
-        (UINT8) (sizeof (EFI_DEVICE_PATH_PROTOCOL)),
-        (UINT8) (sizeof (EFI_DEVICE_PATH_PROTOCOL) >> 8)
-      }
-    },
-  },
-  GDB_STDIN,
-  GDB_STDOUT
-};
-
-
-/**
-  Make two serial consoles: 1) StdIn and StdOut via GDB. 2) StdErr via GDB.
-  
-  These console show up on the remote system running GDB
-
-**/
-VOID
-GdbInitializeSerialConsole (
-  VOID
-  )
-{
-  EFI_STATUS      Status;
-  GDB_SERIAL_DEV  *StdOutSerialDev;
-  GDB_SERIAL_DEV  *StdErrSerialDev;
-
-  // Use the template to make a copy of the Serial Console private data structure.
-  StdOutSerialDev = AllocateCopyPool (sizeof (GDB_SERIAL_DEV),  &gdbSerialDevTemplate);
-  ASSERT (StdOutSerialDev != NULL);
-  
-  // Fixup pointer after the copy
-  StdOutSerialDev->SerialIo.Mode = &StdOutSerialDev->SerialMode;
-  
-  StdErrSerialDev = AllocateCopyPool (sizeof (GDB_SERIAL_DEV),  &gdbSerialDevTemplate);
-  ASSERT (StdErrSerialDev != NULL);
-
-  // Fixup pointer and modify stuff that is different for StdError
-  StdErrSerialDev->SerialIo.Mode = &StdErrSerialDev->SerialMode;  
-  StdErrSerialDev->DevicePath.Index = 1;
-  StdErrSerialDev->OutFileDescriptor = GDB_STDERR;
-  
-  // Make a new handle with Serial IO protocol and its device path on it.
-  Status = gBS->InstallMultipleProtocolInterfaces (
-                  &StdOutSerialDev->Handle, 
-                  &gEfiSerialIoProtocolGuid,   &StdOutSerialDev->SerialIo,
-                  &gEfiDevicePathProtocolGuid, &StdOutSerialDev->DevicePath,
-                  NULL
-                  );
-  ASSERT_EFI_ERROR (Status);
-
-  // Make a new handle with Serial IO protocol and its device path on it.
-  Status = gBS->InstallMultipleProtocolInterfaces (
-                  &StdErrSerialDev->Handle, 
-                  &gEfiSerialIoProtocolGuid,   &StdErrSerialDev->SerialIo,
-                  &gEfiDevicePathProtocolGuid, &StdErrSerialDev->DevicePath,
-                  NULL
-                  );
-  ASSERT_EFI_ERROR (Status);
-}
-
+/** @file\r
+  Serial IO Abstraction for GDB stub. This allows an EFI consoles that shows up on the system \r
+  running GDB. One consle for error information and another console for user input/output.\r
+  \r
+  Basic packet format is $packet-data#checksum. So every comand has 4 bytes of overhead: $, \r
+  #, 0, 0. The 0 and 0 are the ascii characters for the checksum. \r
+  \r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <GdbStubInternal.h>\r
+\r
+//\r
+// Set TRUE if F Reply package signals a ctrl-c. We can not process the Ctrl-c\r
+// here we need to wait for the periodic callback to do this. \r
+//\r
+BOOLEAN gCtrlCBreakFlag = FALSE;\r
+\r
+//\r
+// If the periodic callback is called while we are processing an F packet we need\r
+// to let the callback know to not read from the serail stream as it could steal\r
+// characters from the F reponse packet\r
+//\r
+BOOLEAN gProcessingFPacket = FALSE;\r
+\r
+/**\r
+  Process a control-C break message. \r
+  \r
+  Currently a place holder, remove the ASSERT when it gets implemented. \r
+\r
+  @param  ErrNo   Error infomration from the F reply packet or other source\r
+\r
+**/\r
+\r
+VOID\r
+GdbCtrlCBreakMessage (\r
+  IN  UINTN ErrNo\r
+  )\r
+{\r
+  // See D.10.5 of gdb.pdf\r
+  // This should look like a break message. Should look like SIGINT\r
+\r
+  /* TODO: Make sure if we should do anything with ErrNo */\r
+  //Turn on the global Ctrl-C flag.\r
+  gCtrlCBreakFlag = TRUE;\r
+}\r
+\r
+\r
+/**\r
+  Parse the F reply packet and extract the return value and an ErrNo if it exists.\r
+\r
+  @param  Packet  Packet to parse like an F reply packet\r
+  @param  ErrNo   Buffer to hold Count bytes that were read\r
+\r
+  @retval -1      Error, not a valid F reply packet \r
+  @retval other   Return the return code from the F reply packet \r
+\r
+**/\r
+INTN\r
+GdbParseFReplyPacket (\r
+  IN  CHAR8   *Packet,\r
+  OUT UINTN   *ErrNo   \r
+  )\r
+{\r
+  INTN   RetCode;\r
+   \r
+  if (Packet[0] != 'F') {\r
+    // A valid responce would be an F packet\r
+    return -1;\r
+  }\r
+  \r
+  RetCode = AsciiStrHexToUintn (&Packet[1]);\r
+  \r
+  // Find 1st comma \r
+  for (;*Packet != '\0' && *Packet != ',';  Packet++);  \r
+  if (*Packet == '\0') {\r
+    *ErrNo = 0;\r
+    return RetCode;\r
+  }\r
+  \r
+  *ErrNo = AsciiStrHexToUintn (++Packet);\r
+\r
+  // Find 2nd comma \r
+  for (;*Packet != '\0' && *Packet != ',';  Packet++);  \r
+  if (*Packet == '\0') {\r
+    return RetCode;\r
+  }\r
+  \r
+  if (*(++Packet) == 'C') {\r
+    GdbCtrlCBreakMessage (*ErrNo);  \r
+  }\r
+  \r
+  return RetCode;\r
+}\r
+\r
+\r
+/**\r
+  Read data from a FileDescriptor. On success number of bytes read is returned. Zero indicates \r
+  the end of a file. On error -1 is returned. If count is zero, GdbRead returns zero.\r
+\r
+  @param  FileDescriptor   Device to talk to.\r
+  @param  Buffer           Buffer to hold Count bytes that were read\r
+  @param  Count            Number of bytes to transfer. \r
+\r
+  @retval -1               Error\r
+  @retval {other}          Number of bytes read.\r
+\r
+**/\r
+INTN\r
+GdbRead (\r
+  IN  INTN    FileDescriptor,\r
+  OUT VOID    *Buffer,\r
+  IN  UINTN   Count\r
+  )\r
+{\r
+  CHAR8   Packet[128];\r
+  UINTN   Size;\r
+  INTN    RetCode;\r
+  UINTN   ErrNo;\r
+  BOOLEAN ReceiveDone = FALSE;\r
+   \r
+  // Send:\r
+  // "Fread,XX,YYYYYYYY,XX\r
+  //\r
+  // XX - FileDescriptor in ASCII\r
+  // YYYYYYYY - Buffer address in ASCII \r
+  // XX - Count in ASCII\r
+  // SS - check sum\r
+  //\r
+  Size = AsciiSPrint (Packet, sizeof (Packet), "Fread,%x,%x,%x", FileDescriptor, Buffer, Count);\r
+  // Packet array is too small if you got this ASSERT\r
+  ASSERT (Size < sizeof (Packet));\r
+  \r
+  gProcessingFPacket = TRUE;\r
+  SendPacket (Packet);\r
+  Print ((CHAR16 *)L"Packet sent..\n");\r
+\r
+  do {\r
+    // Reply:\r
+    ReceivePacket (Packet, sizeof (Packet));\r
+    Print ((CHAR16 *)L"Command received..%c\n", Packet[0]);\r
+\r
+    // Process GDB commands\r
+    switch (Packet[0]) {\r
+      //Write memory command.\r
+      //M addr,length:XX...\r
+      case    'M':\r
+        WriteToMemory (Packet);\r
+        break;\r
+\r
+      //Fretcode, errno, Ctrl-C flag\r
+      //retcode - Count read\r
+      case    'F':\r
+        //Once target receives F reply packet that means the previous\r
+        //transactions are finished.\r
+        ReceiveDone = TRUE;\r
+        break;\r
+\r
+      //Send empty buffer\r
+      default    :\r
+        SendNotSupported();\r
+        break;\r
+    }\r
+  } while (ReceiveDone == FALSE);\r
+\r
+  RetCode = GdbParseFReplyPacket (Packet, &ErrNo);\r
+  Print ((CHAR16 *)L"RetCode: %x..ErrNo: %x..\n", RetCode, ErrNo);\r
+  \r
+  if (ErrNo > 0) {\r
+    //Send error to the host if there is any.\r
+    SendError ((UINT8)ErrNo);\r
+  }\r
+  \r
+  gProcessingFPacket = FALSE;\r
+\r
+  return RetCode;\r
+}  \r
+  \r
+\r
+/**\r
+  Write data to a FileDescriptor. On success number of bytes written is returned. Zero indicates \r
+  nothing was written. On error -1 is returned. \r
+\r
+  @param  FileDescriptor   Device to talk to.\r
+  @param  Buffer           Buffer to hold Count bytes that are to be written\r
+  @param  Count            Number of bytes to transfer. \r
+\r
+  @retval -1               Error\r
+  @retval {other}          Number of bytes written.\r
+\r
+**/\r
+INTN\r
+GdbWrite (\r
+  IN  INTN          FileDescriptor,\r
+  OUT CONST VOID    *Buffer,\r
+  IN  UINTN         Count\r
+  )\r
+{\r
+  CHAR8   Packet[128];\r
+  UINTN   Size;\r
+  INTN    RetCode;\r
+  UINTN   ErrNo;\r
+  BOOLEAN ReceiveDone = FALSE;\r
+\r
+  // Send:\r
+  // #Fwrite,XX,YYYYYYYY,XX$SS\r
+  //\r
+  // XX - FileDescriptor in ASCII\r
+  // YYYYYYYY - Buffer address in ASCII \r
+  // XX - Count in ASCII\r
+  // SS - check sum\r
+  //\r
+  Size = AsciiSPrint (Packet, sizeof (Packet), "Fwrite,%x,%x,%x", FileDescriptor, Buffer, Count);\r
+  // Packet array is too small if you got this ASSERT\r
+  ASSERT (Size < sizeof (Packet));\r
+  \r
+  SendPacket (Packet);\r
+  Print ((CHAR16 *)L"Packet sent..\n");\r
+\r
+  do {\r
+    // Reply:\r
+    ReceivePacket (Packet, sizeof (Packet));\r
+    Print ((CHAR16 *)L"Command received..%c\n", Packet[0]);\r
+\r
+    // Process GDB commands\r
+    switch (Packet[0]) {\r
+      //Read memory command.\r
+      //m addr,length. \r
+      case    'm':\r
+        ReadFromMemory (Packet);\r
+        break;\r
+\r
+      //Fretcode, errno, Ctrl-C flag\r
+      //retcode - Count read\r
+      case    'F':\r
+        //Once target receives F reply packet that means the previous \r
+        //transactions are finished.\r
+        ReceiveDone = TRUE;\r
+        break;\r
+      \r
+      //Send empty buffer\r
+      default    :  \r
+        SendNotSupported();\r
+        break;\r
+    }\r
+  } while (ReceiveDone == FALSE);\r
+\r
+  RetCode = GdbParseFReplyPacket (Packet, &ErrNo);\r
+  Print ((CHAR16 *)L"RetCode: %x..ErrNo: %x..\n", RetCode, ErrNo);\r
+\r
+  //Send error to the host if there is any.\r
+  if (ErrNo > 0) {\r
+    SendError((UINT8)ErrNo);\r
+  }\r
\r
+  return RetCode;\r
+}\r
+\r
+\r
+/**\r
+  Reset the serial device.\r
+\r
+  @param  This              Protocol instance pointer.\r
+                            \r
+  @retval EFI_SUCCESS       The device was reset.\r
+  @retval EFI_DEVICE_ERROR  The serial device could not be reset.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GdbSerialReset (\r
+  IN EFI_SERIAL_IO_PROTOCOL  *This\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Sets the baud rate, receive FIFO depth, transmit/receice time out, parity, \r
+  data buts, and stop bits on a serial device.\r
+\r
+  @param  This             Protocol instance pointer.\r
+  @param  BaudRate         The requested baud rate. A BaudRate value of 0 will use the the\r
+                           device's default interface speed.\r
+  @param  ReveiveFifoDepth The requested depth of the FIFO on the receive side of the\r
+                           serial interface. A ReceiveFifoDepth value of 0 will use\r
+                           the device's dfault FIFO depth.\r
+  @param  Timeout          The requested time out for a single character in microseconds.\r
+                           This timeout applies to both the transmit and receive side of the\r
+                           interface. A Timeout value of 0 will use the device's default time\r
+                           out value.\r
+  @param  Parity           The type of parity to use on this serial device. A Parity value of\r
+                           DefaultParity will use the device's default parity value.\r
+  @param  DataBits         The number of data bits to use on the serial device. A DataBits\r
+                           vaule of 0 will use the device's default data bit setting.\r
+  @param  StopBits         The number of stop bits to use on this serial device. A StopBits\r
+                           value of DefaultStopBits will use the device's default number of\r
+                           stop bits.\r
+\r
+  @retval EFI_SUCCESS      The device was reset.\r
+  @retval EFI_DEVICE_ERROR The serial device could not be reset.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GdbSerialSetAttributes (\r
+  IN EFI_SERIAL_IO_PROTOCOL  *This,\r
+  IN UINT64                  BaudRate,\r
+  IN UINT32                  ReceiveFifoDepth,\r
+  IN UINT32                  Timeout,\r
+  IN EFI_PARITY_TYPE         Parity,\r
+  IN UINT8                   DataBits,\r
+  IN EFI_STOP_BITS_TYPE      StopBits\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Set the control bits on a serial device\r
+\r
+  @param  This             Protocol instance pointer.\r
+  @param  Control          Set the bits of Control that are settable.\r
+\r
+  @retval EFI_SUCCESS      The new control bits were set on the serial device.\r
+  @retval EFI_UNSUPPORTED  The serial device does not support this operation.\r
+  @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GdbSerialSetControl (\r
+  IN EFI_SERIAL_IO_PROTOCOL  *This,\r
+  IN UINT32                  Control\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Retrieves the status of thecontrol bits on a serial device\r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  Control           A pointer to return the current Control signals from the serial device.\r
+                            \r
+  @retval EFI_SUCCESS       The control bits were read from the serial device.\r
+  @retval EFI_DEVICE_ERROR  The serial device is not functioning correctly.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GdbSerialGetControl (\r
+  IN EFI_SERIAL_IO_PROTOCOL  *This,\r
+  OUT UINT32                 *Control\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Writes data to a serial device.\r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  BufferSize        On input, the size of the Buffer. On output, the amount of\r
+                            data actually written.\r
+  @param  Buffer            The buffer of data to write\r
+\r
+  @retval EFI_SUCCESS       The data was written.\r
+  @retval EFI_DEVICE_ERROR  The device reported an error.\r
+  @retval EFI_TIMEOUT       The data write was stopped due to a timeout.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GdbSerialWrite (\r
+  IN EFI_SERIAL_IO_PROTOCOL  *This,\r
+  IN OUT UINTN               *BufferSize,\r
+  IN VOID                    *Buffer\r
+  )\r
+{\r
+  GDB_SERIAL_DEV  *SerialDev;\r
+  UINTN            Return;\r
+\r
+  SerialDev = GDB_SERIAL_DEV_FROM_THIS (This);\r
+  \r
+  Return = GdbWrite (SerialDev->OutFileDescriptor, Buffer, *BufferSize);\r
+  if (Return == (UINTN)-1) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  \r
+  if (Return != *BufferSize) {\r
+    *BufferSize = Return;\r
+  }\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Writes data to a serial device.\r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  BufferSize        On input, the size of the Buffer. On output, the amount of\r
+                            data returned in Buffer.\r
+  @param  Buffer            The buffer to return the data into.\r
+\r
+  @retval EFI_SUCCESS       The data was read.\r
+  @retval EFI_DEVICE_ERROR  The device reported an error.\r
+  @retval EFI_TIMEOUT       The data write was stopped due to a timeout.\r
+\r
+**/\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GdbSerialRead (\r
+  IN EFI_SERIAL_IO_PROTOCOL  *This,\r
+  IN OUT UINTN               *BufferSize,\r
+  OUT VOID                   *Buffer\r
+  )\r
+{\r
+  GDB_SERIAL_DEV  *SerialDev;\r
+  UINTN            Return;\r
+\r
+  SerialDev = GDB_SERIAL_DEV_FROM_THIS (This);\r
+  \r
+  Return = GdbRead (SerialDev->InFileDescriptor, Buffer, *BufferSize);\r
+  if (Return == (UINTN)-1) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  \r
+  if (Return != *BufferSize) {\r
+    *BufferSize = Return;\r
+  }\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+// \r
+// Template used to initailize the GDB Serial IO protocols\r
+//\r
+GDB_SERIAL_DEV gdbSerialDevTemplate = {\r
+  GDB_SERIAL_DEV_SIGNATURE,\r
+  NULL,\r
+  \r
+  { // SerialIo\r
+    SERIAL_IO_INTERFACE_REVISION,\r
+    GdbSerialReset,\r
+    GdbSerialSetAttributes,\r
+    GdbSerialSetControl,\r
+    GdbSerialGetControl,\r
+    GdbSerialWrite,\r
+    GdbSerialRead,\r
+    NULL\r
+  },\r
+  { // SerialMode\r
+    0,      // ControlMask\r
+    0,      // Timeout\r
+    0,      // BaudRate\r
+    1,      // RceiveFifoDepth\r
+    0,      // DataBits\r
+    0,      // Parity\r
+    0       // StopBits\r
+  },\r
+  { \r
+    {\r
+      HARDWARE_DEVICE_PATH,\r
+      HW_VENDOR_DP,\r
+      {\r
+        (UINT8) (sizeof (VENDOR_DEVICE_PATH) + sizeof (UINT32)),\r
+        (UINT8) ((sizeof (VENDOR_DEVICE_PATH) + sizeof (UINT32)) >> 8)\r
+      },\r
+      EFI_SERIAL_IO_PROTOCOL_GUID,\r
+    },\r
+    0,\r
+    {\r
+      END_DEVICE_PATH_TYPE,\r
+      END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+      {\r
+        (UINT8) (sizeof (EFI_DEVICE_PATH_PROTOCOL)),\r
+        (UINT8) (sizeof (EFI_DEVICE_PATH_PROTOCOL) >> 8)\r
+      }\r
+    },\r
+  },\r
+  GDB_STDIN,\r
+  GDB_STDOUT\r
+};\r
+\r
+\r
+/**\r
+  Make two serial consoles: 1) StdIn and StdOut via GDB. 2) StdErr via GDB.\r
+  \r
+  These console show up on the remote system running GDB\r
+\r
+**/\r
+VOID\r
+GdbInitializeSerialConsole (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+  GDB_SERIAL_DEV  *StdOutSerialDev;\r
+  GDB_SERIAL_DEV  *StdErrSerialDev;\r
+\r
+  // Use the template to make a copy of the Serial Console private data structure.\r
+  StdOutSerialDev = AllocateCopyPool (sizeof (GDB_SERIAL_DEV),  &gdbSerialDevTemplate);\r
+  ASSERT (StdOutSerialDev != NULL);\r
+  \r
+  // Fixup pointer after the copy\r
+  StdOutSerialDev->SerialIo.Mode = &StdOutSerialDev->SerialMode;\r
+  \r
+  StdErrSerialDev = AllocateCopyPool (sizeof (GDB_SERIAL_DEV),  &gdbSerialDevTemplate);\r
+  ASSERT (StdErrSerialDev != NULL);\r
+\r
+  // Fixup pointer and modify stuff that is different for StdError\r
+  StdErrSerialDev->SerialIo.Mode = &StdErrSerialDev->SerialMode;  \r
+  StdErrSerialDev->DevicePath.Index = 1;\r
+  StdErrSerialDev->OutFileDescriptor = GDB_STDERR;\r
+  \r
+  // Make a new handle with Serial IO protocol and its device path on it.\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &StdOutSerialDev->Handle, \r
+                  &gEfiSerialIoProtocolGuid,   &StdOutSerialDev->SerialIo,\r
+                  &gEfiDevicePathProtocolGuid, &StdOutSerialDev->DevicePath,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  // Make a new handle with Serial IO protocol and its device path on it.\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &StdErrSerialDev->Handle, \r
+                  &gEfiSerialIoProtocolGuid,   &StdErrSerialDev->SerialIo,\r
+                  &gEfiDevicePathProtocolGuid, &StdErrSerialDev->DevicePath,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
index 6a363e00027560f06098f82da3c3735bbdb9cd63..1b9769509b982df212f300fd5c9962b012b57437 100755 (executable)
@@ -60,4 +60,4 @@ DebugAgentTimerEndOfInterrupt (
 #endif\r
 \r
 \r
 #endif\r
 \r
 \r
-  
\ No newline at end of file
+  \r
\ No newline at end of file
index badaf21361a915a7255784df60c2f76f4474d7d0..6e876dd26ab04b8b110cfd4895371454d7b04071 100755 (executable)
@@ -1,45 +1,45 @@
-/** @file
-  DMA abstraction library APIs. Based on UEFI PCI IO protocol DMA abstractions.
-  At some point these functions will probably end up in a non PCI protocol 
-  for embedded systems.
-
+/** @file\r
+  DMA abstraction library APIs. Based on UEFI PCI IO protocol DMA abstractions.\r
+  At some point these functions will probably end up in a non PCI protocol \r
+  for embedded systems.\r
+\r
   DMA Bus Master Read Operation:\r
   DMA Bus Master Read Operation:\r
-    Call DmaMap() for MapOperationBusMasterRead. 
-    Program the DMA Bus Master with the DeviceAddress returned by DmaMap(). 
-    Start the DMA Bus Master. 
-    Wait for DMA Bus Master to complete the read operation. 
-    Call DmaUnmap().
-
-  DMA Bus Master Write Operation:
+    Call DmaMap() for MapOperationBusMasterRead. \r
+    Program the DMA Bus Master with the DeviceAddress returned by DmaMap(). \r
+    Start the DMA Bus Master. \r
+    Wait for DMA Bus Master to complete the read operation. \r
+    Call DmaUnmap().\r
+\r
+  DMA Bus Master Write Operation:\r
     Call DmaMap() for MapOperationBusMasterWrite.\r
     Program the DMA Bus Master with the DeviceAddress returned by DmaMap().\r
     Start the DMA Bus Master.\r
     Wait for DMA Bus Master to complete the write operation.\r
     Call DmaMap() for MapOperationBusMasterWrite.\r
     Program the DMA Bus Master with the DeviceAddress returned by DmaMap().\r
     Start the DMA Bus Master.\r
     Wait for DMA Bus Master to complete the write operation.\r
-    Call DmaUnmap().
-
-  DMA Bus Master Common Buffer Operation:
-    Call DmaAllocateBuffer() to allocate a common buffer. 
-    Call DmaMap() for MapOperationBusMasterCommonBuffer. 
-    Program the DMA Bus Master with the DeviceAddress returned by DmaMap(). 
-    The common buffer can now be accessed equally by the processor and the DMA bus master. 
-    Call DmaUnmap(). 
-    Call DmaFreeBuffer().
-
-  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __DMA_LIB_H__
-#define __DMA_LIB_H__
-
+    Call DmaUnmap().\r
+\r
+  DMA Bus Master Common Buffer Operation:\r
+    Call DmaAllocateBuffer() to allocate a common buffer. \r
+    Call DmaMap() for MapOperationBusMasterCommonBuffer. \r
+    Program the DMA Bus Master with the DeviceAddress returned by DmaMap(). \r
+    The common buffer can now be accessed equally by the processor and the DMA bus master. \r
+    Call DmaUnmap(). \r
+    Call DmaFreeBuffer().\r
+\r
+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __DMA_LIB_H__\r
+#define __DMA_LIB_H__\r
+\r
 typedef enum {\r
   ///\r
   /// A read operation from system memory by a bus master.\r
 typedef enum {\r
   ///\r
   /// A read operation from system memory by a bus master.\r
@@ -56,10 +56,10 @@ typedef enum {
   MapOperationBusMasterCommonBuffer,\r
   MapOperationMaximum\r
 } DMA_MAP_OPERATION;\r
   MapOperationBusMasterCommonBuffer,\r
   MapOperationMaximum\r
 } DMA_MAP_OPERATION;\r
-
-
-
-
+\r
+\r
+\r
+\r
 /**                                                                 \r
   Provides the DMA controller-specific addresses needed to access system memory.\r
   \r
 /**                                                                 \r
   Provides the DMA controller-specific addresses needed to access system memory.\r
   \r
@@ -79,20 +79,20 @@ typedef enum {
   @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
   @retval EFI_DEVICE_ERROR      The system hardware could not map the requested address.\r
                                    \r
   @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
   @retval EFI_DEVICE_ERROR      The system hardware could not map the requested address.\r
                                    \r
-**/
-EFI_STATUS
-EFIAPI
-DmaMap (
-  IN     DMA_MAP_OPERATION              Operation,
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DmaMap (\r
+  IN     DMA_MAP_OPERATION              Operation,\r
   IN     VOID                           *HostAddress,\r
   IN OUT UINTN                          *NumberOfBytes,\r
   OUT    PHYSICAL_ADDRESS               *DeviceAddress,\r
   OUT    VOID                           **Mapping\r
   IN     VOID                           *HostAddress,\r
   IN OUT UINTN                          *NumberOfBytes,\r
   OUT    PHYSICAL_ADDRESS               *DeviceAddress,\r
   OUT    VOID                           **Mapping\r
-  );
-
-
-
-
+  );\r
+\r
+\r
+\r
+\r
 /**                                                                 \r
   Completes the DmaMapBusMasterRead, DmaMapBusMasterWrite, or DmaMapBusMasterCommonBuffer\r
   operation and releases any corresponding resources.\r
 /**                                                                 \r
   Completes the DmaMapBusMasterRead, DmaMapBusMasterWrite, or DmaMapBusMasterCommonBuffer\r
   operation and releases any corresponding resources.\r
@@ -102,14 +102,14 @@ DmaMap (
   @retval EFI_SUCCESS           The range was unmapped.\r
   @retval EFI_DEVICE_ERROR      The data was not committed to the target system memory.\r
                                    \r
   @retval EFI_SUCCESS           The range was unmapped.\r
   @retval EFI_DEVICE_ERROR      The data was not committed to the target system memory.\r
                                    \r
-**/
-EFI_STATUS
-EFIAPI
-DmaUnmap (
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DmaUnmap (\r
   IN  VOID                         *Mapping\r
   IN  VOID                         *Mapping\r
-  );
-
-
+  );\r
+\r
+\r
 /**                                                                 \r
   Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.\r
   mapping.                                                                       \r
 /**                                                                 \r
   Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.\r
   mapping.                                                                       \r
@@ -126,16 +126,16 @@ DmaUnmap (
   @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
   @retval EFI_OUT_OF_RESOURCES  The memory pages could not be allocated.  \r
                                    \r
   @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
   @retval EFI_OUT_OF_RESOURCES  The memory pages could not be allocated.  \r
                                    \r
-**/
-EFI_STATUS
-EFIAPI
-DmaAllocateBuffer (
-  IN  EFI_MEMORY_TYPE              MemoryType,
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DmaAllocateBuffer (\r
+  IN  EFI_MEMORY_TYPE              MemoryType,\r
   IN  UINTN                        Pages,\r
   OUT VOID                         **HostAddress\r
   );\r
   IN  UINTN                        Pages,\r
   OUT VOID                         **HostAddress\r
   );\r
-
-
+\r
+\r
 /**                                                                 \r
   Frees memory that was allocated with DmaAllocateBuffer().\r
             \r
 /**                                                                 \r
   Frees memory that was allocated with DmaAllocateBuffer().\r
             \r
@@ -147,13 +147,13 @@ DmaAllocateBuffer (
                                 was not allocated with DmaAllocateBuffer().\r
                                      \r
 **/\r
                                 was not allocated with DmaAllocateBuffer().\r
                                      \r
 **/\r
-EFI_STATUS
-EFIAPI
-DmaFreeBuffer (
+EFI_STATUS\r
+EFIAPI\r
+DmaFreeBuffer (\r
   IN  UINTN                        Pages,\r
   IN  VOID                         *HostAddress\r
   );\r
   IN  UINTN                        Pages,\r
   IN  VOID                         *HostAddress\r
   );\r
-
-
-#endif 
-
+\r
+\r
+#endif \r
+\r
index c00d04f4d48115440637db9fe19cc07b758b5944..f760f8e2afc11d47857950622de0e2f8d5139ea6 100644 (file)
-/** @file
-  Include file for basic command line parser for EBL (Embedded Boot Loader)
-
-  Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
-  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __EBL_ADD_EXTERNAL_COMMAND_LIB_H__
-#define __EBL_ADD_EXTERNAL_COMMAND_LIB_H__
-
-#include <PiDxe.h>
-#include <Protocol/EblAddCommand.h>
-
-
-EFI_STATUS
-EFIAPI
-EblAddExternalCommands (
-  IN const EBL_COMMAND_TABLE   *EntryArray,
-  IN UINTN                     ArrayCount
-  );
-
-/**
-
-  Return a keypress or optionally timeout if a timeout value was passed in.
-
-  An optional callback function is called every second when waiting for a
-
-  timeout.
-
-
-
-  @param  Key           EFI Key information returned
-
-  @param  TimeoutInSec  Number of seconds to wait to timeout
-
-  @param  CallBack      Callback called every second during the timeout wait 
-
-
-
-  @return EFI_SUCCESS  Key was returned
-
-  @return EFI_TIMEOUT  If the TimoutInSec expired
-
-
-
-**/
-
-EFI_STATUS
-
-EFIAPI
-
-EblGetCharKey (
-
-  IN OUT EFI_INPUT_KEY            *Key,
-
-  IN     UINTN                    TimeoutInSec,
-
-  IN     EBL_GET_CHAR_CALL_BACK   CallBack   OPTIONAL
-
-  );
-
-
-
-
-
-/**
-
-  This routine is used prevent command output data from scrolling off the end
-
-  of the screen. The global gPageBreak is used to turn on or off this feature.
-
-  If the CurrentRow is near the end of the screen pause and print out a prompt
-
-  If the use hits Q to quit return TRUE else for any other key return FALSE.
-
-  PrefixNewline is used to figure out if a newline is needed before the prompt
-
-  string. This depends on the last print done before calling this function.
-
-  CurrentRow is updated by one on a call or set back to zero if a prompt is 
-
-  needed.
-
-
-
-  @param  CurrentRow  Used to figure out if its the end of the page and updated
-
-  @param  PrefixNewline  Did previous print issue a newline
-
-
-
-  @return TRUE if Q was hit to quit, FALSE in all other cases.
-
-
-
-**/
-
-BOOLEAN
-
-EFIAPI
-
-EblAnyKeyToContinueQtoQuit (
-
-  IN  UINTN   *CurrentRow,
-
-  IN  BOOLEAN PrefixNewline
-
-  );
-
-
-
-#endif
-
+/** @file\r
+  Include file for basic command line parser for EBL (Embedded Boot Loader)\r
+\r
+  Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
+  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __EBL_ADD_EXTERNAL_COMMAND_LIB_H__\r
+#define __EBL_ADD_EXTERNAL_COMMAND_LIB_H__\r
+\r
+#include <PiDxe.h>\r
+#include <Protocol/EblAddCommand.h>\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EblAddExternalCommands (\r
+  IN const EBL_COMMAND_TABLE   *EntryArray,\r
+  IN UINTN                     ArrayCount\r
+  );\r
+\r
+/**\r
+\r
+  Return a keypress or optionally timeout if a timeout value was passed in.\r
+\r
+  An optional callback function is called every second when waiting for a\r
+\r
+  timeout.\r
+\r
+\r
+\r
+  @param  Key           EFI Key information returned\r
+\r
+  @param  TimeoutInSec  Number of seconds to wait to timeout\r
+\r
+  @param  CallBack      Callback called every second during the timeout wait \r
+\r
+\r
+\r
+  @return EFI_SUCCESS  Key was returned\r
+\r
+  @return EFI_TIMEOUT  If the TimoutInSec expired\r
+\r
+\r
+\r
+**/\r
+\r
+EFI_STATUS\r
+\r
+EFIAPI\r
+\r
+EblGetCharKey (\r
+\r
+  IN OUT EFI_INPUT_KEY            *Key,\r
+\r
+  IN     UINTN                    TimeoutInSec,\r
+\r
+  IN     EBL_GET_CHAR_CALL_BACK   CallBack   OPTIONAL\r
+\r
+  );\r
+\r
+\r
+\r
+\r
+\r
+/**\r
+\r
+  This routine is used prevent command output data from scrolling off the end\r
+\r
+  of the screen. The global gPageBreak is used to turn on or off this feature.\r
+\r
+  If the CurrentRow is near the end of the screen pause and print out a prompt\r
+\r
+  If the use hits Q to quit return TRUE else for any other key return FALSE.\r
+\r
+  PrefixNewline is used to figure out if a newline is needed before the prompt\r
+\r
+  string. This depends on the last print done before calling this function.\r
+\r
+  CurrentRow is updated by one on a call or set back to zero if a prompt is \r
+\r
+  needed.\r
+\r
+\r
+\r
+  @param  CurrentRow  Used to figure out if its the end of the page and updated\r
+\r
+  @param  PrefixNewline  Did previous print issue a newline\r
+\r
+\r
+\r
+  @return TRUE if Q was hit to quit, FALSE in all other cases.\r
+\r
+\r
+\r
+**/\r
+\r
+BOOLEAN\r
+\r
+EFIAPI\r
+\r
+EblAnyKeyToContinueQtoQuit (\r
+\r
+  IN  UINTN   *CurrentRow,\r
+\r
+  IN  BOOLEAN PrefixNewline\r
+\r
+  );\r
+\r
+\r
+\r
+#endif\r
+\r
index 8974463c8c97559063d30b2c7d826ff98c1806c2..5c21d05f00093754c918ed99bbec57ce3a9395e0 100644 (file)
@@ -1,48 +1,48 @@
-/** @file
-  Include file for basic command line parser for EBL (Embedded Boot Loader)
-
-  Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
-  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __EBL_LIB_H__
-#define __EBL_LIB_H__
-
-#include <PiDxe.h>
-#include <Protocol/EblAddCommand.h>
-
-
-VOID
-EblAddCommand (
-  IN const EBL_COMMAND_TABLE   *Entry
-  );
-
-VOID
-EblAddCommands (
-  IN const EBL_COMMAND_TABLE   *EntryArray,
-  IN UINTN                     ArrayCount
-  );
-
-
-//
-// LIbrary constructor called directly from Ebl Code. 
-// This module calls EblAddCommand () or EblAddCommands () to register new commands
-//
-VOID
-EblInitializeExternalCmd (
-  VOID
-  );
-
-
-
-#endif
-
+/** @file\r
+  Include file for basic command line parser for EBL (Embedded Boot Loader)\r
+\r
+  Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
+  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __EBL_LIB_H__\r
+#define __EBL_LIB_H__\r
+\r
+#include <PiDxe.h>\r
+#include <Protocol/EblAddCommand.h>\r
+\r
+\r
+VOID\r
+EblAddCommand (\r
+  IN const EBL_COMMAND_TABLE   *Entry\r
+  );\r
+\r
+VOID\r
+EblAddCommands (\r
+  IN const EBL_COMMAND_TABLE   *EntryArray,\r
+  IN UINTN                     ArrayCount\r
+  );\r
+\r
+\r
+//\r
+// LIbrary constructor called directly from Ebl Code. \r
+// This module calls EblAddCommand () or EblAddCommands () to register new commands\r
+//\r
+VOID\r
+EblInitializeExternalCmd (\r
+  VOID\r
+  );\r
+\r
+\r
+\r
+#endif\r
+\r
index c72973b753b11b8598a64c6e716478bbc63e1ff8..9292cf9b0f4fe832ce75c83fa9ae3a228fba051f 100644 (file)
@@ -1,68 +1,68 @@
-/** @file
-  Abstractions for Ebl network accesses.
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __EBL_NETWORK_LIB_H__
-#define __EBL_NETWORK_LIB_H__
-
-#include <Protocol/PxeBaseCode.h>
-
-
-EFI_STATUS
-EFIAPI
-EblGetCurrentIpAddress (
-  IN OUT EFI_IP_ADDRESS *Ip
-  );
-
-EFI_STATUS
-EFIAPI
-EblGetCurrentMacAddress (
-  IN OUT  EFI_MAC_ADDRESS *Mac
-  );
-
-CHAR8 *
-EFIAPI
-EblLoadFileBootTypeString (
-  IN  EFI_HANDLE Handle
-  );
-
-EFI_STATUS
-EFIAPI
-EblPerformDHCP (
-  IN  BOOLEAN  SortOffers
-  );
-
-EFI_STATUS
-EFIAPI
-EblSetStationIp (
-  IN EFI_IP_ADDRESS *NewStationIp,  OPTIONAL
-  IN EFI_IP_ADDRESS *NewSubnetMask  OPTIONAL
-  );
-  
-EFI_STATUS
-EFIAPI
-EblMtftp (
-  IN EFI_PXE_BASE_CODE_TFTP_OPCODE             Operation,
-  IN OUT VOID                                  *BufferPtr OPTIONAL,
-  IN BOOLEAN                                   Overwrite,
-  IN OUT UINT64                                *BufferSize,
-  IN UINTN                                     *BlockSize OPTIONAL,
-  IN EFI_IP_ADDRESS                            *ServerIp,
-  IN UINT8                                     *Filename  OPTIONAL,
-  IN EFI_PXE_BASE_CODE_MTFTP_INFO              *Info      OPTIONAL,
-  IN BOOLEAN                                   DontUseBuffer
-  );
-  
-#endif
-
+/** @file\r
+  Abstractions for Ebl network accesses.\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __EBL_NETWORK_LIB_H__\r
+#define __EBL_NETWORK_LIB_H__\r
+\r
+#include <Protocol/PxeBaseCode.h>\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EblGetCurrentIpAddress (\r
+  IN OUT EFI_IP_ADDRESS *Ip\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EblGetCurrentMacAddress (\r
+  IN OUT  EFI_MAC_ADDRESS *Mac\r
+  );\r
+\r
+CHAR8 *\r
+EFIAPI\r
+EblLoadFileBootTypeString (\r
+  IN  EFI_HANDLE Handle\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EblPerformDHCP (\r
+  IN  BOOLEAN  SortOffers\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EblSetStationIp (\r
+  IN EFI_IP_ADDRESS *NewStationIp,  OPTIONAL\r
+  IN EFI_IP_ADDRESS *NewSubnetMask  OPTIONAL\r
+  );\r
+  \r
+EFI_STATUS\r
+EFIAPI\r
+EblMtftp (\r
+  IN EFI_PXE_BASE_CODE_TFTP_OPCODE             Operation,\r
+  IN OUT VOID                                  *BufferPtr OPTIONAL,\r
+  IN BOOLEAN                                   Overwrite,\r
+  IN OUT UINT64                                *BufferSize,\r
+  IN UINTN                                     *BlockSize OPTIONAL,\r
+  IN EFI_IP_ADDRESS                            *ServerIp,\r
+  IN UINT8                                     *Filename  OPTIONAL,\r
+  IN EFI_PXE_BASE_CODE_MTFTP_INFO              *Info      OPTIONAL,\r
+  IN BOOLEAN                                   DontUseBuffer\r
+  );\r
+  \r
+#endif\r
+\r
index 55800b9fc52a4a420a93060bff68443f3aefc50d..6e8eeb4e6f32e0ae37bb953e8b0a841aaaae6657 100644 (file)
-/** @file
-  Basic serial IO abstaction for GDB
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __GDB_SERIAL_LIB_H__
-#define __GDB_SERIAL_LIB_H__
-
-
-
-/**
-  Sets the baud rate, receive FIFO depth, transmit/receice time out, parity, 
-  data buts, and stop bits on a serial device. This call is optional as the serial
-  port will be set up with defaults base on PCD values.
-
-  @param  BaudRate         The requested baud rate. A BaudRate value of 0 will use the the
-                           device's default interface speed.
-  @param  Parity           The type of parity to use on this serial device. A Parity value of
-                           DefaultParity will use the device's default parity value.
-  @param  DataBits         The number of data bits to use on the serial device. A DataBits
-                           vaule of 0 will use the device's default data bit setting.
-  @param  StopBits         The number of stop bits to use on this serial device. A StopBits
-                           value of DefaultStopBits will use the device's default number of
-                           stop bits.
-
-  @retval EFI_SUCCESS      The device was configured.
-  @retval EFI_DEVICE_ERROR The serial device could not be coonfigured.
-
-**/
-RETURN_STATUS
-EFIAPI
-GdbSerialInit (
-  IN UINT64     BaudRate, 
-  IN UINT8      Parity, 
-  IN UINT8      DataBits, 
-  IN UINT8      StopBits 
-  ); 
-
-
-/**
-  Check to see if a character is available from GDB. Do not read the character as that is
-  done via GdbGetChar().
-
-  @return TRUE  - Character availible
-  @return FALSE - Character not availible
-  
-**/
-BOOLEAN
-EFIAPI
-GdbIsCharAvailable (
-  VOID
-  );
-
-/**
-  Get a character from GDB. This function must be able to run in interrupt context.
-
-  @return A character from GDB
-  
-**/
-CHAR8
-EFIAPI
-GdbGetChar (
-  VOID
-  );
-
-
-/**
-  Send a character to GDB. This function must be able to run in interrupt context.
-
-
-  @param  Char    Send a character to GDB
-
-**/
-
-VOID
-EFIAPI
-GdbPutChar (
-  IN  CHAR8   Char
-  );
-
-
-/**
-  Send an ASCII string to GDB. This function must be able to run in interrupt context.
-
-
-  @param  String    Send a string to GDB
-
-**/
-
-VOID
-GdbPutString (
-  IN CHAR8  *String
-  );
-
-
-#endif
-
+/** @file\r
+  Basic serial IO abstaction for GDB\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __GDB_SERIAL_LIB_H__\r
+#define __GDB_SERIAL_LIB_H__\r
+\r
+\r
+\r
+/**\r
+  Sets the baud rate, receive FIFO depth, transmit/receice time out, parity, \r
+  data buts, and stop bits on a serial device. This call is optional as the serial\r
+  port will be set up with defaults base on PCD values.\r
+\r
+  @param  BaudRate         The requested baud rate. A BaudRate value of 0 will use the the\r
+                           device's default interface speed.\r
+  @param  Parity           The type of parity to use on this serial device. A Parity value of\r
+                           DefaultParity will use the device's default parity value.\r
+  @param  DataBits         The number of data bits to use on the serial device. A DataBits\r
+                           vaule of 0 will use the device's default data bit setting.\r
+  @param  StopBits         The number of stop bits to use on this serial device. A StopBits\r
+                           value of DefaultStopBits will use the device's default number of\r
+                           stop bits.\r
+\r
+  @retval EFI_SUCCESS      The device was configured.\r
+  @retval EFI_DEVICE_ERROR The serial device could not be coonfigured.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+GdbSerialInit (\r
+  IN UINT64     BaudRate, \r
+  IN UINT8      Parity, \r
+  IN UINT8      DataBits, \r
+  IN UINT8      StopBits \r
+  ); \r
+\r
+\r
+/**\r
+  Check to see if a character is available from GDB. Do not read the character as that is\r
+  done via GdbGetChar().\r
+\r
+  @return TRUE  - Character availible\r
+  @return FALSE - Character not availible\r
+  \r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+GdbIsCharAvailable (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Get a character from GDB. This function must be able to run in interrupt context.\r
+\r
+  @return A character from GDB\r
+  \r
+**/\r
+CHAR8\r
+EFIAPI\r
+GdbGetChar (\r
+  VOID\r
+  );\r
+\r
+\r
+/**\r
+  Send a character to GDB. This function must be able to run in interrupt context.\r
+\r
+\r
+  @param  Char    Send a character to GDB\r
+\r
+**/\r
+\r
+VOID\r
+EFIAPI\r
+GdbPutChar (\r
+  IN  CHAR8   Char\r
+  );\r
+\r
+\r
+/**\r
+  Send an ASCII string to GDB. This function must be able to run in interrupt context.\r
+\r
+\r
+  @param  String    Send a string to GDB\r
+\r
+**/\r
+\r
+VOID\r
+GdbPutString (\r
+  IN CHAR8  *String\r
+  );\r
+\r
+\r
+#endif\r
+\r
index 444d7e2885c507100f03bb80503c0cf5f849fbff..6144513a86ec57d0af6b7d09df8b849fd581b2fd 100644 (file)
-/** @file
-  Library that helps implement monolithic PEI. (SEC goes to DXE)
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __PRE_PI_LIB_H__
-#define __PRE_PI_LIB_H__
-
-#include <Guid/ExtractSection.h>
-
-/**
-  This service enables discovery of additional firmware volumes.
-
-  @param  Instance              This instance of the firmware volume to find.  The value 0 is the
-                                Boot Firmware Volume (BFV).
-  @param  FwVolHeader           Pointer to the firmware volume header of the volume to return.
-
-  @retval EFI_SUCCESS           The volume was found.
-  @retval EFI_NOT_FOUND         The volume was not found.
-  @retval EFI_INVALID_PARAMETER FwVolHeader is NULL.
-
-**/
-EFI_STATUS
-EFIAPI
-FfsFindNextVolume (
-  IN UINTN                          Instance,
-  IN OUT EFI_PEI_FV_HANDLE          *VolumeHandle
-  );
-
-
-/**
-  This service enables discovery of additional firmware files.
-
-  @param  SearchType            A filter to find files only of this type.
-  @param  FwVolHeader           Pointer to the firmware volume header of the volume to search.
-                                This parameter must point to a valid FFS volume.
-  @param  FileHeader            Pointer to the current file from which to begin searching.
-
-  @retval EFI_SUCCESS           The file was found.
-  @retval EFI_NOT_FOUND         The file was not found.
-  @retval EFI_NOT_FOUND         The header checksum was not zero.
-
-**/
-EFI_STATUS
-EFIAPI
-FfsFindNextFile (
-  IN EFI_FV_FILETYPE            SearchType,
-  IN EFI_PEI_FV_HANDLE          VolumeHandle,
-  IN OUT EFI_PEI_FILE_HANDLE    *FileHandle
-  );
-
-
-/**
-  This service enables discovery sections of a given type within a valid FFS file.
-
-  @param  SearchType            The value of the section type to find.
-  @param  FfsFileHeader         A pointer to the file header that contains the set of sections to
-                                be searched.
-  @param  SectionData           A pointer to the discovered section, if successful.
-
-  @retval EFI_SUCCESS           The section was found.
-  @retval EFI_NOT_FOUND         The section was not found.
-
-**/
-EFI_STATUS
-EFIAPI
-FfsFindSectionData (
-  IN EFI_SECTION_TYPE           SectionType,
-  IN EFI_PEI_FILE_HANDLE        FileHandle,
-  OUT VOID                      **SectionData
-  );
-
-
-/**
-  Find a file in the volume by name
-  
-  @param FileName       A pointer to the name of the file to
-                        find within the firmware volume.
-
-  @param VolumeHandle   The firmware volume to search FileHandle
-                        Upon exit, points to the found file's
-                        handle or NULL if it could not be found.
-
-  @retval EFI_SUCCESS             File was found.
-
-  @retval EFI_NOT_FOUND           File was not found.
-
-  @retval EFI_INVALID_PARAMETER   VolumeHandle or FileHandle or
-                                  FileName was NULL.
-
-**/
-EFI_STATUS
-EFIAPI
-FfsFindByName (
-  IN CONST  EFI_GUID            *FileName,
-  IN CONST  EFI_PEI_FV_HANDLE   VolumeHandle,
-  OUT       EFI_PEI_FILE_HANDLE *FileHandle
-  );
-
-
-/**
-  Get information about the file by name.
-
-  @param FileHandle   Handle of the file.
-
-  @param FileInfo     Upon exit, points to the file's
-                      information.
-
-  @retval EFI_SUCCESS             File information returned.
-  
-  @retval EFI_INVALID_PARAMETER   If FileHandle does not
-                                  represent a valid file.
-  
-  @retval EFI_INVALID_PARAMETER   If FileInfo is NULL.
-  
-**/
-EFI_STATUS
-EFIAPI 
-FfsGetFileInfo (
-  IN CONST  EFI_PEI_FILE_HANDLE   FileHandle,
-  OUT EFI_FV_FILE_INFO            *FileInfo
-  );
-
-
-/**
-  Get Information about the volume by name
-
-  @param VolumeHandle   Handle of the volume.
-
-  @param VolumeInfo     Upon exit, points to the volume's
-                        information.
-
-  @retval EFI_SUCCESS             File information returned.
-  
-  @retval EFI_INVALID_PARAMETER   If FileHandle does not
-                                  represent a valid file.
-  
-  @retval EFI_INVALID_PARAMETER   If FileInfo is NULL.
-
-**/
-EFI_STATUS
-EFIAPI
-FfsGetVolumeInfo (
-  IN  EFI_PEI_FV_HANDLE       VolumeHandle,
-  OUT EFI_FV_INFO             *VolumeInfo
-  );
-
-
-
-/**
-  Get Fv image from the FV type file, then add FV & FV2 Hob.
-
-       @param FileHandle               File handle of a Fv type file.
-
-
-  @retval EFI_NOT_FOUND                                FV image can't be found.
-  @retval EFI_SUCCESS                                          Successfully to process it.
-
-**/
-EFI_STATUS
-EFIAPI
-FfsProcessFvFile (
-  IN  EFI_PEI_FILE_HANDLE   FvFileHandle
-  );
-
-
-/**
-  Search through every FV until you find a file of type FileType
-
-       @param FileType             File handle of a Fv type file.
-  @param Volumehandle   On succes Volume Handle of the match
-  @param FileHandle     On success File Handle of the match
-  
-  @retval EFI_NOT_FOUND                                FV image can't be found.
-  @retval EFI_SUCCESS                                          Successfully found FileType
-
-**/
-EFI_STATUS
-EFIAPI
-FfsAnyFvFindFirstFile (
-  IN  EFI_FV_FILETYPE       FileType,
-  OUT EFI_PEI_FV_HANDLE     *VolumeHandle,
-  OUT EFI_PEI_FILE_HANDLE   *FileHandle
-  );
-
-
-/**
-  Get Fv image from the FV type file, then add FV & FV2 Hob.
-
-       @param FileHandle               File handle of a Fv type file.
-
-
-  @retval EFI_NOT_FOUND                                FV image can't be found.
-  @retval EFI_SUCCESS                                          Successfully to process it.
-
-**/
-EFI_STATUS
-EFIAPI
-FfsProcessFvFile (
-  IN  EFI_PEI_FILE_HANDLE   FvFileHandle
-  );
-
-
-/**
-  This service enables PEIMs to ascertain the present value of the boot mode.  
-
-
-  @retval BootMode           
-
-**/
-EFI_BOOT_MODE
-EFIAPI
-GetBootMode (
-  VOID
-  );
-
-
-/**
-  This service enables PEIMs to update the boot mode variable.    
-
-  @param  BootMode              The value of the boot mode to set.
-
-  @retval EFI_SUCCESS           The value was successfully updated
-
-**/
-EFI_STATUS
-EFIAPI
-SetBootMode (
-  IN EFI_BOOT_MODE              BootMode
-  );
-
-/**
-  This service enables a PEIM to ascertain the address of the list of HOBs in memory.
-
-  @param  HobList               A pointer to the list of HOBs that the PEI Foundation will initialize.
-
-  @retval EFI_SUCCESS           The list was successfully returned.
-  @retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published.
-
-**/
-VOID *
-EFIAPI
-GetHobList (
-  VOID         
-  );
-
-
-/**
-  Updates the pointer to the HOB list.
-
-  @param  HobList       Hob list pointer to store
-  
-**/
-EFI_STATUS
-EFIAPI
-SetHobList (
-  IN  VOID      *HobList
-  );
-
-EFI_HOB_HANDOFF_INFO_TABLE*
-HobConstructor (
-  IN VOID   *EfiMemoryBegin,
-  IN UINTN  EfiMemoryLength,
-  IN VOID   *EfiFreeMemoryBottom,
-  IN VOID   *EfiFreeMemoryTop
-  );
-
-/**
-  Retrieves the magic value from the PE/COFF header.
-
-  @param  Hdr             The buffer in which to return the PE32, PE32+, or TE header.
-
-  @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32
-  @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+
-
-**/
-VOID
-CreateHobList (
-  IN VOID   *MemoryBegin,
-  IN UINTN  MemoryLength,
-  IN VOID   *HobBase,
-  IN VOID   *StackBase
-  );
-
-
-/**
-  This service enables PEIMs to create various types of HOBs.
-
-  @param  Type                  The type of HOB to be installed.
-  @param  Length                The length of the HOB to be added.
-
-  @retval !NULL                 The HOB was successfully created.
-  @retval NULL                  There is no additional space for HOB creation.
-
-**/
-VOID *
-CreateHob (
-  IN  UINT16    HobType,
-  IN  UINT16    HobLenght
-  );
-
-
-/**
-  Returns the next instance of a HOB type from the starting HOB.
-
-  This function searches the first instance of a HOB type from the starting HOB pointer. 
-  If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
-  In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
-  unconditionally: it returns HobStart back if HobStart itself meets the requirement;
-  caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
-  If HobStart is NULL, then ASSERT().
-
-  @param  Type          The HOB type to return.
-  @param  HobStart      The starting HOB pointer to search from.
-
-  @return The next instance of a HOB type from the starting HOB.
-
-**/
-VOID *
-EFIAPI
-GetNextHob (
-  IN UINT16                 Type,
-  IN CONST VOID             *HobStart
-  );
-
-/**
-  Returns the first instance of a HOB type among the whole HOB list.
-
-  This function searches the first instance of a HOB type among the whole HOB list. 
-  If there does not exist such HOB type in the HOB list, it will return NULL. 
-
-  @param  Type          The HOB type to return.
-
-  @return The next instance of a HOB type from the starting HOB.
-
-**/
-VOID *
-EFIAPI
-GetFirstHob (
-  IN UINT16                 Type
-  );
-
-/**
-  This function searches the first instance of a HOB from the starting HOB pointer. 
-  Such HOB should satisfy two conditions: 
-  its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid. 
-  If there does not exist such HOB from the starting HOB pointer, it will return NULL. 
-  Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
-  to extract the data section and its size info respectively.
-  In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
-  unconditionally: it returns HobStart back if HobStart itself meets the requirement;
-  caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
-  If Guid is NULL, then ASSERT().
-  If HobStart is NULL, then ASSERT().
-
-  @param  Guid          The GUID to match with in the HOB list.
-  @param  HobStart      A pointer to a Guid.
-
-  @return The next instance of the matched GUID HOB from the starting HOB.
-
-**/
-VOID *
-EFIAPI
-GetNextGuidHob (
-  IN CONST EFI_GUID         *Guid,
-  IN CONST VOID             *HobStart
-  );
-
-/**
-  This function searches the first instance of a HOB among the whole HOB list. 
-  Such HOB should satisfy two conditions:
-  its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
-  If there does not exist such HOB from the starting HOB pointer, it will return NULL.
-  Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
-  to extract the data section and its size info respectively.
-  If Guid is NULL, then ASSERT().
-
-  @param  Guid          The GUID to match with in the HOB list.
-
-  @return The first instance of the matched GUID HOB among the whole HOB list.
-
-**/
-VOID *
-EFIAPI
-GetFirstGuidHob (
-  IN CONST EFI_GUID         *Guid
-  );
-
-
-/**
-  Builds a HOB for a loaded PE32 module.
-
-  This function builds a HOB for a loaded PE32 module.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If ModuleName is NULL, then ASSERT().
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  ModuleName              The GUID File Name of the module.
-  @param  MemoryAllocationModule  The 64 bit physical address of the module.
-  @param  ModuleLength            The length of the module in bytes.
-  @param  EntryPoint              The 64 bit physical address of the module entry point.
-
-**/
-VOID
-EFIAPI
-BuildModuleHob (
-  IN CONST EFI_GUID         *ModuleName,
-  IN EFI_PHYSICAL_ADDRESS   MemoryAllocationModule,
-  IN UINT64                 ModuleLength,
-  IN EFI_PHYSICAL_ADDRESS   EntryPoint
-  );
-
-/**
-  Builds a HOB that describes a chunk of system memory.
-
-  This function builds a HOB that describes a chunk of system memory.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  ResourceType        The type of resource described by this HOB.
-  @param  ResourceAttribute   The resource attributes of the memory described by this HOB.
-  @param  PhysicalStart       The 64 bit physical address of memory described by this HOB.
-  @param  NumberOfBytes       The length of the memory described by this HOB in bytes.
-
-**/
-VOID
-EFIAPI
-BuildResourceDescriptorHob (
-  IN EFI_RESOURCE_TYPE            ResourceType,
-  IN EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute,
-  IN EFI_PHYSICAL_ADDRESS         PhysicalStart,
-  IN UINT64                       NumberOfBytes
-  );
-
-/**
-  Builds a GUID HOB with a certain data length.
-
-  This function builds a customized HOB tagged with a GUID for identification 
-  and returns the start address of GUID HOB data so that caller can fill the customized data. 
-  The HOB Header and Name field is already stripped.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If Guid is NULL, then ASSERT().
-  If there is no additional space for HOB creation, then ASSERT().
-  If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
-
-  @param  Guid          The GUID to tag the customized HOB.
-  @param  DataLength    The size of the data payload for the GUID HOB.
-
-  @return The start address of GUID HOB data.
-
-**/
-VOID *
-EFIAPI
-BuildGuidHob (
-  IN CONST EFI_GUID              *Guid,
-  IN UINTN                       DataLength
-  );
-
-/**
-  Copies a data buffer to a newly-built HOB.
-
-  This function builds a customized HOB tagged with a GUID for identification,
-  copies the input data to the HOB data field and returns the start address of the GUID HOB data.
-  The HOB Header and Name field is already stripped.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If Guid is NULL, then ASSERT().
-  If Data is NULL and DataLength > 0, then ASSERT().
-  If there is no additional space for HOB creation, then ASSERT().
-  If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
-
-  @param  Guid          The GUID to tag the customized HOB.
-  @param  Data          The data to be copied into the data field of the GUID HOB.
-  @param  DataLength    The size of the data payload for the GUID HOB.
-
-  @return The start address of GUID HOB data.
-
-**/
-VOID *
-EFIAPI
-BuildGuidDataHob (
-  IN CONST EFI_GUID              *Guid,
-  IN VOID                        *Data,
-  IN UINTN                       DataLength
-  );
-
-/**
-  Builds a Firmware Volume HOB.
-
-  This function builds a Firmware Volume HOB.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  BaseAddress   The base address of the Firmware Volume.
-  @param  Length        The size of the Firmware Volume in bytes.
-
-**/
-VOID
-EFIAPI
-BuildFvHob (
-  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
-  IN UINT64                      Length
-  );
-
-/**
-  Builds a Firmware Volume HOB and a resrouce descriptor hob 
-
-  This function builds a Firmware Volume HOB.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  BaseAddress   The base address of the Firmware Volume.
-  @param  Length        The size of the Firmware Volume in bytes.
-
-**/
-VOID
-EFIAPI
-BuildFvHobs (  
-  IN EFI_PHYSICAL_ADDRESS         PhysicalStart,
-  IN UINT64                       NumberOfBytes,
-  IN EFI_RESOURCE_ATTRIBUTE_TYPE  *ResourceAttribute  OPTIONAL
-  ); 
-
-
-/**
-  Builds a EFI_HOB_TYPE_FV2 HOB.
-
-  This function builds a EFI_HOB_TYPE_FV2 HOB.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  BaseAddress   The base address of the Firmware Volume.
-  @param  Length        The size of the Firmware Volume in bytes.
-  @param  FvName       The name of the Firmware Volume.
-  @param  FileName      The name of the file.
-  
-**/
-VOID
-EFIAPI
-BuildFv2Hob (
-  IN          EFI_PHYSICAL_ADDRESS        BaseAddress,
-  IN          UINT64                      Length,
-  IN CONST    EFI_GUID                    *FvName,
-  IN CONST    EFI_GUID                    *FileName
-  );
-
-/**
-  Builds a Capsule Volume HOB.
-
-  This function builds a Capsule Volume HOB.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  BaseAddress   The base address of the Capsule Volume.
-  @param  Length        The size of the Capsule Volume in bytes.
-
-**/
-VOID
-EFIAPI
-BuildCvHob (
-  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
-  IN UINT64                      Length
-  );
-
-/**
-  Builds a HOB for the CPU.
-
-  This function builds a HOB for the CPU.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  SizeOfMemorySpace   The maximum physical memory addressability of the processor.
-  @param  SizeOfIoSpace       The maximum physical I/O addressability of the processor.
-
-**/
-VOID
-EFIAPI
-BuildCpuHob (
-  IN UINT8                       SizeOfMemorySpace,
-  IN UINT8                       SizeOfIoSpace
-  );
-
-/**
-  Builds a HOB for the Stack.
-
-  This function builds a HOB for the stack.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  BaseAddress   The 64 bit physical address of the Stack.
-  @param  Length        The length of the stack in bytes.
-
-**/
-VOID
-EFIAPI
-BuildStackHob (
-  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
-  IN UINT64                      Length
-  );
-
-/**
-  Update the Stack Hob if the stack has been moved
-
-  @param  BaseAddress   The 64 bit physical address of the Stack.
-  @param  Length        The length of the stack in bytes.
-
-**/
-VOID
-UpdateStackHob (
-  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
-  IN UINT64                      Length
-  );
-
-
-/**
-  Builds a HOB for the BSP store.
-
-  This function builds a HOB for BSP store.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  BaseAddress   The 64 bit physical address of the BSP.
-  @param  Length        The length of the BSP store in bytes.
-  @param  MemoryType    Type of memory allocated by this HOB.
-
-**/
-VOID
-EFIAPI
-BuildBspStoreHob (
-  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
-  IN UINT64                      Length,
-  IN EFI_MEMORY_TYPE             MemoryType
-  );
-
-/**
-  Builds a HOB for the memory allocation.
-
-  This function builds a HOB for the memory allocation.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  BaseAddress   The 64 bit physical address of the memory.
-  @param  Length        The length of the memory allocation in bytes.
-  @param  MemoryType    Type of memory allocated by this HOB.
-
-**/
-VOID
-EFIAPI
-BuildMemoryAllocationHob (
-  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
-  IN UINT64                      Length,
-  IN EFI_MEMORY_TYPE             MemoryType
-  );
-
-
-VOID
-EFIAPI
-BuildExtractSectionHob (
-  IN  EFI_GUID                                  *Guid,
-  IN  EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER   SectionGetInfo,
-  IN  EXTRACT_GUIDED_SECTION_DECODE_HANDLER     SectionExtraction
-  );
-
-VOID
-EFIAPI
-BuildPeCoffLoaderHob (
-  VOID
-  );
-
-
-/**
-  Allocates one or more 4KB pages of type EfiBootServicesData.
-
-  Allocates the number of 4KB pages of MemoryType and returns a pointer to the
-  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL
-  is returned.  If there is not enough memory remaining to satisfy the request, then NULL is
-  returned.
-
-  @param  Pages                 The number of 4 KB pages to allocate.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID * 
-EFIAPI
-AllocatePages (
-  IN UINTN            Pages
-  );
-  
-/**
-  Allocates a buffer of type EfiBootServicesData.
-
-  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
-  pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is
-  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.
-
-  @param  AllocationSize        The number of bytes to allocate.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-AllocatePool (
-  IN UINTN  AllocationSize
-  );
-  
-  
-/**
-  Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
-
-  Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
-  alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is
-  returned.  If there is not enough memory at the specified alignment remaining to satisfy the
-  request, then NULL is returned.
-  If Alignment is not a power of two and Alignment is not zero, then ASSERT().
-
-  @param  Pages                 The number of 4 KB pages to allocate.
-  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.
-                                If Alignment is zero, then byte alignment is used.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
-VOID *
-EFIAPI
-AllocateAlignedPages (
-  IN UINTN  Pages,
-  IN UINTN  Alignment
-  );
-
-
-EFI_STATUS
-EFIAPI
-LoadPeCoffImage (
-  IN  VOID                                      *PeCoffImage,
-  OUT EFI_PHYSICAL_ADDRESS                      *ImageAddress,
-  OUT UINT64                                    *ImageSize,
-  OUT EFI_PHYSICAL_ADDRESS                      *EntryPoint
-  );
-
-EFI_STATUS
-EFIAPI
-LoadDxeCoreFromFfsFile (
-  IN EFI_PEI_FILE_HANDLE  FileHandle,
-  IN UINTN                StackSize
-  );
-
-EFI_STATUS
-EFIAPI
-LoadDxeCoreFromFv (
-  IN UINTN  *FvInstance,   OPTIONAL
-  IN UINTN  StackSize
-  );
-
-EFI_STATUS
-EFIAPI
-DecompressFirstFv (
-  VOID
-  );
-
-VOID
-EFIAPI
-AddDxeCoreReportStatusCodeCallback (
-  VOID
-  );
-
-
-#endif
+/** @file\r
+  Library that helps implement monolithic PEI. (SEC goes to DXE)\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __PRE_PI_LIB_H__\r
+#define __PRE_PI_LIB_H__\r
+\r
+#include <Guid/ExtractSection.h>\r
+\r
+/**\r
+  This service enables discovery of additional firmware volumes.\r
+\r
+  @param  Instance              This instance of the firmware volume to find.  The value 0 is the\r
+                                Boot Firmware Volume (BFV).\r
+  @param  FwVolHeader           Pointer to the firmware volume header of the volume to return.\r
+\r
+  @retval EFI_SUCCESS           The volume was found.\r
+  @retval EFI_NOT_FOUND         The volume was not found.\r
+  @retval EFI_INVALID_PARAMETER FwVolHeader is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FfsFindNextVolume (\r
+  IN UINTN                          Instance,\r
+  IN OUT EFI_PEI_FV_HANDLE          *VolumeHandle\r
+  );\r
+\r
+\r
+/**\r
+  This service enables discovery of additional firmware files.\r
+\r
+  @param  SearchType            A filter to find files only of this type.\r
+  @param  FwVolHeader           Pointer to the firmware volume header of the volume to search.\r
+                                This parameter must point to a valid FFS volume.\r
+  @param  FileHeader            Pointer to the current file from which to begin searching.\r
+\r
+  @retval EFI_SUCCESS           The file was found.\r
+  @retval EFI_NOT_FOUND         The file was not found.\r
+  @retval EFI_NOT_FOUND         The header checksum was not zero.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FfsFindNextFile (\r
+  IN EFI_FV_FILETYPE            SearchType,\r
+  IN EFI_PEI_FV_HANDLE          VolumeHandle,\r
+  IN OUT EFI_PEI_FILE_HANDLE    *FileHandle\r
+  );\r
+\r
+\r
+/**\r
+  This service enables discovery sections of a given type within a valid FFS file.\r
+\r
+  @param  SearchType            The value of the section type to find.\r
+  @param  FfsFileHeader         A pointer to the file header that contains the set of sections to\r
+                                be searched.\r
+  @param  SectionData           A pointer to the discovered section, if successful.\r
+\r
+  @retval EFI_SUCCESS           The section was found.\r
+  @retval EFI_NOT_FOUND         The section was not found.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FfsFindSectionData (\r
+  IN EFI_SECTION_TYPE           SectionType,\r
+  IN EFI_PEI_FILE_HANDLE        FileHandle,\r
+  OUT VOID                      **SectionData\r
+  );\r
+\r
+\r
+/**\r
+  Find a file in the volume by name\r
+  \r
+  @param FileName       A pointer to the name of the file to\r
+                        find within the firmware volume.\r
+\r
+  @param VolumeHandle   The firmware volume to search FileHandle\r
+                        Upon exit, points to the found file's\r
+                        handle or NULL if it could not be found.\r
+\r
+  @retval EFI_SUCCESS             File was found.\r
+\r
+  @retval EFI_NOT_FOUND           File was not found.\r
+\r
+  @retval EFI_INVALID_PARAMETER   VolumeHandle or FileHandle or\r
+                                  FileName was NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FfsFindByName (\r
+  IN CONST  EFI_GUID            *FileName,\r
+  IN CONST  EFI_PEI_FV_HANDLE   VolumeHandle,\r
+  OUT       EFI_PEI_FILE_HANDLE *FileHandle\r
+  );\r
+\r
+\r
+/**\r
+  Get information about the file by name.\r
+\r
+  @param FileHandle   Handle of the file.\r
+\r
+  @param FileInfo     Upon exit, points to the file's\r
+                      information.\r
+\r
+  @retval EFI_SUCCESS             File information returned.\r
+  \r
+  @retval EFI_INVALID_PARAMETER   If FileHandle does not\r
+                                  represent a valid file.\r
+  \r
+  @retval EFI_INVALID_PARAMETER   If FileInfo is NULL.\r
+  \r
+**/\r
+EFI_STATUS\r
+EFIAPI \r
+FfsGetFileInfo (\r
+  IN CONST  EFI_PEI_FILE_HANDLE   FileHandle,\r
+  OUT EFI_FV_FILE_INFO            *FileInfo\r
+  );\r
+\r
+\r
+/**\r
+  Get Information about the volume by name\r
+\r
+  @param VolumeHandle   Handle of the volume.\r
+\r
+  @param VolumeInfo     Upon exit, points to the volume's\r
+                        information.\r
+\r
+  @retval EFI_SUCCESS             File information returned.\r
+  \r
+  @retval EFI_INVALID_PARAMETER   If FileHandle does not\r
+                                  represent a valid file.\r
+  \r
+  @retval EFI_INVALID_PARAMETER   If FileInfo is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FfsGetVolumeInfo (\r
+  IN  EFI_PEI_FV_HANDLE       VolumeHandle,\r
+  OUT EFI_FV_INFO             *VolumeInfo\r
+  );\r
+\r
+\r
+\r
+/**\r
+  Get Fv image from the FV type file, then add FV & FV2 Hob.\r
+\r
+       @param FileHandle               File handle of a Fv type file.\r
+\r
+\r
+  @retval EFI_NOT_FOUND                                FV image can't be found.\r
+  @retval EFI_SUCCESS                                          Successfully to process it.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FfsProcessFvFile (\r
+  IN  EFI_PEI_FILE_HANDLE   FvFileHandle\r
+  );\r
+\r
+\r
+/**\r
+  Search through every FV until you find a file of type FileType\r
+\r
+       @param FileType             File handle of a Fv type file.\r
+  @param Volumehandle   On succes Volume Handle of the match\r
+  @param FileHandle     On success File Handle of the match\r
+  \r
+  @retval EFI_NOT_FOUND                                FV image can't be found.\r
+  @retval EFI_SUCCESS                                          Successfully found FileType\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FfsAnyFvFindFirstFile (\r
+  IN  EFI_FV_FILETYPE       FileType,\r
+  OUT EFI_PEI_FV_HANDLE     *VolumeHandle,\r
+  OUT EFI_PEI_FILE_HANDLE   *FileHandle\r
+  );\r
+\r
+\r
+/**\r
+  Get Fv image from the FV type file, then add FV & FV2 Hob.\r
+\r
+       @param FileHandle               File handle of a Fv type file.\r
+\r
+\r
+  @retval EFI_NOT_FOUND                                FV image can't be found.\r
+  @retval EFI_SUCCESS                                          Successfully to process it.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FfsProcessFvFile (\r
+  IN  EFI_PEI_FILE_HANDLE   FvFileHandle\r
+  );\r
+\r
+\r
+/**\r
+  This service enables PEIMs to ascertain the present value of the boot mode.  \r
+\r
+\r
+  @retval BootMode           \r
+\r
+**/\r
+EFI_BOOT_MODE\r
+EFIAPI\r
+GetBootMode (\r
+  VOID\r
+  );\r
+\r
+\r
+/**\r
+  This service enables PEIMs to update the boot mode variable.    \r
+\r
+  @param  BootMode              The value of the boot mode to set.\r
+\r
+  @retval EFI_SUCCESS           The value was successfully updated\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SetBootMode (\r
+  IN EFI_BOOT_MODE              BootMode\r
+  );\r
+\r
+/**\r
+  This service enables a PEIM to ascertain the address of the list of HOBs in memory.\r
+\r
+  @param  HobList               A pointer to the list of HOBs that the PEI Foundation will initialize.\r
+\r
+  @retval EFI_SUCCESS           The list was successfully returned.\r
+  @retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+GetHobList (\r
+  VOID         \r
+  );\r
+\r
+\r
+/**\r
+  Updates the pointer to the HOB list.\r
+\r
+  @param  HobList       Hob list pointer to store\r
+  \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SetHobList (\r
+  IN  VOID      *HobList\r
+  );\r
+\r
+EFI_HOB_HANDOFF_INFO_TABLE*\r
+HobConstructor (\r
+  IN VOID   *EfiMemoryBegin,\r
+  IN UINTN  EfiMemoryLength,\r
+  IN VOID   *EfiFreeMemoryBottom,\r
+  IN VOID   *EfiFreeMemoryTop\r
+  );\r
+\r
+/**\r
+  Retrieves the magic value from the PE/COFF header.\r
+\r
+  @param  Hdr             The buffer in which to return the PE32, PE32+, or TE header.\r
+\r
+  @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32\r
+  @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+\r
+\r
+**/\r
+VOID\r
+CreateHobList (\r
+  IN VOID   *MemoryBegin,\r
+  IN UINTN  MemoryLength,\r
+  IN VOID   *HobBase,\r
+  IN VOID   *StackBase\r
+  );\r
+\r
+\r
+/**\r
+  This service enables PEIMs to create various types of HOBs.\r
+\r
+  @param  Type                  The type of HOB to be installed.\r
+  @param  Length                The length of the HOB to be added.\r
+\r
+  @retval !NULL                 The HOB was successfully created.\r
+  @retval NULL                  There is no additional space for HOB creation.\r
+\r
+**/\r
+VOID *\r
+CreateHob (\r
+  IN  UINT16    HobType,\r
+  IN  UINT16    HobLenght\r
+  );\r
+\r
+\r
+/**\r
+  Returns the next instance of a HOB type from the starting HOB.\r
+\r
+  This function searches the first instance of a HOB type from the starting HOB pointer. \r
+  If there does not exist such HOB type from the starting HOB pointer, it will return NULL.\r
+  In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
+  unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
+  caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
+  If HobStart is NULL, then ASSERT().\r
+\r
+  @param  Type          The HOB type to return.\r
+  @param  HobStart      The starting HOB pointer to search from.\r
+\r
+  @return The next instance of a HOB type from the starting HOB.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+GetNextHob (\r
+  IN UINT16                 Type,\r
+  IN CONST VOID             *HobStart\r
+  );\r
+\r
+/**\r
+  Returns the first instance of a HOB type among the whole HOB list.\r
+\r
+  This function searches the first instance of a HOB type among the whole HOB list. \r
+  If there does not exist such HOB type in the HOB list, it will return NULL. \r
+\r
+  @param  Type          The HOB type to return.\r
+\r
+  @return The next instance of a HOB type from the starting HOB.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+GetFirstHob (\r
+  IN UINT16                 Type\r
+  );\r
+\r
+/**\r
+  This function searches the first instance of a HOB from the starting HOB pointer. \r
+  Such HOB should satisfy two conditions: \r
+  its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid. \r
+  If there does not exist such HOB from the starting HOB pointer, it will return NULL. \r
+  Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
+  to extract the data section and its size info respectively.\r
+  In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
+  unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
+  caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
+  If Guid is NULL, then ASSERT().\r
+  If HobStart is NULL, then ASSERT().\r
+\r
+  @param  Guid          The GUID to match with in the HOB list.\r
+  @param  HobStart      A pointer to a Guid.\r
+\r
+  @return The next instance of the matched GUID HOB from the starting HOB.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+GetNextGuidHob (\r
+  IN CONST EFI_GUID         *Guid,\r
+  IN CONST VOID             *HobStart\r
+  );\r
+\r
+/**\r
+  This function searches the first instance of a HOB among the whole HOB list. \r
+  Such HOB should satisfy two conditions:\r
+  its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.\r
+  If there does not exist such HOB from the starting HOB pointer, it will return NULL.\r
+  Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
+  to extract the data section and its size info respectively.\r
+  If Guid is NULL, then ASSERT().\r
+\r
+  @param  Guid          The GUID to match with in the HOB list.\r
+\r
+  @return The first instance of the matched GUID HOB among the whole HOB list.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+GetFirstGuidHob (\r
+  IN CONST EFI_GUID         *Guid\r
+  );\r
+\r
+\r
+/**\r
+  Builds a HOB for a loaded PE32 module.\r
+\r
+  This function builds a HOB for a loaded PE32 module.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If ModuleName is NULL, then ASSERT().\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  ModuleName              The GUID File Name of the module.\r
+  @param  MemoryAllocationModule  The 64 bit physical address of the module.\r
+  @param  ModuleLength            The length of the module in bytes.\r
+  @param  EntryPoint              The 64 bit physical address of the module entry point.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+BuildModuleHob (\r
+  IN CONST EFI_GUID         *ModuleName,\r
+  IN EFI_PHYSICAL_ADDRESS   MemoryAllocationModule,\r
+  IN UINT64                 ModuleLength,\r
+  IN EFI_PHYSICAL_ADDRESS   EntryPoint\r
+  );\r
+\r
+/**\r
+  Builds a HOB that describes a chunk of system memory.\r
+\r
+  This function builds a HOB that describes a chunk of system memory.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  ResourceType        The type of resource described by this HOB.\r
+  @param  ResourceAttribute   The resource attributes of the memory described by this HOB.\r
+  @param  PhysicalStart       The 64 bit physical address of memory described by this HOB.\r
+  @param  NumberOfBytes       The length of the memory described by this HOB in bytes.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+BuildResourceDescriptorHob (\r
+  IN EFI_RESOURCE_TYPE            ResourceType,\r
+  IN EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute,\r
+  IN EFI_PHYSICAL_ADDRESS         PhysicalStart,\r
+  IN UINT64                       NumberOfBytes\r
+  );\r
+\r
+/**\r
+  Builds a GUID HOB with a certain data length.\r
+\r
+  This function builds a customized HOB tagged with a GUID for identification \r
+  and returns the start address of GUID HOB data so that caller can fill the customized data. \r
+  The HOB Header and Name field is already stripped.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If Guid is NULL, then ASSERT().\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+  If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
+\r
+  @param  Guid          The GUID to tag the customized HOB.\r
+  @param  DataLength    The size of the data payload for the GUID HOB.\r
+\r
+  @return The start address of GUID HOB data.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+BuildGuidHob (\r
+  IN CONST EFI_GUID              *Guid,\r
+  IN UINTN                       DataLength\r
+  );\r
+\r
+/**\r
+  Copies a data buffer to a newly-built HOB.\r
+\r
+  This function builds a customized HOB tagged with a GUID for identification,\r
+  copies the input data to the HOB data field and returns the start address of the GUID HOB data.\r
+  The HOB Header and Name field is already stripped.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If Guid is NULL, then ASSERT().\r
+  If Data is NULL and DataLength > 0, then ASSERT().\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+  If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
+\r
+  @param  Guid          The GUID to tag the customized HOB.\r
+  @param  Data          The data to be copied into the data field of the GUID HOB.\r
+  @param  DataLength    The size of the data payload for the GUID HOB.\r
+\r
+  @return The start address of GUID HOB data.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+BuildGuidDataHob (\r
+  IN CONST EFI_GUID              *Guid,\r
+  IN VOID                        *Data,\r
+  IN UINTN                       DataLength\r
+  );\r
+\r
+/**\r
+  Builds a Firmware Volume HOB.\r
+\r
+  This function builds a Firmware Volume HOB.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  BaseAddress   The base address of the Firmware Volume.\r
+  @param  Length        The size of the Firmware Volume in bytes.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+BuildFvHob (\r
+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,\r
+  IN UINT64                      Length\r
+  );\r
+\r
+/**\r
+  Builds a Firmware Volume HOB and a resrouce descriptor hob \r
+\r
+  This function builds a Firmware Volume HOB.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  BaseAddress   The base address of the Firmware Volume.\r
+  @param  Length        The size of the Firmware Volume in bytes.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+BuildFvHobs (  \r
+  IN EFI_PHYSICAL_ADDRESS         PhysicalStart,\r
+  IN UINT64                       NumberOfBytes,\r
+  IN EFI_RESOURCE_ATTRIBUTE_TYPE  *ResourceAttribute  OPTIONAL\r
+  ); \r
+\r
+\r
+/**\r
+  Builds a EFI_HOB_TYPE_FV2 HOB.\r
+\r
+  This function builds a EFI_HOB_TYPE_FV2 HOB.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  BaseAddress   The base address of the Firmware Volume.\r
+  @param  Length        The size of the Firmware Volume in bytes.\r
+  @param  FvName       The name of the Firmware Volume.\r
+  @param  FileName      The name of the file.\r
+  \r
+**/\r
+VOID\r
+EFIAPI\r
+BuildFv2Hob (\r
+  IN          EFI_PHYSICAL_ADDRESS        BaseAddress,\r
+  IN          UINT64                      Length,\r
+  IN CONST    EFI_GUID                    *FvName,\r
+  IN CONST    EFI_GUID                    *FileName\r
+  );\r
+\r
+/**\r
+  Builds a Capsule Volume HOB.\r
+\r
+  This function builds a Capsule Volume HOB.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  BaseAddress   The base address of the Capsule Volume.\r
+  @param  Length        The size of the Capsule Volume in bytes.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+BuildCvHob (\r
+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,\r
+  IN UINT64                      Length\r
+  );\r
+\r
+/**\r
+  Builds a HOB for the CPU.\r
+\r
+  This function builds a HOB for the CPU.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  SizeOfMemorySpace   The maximum physical memory addressability of the processor.\r
+  @param  SizeOfIoSpace       The maximum physical I/O addressability of the processor.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+BuildCpuHob (\r
+  IN UINT8                       SizeOfMemorySpace,\r
+  IN UINT8                       SizeOfIoSpace\r
+  );\r
+\r
+/**\r
+  Builds a HOB for the Stack.\r
+\r
+  This function builds a HOB for the stack.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  BaseAddress   The 64 bit physical address of the Stack.\r
+  @param  Length        The length of the stack in bytes.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+BuildStackHob (\r
+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,\r
+  IN UINT64                      Length\r
+  );\r
+\r
+/**\r
+  Update the Stack Hob if the stack has been moved\r
+\r
+  @param  BaseAddress   The 64 bit physical address of the Stack.\r
+  @param  Length        The length of the stack in bytes.\r
+\r
+**/\r
+VOID\r
+UpdateStackHob (\r
+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,\r
+  IN UINT64                      Length\r
+  );\r
+\r
+\r
+/**\r
+  Builds a HOB for the BSP store.\r
+\r
+  This function builds a HOB for BSP store.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  BaseAddress   The 64 bit physical address of the BSP.\r
+  @param  Length        The length of the BSP store in bytes.\r
+  @param  MemoryType    Type of memory allocated by this HOB.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+BuildBspStoreHob (\r
+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,\r
+  IN UINT64                      Length,\r
+  IN EFI_MEMORY_TYPE             MemoryType\r
+  );\r
+\r
+/**\r
+  Builds a HOB for the memory allocation.\r
+\r
+  This function builds a HOB for the memory allocation.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  BaseAddress   The 64 bit physical address of the memory.\r
+  @param  Length        The length of the memory allocation in bytes.\r
+  @param  MemoryType    Type of memory allocated by this HOB.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+BuildMemoryAllocationHob (\r
+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,\r
+  IN UINT64                      Length,\r
+  IN EFI_MEMORY_TYPE             MemoryType\r
+  );\r
+\r
+\r
+VOID\r
+EFIAPI\r
+BuildExtractSectionHob (\r
+  IN  EFI_GUID                                  *Guid,\r
+  IN  EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER   SectionGetInfo,\r
+  IN  EXTRACT_GUIDED_SECTION_DECODE_HANDLER     SectionExtraction\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+BuildPeCoffLoaderHob (\r
+  VOID\r
+  );\r
+\r
+\r
+/**\r
+  Allocates one or more 4KB pages of type EfiBootServicesData.\r
+\r
+  Allocates the number of 4KB pages of MemoryType and returns a pointer to the\r
+  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL\r
+  is returned.  If there is not enough memory remaining to satisfy the request, then NULL is\r
+  returned.\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID * \r
+EFIAPI\r
+AllocatePages (\r
+  IN UINTN            Pages\r
+  );\r
+  \r
+/**\r
+  Allocates a buffer of type EfiBootServicesData.\r
+\r
+  Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a\r
+  pointer to the allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is\r
+  returned.  If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocatePool (\r
+  IN UINTN  AllocationSize\r
+  );\r
+  \r
+  \r
+/**\r
+  Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.\r
+\r
+  Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an\r
+  alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is\r
+  returned.  If there is not enough memory at the specified alignment remaining to satisfy the\r
+  request, then NULL is returned.\r
+  If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+  @param  Alignment             The requested alignment of the allocation.  Must be a power of two.\r
+                                If Alignment is zero, then byte alignment is used.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAlignedPages (\r
+  IN UINTN  Pages,\r
+  IN UINTN  Alignment\r
+  );\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+LoadPeCoffImage (\r
+  IN  VOID                                      *PeCoffImage,\r
+  OUT EFI_PHYSICAL_ADDRESS                      *ImageAddress,\r
+  OUT UINT64                                    *ImageSize,\r
+  OUT EFI_PHYSICAL_ADDRESS                      *EntryPoint\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+LoadDxeCoreFromFfsFile (\r
+  IN EFI_PEI_FILE_HANDLE  FileHandle,\r
+  IN UINTN                StackSize\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+LoadDxeCoreFromFv (\r
+  IN UINTN  *FvInstance,   OPTIONAL\r
+  IN UINTN  StackSize\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+DecompressFirstFv (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+AddDxeCoreReportStatusCodeCallback (\r
+  VOID\r
+  );\r
+\r
+\r
+#endif\r
index 74f5e4c58c53d9c2087c6d52eedcac2018f12459..a12847ca9493097dd2b5d9cbe9ae83e1d620319e 100644 (file)
@@ -1,66 +1,66 @@
-/** @file
-
-  Copyright (c) 2012, ARM Ltd. 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.
-
-**/
-
-#ifndef __SERIAL_PORT_EXT_LIB_H__
-#define __SERIAL_PORT_EXT_LIB_H__
-
-#include <Uefi/UefiBaseType.h>
-#include <Protocol/SerialIo.h>
-
-/**
-  Set the serial device control bits.
-
-  @return    Always return EFI_UNSUPPORTED.
-
-**/
-RETURN_STATUS
-EFIAPI
-SerialPortSetControl (
-  IN UINT32                   Control
-  );
-
-/**
-  Get the serial device control bits.
-
-  @param  Control                 Control signals read from the serial device.
-
-  @retval EFI_SUCCESS             The control bits were read from the serial device.
-  @retval EFI_DEVICE_ERROR        The serial device is not functioning correctly.
-
-**/
-RETURN_STATUS
-EFIAPI
-SerialPortGetControl (
-  OUT UINT32                  *Control
-  );
-
-/**
-  Set the serial device attributes.
-
-  @return    Always return EFI_UNSUPPORTED.
-
-**/
-RETURN_STATUS
-EFIAPI
-SerialPortSetAttributes (
-  IN UINT64              BaudRate,
-  IN UINT32              ReceiveFifoDepth,
-  IN UINT32              Timeout,
-  IN EFI_PARITY_TYPE     Parity,
-  IN UINT8               DataBits,
-  IN EFI_STOP_BITS_TYPE  StopBits
-  );
-
-#endif
-
+/** @file\r
+\r
+  Copyright (c) 2012, ARM Ltd. All rights reserved.\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __SERIAL_PORT_EXT_LIB_H__\r
+#define __SERIAL_PORT_EXT_LIB_H__\r
+\r
+#include <Uefi/UefiBaseType.h>\r
+#include <Protocol/SerialIo.h>\r
+\r
+/**\r
+  Set the serial device control bits.\r
+\r
+  @return    Always return EFI_UNSUPPORTED.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SerialPortSetControl (\r
+  IN UINT32                   Control\r
+  );\r
+\r
+/**\r
+  Get the serial device control bits.\r
+\r
+  @param  Control                 Control signals read from the serial device.\r
+\r
+  @retval EFI_SUCCESS             The control bits were read from the serial device.\r
+  @retval EFI_DEVICE_ERROR        The serial device is not functioning correctly.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SerialPortGetControl (\r
+  OUT UINT32                  *Control\r
+  );\r
+\r
+/**\r
+  Set the serial device attributes.\r
+\r
+  @return    Always return EFI_UNSUPPORTED.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SerialPortSetAttributes (\r
+  IN UINT64              BaudRate,\r
+  IN UINT32              ReceiveFifoDepth,\r
+  IN UINT32              Timeout,\r
+  IN EFI_PARITY_TYPE     Parity,\r
+  IN UINT8               DataBits,\r
+  IN EFI_STOP_BITS_TYPE  StopBits\r
+  );\r
+\r
+#endif\r
+\r
index 1ce5a8f3bfc26715c5666553057744022a5b15d5..a7809b27b3ec22971a81f6aa7b7b7777539c03a2 100644 (file)
@@ -73,11 +73,11 @@ VOID
   );\r
 \r
 \r
   );\r
 \r
 \r
-typedef 
-VOID
-(EFIAPI *EBL_GET_CHAR_CALL_BACK) (
-  IN  UINTN   ElapsedTime
-  );
+typedef \r
+VOID\r
+(EFIAPI *EBL_GET_CHAR_CALL_BACK) (\r
+  IN  UINTN   ElapsedTime\r
+  );\r
 \r
 /**\r
   Return a keypress or optionally timeout if a timeout value was passed in.\r
 \r
 /**\r
   Return a keypress or optionally timeout if a timeout value was passed in.\r
index 17188f04aa88d0bda8b2f5411fbe0a211f743eb0..603dc5ed86d3734a81be84c4c8d13ce2e375798a 100644 (file)
@@ -1,94 +1,94 @@
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __EMBEDDED_EXTERNAL_DEVICE_H__
-#define __EMBEDDED_EXTERNAL_DEVICE_H__
-
-//
-// Protocol GUID
-//
-#define EMBEDDED_EXTERNAL_DEVICE_PROTOCOL_GUID { 0x735F8C64, 0xD696, 0x44D0, { 0xBD, 0xF2, 0x44, 0x7F, 0xD0, 0x5A, 0x54, 0x06 }}
-
-//
-// Protocol interface structure
-//
-typedef struct _EMBEDDED_EXTERNAL_DEVICE EMBEDDED_EXTERNAL_DEVICE;
-
-//
-// Function Prototypes
-//
-typedef
-EFI_STATUS
-(EFIAPI *EMBEDDED_EXTERNAL_DEVICE_READ) (
-    IN  EMBEDDED_EXTERNAL_DEVICE  *This,
-    IN  UINTN                       Register,
-    IN  UINTN                       Length,
-    OUT VOID                        *Buffer
-    )
-/*++
-
-Routine Description:
-
-  Read a set of contiguous external device registers.
-
-Arguments:
-
-  This        - pointer to protocol
-  Offset      - starting register number
-  Length      - number of bytes to read
-  Buffer      - destination buffer
-  
-Returns:
-
-  EFI_SUCCESS - registers read successfully
-
---*/
-;
-
-typedef
-EFI_STATUS
-(EFIAPI *EMBEDDED_EXTERNAL_DEVICE_WRITE) (
-    IN EMBEDDED_EXTERNAL_DEVICE *This,
-    IN UINTN                      Register,
-    IN UINTN                      Length,
-    IN VOID                       *Buffer
-    )
-/*++
-
-Routine Description:
-
-  Write to a set of contiguous external device registers.
-
-Arguments:
-
-  This        - pointer to protocol
-  Offset      - starting register number
-  Length      - number of bytes to write
-  Buffer      - source buffer
-  
-Returns:
-
-  EFI_SUCCESS - registers written successfully
-
---*/
-;
-
-struct _EMBEDDED_EXTERNAL_DEVICE {
-  EMBEDDED_EXTERNAL_DEVICE_READ      Read;
-  EMBEDDED_EXTERNAL_DEVICE_WRITE     Write;
-};
-
-extern EFI_GUID gEmbeddedExternalDeviceProtocolGuid;
-
-#endif // __EMBEDDED_EXTERNAL_DEVICE_H__
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __EMBEDDED_EXTERNAL_DEVICE_H__\r
+#define __EMBEDDED_EXTERNAL_DEVICE_H__\r
+\r
+//\r
+// Protocol GUID\r
+//\r
+#define EMBEDDED_EXTERNAL_DEVICE_PROTOCOL_GUID { 0x735F8C64, 0xD696, 0x44D0, { 0xBD, 0xF2, 0x44, 0x7F, 0xD0, 0x5A, 0x54, 0x06 }}\r
+\r
+//\r
+// Protocol interface structure\r
+//\r
+typedef struct _EMBEDDED_EXTERNAL_DEVICE EMBEDDED_EXTERNAL_DEVICE;\r
+\r
+//\r
+// Function Prototypes\r
+//\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EMBEDDED_EXTERNAL_DEVICE_READ) (\r
+    IN  EMBEDDED_EXTERNAL_DEVICE  *This,\r
+    IN  UINTN                       Register,\r
+    IN  UINTN                       Length,\r
+    OUT VOID                        *Buffer\r
+    )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Read a set of contiguous external device registers.\r
+\r
+Arguments:\r
+\r
+  This        - pointer to protocol\r
+  Offset      - starting register number\r
+  Length      - number of bytes to read\r
+  Buffer      - destination buffer\r
+  \r
+Returns:\r
+\r
+  EFI_SUCCESS - registers read successfully\r
+\r
+--*/\r
+;\r
+\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EMBEDDED_EXTERNAL_DEVICE_WRITE) (\r
+    IN EMBEDDED_EXTERNAL_DEVICE *This,\r
+    IN UINTN                      Register,\r
+    IN UINTN                      Length,\r
+    IN VOID                       *Buffer\r
+    )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Write to a set of contiguous external device registers.\r
+\r
+Arguments:\r
+\r
+  This        - pointer to protocol\r
+  Offset      - starting register number\r
+  Length      - number of bytes to write\r
+  Buffer      - source buffer\r
+  \r
+Returns:\r
+\r
+  EFI_SUCCESS - registers written successfully\r
+\r
+--*/\r
+;\r
+\r
+struct _EMBEDDED_EXTERNAL_DEVICE {\r
+  EMBEDDED_EXTERNAL_DEVICE_READ      Read;\r
+  EMBEDDED_EXTERNAL_DEVICE_WRITE     Write;\r
+};\r
+\r
+extern EFI_GUID gEmbeddedExternalDeviceProtocolGuid;\r
+\r
+#endif // __EMBEDDED_EXTERNAL_DEVICE_H__\r
index 97a9a8bd9dc7a7f4fe3e6e65e6f0c1c2d2465af3..77ea7ad034d1d317fff93f0952c1fe7492445e5b 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __EMBEDDED_GPIO_H__
-#define __EMBEDDED_GPIO_H__
-
-//
-// Protocol interface structure
-//
-typedef struct _EMBEDDED_GPIO   EMBEDDED_GPIO;
-
-//
-// Data Types
-//
-typedef UINTN EMBEDDED_GPIO_PIN;
-
-#define GPIO(Port, Pin) ((EMBEDDED_GPIO_PIN)(((Port) << (16)) | (Pin)))
-#define GPIO_PIN(x)     ((EMBEDDED_GPIO_PIN)(x) & (0xFFFF))
-#define GPIO_PORT(x)    ((EMBEDDED_GPIO_PIN)(x) >> (16))
-
-typedef enum {
-  GPIO_MODE_INPUT                 = 0x00,
-  GPIO_MODE_OUTPUT_0              = 0x0E,
-  GPIO_MODE_OUTPUT_1              = 0x0F,
-  GPIO_MODE_SPECIAL_FUNCTION_2    = 0x02,
-  GPIO_MODE_SPECIAL_FUNCTION_3    = 0x03,
-  GPIO_MODE_SPECIAL_FUNCTION_4    = 0x04,
-  GPIO_MODE_SPECIAL_FUNCTION_5    = 0x05,
-  GPIO_MODE_SPECIAL_FUNCTION_6    = 0x06,
-  GPIO_MODE_SPECIAL_FUNCTION_7    = 0x07
-} EMBEDDED_GPIO_MODE;
-
-typedef enum {
-  GPIO_PULL_NONE,
-  GPIO_PULL_UP,
-  GPIO_PULL_DOWN
-} EMBEDDED_GPIO_PULL;
-
-//
-// Function Prototypes
-//
-typedef
-EFI_STATUS
-(EFIAPI *EMBEDDED_GPIO_GET) (
-  IN  EMBEDDED_GPIO       *This,
-  IN  EMBEDDED_GPIO_PIN   Gpio,
-  OUT UINTN               *Value
-  );
-/*++
-
-Routine Description:
-
-  Gets the state of a GPIO pin
-
-Arguments:
-
-  This  - pointer to protocol
-  Gpio  - which pin to read
-  Value - state of the pin
-  
-Returns:
-
-  EFI_SUCCESS - GPIO state returned in Value
-
---*/
-
-
-typedef
-EFI_STATUS
-(EFIAPI *EMBEDDED_GPIO_SET) (
-    IN EMBEDDED_GPIO      *This,
-    IN EMBEDDED_GPIO_PIN  Gpio,
-    IN EMBEDDED_GPIO_MODE Mode
-    );
-/*++
-
-Routine Description:
-
-  Sets the state of a GPIO pin
-
-Arguments:
-
-  This  - pointer to protocol
-  Gpio  - which pin to modify
-  Mode  - mode to set
-  
-Returns:
-
-  EFI_SUCCESS - GPIO set as requested
-
---*/
-
-
-typedef
-EFI_STATUS
-(EFIAPI *EMBEDDED_GPIO_GET_MODE) (
-    IN  EMBEDDED_GPIO         *This,
-    IN  EMBEDDED_GPIO_PIN     Gpio,
-    OUT EMBEDDED_GPIO_MODE    *Mode
-    );
-/*++
-
-Routine Description:
-
-  Gets the mode (function) of a GPIO pin
-
-Arguments:
-
-  This  - pointer to protocol
-  Gpio  - which pin
-  Mode  - pointer to output mode value
-  
-Returns:
-
-  EFI_SUCCESS - mode value retrieved
-
---*/
-
-
-typedef
-EFI_STATUS
-(EFIAPI *EMBEDDED_GPIO_SET_PULL) (
-    IN  EMBEDDED_GPIO      *This,
-    IN  EMBEDDED_GPIO_PIN  Gpio,
-    IN  EMBEDDED_GPIO_PULL Direction
-    );
-/*++
-
-Routine Description:
-
-  Sets the pull-up / pull-down resistor of a GPIO pin
-
-Arguments:
-
-  This  - pointer to protocol
-  Gpio  - which pin
-  Direction - pull-up, pull-down, or none
-  
-Returns:
-
-  EFI_SUCCESS - pin was set
-
---*/
-
-
-
-struct _EMBEDDED_GPIO {
-  EMBEDDED_GPIO_GET       Get;
-  EMBEDDED_GPIO_SET       Set;
-  EMBEDDED_GPIO_GET_MODE  GetMode;
-  EMBEDDED_GPIO_SET_PULL  SetPull;
-};
-
-extern EFI_GUID gEmbeddedGpioProtocolGuid;
-
-#endif 
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __EMBEDDED_GPIO_H__\r
+#define __EMBEDDED_GPIO_H__\r
+\r
+//\r
+// Protocol interface structure\r
+//\r
+typedef struct _EMBEDDED_GPIO   EMBEDDED_GPIO;\r
+\r
+//\r
+// Data Types\r
+//\r
+typedef UINTN EMBEDDED_GPIO_PIN;\r
+\r
+#define GPIO(Port, Pin) ((EMBEDDED_GPIO_PIN)(((Port) << (16)) | (Pin)))\r
+#define GPIO_PIN(x)     ((EMBEDDED_GPIO_PIN)(x) & (0xFFFF))\r
+#define GPIO_PORT(x)    ((EMBEDDED_GPIO_PIN)(x) >> (16))\r
+\r
+typedef enum {\r
+  GPIO_MODE_INPUT                 = 0x00,\r
+  GPIO_MODE_OUTPUT_0              = 0x0E,\r
+  GPIO_MODE_OUTPUT_1              = 0x0F,\r
+  GPIO_MODE_SPECIAL_FUNCTION_2    = 0x02,\r
+  GPIO_MODE_SPECIAL_FUNCTION_3    = 0x03,\r
+  GPIO_MODE_SPECIAL_FUNCTION_4    = 0x04,\r
+  GPIO_MODE_SPECIAL_FUNCTION_5    = 0x05,\r
+  GPIO_MODE_SPECIAL_FUNCTION_6    = 0x06,\r
+  GPIO_MODE_SPECIAL_FUNCTION_7    = 0x07\r
+} EMBEDDED_GPIO_MODE;\r
+\r
+typedef enum {\r
+  GPIO_PULL_NONE,\r
+  GPIO_PULL_UP,\r
+  GPIO_PULL_DOWN\r
+} EMBEDDED_GPIO_PULL;\r
+\r
+//\r
+// Function Prototypes\r
+//\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EMBEDDED_GPIO_GET) (\r
+  IN  EMBEDDED_GPIO       *This,\r
+  IN  EMBEDDED_GPIO_PIN   Gpio,\r
+  OUT UINTN               *Value\r
+  );\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Gets the state of a GPIO pin\r
+\r
+Arguments:\r
+\r
+  This  - pointer to protocol\r
+  Gpio  - which pin to read\r
+  Value - state of the pin\r
+  \r
+Returns:\r
+\r
+  EFI_SUCCESS - GPIO state returned in Value\r
+\r
+--*/\r
+\r
+\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EMBEDDED_GPIO_SET) (\r
+    IN EMBEDDED_GPIO      *This,\r
+    IN EMBEDDED_GPIO_PIN  Gpio,\r
+    IN EMBEDDED_GPIO_MODE Mode\r
+    );\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Sets the state of a GPIO pin\r
+\r
+Arguments:\r
+\r
+  This  - pointer to protocol\r
+  Gpio  - which pin to modify\r
+  Mode  - mode to set\r
+  \r
+Returns:\r
+\r
+  EFI_SUCCESS - GPIO set as requested\r
+\r
+--*/\r
+\r
+\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EMBEDDED_GPIO_GET_MODE) (\r
+    IN  EMBEDDED_GPIO         *This,\r
+    IN  EMBEDDED_GPIO_PIN     Gpio,\r
+    OUT EMBEDDED_GPIO_MODE    *Mode\r
+    );\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Gets the mode (function) of a GPIO pin\r
+\r
+Arguments:\r
+\r
+  This  - pointer to protocol\r
+  Gpio  - which pin\r
+  Mode  - pointer to output mode value\r
+  \r
+Returns:\r
+\r
+  EFI_SUCCESS - mode value retrieved\r
+\r
+--*/\r
+\r
+\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EMBEDDED_GPIO_SET_PULL) (\r
+    IN  EMBEDDED_GPIO      *This,\r
+    IN  EMBEDDED_GPIO_PIN  Gpio,\r
+    IN  EMBEDDED_GPIO_PULL Direction\r
+    );\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Sets the pull-up / pull-down resistor of a GPIO pin\r
+\r
+Arguments:\r
+\r
+  This  - pointer to protocol\r
+  Gpio  - which pin\r
+  Direction - pull-up, pull-down, or none\r
+  \r
+Returns:\r
+\r
+  EFI_SUCCESS - pin was set\r
+\r
+--*/\r
+\r
+\r
+\r
+struct _EMBEDDED_GPIO {\r
+  EMBEDDED_GPIO_GET       Get;\r
+  EMBEDDED_GPIO_SET       Set;\r
+  EMBEDDED_GPIO_GET_MODE  GetMode;\r
+  EMBEDDED_GPIO_SET_PULL  SetPull;\r
+};\r
+\r
+extern EFI_GUID gEmbeddedGpioProtocolGuid;\r
+\r
+#endif \r
index 6e7a8b39733298e6d46154fa8f56cdc543572ca7..3b7c37102d547af4b7a39e96ea2ab1eb5625e83c 100644 (file)
@@ -1,74 +1,74 @@
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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.             
-*
-**/
-
-#ifndef _FDT_H
-#define _FDT_H
-
-#ifndef __ASSEMBLY__
-
-struct fdt_header {
-       uint32_t magic;                  /* magic word FDT_MAGIC */
-       uint32_t totalsize;              /* total size of DT block */
-       uint32_t off_dt_struct;          /* offset to structure */
-       uint32_t off_dt_strings;         /* offset to strings */
-       uint32_t off_mem_rsvmap;         /* offset to memory reserve map */
-       uint32_t version;                /* format version */
-       uint32_t last_comp_version;      /* last compatible version */
-
-       /* version 2 fields below */
-       uint32_t boot_cpuid_phys;        /* Which physical CPU id we're
-                                           booting on */
-       /* version 3 fields below */
-       uint32_t size_dt_strings;        /* size of the strings block */
-
-       /* version 17 fields below */
-       uint32_t size_dt_struct;         /* size of the structure block */
-};
-
-struct fdt_reserve_entry {
-       uint64_t address;
-       uint64_t size;
-};
-
-struct fdt_node_header {
-       uint32_t tag;
-       char name[0];
-};
-
-struct fdt_property {
-       uint32_t tag;
-       uint32_t len;
-       uint32_t nameoff;
-       char data[0];
-};
-
-#endif /* !__ASSEMBLY */
-
-#define FDT_MAGIC      0xd00dfeed      /* 4: version, 4: total size */
-#define FDT_TAGSIZE    sizeof(uint32_t)
-
-#define FDT_BEGIN_NODE 0x1             /* Start node: full name */
-#define FDT_END_NODE   0x2             /* End node */
-#define FDT_PROP       0x3             /* Property: name off,
-                                          size, content */
-#define FDT_NOP                0x4             /* nop */
-#define FDT_END                0x9
-
-#define FDT_V1_SIZE    (7*sizeof(uint32_t))
-#define FDT_V2_SIZE    (FDT_V1_SIZE + sizeof(uint32_t))
-#define FDT_V3_SIZE    (FDT_V2_SIZE + sizeof(uint32_t))
-#define FDT_V16_SIZE   FDT_V3_SIZE
-#define FDT_V17_SIZE   (FDT_V16_SIZE + sizeof(uint32_t))
-
-#endif /* _FDT_H */
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#ifndef _FDT_H\r
+#define _FDT_H\r
+\r
+#ifndef __ASSEMBLY__\r
+\r
+struct fdt_header {\r
+       uint32_t magic;                  /* magic word FDT_MAGIC */\r
+       uint32_t totalsize;              /* total size of DT block */\r
+       uint32_t off_dt_struct;          /* offset to structure */\r
+       uint32_t off_dt_strings;         /* offset to strings */\r
+       uint32_t off_mem_rsvmap;         /* offset to memory reserve map */\r
+       uint32_t version;                /* format version */\r
+       uint32_t last_comp_version;      /* last compatible version */\r
+\r
+       /* version 2 fields below */\r
+       uint32_t boot_cpuid_phys;        /* Which physical CPU id we're\r
+                                           booting on */\r
+       /* version 3 fields below */\r
+       uint32_t size_dt_strings;        /* size of the strings block */\r
+\r
+       /* version 17 fields below */\r
+       uint32_t size_dt_struct;         /* size of the structure block */\r
+};\r
+\r
+struct fdt_reserve_entry {\r
+       uint64_t address;\r
+       uint64_t size;\r
+};\r
+\r
+struct fdt_node_header {\r
+       uint32_t tag;\r
+       char name[0];\r
+};\r
+\r
+struct fdt_property {\r
+       uint32_t tag;\r
+       uint32_t len;\r
+       uint32_t nameoff;\r
+       char data[0];\r
+};\r
+\r
+#endif /* !__ASSEMBLY */\r
+\r
+#define FDT_MAGIC      0xd00dfeed      /* 4: version, 4: total size */\r
+#define FDT_TAGSIZE    sizeof(uint32_t)\r
+\r
+#define FDT_BEGIN_NODE 0x1             /* Start node: full name */\r
+#define FDT_END_NODE   0x2             /* End node */\r
+#define FDT_PROP       0x3             /* Property: name off,\r
+                                          size, content */\r
+#define FDT_NOP                0x4             /* nop */\r
+#define FDT_END                0x9\r
+\r
+#define FDT_V1_SIZE    (7*sizeof(uint32_t))\r
+#define FDT_V2_SIZE    (FDT_V1_SIZE + sizeof(uint32_t))\r
+#define FDT_V3_SIZE    (FDT_V2_SIZE + sizeof(uint32_t))\r
+#define FDT_V16_SIZE   FDT_V3_SIZE\r
+#define FDT_V17_SIZE   (FDT_V16_SIZE + sizeof(uint32_t))\r
+\r
+#endif /* _FDT_H */\r
index 73f49759a5e71b79aa5bb4ae172681ce329cd294..85fe324c4d9eaeff87a88a2dc6d895b631f25263 100644 (file)
-#ifndef _LIBFDT_H
-#define _LIBFDT_H
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2006 David Gibson, IBM Corporation.
- *
- * libfdt is dual licensed: you can use it either under the terms of
- * the GPL, or the BSD license, at your option.
- *
- *  a) This library is free software; you can redistribute it and/or
- *     modify it under the terms of the GNU General Public License as
- *     published by the Free Software Foundation; either version 2 of the
- *     License, or (at your option) any later version.
- *
- *     This library is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- *
- *     You should have received a copy of the GNU General Public
- *     License along with this library; if not, write to the Free
- *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
- *     MA 02110-1301 USA
- *
- * Alternatively,
- *
- *  b) Redistribution and use in source and binary forms, with or
- *     without modification, are permitted provided that the following
- *     conditions are met:
- *
- *     1. Redistributions of source code must retain the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer.
- *     2. Redistributions in binary form must reproduce the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer in the documentation and/or other materials
- *        provided with the distribution.
- *
- *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <libfdt_env.h>
-#include <fdt.h>
-
-#define FDT_FIRST_SUPPORTED_VERSION    0x10
-#define FDT_LAST_SUPPORTED_VERSION     0x11
-
-/* Error codes: informative error codes */
-#define FDT_ERR_NOTFOUND       1
-       /* FDT_ERR_NOTFOUND: The requested node or property does not exist */
-#define FDT_ERR_EXISTS         2
-       /* FDT_ERR_EXISTS: Attemped to create a node or property which
-        * already exists */
-#define FDT_ERR_NOSPACE                3
-       /* FDT_ERR_NOSPACE: Operation needed to expand the device
-        * tree, but its buffer did not have sufficient space to
-        * contain the expanded tree. Use fdt_open_into() to move the
-        * device tree to a buffer with more space. */
-
-/* Error codes: codes for bad parameters */
-#define FDT_ERR_BADOFFSET      4
-       /* FDT_ERR_BADOFFSET: Function was passed a structure block
-        * offset which is out-of-bounds, or which points to an
-        * unsuitable part of the structure for the operation. */
-#define FDT_ERR_BADPATH                5
-       /* FDT_ERR_BADPATH: Function was passed a badly formatted path
-        * (e.g. missing a leading / for a function which requires an
-        * absolute path) */
-#define FDT_ERR_BADPHANDLE     6
-       /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle
-        * value.  phandle values of 0 and -1 are not permitted. */
-#define FDT_ERR_BADSTATE       7
-       /* FDT_ERR_BADSTATE: Function was passed an incomplete device
-        * tree created by the sequential-write functions, which is
-        * not sufficiently complete for the requested operation. */
-
-/* Error codes: codes for bad device tree blobs */
-#define FDT_ERR_TRUNCATED      8
-       /* FDT_ERR_TRUNCATED: Structure block of the given device tree
-        * ends without an FDT_END tag. */
-#define FDT_ERR_BADMAGIC       9
-       /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
-        * device tree at all - it is missing the flattened device
-        * tree magic number. */
-#define FDT_ERR_BADVERSION     10
-       /* FDT_ERR_BADVERSION: Given device tree has a version which
-        * can't be handled by the requested operation.  For
-        * read-write functions, this may mean that fdt_open_into() is
-        * required to convert the tree to the expected version. */
-#define FDT_ERR_BADSTRUCTURE   11
-       /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
-        * structure block or other serious error (e.g. misnested
-        * nodes, or subnodes preceding properties). */
-#define FDT_ERR_BADLAYOUT      12
-       /* FDT_ERR_BADLAYOUT: For read-write functions, the given
-        * device tree has it's sub-blocks in an order that the
-        * function can't handle (memory reserve map, then structure,
-        * then strings).  Use fdt_open_into() to reorganize the tree
-        * into a form suitable for the read-write operations. */
-
-/* "Can't happen" error indicating a bug in libfdt */
-#define FDT_ERR_INTERNAL       13
-       /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
-        * Should never be returned, if it is, it indicates a bug in
-        * libfdt itself. */
-
-#define FDT_ERR_MAX            13
-
-/**********************************************************************/
-/* Low-level functions (you probably don't need these)                */
-/**********************************************************************/
-
-const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
-static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
-{
-       return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
-}
-
-uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
-
-/**********************************************************************/
-/* Traversal functions                                                */
-/**********************************************************************/
-
-int fdt_next_node(const void *fdt, int offset, int *depth);
-
-/**********************************************************************/
-/* General functions                                                  */
-/**********************************************************************/
-
-#define fdt_get_header(fdt, field) \
-       (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))
-#define fdt_magic(fdt)                         (fdt_get_header(fdt, magic))
-#define fdt_totalsize(fdt)             (fdt_get_header(fdt, totalsize))
-#define fdt_off_dt_struct(fdt)         (fdt_get_header(fdt, off_dt_struct))
-#define fdt_off_dt_strings(fdt)                (fdt_get_header(fdt, off_dt_strings))
-#define fdt_off_mem_rsvmap(fdt)                (fdt_get_header(fdt, off_mem_rsvmap))
-#define fdt_version(fdt)               (fdt_get_header(fdt, version))
-#define fdt_last_comp_version(fdt)     (fdt_get_header(fdt, last_comp_version))
-#define fdt_boot_cpuid_phys(fdt)       (fdt_get_header(fdt, boot_cpuid_phys))
-#define fdt_size_dt_strings(fdt)       (fdt_get_header(fdt, size_dt_strings))
-#define fdt_size_dt_struct(fdt)                (fdt_get_header(fdt, size_dt_struct))
-
-#define __fdt_set_hdr(name) \
-       static inline void fdt_set_##name(void *fdt, uint32_t val) \
-       { \
-               struct fdt_header *fdth = (struct fdt_header*)fdt; \
-               fdth->name = cpu_to_fdt32(val); \
-       }
-__fdt_set_hdr(magic);
-__fdt_set_hdr(totalsize);
-__fdt_set_hdr(off_dt_struct);
-__fdt_set_hdr(off_dt_strings);
-__fdt_set_hdr(off_mem_rsvmap);
-__fdt_set_hdr(version);
-__fdt_set_hdr(last_comp_version);
-__fdt_set_hdr(boot_cpuid_phys);
-__fdt_set_hdr(size_dt_strings);
-__fdt_set_hdr(size_dt_struct);
-#undef __fdt_set_hdr
-
-/**
- * fdt_check_header - sanity check a device tree or possible device tree
- * @fdt: pointer to data which might be a flattened device tree
- *
- * fdt_check_header() checks that the given buffer contains what
- * appears to be a flattened device tree with sane information in its
- * header.
- *
- * returns:
- *     0, if the buffer appears to contain a valid device tree
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE, standard meanings, as above
- */
-int fdt_check_header(const void *fdt);
-
-/**
- * fdt_move - move a device tree around in memory
- * @fdt: pointer to the device tree to move
- * @buf: pointer to memory where the device is to be moved
- * @bufsize: size of the memory space at buf
- *
- * fdt_move() relocates, if possible, the device tree blob located at
- * fdt to the buffer at buf of size bufsize.  The buffer may overlap
- * with the existing device tree blob at fdt.  Therefore,
- *     fdt_move(fdt, fdt, fdt_totalsize(fdt))
- * should always succeed.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE, standard meanings
- */
-int fdt_move(const void *fdt, void *buf, int bufsize);
-
-/**********************************************************************/
-/* Read-only functions                                                */
-/**********************************************************************/
-
-/**
- * fdt_string - retrieve a string from the strings block of a device tree
- * @fdt: pointer to the device tree blob
- * @stroffset: offset of the string within the strings block (native endian)
- *
- * fdt_string() retrieves a pointer to a single string from the
- * strings block of the device tree blob at fdt.
- *
- * returns:
- *     a pointer to the string, on success
- *     NULL, if stroffset is out of bounds
- */
-const char *fdt_string(const void *fdt, int stroffset);
-
-/**
- * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
- * @fdt: pointer to the device tree blob
- *
- * Returns the number of entries in the device tree blob's memory
- * reservation map.  This does not include the terminating 0,0 entry
- * or any other (0,0) entries reserved for expansion.
- *
- * returns:
- *     the number of entries
- */
-int fdt_num_mem_rsv(const void *fdt);
-
-/**
- * fdt_get_mem_rsv - retrieve one memory reserve map entry
- * @fdt: pointer to the device tree blob
- * @address, @size: pointers to 64-bit variables
- *
- * On success, *address and *size will contain the address and size of
- * the n-th reserve map entry from the device tree blob, in
- * native-endian format.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE, standard meanings
- */
-int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
-
-/**
- * fdt_subnode_offset_namelen - find a subnode based on substring
- * @fdt: pointer to the device tree blob
- * @parentoffset: structure block offset of a node
- * @name: name of the subnode to locate
- * @namelen: number of characters of name to consider
- *
- * Identical to fdt_subnode_offset(), but only examine the first
- * namelen characters of name for matching the subnode name.  This is
- * useful for finding subnodes based on a portion of a larger string,
- * such as a full path.
- */
-int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
-                              const char *name, int namelen);
-/**
- * fdt_subnode_offset - find a subnode of a given node
- * @fdt: pointer to the device tree blob
- * @parentoffset: structure block offset of a node
- * @name: name of the subnode to locate
- *
- * fdt_subnode_offset() finds a subnode of the node at structure block
- * offset parentoffset with the given name.  name may include a unit
- * address, in which case fdt_subnode_offset() will find the subnode
- * with that unit address, or the unit address may be omitted, in
- * which case fdt_subnode_offset() will find an arbitrary subnode
- * whose name excluding unit address matches the given name.
- *
- * returns:
- *     structure block offset of the requested subnode (>=0), on success
- *     -FDT_ERR_NOTFOUND, if the requested subnode does not exist
- *     -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
- *      -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_TRUNCATED, standard meanings.
- */
-int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
-
-/**
- * fdt_path_offset - find a tree node by its full path
- * @fdt: pointer to the device tree blob
- * @path: full path of the node to locate
- *
- * fdt_path_offset() finds a node of a given path in the device tree.
- * Each path component may omit the unit address portion, but the
- * results of this are undefined if any such path component is
- * ambiguous (that is if there are multiple nodes at the relevant
- * level matching the given component, differentiated only by unit
- * address).
- *
- * returns:
- *     structure block offset of the node with the requested path (>=0), on success
- *     -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
- *     -FDT_ERR_NOTFOUND, if the requested node does not exist
- *      -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_TRUNCATED, standard meanings.
- */
-int fdt_path_offset(const void *fdt, const char *path);
-
-/**
- * fdt_get_name - retrieve the name of a given node
- * @fdt: pointer to the device tree blob
- * @nodeoffset: structure block offset of the starting node
- * @lenp: pointer to an integer variable (will be overwritten) or NULL
- *
- * fdt_get_name() retrieves the name (including unit address) of the
- * device tree node at structure block offset nodeoffset.  If lenp is
- * non-NULL, the length of this name is also returned, in the integer
- * pointed to by lenp.
- *
- * returns:
- *     pointer to the node's name, on success
- *             If lenp is non-NULL, *lenp contains the length of that name (>=0)
- *     NULL, on error
- *             if lenp is non-NULL *lenp contains an error code (<0):
- *             -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *             -FDT_ERR_BADMAGIC,
- *             -FDT_ERR_BADVERSION,
- *             -FDT_ERR_BADSTATE, standard meanings
- */
-const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
-
-/**
- * fdt_first_property_offset - find the offset of a node's first property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: structure block offset of a node
- *
- * fdt_first_property_offset() finds the first property of the node at
- * the given structure block offset.
- *
- * returns:
- *     structure block offset of the property (>=0), on success
- *     -FDT_ERR_NOTFOUND, if the requested node has no properties
- *     -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
- *      -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_TRUNCATED, standard meanings.
- */
-int fdt_first_property_offset(const void *fdt, int nodeoffset);
-
-/**
- * fdt_next_property_offset - step through a node's properties
- * @fdt: pointer to the device tree blob
- * @offset: structure block offset of a property
- *
- * fdt_next_property_offset() finds the property immediately after the
- * one at the given structure block offset.  This will be a property
- * of the same node as the given property.
- *
- * returns:
- *     structure block offset of the next property (>=0), on success
- *     -FDT_ERR_NOTFOUND, if the given property is the last in its node
- *     -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag
- *      -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_TRUNCATED, standard meanings.
- */
-int fdt_next_property_offset(const void *fdt, int offset);
-
-/**
- * fdt_get_property_by_offset - retrieve the property at a given offset
- * @fdt: pointer to the device tree blob
- * @offset: offset of the property to retrieve
- * @lenp: pointer to an integer variable (will be overwritten) or NULL
- *
- * fdt_get_property_by_offset() retrieves a pointer to the
- * fdt_property structure within the device tree blob at the given
- * offset.  If lenp is non-NULL, the length of the property value is
- * also returned, in the integer pointed to by lenp.
- *
- * returns:
- *     pointer to the structure representing the property
- *             if lenp is non-NULL, *lenp contains the length of the property
- *             value (>=0)
- *     NULL, on error
- *             if lenp is non-NULL, *lenp contains an error code (<0):
- *             -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
- *             -FDT_ERR_BADMAGIC,
- *             -FDT_ERR_BADVERSION,
- *             -FDT_ERR_BADSTATE,
- *             -FDT_ERR_BADSTRUCTURE,
- *             -FDT_ERR_TRUNCATED, standard meanings
- */
-const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
-                                                     int offset,
-                                                     int *lenp);
-
-/**
- * fdt_get_property_namelen - find a property based on substring
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to find
- * @name: name of the property to find
- * @namelen: number of characters of name to consider
- * @lenp: pointer to an integer variable (will be overwritten) or NULL
- *
- * Identical to fdt_get_property_namelen(), but only examine the first
- * namelen characters of name for matching the property name.
- */
-const struct fdt_property *fdt_get_property_namelen(const void *fdt,
-                                                   int nodeoffset,
-                                                   const char *name,
-                                                   int namelen, int *lenp);
-
-/**
- * fdt_get_property - find a given property in a given node
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to find
- * @name: name of the property to find
- * @lenp: pointer to an integer variable (will be overwritten) or NULL
- *
- * fdt_get_property() retrieves a pointer to the fdt_property
- * structure within the device tree blob corresponding to the property
- * named 'name' of the node at offset nodeoffset.  If lenp is
- * non-NULL, the length of the property value is also returned, in the
- * integer pointed to by lenp.
- *
- * returns:
- *     pointer to the structure representing the property
- *             if lenp is non-NULL, *lenp contains the length of the property
- *             value (>=0)
- *     NULL, on error
- *             if lenp is non-NULL, *lenp contains an error code (<0):
- *             -FDT_ERR_NOTFOUND, node does not have named property
- *             -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *             -FDT_ERR_BADMAGIC,
- *             -FDT_ERR_BADVERSION,
- *             -FDT_ERR_BADSTATE,
- *             -FDT_ERR_BADSTRUCTURE,
- *             -FDT_ERR_TRUNCATED, standard meanings
- */
-const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
-                                           const char *name, int *lenp);
-static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
-                                                     const char *name,
-                                                     int *lenp)
-{
-       return (struct fdt_property *)(uintptr_t)
-               fdt_get_property(fdt, nodeoffset, name, lenp);
-}
-
-/**
- * fdt_getprop_by_offset - retrieve the value of a property at a given offset
- * @fdt: pointer to the device tree blob
- * @ffset: offset of the property to read
- * @namep: pointer to a string variable (will be overwritten) or NULL
- * @lenp: pointer to an integer variable (will be overwritten) or NULL
- *
- * fdt_getprop_by_offset() retrieves a pointer to the value of the
- * property at structure block offset 'offset' (this will be a pointer
- * to within the device blob itself, not a copy of the value).  If
- * lenp is non-NULL, the length of the property value is also
- * returned, in the integer pointed to by lenp.  If namep is non-NULL,
- * the property's namne will also be returned in the char * pointed to
- * by namep (this will be a pointer to within the device tree's string
- * block, not a new copy of the name).
- *
- * returns:
- *     pointer to the property's value
- *             if lenp is non-NULL, *lenp contains the length of the property
- *             value (>=0)
- *             if namep is non-NULL *namep contiains a pointer to the property
- *             name.
- *     NULL, on error
- *             if lenp is non-NULL, *lenp contains an error code (<0):
- *             -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
- *             -FDT_ERR_BADMAGIC,
- *             -FDT_ERR_BADVERSION,
- *             -FDT_ERR_BADSTATE,
- *             -FDT_ERR_BADSTRUCTURE,
- *             -FDT_ERR_TRUNCATED, standard meanings
- */
-const void *fdt_getprop_by_offset(const void *fdt, int offset,
-                                 const char **namep, int *lenp);
-
-/**
- * fdt_getprop_namelen - get property value based on substring
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to find
- * @name: name of the property to find
- * @namelen: number of characters of name to consider
- * @lenp: pointer to an integer variable (will be overwritten) or NULL
- *
- * Identical to fdt_getprop(), but only examine the first namelen
- * characters of name for matching the property name.
- */
-const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
-                               const char *name, int namelen, int *lenp);
-
-/**
- * fdt_getprop - retrieve the value of a given property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to find
- * @name: name of the property to find
- * @lenp: pointer to an integer variable (will be overwritten) or NULL
- *
- * fdt_getprop() retrieves a pointer to the value of the property
- * named 'name' of the node at offset nodeoffset (this will be a
- * pointer to within the device blob itself, not a copy of the value).
- * If lenp is non-NULL, the length of the property value is also
- * returned, in the integer pointed to by lenp.
- *
- * returns:
- *     pointer to the property's value
- *             if lenp is non-NULL, *lenp contains the length of the property
- *             value (>=0)
- *     NULL, on error
- *             if lenp is non-NULL, *lenp contains an error code (<0):
- *             -FDT_ERR_NOTFOUND, node does not have named property
- *             -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *             -FDT_ERR_BADMAGIC,
- *             -FDT_ERR_BADVERSION,
- *             -FDT_ERR_BADSTATE,
- *             -FDT_ERR_BADSTRUCTURE,
- *             -FDT_ERR_TRUNCATED, standard meanings
- */
-const void *fdt_getprop(const void *fdt, int nodeoffset,
-                       const char *name, int *lenp);
-static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
-                                 const char *name, int *lenp)
-{
-       return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
-}
-
-/**
- * fdt_get_phandle - retrieve the phandle of a given node
- * @fdt: pointer to the device tree blob
- * @nodeoffset: structure block offset of the node
- *
- * fdt_get_phandle() retrieves the phandle of the device tree node at
- * structure block offset nodeoffset.
- *
- * returns:
- *     the phandle of the node at nodeoffset, on success (!= 0, != -1)
- *     0, if the node has no phandle, or another error occurs
- */
-uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
-
-/**
- * fdt_get_alias_namelen - get alias based on substring
- * @fdt: pointer to the device tree blob
- * @name: name of the alias th look up
- * @namelen: number of characters of name to consider
- *
- * Identical to fdt_get_alias(), but only examine the first namelen
- * characters of name for matching the alias name.
- */
-const char *fdt_get_alias_namelen(const void *fdt,
-                                 const char *name, int namelen);
-
-/**
- * fdt_get_alias - retreive the path referenced by a given alias
- * @fdt: pointer to the device tree blob
- * @name: name of the alias th look up
- *
- * fdt_get_alias() retrieves the value of a given alias.  That is, the
- * value of the property named 'name' in the node /aliases.
- *
- * returns:
- *     a pointer to the expansion of the alias named 'name', of it exists
- *     NULL, if the given alias or the /aliases node does not exist
- */
-const char *fdt_get_alias(const void *fdt, const char *name);
-
-/**
- * fdt_get_path - determine the full path of a node
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose path to find
- * @buf: character buffer to contain the returned path (will be overwritten)
- * @buflen: size of the character buffer at buf
- *
- * fdt_get_path() computes the full path of the node at offset
- * nodeoffset, and records that path in the buffer at buf.
- *
- * NOTE: This function is expensive, as it must scan the device tree
- * structure from the start to nodeoffset.
- *
- * returns:
- *     0, on success
- *             buf contains the absolute path of the node at
- *             nodeoffset, as a NUL-terminated string.
- *     -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
- *     -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
- *             characters and will not fit in the given buffer.
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE, standard meanings
- */
-int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
-
-/**
- * fdt_supernode_atdepth_offset - find a specific ancestor of a node
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose parent to find
- * @supernodedepth: depth of the ancestor to find
- * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
- *
- * fdt_supernode_atdepth_offset() finds an ancestor of the given node
- * at a specific depth from the root (where the root itself has depth
- * 0, its immediate subnodes depth 1 and so forth).  So
- *     fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
- * will always return 0, the offset of the root node.  If the node at
- * nodeoffset has depth D, then:
- *     fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
- * will return nodeoffset itself.
- *
- * NOTE: This function is expensive, as it must scan the device tree
- * structure from the start to nodeoffset.
- *
- * returns:
-
- *     structure block offset of the node at node offset's ancestor
- *             of depth supernodedepth (>=0), on success
- *     -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
-*      -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of nodeoffset
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE, standard meanings
- */
-int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
-                                int supernodedepth, int *nodedepth);
-
-/**
- * fdt_node_depth - find the depth of a given node
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose parent to find
- *
- * fdt_node_depth() finds the depth of a given node.  The root node
- * has depth 0, its immediate subnodes depth 1 and so forth.
- *
- * NOTE: This function is expensive, as it must scan the device tree
- * structure from the start to nodeoffset.
- *
- * returns:
- *     depth of the node at nodeoffset (>=0), on success
- *     -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE, standard meanings
- */
-int fdt_node_depth(const void *fdt, int nodeoffset);
-
-/**
- * fdt_parent_offset - find the parent of a given node
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose parent to find
- *
- * fdt_parent_offset() locates the parent node of a given node (that
- * is, it finds the offset of the node which contains the node at
- * nodeoffset as a subnode).
- *
- * NOTE: This function is expensive, as it must scan the device tree
- * structure from the start to nodeoffset, *twice*.
- *
- * returns:
- *     structure block offset of the parent of the node at nodeoffset
- *             (>=0), on success
- *     -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE, standard meanings
- */
-int fdt_parent_offset(const void *fdt, int nodeoffset);
-
-/**
- * fdt_node_offset_by_prop_value - find nodes with a given property value
- * @fdt: pointer to the device tree blob
- * @startoffset: only find nodes after this offset
- * @propname: property name to check
- * @propval: property value to search for
- * @proplen: length of the value in propval
- *
- * fdt_node_offset_by_prop_value() returns the offset of the first
- * node after startoffset, which has a property named propname whose
- * value is of length proplen and has value equal to propval; or if
- * startoffset is -1, the very first such node in the tree.
- *
- * To iterate through all nodes matching the criterion, the following
- * idiom can be used:
- *     offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
- *                                            propval, proplen);
- *     while (offset != -FDT_ERR_NOTFOUND) {
- *             // other code here
- *             offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
- *                                                    propval, proplen);
- *     }
- *
- * Note the -1 in the first call to the function, if 0 is used here
- * instead, the function will never locate the root node, even if it
- * matches the criterion.
- *
- * returns:
- *     structure block offset of the located node (>= 0, >startoffset),
- *              on success
- *     -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
- *             tree after startoffset
- *     -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE, standard meanings
- */
-int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
-                                 const char *propname,
-                                 const void *propval, int proplen);
-
-/**
- * fdt_node_offset_by_phandle - find the node with a given phandle
- * @fdt: pointer to the device tree blob
- * @phandle: phandle value
- *
- * fdt_node_offset_by_phandle() returns the offset of the node
- * which has the given phandle value.  If there is more than one node
- * in the tree with the given phandle (an invalid tree), results are
- * undefined.
- *
- * returns:
- *     structure block offset of the located node (>= 0), on success
- *     -FDT_ERR_NOTFOUND, no node with that phandle exists
- *     -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE, standard meanings
- */
-int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
-
-/**
- * fdt_node_check_compatible: check a node's compatible property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of a tree node
- * @compatible: string to match against
- *
- *
- * fdt_node_check_compatible() returns 0 if the given node contains a
- * 'compatible' property with the given string as one of its elements,
- * it returns non-zero otherwise, or on error.
- *
- * returns:
- *     0, if the node has a 'compatible' property listing the given string
- *     1, if the node has a 'compatible' property, but it does not list
- *             the given string
- *     -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
- *     -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE, standard meanings
- */
-int fdt_node_check_compatible(const void *fdt, int nodeoffset,
-                             const char *compatible);
-
-/**
- * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
- * @fdt: pointer to the device tree blob
- * @startoffset: only find nodes after this offset
- * @compatible: 'compatible' string to match against
- *
- * fdt_node_offset_by_compatible() returns the offset of the first
- * node after startoffset, which has a 'compatible' property which
- * lists the given compatible string; or if startoffset is -1, the
- * very first such node in the tree.
- *
- * To iterate through all nodes matching the criterion, the following
- * idiom can be used:
- *     offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
- *     while (offset != -FDT_ERR_NOTFOUND) {
- *             // other code here
- *             offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
- *     }
- *
- * Note the -1 in the first call to the function, if 0 is used here
- * instead, the function will never locate the root node, even if it
- * matches the criterion.
- *
- * returns:
- *     structure block offset of the located node (>= 0, >startoffset),
- *              on success
- *     -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
- *             tree after startoffset
- *     -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE, standard meanings
- */
-int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
-                                 const char *compatible);
-
-/**********************************************************************/
-/* Write-in-place functions                                           */
-/**********************************************************************/
-
-/**
- * fdt_setprop_inplace - change a property's value, but not its size
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: pointer to data to replace the property value with
- * @len: length of the property value
- *
- * fdt_setprop_inplace() replaces the value of a given property with
- * the data in val, of length len.  This function cannot change the
- * size of a property, and so will only work if len is equal to the
- * current length of the property.
- *
- * This function will alter only the bytes in the blob which contain
- * the given property value, and will not alter or move any other part
- * of the tree.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_NOSPACE, if len is not equal to the property's current length
- *     -FDT_ERR_NOTFOUND, node does not have the named property
- *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
-                       const void *val, int len);
-
-/**
- * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: 32-bit integer value to replace the property with
- *
- * fdt_setprop_inplace_u32() replaces the value of a given property
- * with the 32-bit integer value in val, converting val to big-endian
- * if necessary.  This function cannot change the size of a property,
- * and so will only work if the property already exists and has length
- * 4.
- *
- * This function will alter only the bytes in the blob which contain
- * the given property value, and will not alter or move any other part
- * of the tree.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_NOSPACE, if the property's length is not equal to 4
- *     -FDT_ERR_NOTFOUND, node does not have the named property
- *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_TRUNCATED, standard meanings
- */
-static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
-                                         const char *name, uint32_t val)
-{
-       val = cpu_to_fdt32(val);
-       return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));
-}
-
-/**
- * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: 64-bit integer value to replace the property with
- *
- * fdt_setprop_inplace_u64() replaces the value of a given property
- * with the 64-bit integer value in val, converting val to big-endian
- * if necessary.  This function cannot change the size of a property,
- * and so will only work if the property already exists and has length
- * 8.
- *
- * This function will alter only the bytes in the blob which contain
- * the given property value, and will not alter or move any other part
- * of the tree.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_NOSPACE, if the property's length is not equal to 8
- *     -FDT_ERR_NOTFOUND, node does not have the named property
- *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_TRUNCATED, standard meanings
- */
-static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
-                                         const char *name, uint64_t val)
-{
-       val = cpu_to_fdt64(val);
-       return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));
-}
-
-/**
- * fdt_setprop_inplace_cell - change the value of a single-cell property
- *
- * This is an alternative name for fdt_setprop_inplace_u32()
- */
-static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
-                                          const char *name, uint32_t val)
-{
-       return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
-}
-
-/**
- * fdt_nop_property - replace a property with nop tags
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to nop
- * @name: name of the property to nop
- *
- * fdt_nop_property() will replace a given property's representation
- * in the blob with FDT_NOP tags, effectively removing it from the
- * tree.
- *
- * This function will alter only the bytes in the blob which contain
- * the property, and will not alter or move any other part of the
- * tree.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_NOTFOUND, node does not have the named property
- *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
-
-/**
- * fdt_nop_node - replace a node (subtree) with nop tags
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node to nop
- *
- * fdt_nop_node() will replace a given node's representation in the
- * blob, including all its subnodes, if any, with FDT_NOP tags,
- * effectively removing it from the tree.
- *
- * This function will alter only the bytes in the blob which contain
- * the node and its properties and subnodes, and will not alter or
- * move any other part of the tree.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_nop_node(void *fdt, int nodeoffset);
-
-/**********************************************************************/
-/* Sequential write functions                                         */
-/**********************************************************************/
-
-int fdt_create(void *buf, int bufsize);
-int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
-int fdt_finish_reservemap(void *fdt);
-int fdt_begin_node(void *fdt, const char *name);
-int fdt_property(void *fdt, const char *name, const void *val, int len);
-static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)
-{
-       val = cpu_to_fdt32(val);
-       return fdt_property(fdt, name, &val, sizeof(val));
-}
-static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
-{
-       val = cpu_to_fdt64(val);
-       return fdt_property(fdt, name, &val, sizeof(val));
-}
-static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
-{
-       return fdt_property_u32(fdt, name, val);
-}
-#define fdt_property_string(fdt, name, str) \
-       fdt_property(fdt, name, str, strlen(str)+1)
-int fdt_end_node(void *fdt);
-int fdt_finish(void *fdt);
-
-/**********************************************************************/
-/* Read-write functions                                               */
-/**********************************************************************/
-
-int fdt_create_empty_tree(void *buf, int bufsize);
-int fdt_open_into(const void *fdt, void *buf, int bufsize);
-int fdt_pack(void *fdt);
-
-/**
- * fdt_add_mem_rsv - add one memory reserve map entry
- * @fdt: pointer to the device tree blob
- * @address, @size: 64-bit values (native endian)
- *
- * Adds a reserve map entry to the given blob reserving a region at
- * address address of length size.
- *
- * This function will insert data into the reserve map and will
- * therefore change the indexes of some entries in the table.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- *             contain the new reservation entry
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
-
-/**
- * fdt_del_mem_rsv - remove a memory reserve map entry
- * @fdt: pointer to the device tree blob
- * @n: entry to remove
- *
- * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
- * the blob.
- *
- * This function will delete data from the reservation table and will
- * therefore change the indexes of some entries in the table.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
- *             are less than n+1 reserve map entries)
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_del_mem_rsv(void *fdt, int n);
-
-/**
- * fdt_set_name - change the name of a given node
- * @fdt: pointer to the device tree blob
- * @nodeoffset: structure block offset of a node
- * @name: name to give the node
- *
- * fdt_set_name() replaces the name (including unit address, if any)
- * of the given node with the given string.  NOTE: this function can't
- * efficiently check if the new name is unique amongst the given
- * node's siblings; results are undefined if this function is invoked
- * with a name equal to one of the given node's siblings.
- *
- * This function may insert or delete data from the blob, and will
- * therefore change the offsets of some existing nodes.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob
- *             to contain the new name
- *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE, standard meanings
- */
-int fdt_set_name(void *fdt, int nodeoffset, const char *name);
-
-/**
- * fdt_setprop - create or change a property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: pointer to data to set the property value to
- * @len: length of the property value
- *
- * fdt_setprop() sets the value of the named property in the given
- * node to the given value and length, creating the property if it
- * does not already exist.
- *
- * This function may insert or delete data from the blob, and will
- * therefore change the offsets of some existing nodes.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- *             contain the new property value
- *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_setprop(void *fdt, int nodeoffset, const char *name,
-               const void *val, int len);
-
-/**
- * fdt_setprop_u32 - set a property to a 32-bit integer
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: 32-bit integer value for the property (native endian)
- *
- * fdt_setprop_u32() sets the value of the named property in the given
- * node to the given 32-bit integer value (converting to big-endian if
- * necessary), or creates a new property with that value if it does
- * not already exist.
- *
- * This function may insert or delete data from the blob, and will
- * therefore change the offsets of some existing nodes.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- *             contain the new property value
- *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_TRUNCATED, standard meanings
- */
-static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
-                                 uint32_t val)
-{
-       val = cpu_to_fdt32(val);
-       return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));
-}
-
-/**
- * fdt_setprop_u64 - set a property to a 64-bit integer
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: 64-bit integer value for the property (native endian)
- *
- * fdt_setprop_u64() sets the value of the named property in the given
- * node to the given 64-bit integer value (converting to big-endian if
- * necessary), or creates a new property with that value if it does
- * not already exist.
- *
- * This function may insert or delete data from the blob, and will
- * therefore change the offsets of some existing nodes.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- *             contain the new property value
- *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_TRUNCATED, standard meanings
- */
-static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
-                                 uint64_t val)
-{
-       val = cpu_to_fdt64(val);
-       return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));
-}
-
-/**
- * fdt_setprop_cell - set a property to a single cell value
- *
- * This is an alternative name for fdt_setprop_u32()
- */
-static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
-                                  uint32_t val)
-{
-       return fdt_setprop_u32(fdt, nodeoffset, name, val);
-}
-
-/**
- * fdt_setprop_string - set a property to a string value
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @str: string value for the property
- *
- * fdt_setprop_string() sets the value of the named property in the
- * given node to the given string value (using the length of the
- * string to determine the new length of the property), or creates a
- * new property with that value if it does not already exist.
- *
- * This function may insert or delete data from the blob, and will
- * therefore change the offsets of some existing nodes.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- *             contain the new property value
- *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_TRUNCATED, standard meanings
- */
-#define fdt_setprop_string(fdt, nodeoffset, name, str) \
-       fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
-
-/**
- * fdt_appendprop - append to or create a property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to append to
- * @val: pointer to data to append to the property value
- * @len: length of the data to append to the property value
- *
- * fdt_appendprop() appends the value to the named property in the
- * given node, creating the property if it does not already exist.
- *
- * This function may insert data into the blob, and will therefore
- * change the offsets of some existing nodes.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- *             contain the new property value
- *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
-                  const void *val, int len);
-
-/**
- * fdt_appendprop_u32 - append a 32-bit integer value to a property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: 32-bit integer value to append to the property (native endian)
- *
- * fdt_appendprop_u32() appends the given 32-bit integer value
- * (converting to big-endian if necessary) to the value of the named
- * property in the given node, or creates a new property with that
- * value if it does not already exist.
- *
- * This function may insert data into the blob, and will therefore
- * change the offsets of some existing nodes.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- *             contain the new property value
- *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_TRUNCATED, standard meanings
- */
-static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
-                                    const char *name, uint32_t val)
-{
-       val = cpu_to_fdt32(val);
-       return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val));
-}
-
-/**
- * fdt_appendprop_u64 - append a 64-bit integer value to a property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @val: 64-bit integer value to append to the property (native endian)
- *
- * fdt_appendprop_u64() appends the given 64-bit integer value
- * (converting to big-endian if necessary) to the value of the named
- * property in the given node, or creates a new property with that
- * value if it does not already exist.
- *
- * This function may insert data into the blob, and will therefore
- * change the offsets of some existing nodes.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- *             contain the new property value
- *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_TRUNCATED, standard meanings
- */
-static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
-                                    const char *name, uint64_t val)
-{
-       val = cpu_to_fdt64(val);
-       return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val));
-}
-
-/**
- * fdt_appendprop_cell - append a single cell value to a property
- *
- * This is an alternative name for fdt_appendprop_u32()
- */
-static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
-                                     const char *name, uint32_t val)
-{
-       return fdt_appendprop_u32(fdt, nodeoffset, name, val);
-}
-
-/**
- * fdt_appendprop_string - append a string to a property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to change
- * @name: name of the property to change
- * @str: string value to append to the property
- *
- * fdt_appendprop_string() appends the given string to the value of
- * the named property in the given node, or creates a new property
- * with that value if it does not already exist.
- *
- * This function may insert data into the blob, and will therefore
- * change the offsets of some existing nodes.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
- *             contain the new property value
- *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_TRUNCATED, standard meanings
- */
-#define fdt_appendprop_string(fdt, nodeoffset, name, str) \
-       fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
-
-/**
- * fdt_delprop - delete a property
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node whose property to nop
- * @name: name of the property to nop
- *
- * fdt_del_property() will delete the given property.
- *
- * This function will delete data from the blob, and will therefore
- * change the offsets of some existing nodes.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_NOTFOUND, node does not have the named property
- *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_delprop(void *fdt, int nodeoffset, const char *name);
-
-/**
- * fdt_add_subnode_namelen - creates a new node based on substring
- * @fdt: pointer to the device tree blob
- * @parentoffset: structure block offset of a node
- * @name: name of the subnode to locate
- * @namelen: number of characters of name to consider
- *
- * Identical to fdt_add_subnode(), but use only the first namelen
- * characters of name as the name of the new node.  This is useful for
- * creating subnodes based on a portion of a larger string, such as a
- * full path.
- */
-int fdt_add_subnode_namelen(void *fdt, int parentoffset,
-                           const char *name, int namelen);
-
-/**
- * fdt_add_subnode - creates a new node
- * @fdt: pointer to the device tree blob
- * @parentoffset: structure block offset of a node
- * @name: name of the subnode to locate
- *
- * fdt_add_subnode() creates a new node as a subnode of the node at
- * structure block offset parentoffset, with the given name (which
- * should include the unit address, if any).
- *
- * This function will insert data into the blob, and will therefore
- * change the offsets of some existing nodes.
-
- * returns:
- *     structure block offset of the created nodeequested subnode (>=0), on success
- *     -FDT_ERR_NOTFOUND, if the requested subnode does not exist
- *     -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
- *     -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
- *             the given name
- *     -FDT_ERR_NOSPACE, if there is insufficient free space in the
- *             blob to contain the new node
- *     -FDT_ERR_NOSPACE
- *     -FDT_ERR_BADLAYOUT
- *      -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_TRUNCATED, standard meanings.
- */
-int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
-
-/**
- * fdt_del_node - delete a node (subtree)
- * @fdt: pointer to the device tree blob
- * @nodeoffset: offset of the node to nop
- *
- * fdt_del_node() will remove the given node, including all its
- * subnodes if any, from the blob.
- *
- * This function will delete data from the blob, and will therefore
- * change the offsets of some existing nodes.
- *
- * returns:
- *     0, on success
- *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
- *     -FDT_ERR_BADLAYOUT,
- *     -FDT_ERR_BADMAGIC,
- *     -FDT_ERR_BADVERSION,
- *     -FDT_ERR_BADSTATE,
- *     -FDT_ERR_BADSTRUCTURE,
- *     -FDT_ERR_TRUNCATED, standard meanings
- */
-int fdt_del_node(void *fdt, int nodeoffset);
-
-/**********************************************************************/
-/* Debugging / informational functions                                */
-/**********************************************************************/
-
-const char *fdt_strerror(int errval);
-
-#endif /* _LIBFDT_H */
+#ifndef _LIBFDT_H\r
+#define _LIBFDT_H\r
+/*\r
+ * libfdt - Flat Device Tree manipulation\r
+ * Copyright (C) 2006 David Gibson, IBM Corporation.\r
+ *\r
+ * libfdt is dual licensed: you can use it either under the terms of\r
+ * the GPL, or the BSD license, at your option.\r
+ *\r
+ *  a) This library is free software; you can redistribute it and/or\r
+ *     modify it under the terms of the GNU General Public License as\r
+ *     published by the Free Software Foundation; either version 2 of the\r
+ *     License, or (at your option) any later version.\r
+ *\r
+ *     This library is distributed in the hope that it will be useful,\r
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ *     GNU General Public License for more details.\r
+ *\r
+ *     You should have received a copy of the GNU General Public\r
+ *     License along with this library; if not, write to the Free\r
+ *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\r
+ *     MA 02110-1301 USA\r
+ *\r
+ * Alternatively,\r
+ *\r
+ *  b) Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *     1. Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *     2. Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\r
+ *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,\r
+ *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
+ *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+ *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
+ *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
+ *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
+ *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#include <libfdt_env.h>\r
+#include <fdt.h>\r
+\r
+#define FDT_FIRST_SUPPORTED_VERSION    0x10\r
+#define FDT_LAST_SUPPORTED_VERSION     0x11\r
+\r
+/* Error codes: informative error codes */\r
+#define FDT_ERR_NOTFOUND       1\r
+       /* FDT_ERR_NOTFOUND: The requested node or property does not exist */\r
+#define FDT_ERR_EXISTS         2\r
+       /* FDT_ERR_EXISTS: Attemped to create a node or property which\r
+        * already exists */\r
+#define FDT_ERR_NOSPACE                3\r
+       /* FDT_ERR_NOSPACE: Operation needed to expand the device\r
+        * tree, but its buffer did not have sufficient space to\r
+        * contain the expanded tree. Use fdt_open_into() to move the\r
+        * device tree to a buffer with more space. */\r
+\r
+/* Error codes: codes for bad parameters */\r
+#define FDT_ERR_BADOFFSET      4\r
+       /* FDT_ERR_BADOFFSET: Function was passed a structure block\r
+        * offset which is out-of-bounds, or which points to an\r
+        * unsuitable part of the structure for the operation. */\r
+#define FDT_ERR_BADPATH                5\r
+       /* FDT_ERR_BADPATH: Function was passed a badly formatted path\r
+        * (e.g. missing a leading / for a function which requires an\r
+        * absolute path) */\r
+#define FDT_ERR_BADPHANDLE     6\r
+       /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle\r
+        * value.  phandle values of 0 and -1 are not permitted. */\r
+#define FDT_ERR_BADSTATE       7\r
+       /* FDT_ERR_BADSTATE: Function was passed an incomplete device\r
+        * tree created by the sequential-write functions, which is\r
+        * not sufficiently complete for the requested operation. */\r
+\r
+/* Error codes: codes for bad device tree blobs */\r
+#define FDT_ERR_TRUNCATED      8\r
+       /* FDT_ERR_TRUNCATED: Structure block of the given device tree\r
+        * ends without an FDT_END tag. */\r
+#define FDT_ERR_BADMAGIC       9\r
+       /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a\r
+        * device tree at all - it is missing the flattened device\r
+        * tree magic number. */\r
+#define FDT_ERR_BADVERSION     10\r
+       /* FDT_ERR_BADVERSION: Given device tree has a version which\r
+        * can't be handled by the requested operation.  For\r
+        * read-write functions, this may mean that fdt_open_into() is\r
+        * required to convert the tree to the expected version. */\r
+#define FDT_ERR_BADSTRUCTURE   11\r
+       /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt\r
+        * structure block or other serious error (e.g. misnested\r
+        * nodes, or subnodes preceding properties). */\r
+#define FDT_ERR_BADLAYOUT      12\r
+       /* FDT_ERR_BADLAYOUT: For read-write functions, the given\r
+        * device tree has it's sub-blocks in an order that the\r
+        * function can't handle (memory reserve map, then structure,\r
+        * then strings).  Use fdt_open_into() to reorganize the tree\r
+        * into a form suitable for the read-write operations. */\r
+\r
+/* "Can't happen" error indicating a bug in libfdt */\r
+#define FDT_ERR_INTERNAL       13\r
+       /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.\r
+        * Should never be returned, if it is, it indicates a bug in\r
+        * libfdt itself. */\r
+\r
+#define FDT_ERR_MAX            13\r
+\r
+/**********************************************************************/\r
+/* Low-level functions (you probably don't need these)                */\r
+/**********************************************************************/\r
+\r
+const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);\r
+static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)\r
+{\r
+       return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);\r
+}\r
+\r
+uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);\r
+\r
+/**********************************************************************/\r
+/* Traversal functions                                                */\r
+/**********************************************************************/\r
+\r
+int fdt_next_node(const void *fdt, int offset, int *depth);\r
+\r
+/**********************************************************************/\r
+/* General functions                                                  */\r
+/**********************************************************************/\r
+\r
+#define fdt_get_header(fdt, field) \\r
+       (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))\r
+#define fdt_magic(fdt)                         (fdt_get_header(fdt, magic))\r
+#define fdt_totalsize(fdt)             (fdt_get_header(fdt, totalsize))\r
+#define fdt_off_dt_struct(fdt)         (fdt_get_header(fdt, off_dt_struct))\r
+#define fdt_off_dt_strings(fdt)                (fdt_get_header(fdt, off_dt_strings))\r
+#define fdt_off_mem_rsvmap(fdt)                (fdt_get_header(fdt, off_mem_rsvmap))\r
+#define fdt_version(fdt)               (fdt_get_header(fdt, version))\r
+#define fdt_last_comp_version(fdt)     (fdt_get_header(fdt, last_comp_version))\r
+#define fdt_boot_cpuid_phys(fdt)       (fdt_get_header(fdt, boot_cpuid_phys))\r
+#define fdt_size_dt_strings(fdt)       (fdt_get_header(fdt, size_dt_strings))\r
+#define fdt_size_dt_struct(fdt)                (fdt_get_header(fdt, size_dt_struct))\r
+\r
+#define __fdt_set_hdr(name) \\r
+       static inline void fdt_set_##name(void *fdt, uint32_t val) \\r
+       { \\r
+               struct fdt_header *fdth = (struct fdt_header*)fdt; \\r
+               fdth->name = cpu_to_fdt32(val); \\r
+       }\r
+__fdt_set_hdr(magic);\r
+__fdt_set_hdr(totalsize);\r
+__fdt_set_hdr(off_dt_struct);\r
+__fdt_set_hdr(off_dt_strings);\r
+__fdt_set_hdr(off_mem_rsvmap);\r
+__fdt_set_hdr(version);\r
+__fdt_set_hdr(last_comp_version);\r
+__fdt_set_hdr(boot_cpuid_phys);\r
+__fdt_set_hdr(size_dt_strings);\r
+__fdt_set_hdr(size_dt_struct);\r
+#undef __fdt_set_hdr\r
+\r
+/**\r
+ * fdt_check_header - sanity check a device tree or possible device tree\r
+ * @fdt: pointer to data which might be a flattened device tree\r
+ *\r
+ * fdt_check_header() checks that the given buffer contains what\r
+ * appears to be a flattened device tree with sane information in its\r
+ * header.\r
+ *\r
+ * returns:\r
+ *     0, if the buffer appears to contain a valid device tree\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE, standard meanings, as above\r
+ */\r
+int fdt_check_header(const void *fdt);\r
+\r
+/**\r
+ * fdt_move - move a device tree around in memory\r
+ * @fdt: pointer to the device tree to move\r
+ * @buf: pointer to memory where the device is to be moved\r
+ * @bufsize: size of the memory space at buf\r
+ *\r
+ * fdt_move() relocates, if possible, the device tree blob located at\r
+ * fdt to the buffer at buf of size bufsize.  The buffer may overlap\r
+ * with the existing device tree blob at fdt.  Therefore,\r
+ *     fdt_move(fdt, fdt, fdt_totalsize(fdt))\r
+ * should always succeed.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE, standard meanings\r
+ */\r
+int fdt_move(const void *fdt, void *buf, int bufsize);\r
+\r
+/**********************************************************************/\r
+/* Read-only functions                                                */\r
+/**********************************************************************/\r
+\r
+/**\r
+ * fdt_string - retrieve a string from the strings block of a device tree\r
+ * @fdt: pointer to the device tree blob\r
+ * @stroffset: offset of the string within the strings block (native endian)\r
+ *\r
+ * fdt_string() retrieves a pointer to a single string from the\r
+ * strings block of the device tree blob at fdt.\r
+ *\r
+ * returns:\r
+ *     a pointer to the string, on success\r
+ *     NULL, if stroffset is out of bounds\r
+ */\r
+const char *fdt_string(const void *fdt, int stroffset);\r
+\r
+/**\r
+ * fdt_num_mem_rsv - retrieve the number of memory reserve map entries\r
+ * @fdt: pointer to the device tree blob\r
+ *\r
+ * Returns the number of entries in the device tree blob's memory\r
+ * reservation map.  This does not include the terminating 0,0 entry\r
+ * or any other (0,0) entries reserved for expansion.\r
+ *\r
+ * returns:\r
+ *     the number of entries\r
+ */\r
+int fdt_num_mem_rsv(const void *fdt);\r
+\r
+/**\r
+ * fdt_get_mem_rsv - retrieve one memory reserve map entry\r
+ * @fdt: pointer to the device tree blob\r
+ * @address, @size: pointers to 64-bit variables\r
+ *\r
+ * On success, *address and *size will contain the address and size of\r
+ * the n-th reserve map entry from the device tree blob, in\r
+ * native-endian format.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE, standard meanings\r
+ */\r
+int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);\r
+\r
+/**\r
+ * fdt_subnode_offset_namelen - find a subnode based on substring\r
+ * @fdt: pointer to the device tree blob\r
+ * @parentoffset: structure block offset of a node\r
+ * @name: name of the subnode to locate\r
+ * @namelen: number of characters of name to consider\r
+ *\r
+ * Identical to fdt_subnode_offset(), but only examine the first\r
+ * namelen characters of name for matching the subnode name.  This is\r
+ * useful for finding subnodes based on a portion of a larger string,\r
+ * such as a full path.\r
+ */\r
+int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,\r
+                              const char *name, int namelen);\r
+/**\r
+ * fdt_subnode_offset - find a subnode of a given node\r
+ * @fdt: pointer to the device tree blob\r
+ * @parentoffset: structure block offset of a node\r
+ * @name: name of the subnode to locate\r
+ *\r
+ * fdt_subnode_offset() finds a subnode of the node at structure block\r
+ * offset parentoffset with the given name.  name may include a unit\r
+ * address, in which case fdt_subnode_offset() will find the subnode\r
+ * with that unit address, or the unit address may be omitted, in\r
+ * which case fdt_subnode_offset() will find an arbitrary subnode\r
+ * whose name excluding unit address matches the given name.\r
+ *\r
+ * returns:\r
+ *     structure block offset of the requested subnode (>=0), on success\r
+ *     -FDT_ERR_NOTFOUND, if the requested subnode does not exist\r
+ *     -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag\r
+ *      -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings.\r
+ */\r
+int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);\r
+\r
+/**\r
+ * fdt_path_offset - find a tree node by its full path\r
+ * @fdt: pointer to the device tree blob\r
+ * @path: full path of the node to locate\r
+ *\r
+ * fdt_path_offset() finds a node of a given path in the device tree.\r
+ * Each path component may omit the unit address portion, but the\r
+ * results of this are undefined if any such path component is\r
+ * ambiguous (that is if there are multiple nodes at the relevant\r
+ * level matching the given component, differentiated only by unit\r
+ * address).\r
+ *\r
+ * returns:\r
+ *     structure block offset of the node with the requested path (>=0), on success\r
+ *     -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid\r
+ *     -FDT_ERR_NOTFOUND, if the requested node does not exist\r
+ *      -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings.\r
+ */\r
+int fdt_path_offset(const void *fdt, const char *path);\r
+\r
+/**\r
+ * fdt_get_name - retrieve the name of a given node\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: structure block offset of the starting node\r
+ * @lenp: pointer to an integer variable (will be overwritten) or NULL\r
+ *\r
+ * fdt_get_name() retrieves the name (including unit address) of the\r
+ * device tree node at structure block offset nodeoffset.  If lenp is\r
+ * non-NULL, the length of this name is also returned, in the integer\r
+ * pointed to by lenp.\r
+ *\r
+ * returns:\r
+ *     pointer to the node's name, on success\r
+ *             If lenp is non-NULL, *lenp contains the length of that name (>=0)\r
+ *     NULL, on error\r
+ *             if lenp is non-NULL *lenp contains an error code (<0):\r
+ *             -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *             -FDT_ERR_BADMAGIC,\r
+ *             -FDT_ERR_BADVERSION,\r
+ *             -FDT_ERR_BADSTATE, standard meanings\r
+ */\r
+const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);\r
+\r
+/**\r
+ * fdt_first_property_offset - find the offset of a node's first property\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: structure block offset of a node\r
+ *\r
+ * fdt_first_property_offset() finds the first property of the node at\r
+ * the given structure block offset.\r
+ *\r
+ * returns:\r
+ *     structure block offset of the property (>=0), on success\r
+ *     -FDT_ERR_NOTFOUND, if the requested node has no properties\r
+ *     -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag\r
+ *      -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings.\r
+ */\r
+int fdt_first_property_offset(const void *fdt, int nodeoffset);\r
+\r
+/**\r
+ * fdt_next_property_offset - step through a node's properties\r
+ * @fdt: pointer to the device tree blob\r
+ * @offset: structure block offset of a property\r
+ *\r
+ * fdt_next_property_offset() finds the property immediately after the\r
+ * one at the given structure block offset.  This will be a property\r
+ * of the same node as the given property.\r
+ *\r
+ * returns:\r
+ *     structure block offset of the next property (>=0), on success\r
+ *     -FDT_ERR_NOTFOUND, if the given property is the last in its node\r
+ *     -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag\r
+ *      -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings.\r
+ */\r
+int fdt_next_property_offset(const void *fdt, int offset);\r
+\r
+/**\r
+ * fdt_get_property_by_offset - retrieve the property at a given offset\r
+ * @fdt: pointer to the device tree blob\r
+ * @offset: offset of the property to retrieve\r
+ * @lenp: pointer to an integer variable (will be overwritten) or NULL\r
+ *\r
+ * fdt_get_property_by_offset() retrieves a pointer to the\r
+ * fdt_property structure within the device tree blob at the given\r
+ * offset.  If lenp is non-NULL, the length of the property value is\r
+ * also returned, in the integer pointed to by lenp.\r
+ *\r
+ * returns:\r
+ *     pointer to the structure representing the property\r
+ *             if lenp is non-NULL, *lenp contains the length of the property\r
+ *             value (>=0)\r
+ *     NULL, on error\r
+ *             if lenp is non-NULL, *lenp contains an error code (<0):\r
+ *             -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag\r
+ *             -FDT_ERR_BADMAGIC,\r
+ *             -FDT_ERR_BADVERSION,\r
+ *             -FDT_ERR_BADSTATE,\r
+ *             -FDT_ERR_BADSTRUCTURE,\r
+ *             -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+const struct fdt_property *fdt_get_property_by_offset(const void *fdt,\r
+                                                     int offset,\r
+                                                     int *lenp);\r
+\r
+/**\r
+ * fdt_get_property_namelen - find a property based on substring\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to find\r
+ * @name: name of the property to find\r
+ * @namelen: number of characters of name to consider\r
+ * @lenp: pointer to an integer variable (will be overwritten) or NULL\r
+ *\r
+ * Identical to fdt_get_property_namelen(), but only examine the first\r
+ * namelen characters of name for matching the property name.\r
+ */\r
+const struct fdt_property *fdt_get_property_namelen(const void *fdt,\r
+                                                   int nodeoffset,\r
+                                                   const char *name,\r
+                                                   int namelen, int *lenp);\r
+\r
+/**\r
+ * fdt_get_property - find a given property in a given node\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to find\r
+ * @name: name of the property to find\r
+ * @lenp: pointer to an integer variable (will be overwritten) or NULL\r
+ *\r
+ * fdt_get_property() retrieves a pointer to the fdt_property\r
+ * structure within the device tree blob corresponding to the property\r
+ * named 'name' of the node at offset nodeoffset.  If lenp is\r
+ * non-NULL, the length of the property value is also returned, in the\r
+ * integer pointed to by lenp.\r
+ *\r
+ * returns:\r
+ *     pointer to the structure representing the property\r
+ *             if lenp is non-NULL, *lenp contains the length of the property\r
+ *             value (>=0)\r
+ *     NULL, on error\r
+ *             if lenp is non-NULL, *lenp contains an error code (<0):\r
+ *             -FDT_ERR_NOTFOUND, node does not have named property\r
+ *             -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *             -FDT_ERR_BADMAGIC,\r
+ *             -FDT_ERR_BADVERSION,\r
+ *             -FDT_ERR_BADSTATE,\r
+ *             -FDT_ERR_BADSTRUCTURE,\r
+ *             -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,\r
+                                           const char *name, int *lenp);\r
+static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,\r
+                                                     const char *name,\r
+                                                     int *lenp)\r
+{\r
+       return (struct fdt_property *)(uintptr_t)\r
+               fdt_get_property(fdt, nodeoffset, name, lenp);\r
+}\r
+\r
+/**\r
+ * fdt_getprop_by_offset - retrieve the value of a property at a given offset\r
+ * @fdt: pointer to the device tree blob\r
+ * @ffset: offset of the property to read\r
+ * @namep: pointer to a string variable (will be overwritten) or NULL\r
+ * @lenp: pointer to an integer variable (will be overwritten) or NULL\r
+ *\r
+ * fdt_getprop_by_offset() retrieves a pointer to the value of the\r
+ * property at structure block offset 'offset' (this will be a pointer\r
+ * to within the device blob itself, not a copy of the value).  If\r
+ * lenp is non-NULL, the length of the property value is also\r
+ * returned, in the integer pointed to by lenp.  If namep is non-NULL,\r
+ * the property's namne will also be returned in the char * pointed to\r
+ * by namep (this will be a pointer to within the device tree's string\r
+ * block, not a new copy of the name).\r
+ *\r
+ * returns:\r
+ *     pointer to the property's value\r
+ *             if lenp is non-NULL, *lenp contains the length of the property\r
+ *             value (>=0)\r
+ *             if namep is non-NULL *namep contiains a pointer to the property\r
+ *             name.\r
+ *     NULL, on error\r
+ *             if lenp is non-NULL, *lenp contains an error code (<0):\r
+ *             -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag\r
+ *             -FDT_ERR_BADMAGIC,\r
+ *             -FDT_ERR_BADVERSION,\r
+ *             -FDT_ERR_BADSTATE,\r
+ *             -FDT_ERR_BADSTRUCTURE,\r
+ *             -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+const void *fdt_getprop_by_offset(const void *fdt, int offset,\r
+                                 const char **namep, int *lenp);\r
+\r
+/**\r
+ * fdt_getprop_namelen - get property value based on substring\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to find\r
+ * @name: name of the property to find\r
+ * @namelen: number of characters of name to consider\r
+ * @lenp: pointer to an integer variable (will be overwritten) or NULL\r
+ *\r
+ * Identical to fdt_getprop(), but only examine the first namelen\r
+ * characters of name for matching the property name.\r
+ */\r
+const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,\r
+                               const char *name, int namelen, int *lenp);\r
+\r
+/**\r
+ * fdt_getprop - retrieve the value of a given property\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to find\r
+ * @name: name of the property to find\r
+ * @lenp: pointer to an integer variable (will be overwritten) or NULL\r
+ *\r
+ * fdt_getprop() retrieves a pointer to the value of the property\r
+ * named 'name' of the node at offset nodeoffset (this will be a\r
+ * pointer to within the device blob itself, not a copy of the value).\r
+ * If lenp is non-NULL, the length of the property value is also\r
+ * returned, in the integer pointed to by lenp.\r
+ *\r
+ * returns:\r
+ *     pointer to the property's value\r
+ *             if lenp is non-NULL, *lenp contains the length of the property\r
+ *             value (>=0)\r
+ *     NULL, on error\r
+ *             if lenp is non-NULL, *lenp contains an error code (<0):\r
+ *             -FDT_ERR_NOTFOUND, node does not have named property\r
+ *             -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *             -FDT_ERR_BADMAGIC,\r
+ *             -FDT_ERR_BADVERSION,\r
+ *             -FDT_ERR_BADSTATE,\r
+ *             -FDT_ERR_BADSTRUCTURE,\r
+ *             -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+const void *fdt_getprop(const void *fdt, int nodeoffset,\r
+                       const char *name, int *lenp);\r
+static inline void *fdt_getprop_w(void *fdt, int nodeoffset,\r
+                                 const char *name, int *lenp)\r
+{\r
+       return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);\r
+}\r
+\r
+/**\r
+ * fdt_get_phandle - retrieve the phandle of a given node\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: structure block offset of the node\r
+ *\r
+ * fdt_get_phandle() retrieves the phandle of the device tree node at\r
+ * structure block offset nodeoffset.\r
+ *\r
+ * returns:\r
+ *     the phandle of the node at nodeoffset, on success (!= 0, != -1)\r
+ *     0, if the node has no phandle, or another error occurs\r
+ */\r
+uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);\r
+\r
+/**\r
+ * fdt_get_alias_namelen - get alias based on substring\r
+ * @fdt: pointer to the device tree blob\r
+ * @name: name of the alias th look up\r
+ * @namelen: number of characters of name to consider\r
+ *\r
+ * Identical to fdt_get_alias(), but only examine the first namelen\r
+ * characters of name for matching the alias name.\r
+ */\r
+const char *fdt_get_alias_namelen(const void *fdt,\r
+                                 const char *name, int namelen);\r
+\r
+/**\r
+ * fdt_get_alias - retreive the path referenced by a given alias\r
+ * @fdt: pointer to the device tree blob\r
+ * @name: name of the alias th look up\r
+ *\r
+ * fdt_get_alias() retrieves the value of a given alias.  That is, the\r
+ * value of the property named 'name' in the node /aliases.\r
+ *\r
+ * returns:\r
+ *     a pointer to the expansion of the alias named 'name', of it exists\r
+ *     NULL, if the given alias or the /aliases node does not exist\r
+ */\r
+const char *fdt_get_alias(const void *fdt, const char *name);\r
+\r
+/**\r
+ * fdt_get_path - determine the full path of a node\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose path to find\r
+ * @buf: character buffer to contain the returned path (will be overwritten)\r
+ * @buflen: size of the character buffer at buf\r
+ *\r
+ * fdt_get_path() computes the full path of the node at offset\r
+ * nodeoffset, and records that path in the buffer at buf.\r
+ *\r
+ * NOTE: This function is expensive, as it must scan the device tree\r
+ * structure from the start to nodeoffset.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *             buf contains the absolute path of the node at\r
+ *             nodeoffset, as a NUL-terminated string.\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
+ *     -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)\r
+ *             characters and will not fit in the given buffer.\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE, standard meanings\r
+ */\r
+int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);\r
+\r
+/**\r
+ * fdt_supernode_atdepth_offset - find a specific ancestor of a node\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose parent to find\r
+ * @supernodedepth: depth of the ancestor to find\r
+ * @nodedepth: pointer to an integer variable (will be overwritten) or NULL\r
+ *\r
+ * fdt_supernode_atdepth_offset() finds an ancestor of the given node\r
+ * at a specific depth from the root (where the root itself has depth\r
+ * 0, its immediate subnodes depth 1 and so forth).  So\r
+ *     fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);\r
+ * will always return 0, the offset of the root node.  If the node at\r
+ * nodeoffset has depth D, then:\r
+ *     fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);\r
+ * will return nodeoffset itself.\r
+ *\r
+ * NOTE: This function is expensive, as it must scan the device tree\r
+ * structure from the start to nodeoffset.\r
+ *\r
+ * returns:\r
+\r
+ *     structure block offset of the node at node offset's ancestor\r
+ *             of depth supernodedepth (>=0), on success\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
+*      -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of nodeoffset\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE, standard meanings\r
+ */\r
+int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,\r
+                                int supernodedepth, int *nodedepth);\r
+\r
+/**\r
+ * fdt_node_depth - find the depth of a given node\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose parent to find\r
+ *\r
+ * fdt_node_depth() finds the depth of a given node.  The root node\r
+ * has depth 0, its immediate subnodes depth 1 and so forth.\r
+ *\r
+ * NOTE: This function is expensive, as it must scan the device tree\r
+ * structure from the start to nodeoffset.\r
+ *\r
+ * returns:\r
+ *     depth of the node at nodeoffset (>=0), on success\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE, standard meanings\r
+ */\r
+int fdt_node_depth(const void *fdt, int nodeoffset);\r
+\r
+/**\r
+ * fdt_parent_offset - find the parent of a given node\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose parent to find\r
+ *\r
+ * fdt_parent_offset() locates the parent node of a given node (that\r
+ * is, it finds the offset of the node which contains the node at\r
+ * nodeoffset as a subnode).\r
+ *\r
+ * NOTE: This function is expensive, as it must scan the device tree\r
+ * structure from the start to nodeoffset, *twice*.\r
+ *\r
+ * returns:\r
+ *     structure block offset of the parent of the node at nodeoffset\r
+ *             (>=0), on success\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE, standard meanings\r
+ */\r
+int fdt_parent_offset(const void *fdt, int nodeoffset);\r
+\r
+/**\r
+ * fdt_node_offset_by_prop_value - find nodes with a given property value\r
+ * @fdt: pointer to the device tree blob\r
+ * @startoffset: only find nodes after this offset\r
+ * @propname: property name to check\r
+ * @propval: property value to search for\r
+ * @proplen: length of the value in propval\r
+ *\r
+ * fdt_node_offset_by_prop_value() returns the offset of the first\r
+ * node after startoffset, which has a property named propname whose\r
+ * value is of length proplen and has value equal to propval; or if\r
+ * startoffset is -1, the very first such node in the tree.\r
+ *\r
+ * To iterate through all nodes matching the criterion, the following\r
+ * idiom can be used:\r
+ *     offset = fdt_node_offset_by_prop_value(fdt, -1, propname,\r
+ *                                            propval, proplen);\r
+ *     while (offset != -FDT_ERR_NOTFOUND) {\r
+ *             // other code here\r
+ *             offset = fdt_node_offset_by_prop_value(fdt, offset, propname,\r
+ *                                                    propval, proplen);\r
+ *     }\r
+ *\r
+ * Note the -1 in the first call to the function, if 0 is used here\r
+ * instead, the function will never locate the root node, even if it\r
+ * matches the criterion.\r
+ *\r
+ * returns:\r
+ *     structure block offset of the located node (>= 0, >startoffset),\r
+ *              on success\r
+ *     -FDT_ERR_NOTFOUND, no node matching the criterion exists in the\r
+ *             tree after startoffset\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE, standard meanings\r
+ */\r
+int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,\r
+                                 const char *propname,\r
+                                 const void *propval, int proplen);\r
+\r
+/**\r
+ * fdt_node_offset_by_phandle - find the node with a given phandle\r
+ * @fdt: pointer to the device tree blob\r
+ * @phandle: phandle value\r
+ *\r
+ * fdt_node_offset_by_phandle() returns the offset of the node\r
+ * which has the given phandle value.  If there is more than one node\r
+ * in the tree with the given phandle (an invalid tree), results are\r
+ * undefined.\r
+ *\r
+ * returns:\r
+ *     structure block offset of the located node (>= 0), on success\r
+ *     -FDT_ERR_NOTFOUND, no node with that phandle exists\r
+ *     -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE, standard meanings\r
+ */\r
+int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);\r
+\r
+/**\r
+ * fdt_node_check_compatible: check a node's compatible property\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of a tree node\r
+ * @compatible: string to match against\r
+ *\r
+ *\r
+ * fdt_node_check_compatible() returns 0 if the given node contains a\r
+ * 'compatible' property with the given string as one of its elements,\r
+ * it returns non-zero otherwise, or on error.\r
+ *\r
+ * returns:\r
+ *     0, if the node has a 'compatible' property listing the given string\r
+ *     1, if the node has a 'compatible' property, but it does not list\r
+ *             the given string\r
+ *     -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property\r
+ *     -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE, standard meanings\r
+ */\r
+int fdt_node_check_compatible(const void *fdt, int nodeoffset,\r
+                             const char *compatible);\r
+\r
+/**\r
+ * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value\r
+ * @fdt: pointer to the device tree blob\r
+ * @startoffset: only find nodes after this offset\r
+ * @compatible: 'compatible' string to match against\r
+ *\r
+ * fdt_node_offset_by_compatible() returns the offset of the first\r
+ * node after startoffset, which has a 'compatible' property which\r
+ * lists the given compatible string; or if startoffset is -1, the\r
+ * very first such node in the tree.\r
+ *\r
+ * To iterate through all nodes matching the criterion, the following\r
+ * idiom can be used:\r
+ *     offset = fdt_node_offset_by_compatible(fdt, -1, compatible);\r
+ *     while (offset != -FDT_ERR_NOTFOUND) {\r
+ *             // other code here\r
+ *             offset = fdt_node_offset_by_compatible(fdt, offset, compatible);\r
+ *     }\r
+ *\r
+ * Note the -1 in the first call to the function, if 0 is used here\r
+ * instead, the function will never locate the root node, even if it\r
+ * matches the criterion.\r
+ *\r
+ * returns:\r
+ *     structure block offset of the located node (>= 0, >startoffset),\r
+ *              on success\r
+ *     -FDT_ERR_NOTFOUND, no node matching the criterion exists in the\r
+ *             tree after startoffset\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE, standard meanings\r
+ */\r
+int fdt_node_offset_by_compatible(const void *fdt, int startoffset,\r
+                                 const char *compatible);\r
+\r
+/**********************************************************************/\r
+/* Write-in-place functions                                           */\r
+/**********************************************************************/\r
+\r
+/**\r
+ * fdt_setprop_inplace - change a property's value, but not its size\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to change\r
+ * @name: name of the property to change\r
+ * @val: pointer to data to replace the property value with\r
+ * @len: length of the property value\r
+ *\r
+ * fdt_setprop_inplace() replaces the value of a given property with\r
+ * the data in val, of length len.  This function cannot change the\r
+ * size of a property, and so will only work if len is equal to the\r
+ * current length of the property.\r
+ *\r
+ * This function will alter only the bytes in the blob which contain\r
+ * the given property value, and will not alter or move any other part\r
+ * of the tree.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_NOSPACE, if len is not equal to the property's current length\r
+ *     -FDT_ERR_NOTFOUND, node does not have the named property\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,\r
+                       const void *val, int len);\r
+\r
+/**\r
+ * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to change\r
+ * @name: name of the property to change\r
+ * @val: 32-bit integer value to replace the property with\r
+ *\r
+ * fdt_setprop_inplace_u32() replaces the value of a given property\r
+ * with the 32-bit integer value in val, converting val to big-endian\r
+ * if necessary.  This function cannot change the size of a property,\r
+ * and so will only work if the property already exists and has length\r
+ * 4.\r
+ *\r
+ * This function will alter only the bytes in the blob which contain\r
+ * the given property value, and will not alter or move any other part\r
+ * of the tree.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_NOSPACE, if the property's length is not equal to 4\r
+ *     -FDT_ERR_NOTFOUND, node does not have the named property\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,\r
+                                         const char *name, uint32_t val)\r
+{\r
+       val = cpu_to_fdt32(val);\r
+       return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));\r
+}\r
+\r
+/**\r
+ * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to change\r
+ * @name: name of the property to change\r
+ * @val: 64-bit integer value to replace the property with\r
+ *\r
+ * fdt_setprop_inplace_u64() replaces the value of a given property\r
+ * with the 64-bit integer value in val, converting val to big-endian\r
+ * if necessary.  This function cannot change the size of a property,\r
+ * and so will only work if the property already exists and has length\r
+ * 8.\r
+ *\r
+ * This function will alter only the bytes in the blob which contain\r
+ * the given property value, and will not alter or move any other part\r
+ * of the tree.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_NOSPACE, if the property's length is not equal to 8\r
+ *     -FDT_ERR_NOTFOUND, node does not have the named property\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,\r
+                                         const char *name, uint64_t val)\r
+{\r
+       val = cpu_to_fdt64(val);\r
+       return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));\r
+}\r
+\r
+/**\r
+ * fdt_setprop_inplace_cell - change the value of a single-cell property\r
+ *\r
+ * This is an alternative name for fdt_setprop_inplace_u32()\r
+ */\r
+static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,\r
+                                          const char *name, uint32_t val)\r
+{\r
+       return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);\r
+}\r
+\r
+/**\r
+ * fdt_nop_property - replace a property with nop tags\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to nop\r
+ * @name: name of the property to nop\r
+ *\r
+ * fdt_nop_property() will replace a given property's representation\r
+ * in the blob with FDT_NOP tags, effectively removing it from the\r
+ * tree.\r
+ *\r
+ * This function will alter only the bytes in the blob which contain\r
+ * the property, and will not alter or move any other part of the\r
+ * tree.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_NOTFOUND, node does not have the named property\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+int fdt_nop_property(void *fdt, int nodeoffset, const char *name);\r
+\r
+/**\r
+ * fdt_nop_node - replace a node (subtree) with nop tags\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node to nop\r
+ *\r
+ * fdt_nop_node() will replace a given node's representation in the\r
+ * blob, including all its subnodes, if any, with FDT_NOP tags,\r
+ * effectively removing it from the tree.\r
+ *\r
+ * This function will alter only the bytes in the blob which contain\r
+ * the node and its properties and subnodes, and will not alter or\r
+ * move any other part of the tree.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+int fdt_nop_node(void *fdt, int nodeoffset);\r
+\r
+/**********************************************************************/\r
+/* Sequential write functions                                         */\r
+/**********************************************************************/\r
+\r
+int fdt_create(void *buf, int bufsize);\r
+int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);\r
+int fdt_finish_reservemap(void *fdt);\r
+int fdt_begin_node(void *fdt, const char *name);\r
+int fdt_property(void *fdt, const char *name, const void *val, int len);\r
+static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)\r
+{\r
+       val = cpu_to_fdt32(val);\r
+       return fdt_property(fdt, name, &val, sizeof(val));\r
+}\r
+static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)\r
+{\r
+       val = cpu_to_fdt64(val);\r
+       return fdt_property(fdt, name, &val, sizeof(val));\r
+}\r
+static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)\r
+{\r
+       return fdt_property_u32(fdt, name, val);\r
+}\r
+#define fdt_property_string(fdt, name, str) \\r
+       fdt_property(fdt, name, str, strlen(str)+1)\r
+int fdt_end_node(void *fdt);\r
+int fdt_finish(void *fdt);\r
+\r
+/**********************************************************************/\r
+/* Read-write functions                                               */\r
+/**********************************************************************/\r
+\r
+int fdt_create_empty_tree(void *buf, int bufsize);\r
+int fdt_open_into(const void *fdt, void *buf, int bufsize);\r
+int fdt_pack(void *fdt);\r
+\r
+/**\r
+ * fdt_add_mem_rsv - add one memory reserve map entry\r
+ * @fdt: pointer to the device tree blob\r
+ * @address, @size: 64-bit values (native endian)\r
+ *\r
+ * Adds a reserve map entry to the given blob reserving a region at\r
+ * address address of length size.\r
+ *\r
+ * This function will insert data into the reserve map and will\r
+ * therefore change the indexes of some entries in the table.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
+ *             contain the new reservation entry\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);\r
+\r
+/**\r
+ * fdt_del_mem_rsv - remove a memory reserve map entry\r
+ * @fdt: pointer to the device tree blob\r
+ * @n: entry to remove\r
+ *\r
+ * fdt_del_mem_rsv() removes the n-th memory reserve map entry from\r
+ * the blob.\r
+ *\r
+ * This function will delete data from the reservation table and will\r
+ * therefore change the indexes of some entries in the table.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there\r
+ *             are less than n+1 reserve map entries)\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+int fdt_del_mem_rsv(void *fdt, int n);\r
+\r
+/**\r
+ * fdt_set_name - change the name of a given node\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: structure block offset of a node\r
+ * @name: name to give the node\r
+ *\r
+ * fdt_set_name() replaces the name (including unit address, if any)\r
+ * of the given node with the given string.  NOTE: this function can't\r
+ * efficiently check if the new name is unique amongst the given\r
+ * node's siblings; results are undefined if this function is invoked\r
+ * with a name equal to one of the given node's siblings.\r
+ *\r
+ * This function may insert or delete data from the blob, and will\r
+ * therefore change the offsets of some existing nodes.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob\r
+ *             to contain the new name\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE, standard meanings\r
+ */\r
+int fdt_set_name(void *fdt, int nodeoffset, const char *name);\r
+\r
+/**\r
+ * fdt_setprop - create or change a property\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to change\r
+ * @name: name of the property to change\r
+ * @val: pointer to data to set the property value to\r
+ * @len: length of the property value\r
+ *\r
+ * fdt_setprop() sets the value of the named property in the given\r
+ * node to the given value and length, creating the property if it\r
+ * does not already exist.\r
+ *\r
+ * This function may insert or delete data from the blob, and will\r
+ * therefore change the offsets of some existing nodes.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
+ *             contain the new property value\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+int fdt_setprop(void *fdt, int nodeoffset, const char *name,\r
+               const void *val, int len);\r
+\r
+/**\r
+ * fdt_setprop_u32 - set a property to a 32-bit integer\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to change\r
+ * @name: name of the property to change\r
+ * @val: 32-bit integer value for the property (native endian)\r
+ *\r
+ * fdt_setprop_u32() sets the value of the named property in the given\r
+ * node to the given 32-bit integer value (converting to big-endian if\r
+ * necessary), or creates a new property with that value if it does\r
+ * not already exist.\r
+ *\r
+ * This function may insert or delete data from the blob, and will\r
+ * therefore change the offsets of some existing nodes.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
+ *             contain the new property value\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,\r
+                                 uint32_t val)\r
+{\r
+       val = cpu_to_fdt32(val);\r
+       return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));\r
+}\r
+\r
+/**\r
+ * fdt_setprop_u64 - set a property to a 64-bit integer\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to change\r
+ * @name: name of the property to change\r
+ * @val: 64-bit integer value for the property (native endian)\r
+ *\r
+ * fdt_setprop_u64() sets the value of the named property in the given\r
+ * node to the given 64-bit integer value (converting to big-endian if\r
+ * necessary), or creates a new property with that value if it does\r
+ * not already exist.\r
+ *\r
+ * This function may insert or delete data from the blob, and will\r
+ * therefore change the offsets of some existing nodes.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
+ *             contain the new property value\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,\r
+                                 uint64_t val)\r
+{\r
+       val = cpu_to_fdt64(val);\r
+       return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));\r
+}\r
+\r
+/**\r
+ * fdt_setprop_cell - set a property to a single cell value\r
+ *\r
+ * This is an alternative name for fdt_setprop_u32()\r
+ */\r
+static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,\r
+                                  uint32_t val)\r
+{\r
+       return fdt_setprop_u32(fdt, nodeoffset, name, val);\r
+}\r
+\r
+/**\r
+ * fdt_setprop_string - set a property to a string value\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to change\r
+ * @name: name of the property to change\r
+ * @str: string value for the property\r
+ *\r
+ * fdt_setprop_string() sets the value of the named property in the\r
+ * given node to the given string value (using the length of the\r
+ * string to determine the new length of the property), or creates a\r
+ * new property with that value if it does not already exist.\r
+ *\r
+ * This function may insert or delete data from the blob, and will\r
+ * therefore change the offsets of some existing nodes.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
+ *             contain the new property value\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+#define fdt_setprop_string(fdt, nodeoffset, name, str) \\r
+       fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)\r
+\r
+/**\r
+ * fdt_appendprop - append to or create a property\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to change\r
+ * @name: name of the property to append to\r
+ * @val: pointer to data to append to the property value\r
+ * @len: length of the data to append to the property value\r
+ *\r
+ * fdt_appendprop() appends the value to the named property in the\r
+ * given node, creating the property if it does not already exist.\r
+ *\r
+ * This function may insert data into the blob, and will therefore\r
+ * change the offsets of some existing nodes.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
+ *             contain the new property value\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+int fdt_appendprop(void *fdt, int nodeoffset, const char *name,\r
+                  const void *val, int len);\r
+\r
+/**\r
+ * fdt_appendprop_u32 - append a 32-bit integer value to a property\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to change\r
+ * @name: name of the property to change\r
+ * @val: 32-bit integer value to append to the property (native endian)\r
+ *\r
+ * fdt_appendprop_u32() appends the given 32-bit integer value\r
+ * (converting to big-endian if necessary) to the value of the named\r
+ * property in the given node, or creates a new property with that\r
+ * value if it does not already exist.\r
+ *\r
+ * This function may insert data into the blob, and will therefore\r
+ * change the offsets of some existing nodes.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
+ *             contain the new property value\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,\r
+                                    const char *name, uint32_t val)\r
+{\r
+       val = cpu_to_fdt32(val);\r
+       return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val));\r
+}\r
+\r
+/**\r
+ * fdt_appendprop_u64 - append a 64-bit integer value to a property\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to change\r
+ * @name: name of the property to change\r
+ * @val: 64-bit integer value to append to the property (native endian)\r
+ *\r
+ * fdt_appendprop_u64() appends the given 64-bit integer value\r
+ * (converting to big-endian if necessary) to the value of the named\r
+ * property in the given node, or creates a new property with that\r
+ * value if it does not already exist.\r
+ *\r
+ * This function may insert data into the blob, and will therefore\r
+ * change the offsets of some existing nodes.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
+ *             contain the new property value\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,\r
+                                    const char *name, uint64_t val)\r
+{\r
+       val = cpu_to_fdt64(val);\r
+       return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val));\r
+}\r
+\r
+/**\r
+ * fdt_appendprop_cell - append a single cell value to a property\r
+ *\r
+ * This is an alternative name for fdt_appendprop_u32()\r
+ */\r
+static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,\r
+                                     const char *name, uint32_t val)\r
+{\r
+       return fdt_appendprop_u32(fdt, nodeoffset, name, val);\r
+}\r
+\r
+/**\r
+ * fdt_appendprop_string - append a string to a property\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to change\r
+ * @name: name of the property to change\r
+ * @str: string value to append to the property\r
+ *\r
+ * fdt_appendprop_string() appends the given string to the value of\r
+ * the named property in the given node, or creates a new property\r
+ * with that value if it does not already exist.\r
+ *\r
+ * This function may insert data into the blob, and will therefore\r
+ * change the offsets of some existing nodes.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
+ *             contain the new property value\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+#define fdt_appendprop_string(fdt, nodeoffset, name, str) \\r
+       fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)\r
+\r
+/**\r
+ * fdt_delprop - delete a property\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to nop\r
+ * @name: name of the property to nop\r
+ *\r
+ * fdt_del_property() will delete the given property.\r
+ *\r
+ * This function will delete data from the blob, and will therefore\r
+ * change the offsets of some existing nodes.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_NOTFOUND, node does not have the named property\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+int fdt_delprop(void *fdt, int nodeoffset, const char *name);\r
+\r
+/**\r
+ * fdt_add_subnode_namelen - creates a new node based on substring\r
+ * @fdt: pointer to the device tree blob\r
+ * @parentoffset: structure block offset of a node\r
+ * @name: name of the subnode to locate\r
+ * @namelen: number of characters of name to consider\r
+ *\r
+ * Identical to fdt_add_subnode(), but use only the first namelen\r
+ * characters of name as the name of the new node.  This is useful for\r
+ * creating subnodes based on a portion of a larger string, such as a\r
+ * full path.\r
+ */\r
+int fdt_add_subnode_namelen(void *fdt, int parentoffset,\r
+                           const char *name, int namelen);\r
+\r
+/**\r
+ * fdt_add_subnode - creates a new node\r
+ * @fdt: pointer to the device tree blob\r
+ * @parentoffset: structure block offset of a node\r
+ * @name: name of the subnode to locate\r
+ *\r
+ * fdt_add_subnode() creates a new node as a subnode of the node at\r
+ * structure block offset parentoffset, with the given name (which\r
+ * should include the unit address, if any).\r
+ *\r
+ * This function will insert data into the blob, and will therefore\r
+ * change the offsets of some existing nodes.\r
+\r
+ * returns:\r
+ *     structure block offset of the created nodeequested subnode (>=0), on success\r
+ *     -FDT_ERR_NOTFOUND, if the requested subnode does not exist\r
+ *     -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag\r
+ *     -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of\r
+ *             the given name\r
+ *     -FDT_ERR_NOSPACE, if there is insufficient free space in the\r
+ *             blob to contain the new node\r
+ *     -FDT_ERR_NOSPACE\r
+ *     -FDT_ERR_BADLAYOUT\r
+ *      -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings.\r
+ */\r
+int fdt_add_subnode(void *fdt, int parentoffset, const char *name);\r
+\r
+/**\r
+ * fdt_del_node - delete a node (subtree)\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node to nop\r
+ *\r
+ * fdt_del_node() will remove the given node, including all its\r
+ * subnodes if any, from the blob.\r
+ *\r
+ * This function will delete data from the blob, and will therefore\r
+ * change the offsets of some existing nodes.\r
+ *\r
+ * returns:\r
+ *     0, on success\r
+ *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ *     -FDT_ERR_BADLAYOUT,\r
+ *     -FDT_ERR_BADMAGIC,\r
+ *     -FDT_ERR_BADVERSION,\r
+ *     -FDT_ERR_BADSTATE,\r
+ *     -FDT_ERR_BADSTRUCTURE,\r
+ *     -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+int fdt_del_node(void *fdt, int nodeoffset);\r
+\r
+/**********************************************************************/\r
+/* Debugging / informational functions                                */\r
+/**********************************************************************/\r
+\r
+const char *fdt_strerror(int errval);\r
+\r
+#endif /* _LIBFDT_H */\r
index d35b8692c6c13b509420c6d7e6c09414dbcddeb0..6cc311fe7303ed03cf97d9f7fc334abba7cdbfd2 100644 (file)
@@ -1,77 +1,77 @@
-/** @file
-*
-*  Copyright (c) 2011-2012, ARM Limited. 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.             
-*
-**/
-
-#ifndef _LIBFDT_ENV_H
-#define _LIBFDT_ENV_H
-
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-
-typedef UINT8 uint8_t;
-typedef UINT16 uint16_t;
-typedef UINT32 uint32_t;
-typedef UINT64 uint64_t;
-typedef UINTN uintptr_t;
-typedef UINTN size_t;
-
-static inline uint16_t fdt16_to_cpu(uint16_t x)
-{
-  return SwapBytes16 (x);
-}
-#define cpu_to_fdt16(x) fdt16_to_cpu(x)
-
-static inline uint32_t fdt32_to_cpu(uint32_t x)
-{
-  return SwapBytes32 (x);
-}
-#define cpu_to_fdt32(x) fdt32_to_cpu(x)
-
-static inline uint64_t fdt64_to_cpu(uint64_t x)
-{
-  return SwapBytes64 (x);
-}
-#define cpu_to_fdt64(x) fdt64_to_cpu(x)
-
-static inline void* memcpy(void* dest, const void* src, size_t len) {
-  return CopyMem (dest, src, len);
-}
-
-static inline void *memmove(void *dest, const void *src, size_t n) {
-  return CopyMem (dest, src, n);
-}
-
-static inline void *memset(void *s, int c, size_t n) {
-  return SetMem (s, n, c);
-}
-
-static inline int memcmp(const void* dest, const void* src, int len) {
-  return CompareMem (dest, src, len);
-}
-
-static inline void *memchr(const void *s, int c, size_t n) {
-  return ScanMem8 (s, n, c);
-}
-
-static inline size_t strlen (const char* str) {
-  return AsciiStrLen (str);
-}
-
-static inline char *strchr(const char *s, int c) {
-  char pattern[2];
-  pattern[0] = c;
-  pattern[1] = 0;
-  return AsciiStrStr (s, pattern);
-}
-
-#endif /* _LIBFDT_ENV_H */
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#ifndef _LIBFDT_ENV_H\r
+#define _LIBFDT_ENV_H\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+typedef UINT8 uint8_t;\r
+typedef UINT16 uint16_t;\r
+typedef UINT32 uint32_t;\r
+typedef UINT64 uint64_t;\r
+typedef UINTN uintptr_t;\r
+typedef UINTN size_t;\r
+\r
+static inline uint16_t fdt16_to_cpu(uint16_t x)\r
+{\r
+  return SwapBytes16 (x);\r
+}\r
+#define cpu_to_fdt16(x) fdt16_to_cpu(x)\r
+\r
+static inline uint32_t fdt32_to_cpu(uint32_t x)\r
+{\r
+  return SwapBytes32 (x);\r
+}\r
+#define cpu_to_fdt32(x) fdt32_to_cpu(x)\r
+\r
+static inline uint64_t fdt64_to_cpu(uint64_t x)\r
+{\r
+  return SwapBytes64 (x);\r
+}\r
+#define cpu_to_fdt64(x) fdt64_to_cpu(x)\r
+\r
+static inline void* memcpy(void* dest, const void* src, size_t len) {\r
+  return CopyMem (dest, src, len);\r
+}\r
+\r
+static inline void *memmove(void *dest, const void *src, size_t n) {\r
+  return CopyMem (dest, src, n);\r
+}\r
+\r
+static inline void *memset(void *s, int c, size_t n) {\r
+  return SetMem (s, n, c);\r
+}\r
+\r
+static inline int memcmp(const void* dest, const void* src, int len) {\r
+  return CompareMem (dest, src, len);\r
+}\r
+\r
+static inline void *memchr(const void *s, int c, size_t n) {\r
+  return ScanMem8 (s, n, c);\r
+}\r
+\r
+static inline size_t strlen (const char* str) {\r
+  return AsciiStrLen (str);\r
+}\r
+\r
+static inline char *strchr(const char *s, int c) {\r
+  char pattern[2];\r
+  pattern[0] = c;\r
+  pattern[1] = 0;\r
+  return AsciiStrStr (s, pattern);\r
+}\r
+\r
+#endif /* _LIBFDT_ENV_H */\r
index 7ee5609c5ba6ca9216c445d8099f55313d74add6..7fab09bad6a2ec74766638d7df6d5f284cff3f4e 100755 (executable)
@@ -61,4 +61,4 @@ DebugAgentTimerEndOfInterrupt (
 {\r
 }\r
   \r
 {\r
 }\r
   \r
-  
\ No newline at end of file
+  \r
\ No newline at end of file
index 1429c37f297293a954814f963fcbf4335c23b2fe..03258751c093573d1b237bf8fb9b819ef7412666 100644 (file)
@@ -45,4 +45,4 @@
   gEfiEblAddCommandProtocolGuid\r
   \r
 [Guids]\r
   gEfiEblAddCommandProtocolGuid\r
   \r
 [Guids]\r
\ No newline at end of file
\r
\ No newline at end of file
index 3fd8e92dcdcc13902b14ddf3775fabaae010a94b..52e343997d189a21b2c39b536bf3de8ce6fc077a 100644 (file)
@@ -41,4 +41,4 @@
 [Protocols]\r
   \r
 [Guids]\r
 [Protocols]\r
   \r
 [Guids]\r
\ No newline at end of file
\r
\ No newline at end of file
index 0edd5d018dff071ef923d109f33b1dba377b8075..3b0f6a1c71e4281e419a3ac99327c0c79a1f0b56 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <Uefi.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/DebugLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-
-#include <Protocol/SimpleNetwork.h>
-#include <Protocol/PxeBaseCode.h>
-
-
-BOOLEAN   gUseIpv6 = FALSE;
-
-EFI_STATUS
-EFIAPI
-EblGetCurrentIpAddress (
-  IN OUT   EFI_IP_ADDRESS *Ip
-  )
-{
-  EFI_STATUS                  Status;
-  EFI_PXE_BASE_CODE_PROTOCOL  *Pxe;
-  
-  Status = gBS->LocateProtocol (&gEfiPxeBaseCodeProtocolGuid, NULL, (VOID **)&Pxe);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  Status = Pxe->Start (Pxe, gUseIpv6);
-  if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) {
-    return Status;
-  }
-
-  CopyMem (Ip, &Pxe->Mode->StationIp, sizeof (EFI_IP_ADDRESS));
-
-  return EFI_SUCCESS;
-}
-
-
-EFI_STATUS
-EFIAPI
-EblGetCurrentMacAddress (
-  IN OUT  EFI_MAC_ADDRESS *Mac
-  )
-{
-  EFI_STATUS                    Status;
-  EFI_SIMPLE_NETWORK_PROTOCOL   *SimpleNet;
-
-  Status = gBS->LocateProtocol (&gEfiSimpleNetworkProtocolGuid, NULL, (VOID **)&SimpleNet);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  CopyMem (Mac, SimpleNet->Mode->CurrentAddress.Addr, sizeof (EFI_MAC_ADDRESS));
-  return Status;
-}
-
-
-CHAR8 *
-EFIAPI
-EblLoadFileBootTypeString (
-  IN  EFI_HANDLE Handle
-  )
-{
-  EFI_STATUS    Status;
-  VOID          *NullPtr;
-  
-  Status = gBS->HandleProtocol (Handle, &gEfiPxeBaseCodeProtocolGuid, &NullPtr);
-  if (!EFI_ERROR (Status)) {
-    return "EFI PXE Network Boot";
-  }
-  
-  return ""; 
-}
-
-EFI_STATUS
-EFIAPI
-EblPerformDHCP (
-  IN  BOOLEAN  SortOffers
-  )
-{
-  EFI_STATUS                  Status;
-  EFI_PXE_BASE_CODE_PROTOCOL  *Pxe;
-  
-  Status = gBS->LocateProtocol (&gEfiPxeBaseCodeProtocolGuid, NULL, (VOID **)&Pxe);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  Status = Pxe->Start (Pxe, gUseIpv6);
-  if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) {
-    return Status;
-  }
-
-  Status = Pxe->Dhcp(Pxe, TRUE);
-  return Status;
-}
-
-
-EFI_STATUS
-EFIAPI
-EblSetStationIp (
-  IN EFI_IP_ADDRESS *NewStationIp,  OPTIONAL
-  IN EFI_IP_ADDRESS *NewSubnetMask  OPTIONAL
-  )
-{
-  EFI_STATUS                  Status;
-  EFI_PXE_BASE_CODE_PROTOCOL  *Pxe;
-  
-  Status = gBS->LocateProtocol (&gEfiPxeBaseCodeProtocolGuid, NULL, (VOID **)&Pxe);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  Status = Pxe->Start (Pxe, gUseIpv6);
-  if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) {
-    return Status;
-  }
-     
-  Status = Pxe->SetStationIp (Pxe, NewStationIp, NewSubnetMask);
-  return Status;
-}
-
-  
-EFI_STATUS
-EFIAPI
-EblMtftp (
-  IN EFI_PXE_BASE_CODE_TFTP_OPCODE             Operation,
-  IN OUT VOID                                  *BufferPtr OPTIONAL,
-  IN BOOLEAN                                   Overwrite,
-  IN OUT UINT64                                *BufferSize,
-  IN UINTN                                     *BlockSize OPTIONAL,
-  IN EFI_IP_ADDRESS                            *ServerIp,
-  IN UINT8                                     *Filename  OPTIONAL,
-  IN EFI_PXE_BASE_CODE_MTFTP_INFO              *Info      OPTIONAL,
-  IN BOOLEAN                                   DontUseBuffer
-  )
-{
-  EFI_STATUS                  Status;
-  EFI_PXE_BASE_CODE_PROTOCOL  *Pxe;
-  
-  Status = gBS->LocateProtocol (&gEfiPxeBaseCodeProtocolGuid, NULL, (VOID **)&Pxe);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-  
-  Status = Pxe->Mtftp (
-                  Pxe,
-                  Operation,
-                  BufferPtr,
-                  Overwrite,
-                  BufferSize,
-                  BlockSize,
-                  ServerIp,
-                  Filename,
-                  Info,
-                  DontUseBuffer
-                  );
-  return Status;
-}
-  
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#include <Protocol/SimpleNetwork.h>\r
+#include <Protocol/PxeBaseCode.h>\r
+\r
+\r
+BOOLEAN   gUseIpv6 = FALSE;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EblGetCurrentIpAddress (\r
+  IN OUT   EFI_IP_ADDRESS *Ip\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_PXE_BASE_CODE_PROTOCOL  *Pxe;\r
+  \r
+  Status = gBS->LocateProtocol (&gEfiPxeBaseCodeProtocolGuid, NULL, (VOID **)&Pxe);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = Pxe->Start (Pxe, gUseIpv6);\r
+  if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) {\r
+    return Status;\r
+  }\r
+\r
+  CopyMem (Ip, &Pxe->Mode->StationIp, sizeof (EFI_IP_ADDRESS));\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EblGetCurrentMacAddress (\r
+  IN OUT  EFI_MAC_ADDRESS *Mac\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_SIMPLE_NETWORK_PROTOCOL   *SimpleNet;\r
+\r
+  Status = gBS->LocateProtocol (&gEfiSimpleNetworkProtocolGuid, NULL, (VOID **)&SimpleNet);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  CopyMem (Mac, SimpleNet->Mode->CurrentAddress.Addr, sizeof (EFI_MAC_ADDRESS));\r
+  return Status;\r
+}\r
+\r
+\r
+CHAR8 *\r
+EFIAPI\r
+EblLoadFileBootTypeString (\r
+  IN  EFI_HANDLE Handle\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  VOID          *NullPtr;\r
+  \r
+  Status = gBS->HandleProtocol (Handle, &gEfiPxeBaseCodeProtocolGuid, &NullPtr);\r
+  if (!EFI_ERROR (Status)) {\r
+    return "EFI PXE Network Boot";\r
+  }\r
+  \r
+  return ""; \r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EblPerformDHCP (\r
+  IN  BOOLEAN  SortOffers\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_PXE_BASE_CODE_PROTOCOL  *Pxe;\r
+  \r
+  Status = gBS->LocateProtocol (&gEfiPxeBaseCodeProtocolGuid, NULL, (VOID **)&Pxe);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = Pxe->Start (Pxe, gUseIpv6);\r
+  if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = Pxe->Dhcp(Pxe, TRUE);\r
+  return Status;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EblSetStationIp (\r
+  IN EFI_IP_ADDRESS *NewStationIp,  OPTIONAL\r
+  IN EFI_IP_ADDRESS *NewSubnetMask  OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_PXE_BASE_CODE_PROTOCOL  *Pxe;\r
+  \r
+  Status = gBS->LocateProtocol (&gEfiPxeBaseCodeProtocolGuid, NULL, (VOID **)&Pxe);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = Pxe->Start (Pxe, gUseIpv6);\r
+  if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) {\r
+    return Status;\r
+  }\r
+     \r
+  Status = Pxe->SetStationIp (Pxe, NewStationIp, NewSubnetMask);\r
+  return Status;\r
+}\r
+\r
+  \r
+EFI_STATUS\r
+EFIAPI\r
+EblMtftp (\r
+  IN EFI_PXE_BASE_CODE_TFTP_OPCODE             Operation,\r
+  IN OUT VOID                                  *BufferPtr OPTIONAL,\r
+  IN BOOLEAN                                   Overwrite,\r
+  IN OUT UINT64                                *BufferSize,\r
+  IN UINTN                                     *BlockSize OPTIONAL,\r
+  IN EFI_IP_ADDRESS                            *ServerIp,\r
+  IN UINT8                                     *Filename  OPTIONAL,\r
+  IN EFI_PXE_BASE_CODE_MTFTP_INFO              *Info      OPTIONAL,\r
+  IN BOOLEAN                                   DontUseBuffer\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_PXE_BASE_CODE_PROTOCOL  *Pxe;\r
+  \r
+  Status = gBS->LocateProtocol (&gEfiPxeBaseCodeProtocolGuid, NULL, (VOID **)&Pxe);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+  \r
+  Status = Pxe->Mtftp (\r
+                  Pxe,\r
+                  Operation,\r
+                  BufferPtr,\r
+                  Overwrite,\r
+                  BufferSize,\r
+                  BlockSize,\r
+                  ServerIp,\r
+                  Filename,\r
+                  Info,\r
+                  DontUseBuffer\r
+                  );\r
+  return Status;\r
+}\r
+  \r
index b0d6e80aea666de4938a372e8894a170d2f1139e..4d66bacb81566ee3c2fb0a9877793026a386ce9f 100644 (file)
@@ -31,4 +31,4 @@
   gEfiPxeBaseCodeProtocolGuid\r
 \r
 [Depex]\r
   gEfiPxeBaseCodeProtocolGuid\r
 \r
 [Depex]\r
-  TRUE
\ No newline at end of file
+  TRUE\r
\ No newline at end of file
index 5e0f9ca1172b134ba7ce6cb36d85912225aa9dd5..83a3b7841fe72b1c68a07403f74a10af456b6b81 100644 (file)
-/** @file
-File IO routines inspired by Streams with an EFI flavor
-
-Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
-Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-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.
-
-Basic support for opening files on different device types. The device string
-is in the form of DevType:Path. Current DevType is required as there is no
-current mounted device concept of current working directory concept implement
-by this library.
-
-Device names are case insensitive and only check the leading characters for
-unique matches. Thus the following are all the same:
-LoadFile0:
-l0:
-L0:
-Lo0:
-
-Supported Device Names:
-A0x1234:0x12 - A memory buffer starting at address 0x1234 for 0x12 bytes
-l1:          - EFI LoadFile device one.
-B0:          - EFI BlockIo zero.
-fs3:         - EFI Simple File System device 3
-Fv2:         - EFI Firmware VOlume device 2
-10.0.1.102:  - TFTP service IP followed by the file name
-**/
-
-#include <PiDxe.h>
-#include <Protocol/BlockIo.h>             
-#include <Protocol/DiskIo.h>             
-#include <Protocol/SimpleFileSystem.h>      
-#include <Protocol/FirmwareVolume2.h>        
-#include <Protocol/LoadFile.h>
-#include <Protocol/FirmwareVolumeBlock.h>  
-#include <Guid/FileInfo.h>
-#include <Library/BaseLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/DevicePathLib.h>
-#include <Library/PrintLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/UefiLib.h>   
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/DebugLib.h>
-#include <Library/EfiFileLib.h>
-#include <Library/PcdLib.h>
-#include <Library/EblNetworkLib.h>
-
-
-CHAR8 *gCwd = NULL;
-
-CONST EFI_GUID gZeroGuid  = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } };
-
-#define EFI_OPEN_FILE_GUARD_HEADER  0x4B4D4641
-#define EFI_OPEN_FILE_GUARD_FOOTER  0x444D5A56
-
-// Need to defend against this overflowing
-#define MAX_CMD_LINE  0x200
-
-typedef struct {
-  UINT32            Header;
-  EFI_OPEN_FILE     File;
-  UINT32            Footer;
-} EFI_OPEN_FILE_GUARD;
-
-
-// globals to store current open device info
-EFI_HANDLE            *mBlkIo = NULL;
-UINTN                 mBlkIoCount = 0;
-
-EFI_HANDLE            *mFs = NULL;
-UINTN                 mFsCount = 0;
-// mFsInfo[] array entries must match mFs[] handles
-EFI_FILE_SYSTEM_INFO  **mFsInfo = NULL;
-
-EFI_HANDLE            *mFv = NULL;
-UINTN                 mFvCount = 0;
-EFI_HANDLE            *mLoadFile = NULL;
-UINTN                 mLoadFileCount = 0;
-
-
-
-/**
-Internal worker function to validate a File handle.
-
-@param  File    Open File Handle
-
-@return TRUE    File is valid
-@return FALSE   File is not valid
-
-
-**/
-BOOLEAN
-FileHandleValid (
-  IN EFI_OPEN_FILE  *File
-  )
-{
-  EFI_OPEN_FILE_GUARD  *GuardFile;
-
-  // Look right before and after file structure for the correct signatures
-  GuardFile = BASE_CR (File, EFI_OPEN_FILE_GUARD, File);
-  if ((GuardFile->Header != EFI_OPEN_FILE_GUARD_HEADER) ||
-    (GuardFile->Footer != EFI_OPEN_FILE_GUARD_FOOTER) ) {
-      return FALSE;
-    }
-
-    return TRUE;
-}
-
-/**
-Internal worker function. If Buffer is not NULL free it.
-
-@param  Buffer    Buffer to FreePool()
-
-**/
-VOID
-EblFreePool (
-  IN  VOID  *Buffer
-  )
-{
-  if (Buffer != NULL) {
-    FreePool (Buffer);
-  }
-}
-
-/**
-Update Device List Global Variables
-
-**/
-VOID
-EblUpdateDeviceLists (
-  VOID
-  )
-{
-  EFI_STATUS                        Status;
-  UINTN                             Size;
-  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *Fs;
-  EFI_FILE_HANDLE                   Root;
-  UINTN                             Index;
-
-  if (mBlkIo != NULL) {
-    FreePool (mBlkIo);
-  }
-  gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &mBlkIoCount, &mBlkIo);
-
-
-
-  if (mFv != NULL) {
-    FreePool (mFv);
-  }
-  gBS->LocateHandleBuffer (ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &mFvCount, &mFv);
-
-  if (mLoadFile != NULL) {
-    FreePool (mLoadFile);
-  }
-  gBS->LocateHandleBuffer (ByProtocol, &gEfiLoadFileProtocolGuid, NULL, &mLoadFileCount, &mLoadFile);
-
-  if (mFs != NULL) {
-    FreePool (mFs);
-  }
-
-  if (&mFsInfo[0] != NULL) {
-    // Need to Free the mFsInfo prior to recalculating mFsCount so don't move this code
-    for (Index = 0; Index < mFsCount; Index++) {
-      if (mFsInfo[Index] != NULL) {
-        FreePool (mFsInfo[Index]);
-      }
-    }
-    FreePool (mFsInfo);
-  }
-
-  gBS->LocateHandleBuffer (ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &mFsCount, &mFs);
-
-
-  mFsInfo = AllocateZeroPool (mFsCount * sizeof (EFI_FILE_SYSTEM_INFO *));
-  if (mFsInfo == NULL) {
-    // If we can't do this then we can't support file system entries
-    mFsCount = 0;
-  } else {
-    // Loop through all the file system structures and cache the file system info data
-    for (Index =0; Index < mFsCount; Index++) {
-      Status = gBS->HandleProtocol (mFs[Index], &gEfiSimpleFileSystemProtocolGuid, (VOID **)&Fs);
-      if (!EFI_ERROR (Status)) {
-        Status = Fs->OpenVolume (Fs, &Root);
-        if (!EFI_ERROR (Status)) {
-          // Get information about the volume
-          Size = 0;
-          Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, mFsInfo[Index]);
-          if (Status == EFI_BUFFER_TOO_SMALL) {
-            mFsInfo[Index] = AllocatePool (Size);
-            Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, mFsInfo[Index]);
-          }
-
-          Root->Close (Root);
-        }
-      }
-    }
-  }
-}
-
-
-/**
-PathName is in the form <device name>:<path> for example fs1:\ or ROOT:\.
-Return TRUE if the <devce name> prefix of PathName matches a file system
-Volume Name. MatchIndex is the array  index in mFsInfo[] of the match, 
-and it can be used with mFs[] to find the handle that needs to be opened
-
-@param  PathName      PathName to check
-@param  FileStart     Index of the first character of the <path>
-@param  MatchIndex    Index in mFsInfo[] that matches
-
-@return TRUE      PathName matches a Volume Label and MatchIndex is valid
-@return FALSE     PathName does not match a Volume Label MatchIndex undefined
-
-**/
-BOOLEAN
-EblMatchVolumeName (
-  IN  CHAR8   *PathName,
-  IN  UINTN   FileStart,
-  OUT UINTN   *MatchIndex
-  )
-{
-  UINTN   Index;
-  UINTN   Compare;
-  UINTN   VolStrLen;
-  BOOLEAN Match;
-
-  for (Index =0; Index < mFsCount; Index++) {
-    if (mFsInfo[Index] == NULL) {
-      // FsInfo is not valid so skip it
-      continue;
-    }
-    VolStrLen = StrLen (mFsInfo[Index]->VolumeLabel);
-    for (Compare = 0, Match = TRUE; Compare < (FileStart - 1); Compare++) {
-      if (Compare > VolStrLen) {
-        Match = FALSE;
-        break;
-      }
-      if (PathName[Compare] != (CHAR8)mFsInfo[Index]->VolumeLabel[Compare]) {
-        // If the VolumeLabel has a space allow a _ to match with it in addition to ' '
-        if (!((PathName[Compare] == '_') && (mFsInfo[Index]->VolumeLabel[Compare] == L' '))) {
-          Match = FALSE;
-          break;
-        }
-      }
-    }
-    if (Match) {
-      *MatchIndex = Index;
-      return TRUE;
-    }
-  }
-
-  return FALSE;
-}
-
-
-/**
-Return the number of devices of the current type active in the system
-
-@param  Type      Device type to check
-
-@return 0         Invalid type
-
-**/
-UINTN
-EfiGetDeviceCounts (
-  IN  EFI_OPEN_FILE_TYPE     DeviceType
-  )
-{
-  switch (DeviceType) {
-  case EfiOpenLoadFile:
-    return mLoadFileCount;
-  case EfiOpenFirmwareVolume:
-    return mFvCount;
-  case EfiOpenFileSystem:
-    return mFsCount;
-  case EfiOpenBlockIo:
-    return mBlkIoCount;
-  default:
-    return 0;
-  }
-}
-
-EFI_STATUS
-ConvertIpStringToEfiIp (
-  IN  CHAR8           *PathName, 
-  OUT EFI_IP_ADDRESS  *ServerIp
-  )
-{
-  CHAR8     *Str;
-
-  Str = PathName;
-  ServerIp->v4.Addr[0] = (UINT8)AsciiStrDecimalToUintn (Str);
-
-  Str = AsciiStrStr (Str, ".");
-  if (Str == NULL) {
-    return EFI_DEVICE_ERROR;
-  }
-
-  ServerIp->v4.Addr[1] = (UINT8)AsciiStrDecimalToUintn (++Str);
-
-  Str = AsciiStrStr (Str, ".");
-  if (Str == NULL) {
-    return EFI_DEVICE_ERROR;
-  }
-
-  ServerIp->v4.Addr[2] = (UINT8)AsciiStrDecimalToUintn (++Str);
-
-  Str = AsciiStrStr (Str, ".");
-  if (Str == NULL) {
-    return EFI_DEVICE_ERROR;
-  }
-
-  ServerIp->v4.Addr[3] = (UINT8)AsciiStrDecimalToUintn (++Str);
-
-  return EFI_SUCCESS;
-}
-
-
-/**
-Internal work function to extract a device number from a string skipping 
-text. Easy way to extract numbers from strings like blk7:.
-
-@param  Str   String to extract device number form
-
-@return -1    Device string is not valid
-@return       Device #
-
-**/
-UINTN
-EblConvertDevStringToNumber (
-  IN  CHAR8   *Str
-  )
-{
-  UINTN   Max;
-  UINTN   Index;
-
-
-  // Find the first digit 
-  Max = AsciiStrLen (Str);
-  for  (Index = 0; !((*Str >= '0') && (*Str <= '9')) && (Index < Max); Index++) {
-    Str++;
-  }
-  if (Index == Max) {
-    return (UINTN)-1;
-  }
-
-  return AsciiStrDecimalToUintn (Str);
-}
-
-
-/**
-Internal work function to fill in EFI_OPEN_FILE information for the Fs and BlkIo
-
-@param  File        Open file handle
-@param  FileName    Name of file after device stripped off
-
-
-**/
-EFI_STATUS
-EblFileDevicePath (
-  IN OUT EFI_OPEN_FILE  *File,
-  IN  CHAR8             *FileName,
-  IN  CONST UINT64      OpenMode
-  )
-{
-  EFI_STATUS                        Status;
-  UINTN                             Size;
-  FILEPATH_DEVICE_PATH              *FilePath;
-  EFI_DEVICE_PATH_PROTOCOL          *FileDevicePath;
-  CHAR16                            UnicodeFileName[MAX_PATHNAME];
-  EFI_BLOCK_IO_PROTOCOL             *BlkIo;
-  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *Fs;
-  EFI_FILE_HANDLE                   Root;
-
-
-  if ( *FileName != 0 ) {
-    AsciiStrToUnicodeStr (FileName, UnicodeFileName);
-  } else {
-    AsciiStrToUnicodeStr ("\\", UnicodeFileName);
-  }
-
-  Size = StrSize (UnicodeFileName);
-  FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + sizeof (EFI_DEVICE_PATH_PROTOCOL));
-  if (FileDevicePath != NULL) {
-    FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath;
-    FilePath->Header.Type    = MEDIA_DEVICE_PATH;
-    FilePath->Header.SubType = MEDIA_FILEPATH_DP;
-    CopyMem (&FilePath->PathName, UnicodeFileName, Size);
-    SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH);
-    SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header));
-
-    if (File->EfiHandle != NULL) {
-      File->DevicePath = DevicePathFromHandle (File->EfiHandle);
-    }
-
-    File->DevicePath = AppendDevicePath (File->DevicePath, FileDevicePath);
-    FreePool (FileDevicePath);
-  }
-
-  Status = gBS->HandleProtocol (File->EfiHandle, &gEfiBlockIoProtocolGuid, (VOID **)&BlkIo);
-  if (!EFI_ERROR (Status)) {
-    File->FsBlockIoMedia = BlkIo->Media;
-    File->FsBlockIo = BlkIo;
-
-    // If we are not opening the device this will get over written with file info
-    File->MaxPosition = MultU64x32 (BlkIo->Media->LastBlock + 1, BlkIo->Media->BlockSize);
-  }
-
-  if (File->Type == EfiOpenFileSystem) {
-    Status = gBS->HandleProtocol (File->EfiHandle, &gEfiSimpleFileSystemProtocolGuid, (VOID **)&Fs);
-    if (!EFI_ERROR (Status)) {
-      Status = Fs->OpenVolume (Fs, &Root);
-      if (!EFI_ERROR (Status)) {
-        // Get information about the volume
-        Size = 0;
-        Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, File->FsInfo);
-        if (Status == EFI_BUFFER_TOO_SMALL) {
-          File->FsInfo = AllocatePool (Size);
-          Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, File->FsInfo);
-        }
-
-        // Get information about the file
-        Status = Root->Open (Root, &File->FsFileHandle, UnicodeFileName, OpenMode, 0);
-        if (!EFI_ERROR (Status)) {
-          Size = 0;
-          Status = File->FsFileHandle->GetInfo (File->FsFileHandle, &gEfiFileInfoGuid, &Size, NULL);
-          if (Status == EFI_BUFFER_TOO_SMALL) {
-            File->FsFileInfo = AllocatePool (Size);
-            Status = File->FsFileHandle->GetInfo (File->FsFileHandle, &gEfiFileInfoGuid, &Size, File->FsFileInfo);
-            if (!EFI_ERROR (Status)) {
-              File->Size = (UINTN)File->FsFileInfo->FileSize;
-              File->MaxPosition = (UINT64)File->Size;
-            }
-          }
-        }
-
-        Root->Close (Root);
-      }
-    }
-  } else if (File->Type == EfiOpenBlockIo) {
-    File->Size = (UINTN)File->MaxPosition;
-  }
-
-  return Status;
-}
-
-#define ToUpper(a)  ((((a) >= 'a') && ((a) <= 'z')) ? ((a) - 'a' + 'A') : (a))
-
-EFI_STATUS
-CompareGuidToString (
-  IN  EFI_GUID    *Guid,
-  IN  CHAR8       *String
-  )
-{
-  CHAR8       AsciiGuid[64];
-  CHAR8       *StringPtr;
-  CHAR8       *GuidPtr;
-
-  AsciiSPrint (AsciiGuid, sizeof(AsciiGuid), "%g", Guid);
-
-  StringPtr = String;
-  GuidPtr   = AsciiGuid;
-
-  while ((*StringPtr != '\0') && (*GuidPtr != '\0')) {
-    // Skip dashes
-    if (*StringPtr == '-') {
-      StringPtr++;
-      continue;
-    }
-
-    if (*GuidPtr == '-') {
-      GuidPtr++;
-      continue;
-    }
-
-    if (ToUpper(*StringPtr) != ToUpper(*GuidPtr)) {
-      return EFI_NOT_FOUND;
-    }
-
-    StringPtr++;
-    GuidPtr++;
-  }
-
-  return EFI_SUCCESS;
-}
-
-
-/**
-Internal work function to fill in EFI_OPEN_FILE information for the FV
-
-@param  File        Open file handle
-@param  FileName    Name of file after device stripped off
-
-
-**/
-EFI_STATUS
-EblFvFileDevicePath (
-  IN OUT EFI_OPEN_FILE  *File,
-  IN  CHAR8             *FileName,
-  IN  CONST UINT64      OpenMode
-  )
-{
-  EFI_STATUS                          Status;
-  EFI_STATUS                          GetNextFileStatus;
-  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH   DevicePathNode;
-  EFI_DEVICE_PATH_PROTOCOL            *DevicePath;
-  UINTN                               Key;
-  UINT32                              AuthenticationStatus;
-  CHAR8                               AsciiSection[MAX_PATHNAME];
-  VOID                                *Section;
-  UINTN                               SectionSize;
-  EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *Fvb;
-  EFI_LBA                             Lba;
-  UINTN                               BlockSize;
-  UINTN                               NumberOfBlocks;
-  EFI_FIRMWARE_VOLUME_HEADER          *FvHeader = NULL;
-  UINTN                               Index;
-
-
-  Status = gBS->HandleProtocol (File->EfiHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **)&File->Fv);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  // Get FVB Info about the handle
-  Status = gBS->HandleProtocol (File->EfiHandle, &gEfiFirmwareVolumeBlockProtocolGuid, (VOID **)&Fvb);
-  if (!EFI_ERROR (Status)) {
-    Status = Fvb->GetPhysicalAddress (Fvb, &File->FvStart);
-    if (!EFI_ERROR (Status)) {
-      FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)File->FvStart;
-      File->FvHeaderSize = sizeof (EFI_FIRMWARE_VOLUME_HEADER);
-      for (Index = 0; FvHeader->BlockMap[Index].Length !=0; Index++) {
-        File->FvHeaderSize += sizeof (EFI_FV_BLOCK_MAP_ENTRY);
-      }
-
-      for (Lba = 0, File->FvSize = 0, NumberOfBlocks = 0; ; File->FvSize += (BlockSize * NumberOfBlocks), Lba += NumberOfBlocks) {
-        Status = Fvb->GetBlockSize (Fvb, Lba, &BlockSize, &NumberOfBlocks);
-        if (EFI_ERROR (Status)) {
-          break;
-        }
-      }
-    }
-  }
-
-
-  DevicePath = DevicePathFromHandle (File->EfiHandle);
-
-  if (*FileName == '\0') {
-    File->DevicePath = DuplicateDevicePath (DevicePath);
-    File->Size = File->FvSize;
-    File->MaxPosition = File->Size;
-  } else {
-    Key = 0;
-    do {
-      File->FvType = EFI_FV_FILETYPE_ALL;
-      GetNextFileStatus = File->Fv->GetNextFile (
-        File->Fv, 
-        &Key,
-        &File->FvType,  
-        &File->FvNameGuid, 
-        &File->FvAttributes, 
-        &File->Size
-        );
-      if (!EFI_ERROR (GetNextFileStatus)) {
-        // Compare GUID first
-        Status = CompareGuidToString (&File->FvNameGuid, FileName);
-        if (!EFI_ERROR(Status)) {
-          break;
-        }
-
-        Section = NULL;
-        Status = File->Fv->ReadSection (
-          File->Fv,
-          &File->FvNameGuid,
-          EFI_SECTION_USER_INTERFACE,
-          0,
-          &Section,
-          &SectionSize,
-          &AuthenticationStatus
-          );
-        if (!EFI_ERROR (Status)) {
-          UnicodeStrToAsciiStr (Section, AsciiSection);
-          if (AsciiStriCmp (FileName, AsciiSection) == 0) {
-            FreePool (Section);
-            break;
-          }
-          FreePool (Section);
-        }
-      }
-    } while (!EFI_ERROR (GetNextFileStatus));
-
-    if (EFI_ERROR (GetNextFileStatus)) {
-      return GetNextFileStatus;
-    }
-
-    if (OpenMode != EFI_SECTION_ALL) {
-      // Calculate the size of the section we are targeting
-      Section = NULL;
-      File->Size = 0;
-      Status = File->Fv->ReadSection (
-        File->Fv,
-        &File->FvNameGuid,
-        (EFI_SECTION_TYPE)OpenMode,
-        0,
-        &Section,
-        &File->Size,
-        &AuthenticationStatus
-        );
-      if (EFI_ERROR (Status)) {
-        return Status;
-      }
-    }
-
-    File->MaxPosition = File->Size;
-    EfiInitializeFwVolDevicepathNode (&DevicePathNode, &File->FvNameGuid);
-    File->DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&DevicePathNode);
-  }
-
-
-  // FVB not required if FV was soft loaded...
-  return EFI_SUCCESS;
-}
-
-
-
-
-/**
-Open a device named by PathName. The PathName includes a device name and 
-path separated by a :. See file header for more details on the PathName
-syntax. There is no checking to prevent a file from being opened more than
-one type. 
-
-SectionType is only used to open an FV. Each file in an FV contains multiple
-sections and only the SectionType section is opened.
-
-For any file that is opened with EfiOpen() must be closed with EfiClose().
-
-@param  PathName    Path to parse to open 
-@param  OpenMode    Same as EFI_FILE.Open()
-@param  SectionType Section in FV to open.
-
-@return NULL  Open failed
-@return Valid EFI_OPEN_FILE handle
-
-**/
-EFI_OPEN_FILE *
-EfiOpen (
-  IN        CHAR8               *PathName,
-  IN  CONST UINT64              OpenMode,
-  IN  CONST EFI_SECTION_TYPE    SectionType
-  )
-{
-  EFI_STATUS                Status;
-  EFI_OPEN_FILE             *File;
-  EFI_OPEN_FILE             FileData;
-  UINTN                     StrLen;
-  UINTN                     FileStart;
-  UINTN                     DevNumber = 0;
-  EFI_OPEN_FILE_GUARD       *GuardFile;
-  BOOLEAN                   VolumeNameMatch;
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
-  UINTN                     Size;
-  EFI_IP_ADDRESS            Ip;
-  CHAR8                     *CwdPlusPathName;
-  UINTN                     Index;
-  EFI_SECTION_TYPE          ModifiedSectionType;
-
-  EblUpdateDeviceLists ();
-
-  File = &FileData;
-  ZeroMem (File, sizeof (EFI_OPEN_FILE));
-
-  StrLen = AsciiStrSize (PathName);
-  if (StrLen <= 1) {
-    // Smallest valid path is 1 char and a null
-    return NULL;
-  }
-
-  for (FileStart = 0; FileStart < StrLen; FileStart++) {
-    if (PathName[FileStart] == ':') {
-      FileStart++;
-      break;
-    }
-  }
-
-  //
-  // Matching volume name has precedence over handle based names
-  //
-  VolumeNameMatch = EblMatchVolumeName (PathName, FileStart, &DevNumber);
-  if (!VolumeNameMatch) {
-    if (FileStart == StrLen) {
-      // No Volume name or device name, so try Current Working Directory
-      if (gCwd == NULL) {
-        // No CWD
-        return NULL;
-      }
-
-      // We could add a current working directory concept
-      CwdPlusPathName = AllocatePool (AsciiStrSize (gCwd) + AsciiStrSize (PathName));
-      if (CwdPlusPathName == NULL) {
-        return NULL;
-      }
-
-      if ((PathName[0] == '/') || (PathName[0] == '\\')) {
-        // PathName starts in / so this means we go to the root of the device in the CWD. 
-        CwdPlusPathName[0] = '\0';
-        for (FileStart = 0; gCwd[FileStart] != '\0'; FileStart++) {
-          CwdPlusPathName[FileStart] = gCwd[FileStart];
-          if (gCwd[FileStart] == ':') {
-            FileStart++;
-            CwdPlusPathName[FileStart] = '\0';
-            break;
-          }
-        }
-      } else {
-        AsciiStrCpy (CwdPlusPathName, gCwd);
-        StrLen = AsciiStrLen (gCwd);
-        if ((*PathName != '/') && (*PathName != '\\') && (gCwd[StrLen-1] != '/') && (gCwd[StrLen-1] != '\\')) {
-          AsciiStrCat (CwdPlusPathName, "\\");
-        }
-      }
-
-      AsciiStrCat (CwdPlusPathName, PathName);
-      if (AsciiStrStr (CwdPlusPathName, ":") == NULL) {
-        // Extra error check to make sure we don't recurse and blow stack
-        return NULL;
-      }
-
-      File = EfiOpen (CwdPlusPathName, OpenMode, SectionType);
-      FreePool (CwdPlusPathName);
-      return File;
-    }
-
-    DevNumber = EblConvertDevStringToNumber ((CHAR8 *)PathName); 
-  }
-
-  File->DeviceName = AllocatePool (StrLen);
-  AsciiStrCpy (File->DeviceName, PathName);
-  File->DeviceName[FileStart - 1] = '\0';
-  File->FileName = &File->DeviceName[FileStart];
-  if (File->FileName[0] == '\0') {
-    // if it is just a file name use / as root
-    File->FileName = "\\";
-  } 
-
-  //
-  // Use best match algorithm on the dev names so we only need to look at the
-  // first few charters to match the full device name. Short name forms are 
-  // legal from the caller.
-  //
-  Status = EFI_SUCCESS;
-  if (*PathName == 'f' || *PathName == 'F' || VolumeNameMatch) {
-    if (PathName[1] == 's' || PathName[1] == 'S' || VolumeNameMatch) {
-      if (DevNumber >= mFsCount) {
-        goto ErrorExit;
-      }
-      File->Type = EfiOpenFileSystem;
-      File->EfiHandle = mFs[DevNumber];
-      Status = EblFileDevicePath (File, &PathName[FileStart], OpenMode);
-
-    } else if (PathName[1] == 'v' || PathName[1] == 'V') { 
-      if (DevNumber >= mFvCount) {
-        goto ErrorExit;
-      }
-      File->Type = EfiOpenFirmwareVolume;
-      File->EfiHandle = mFv[DevNumber];
-
-      if ((PathName[FileStart] == '/') || (PathName[FileStart] == '\\')) {
-        // Skip leading / as its not really needed for the FV since no directories are supported
-        FileStart++;
-      }
-
-      // Check for 2nd :
-      ModifiedSectionType = SectionType;
-      for (Index = FileStart; PathName[Index] != '\0'; Index++) {
-        if (PathName[Index] == ':') {
-          // Support fv0:\DxeCore:0x10
-          // This means open the PE32 Section of the file 
-          ModifiedSectionType = (EFI_SECTION_TYPE)AsciiStrHexToUintn (&PathName[Index + 1]);
-          PathName[Index] = '\0';
-        }
-      }
-      File->FvSectionType = ModifiedSectionType;
-      Status = EblFvFileDevicePath (File, &PathName[FileStart], ModifiedSectionType);
-    }
-  } else if ((*PathName == 'A') || (*PathName == 'a')) {
-    // Handle a:0x10000000:0x1234 address form a:ADDRESS:SIZE
-    File->Type = EfiOpenMemoryBuffer;
-    // 1st colon is at PathName[FileStart - 1]
-    File->Buffer = (VOID *)AsciiStrHexToUintn (&PathName[FileStart]);
-
-    // Find 2nd colon
-    while ((PathName[FileStart] != ':') && (PathName[FileStart] != '\0')) {
-      FileStart++;
-    }
-
-    // If we ran out of string, there's no extra data
-    if (PathName[FileStart] == '\0') {
-      File->Size = 0;
-    } else {
-      File->Size = AsciiStrHexToUintn (&PathName[FileStart + 1]);
-    }
-
-    // if there's no number after the second colon, default
-    // the end of memory
-    if (File->Size == 0) {
-      File->Size =  (UINTN)(0 - (UINTN)File->Buffer);
-    }
-
-    File->MaxPosition = File->Size;
-    File->BaseOffset = (UINTN)File->Buffer;
-
-  } else if (*PathName== 'l' || *PathName == 'L') {
-    if (DevNumber >= mLoadFileCount) {
-      goto ErrorExit;
-    }
-    File->Type = EfiOpenLoadFile;
-    File->EfiHandle = mLoadFile[DevNumber];
-
-    Status = gBS->HandleProtocol (File->EfiHandle, &gEfiLoadFileProtocolGuid, (VOID **)&File->LoadFile);
-    if (EFI_ERROR (Status)) {
-      goto ErrorExit;
-    }
-
-    Status = gBS->HandleProtocol (File->EfiHandle, &gEfiDevicePathProtocolGuid, (VOID **)&DevicePath);
-    if (EFI_ERROR (Status)) {
-      goto ErrorExit;
-    }
-    File->DevicePath = DuplicateDevicePath (DevicePath);
-
-  } else if (*PathName == 'b' || *PathName == 'B') {
-    // Handle b#:0x10000000:0x1234 address form b#:ADDRESS:SIZE
-    if (DevNumber >= mBlkIoCount) {
-      goto ErrorExit;
-    }
-    File->Type = EfiOpenBlockIo;
-    File->EfiHandle = mBlkIo[DevNumber];
-    EblFileDevicePath (File, "", OpenMode);
-
-    // 1st colon is at PathName[FileStart - 1]
-    File->DiskOffset = AsciiStrHexToUintn (&PathName[FileStart]);
-
-    // Find 2nd colon
-    while ((PathName[FileStart] != ':') && (PathName[FileStart] != '\0')) {
-      FileStart++;
-    }
-
-    // If we ran out of string, there's no extra data
-    if (PathName[FileStart] == '\0') {
-      Size = 0;
-    } else {
-      Size = AsciiStrHexToUintn (&PathName[FileStart + 1]);
-    }
-
-    // if a zero size is passed in (or the size is left out entirely),
-    // go to the end of the device.
-    if (Size == 0) {
-      File->Size = File->Size - File->DiskOffset;
-    } else {
-      File->Size = Size;
-    }
-
-    File->MaxPosition = File->Size;
-    File->BaseOffset = File->DiskOffset;
-  } else if ((*PathName) >= '0' && (*PathName <= '9')) {
-
-    // Get current IP address
-    Status = EblGetCurrentIpAddress (&Ip);
-    if (EFI_ERROR(Status)) {
-      AsciiPrint("Device IP Address is not configured.\n");
-      goto ErrorExit;
-    }
-
-
-    // Parse X.X.X.X:Filename, only support IPv4 TFTP for now...
-    File->Type = EfiOpenTftp;
-    File->IsDirty = FALSE;
-    File->IsBufferValid = FALSE;
-
-    Status = ConvertIpStringToEfiIp (PathName, &File->ServerIp);
-  }
-
-  if (EFI_ERROR (Status)) {
-    goto ErrorExit;
-  }
-
-  GuardFile = (EFI_OPEN_FILE_GUARD *)AllocateZeroPool (sizeof (EFI_OPEN_FILE_GUARD));
-  if (GuardFile == NULL) {
-    goto ErrorExit;
-  }
-
-  GuardFile->Header = EFI_OPEN_FILE_GUARD_HEADER;
-  CopyMem (&(GuardFile->File), &FileData, sizeof (EFI_OPEN_FILE));
-  GuardFile->Footer = EFI_OPEN_FILE_GUARD_FOOTER;
-
-  return &(GuardFile->File);
-
-ErrorExit:
-  FreePool (File->DeviceName);
-  return NULL;
-}
-
-#define FILE_COPY_CHUNK 0x01000000
-
-EFI_STATUS
-EfiCopyFile (
-  IN        CHAR8               *DestinationFile,
-  IN        CHAR8               *SourceFile
-  )
-{
-  EFI_OPEN_FILE *Source      = NULL;
-  EFI_OPEN_FILE *Destination = NULL;
-  EFI_STATUS    Status       = EFI_SUCCESS;
-  VOID          *Buffer      = NULL;
-  UINTN         Size;
-  UINTN         Offset;
-  UINTN         Chunk = FILE_COPY_CHUNK;
-
-  Source = EfiOpen (SourceFile, EFI_FILE_MODE_READ, 0);
-  if (Source == NULL) {
-    AsciiPrint("Source file open error.\n");
-    Status = EFI_NOT_FOUND;
-    goto Exit;
-  }
-
-  Destination = EfiOpen (DestinationFile, EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0);
-  if (Destination == NULL) {
-    AsciiPrint("Destination file open error.\n");
-    Status = EFI_NOT_FOUND;
-    goto Exit;
-  }
-
-  Buffer = AllocatePool(FILE_COPY_CHUNK);
-  if (Buffer == NULL) {
-    Status = EFI_OUT_OF_RESOURCES;
-    goto Exit;
-  }
-
-  Size = EfiTell(Source, NULL);
-
-  for (Offset = 0; Offset + FILE_COPY_CHUNK <= Size; Offset += Chunk) {
-    Chunk = FILE_COPY_CHUNK;
-
-    Status = EfiRead(Source, Buffer, &Chunk);
-    if (EFI_ERROR(Status)) {
-      AsciiPrint("Read file error %r\n", Status);
-      goto Exit;
-    }
-
-    Status = EfiWrite(Destination, Buffer, &Chunk);
-    if (EFI_ERROR(Status)) {
-      AsciiPrint("Write file error %r\n", Status);
-      goto Exit;
-    }    
-  }
-
-  // Any left over?
-  if (Offset < Size) {
-    Chunk = Size - Offset;
-
-    Status = EfiRead(Source, Buffer, &Chunk);
-    if (EFI_ERROR(Status)) {
-      AsciiPrint("Read file error\n");
-      goto Exit;
-    }
-
-    Status = EfiWrite(Destination, Buffer, &Chunk);
-    if (EFI_ERROR(Status)) {
-      AsciiPrint("Write file error\n");
-      goto Exit;
-    }    
-  }
-
-Exit:
-  if (Source != NULL) {
-    Status = EfiClose(Source);
-    if (EFI_ERROR(Status)) {
-      AsciiPrint("Source close error");
-    }
-  }
-
-  if (Destination != NULL) {
-    Status = EfiClose(Destination);
-    if (EFI_ERROR(Status)) {
-      AsciiPrint("Destination close error");
-    }
-  }
-
-  if (Buffer != NULL) {
-    FreePool(Buffer);
-  }
-
-  return Status;
-}
-
-/**
-Use DeviceType and Index to form a valid PathName and try and open it.
-
-@param  DeviceType  Device type to open
-@param  Index       Device Index to use. Zero relative.
-
-@return NULL  Open failed
-@return Valid EFI_OPEN_FILE handle
-
-**/
-EFI_OPEN_FILE  *
-EfiDeviceOpenByType (
-  IN  EFI_OPEN_FILE_TYPE    DeviceType,
-  IN  UINTN                 Index
-  )
-{
-  CHAR8   *DevStr;
-  CHAR8   Path[MAX_CMD_LINE];
-
-  switch (DeviceType) {
-  case EfiOpenLoadFile:
-    DevStr = "loadfile%d:";
-    break;
-  case EfiOpenFirmwareVolume:
-    DevStr = "fv%d:";    
-    break;
-  case EfiOpenFileSystem:
-    DevStr = "fs%d:";    
-    break;
-  case EfiOpenBlockIo:
-    DevStr = "blk%d:";    
-    break;
-  case EfiOpenMemoryBuffer:
-    DevStr = "a%d:";    
-    break;
-  default:
-    return NULL;
-  }
-
-  AsciiSPrint (Path, MAX_PATHNAME, DevStr, Index);
-
-  return EfiOpen (Path, EFI_FILE_MODE_READ, 0);
-}
-
-
-/**
-Close a file handle opened by EfiOpen() and free all resources allocated by
-EfiOpen().
-
-@param  Stream    Open File Handle
-
-@return EFI_INVALID_PARAMETER  Stream is not an Open File
-@return EFI_SUCCESS            Steam closed
-
-**/
-EFI_STATUS
-EfiClose (
-  IN  EFI_OPEN_FILE     *File
-  )
-{
-  EFI_STATUS          Status;
-  UINT64              TftpBufferSize;
-
-  if (!FileHandleValid (File)) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  //Write the buffer contents to TFTP file.
-  if ((File->Type == EfiOpenTftp) && (File->IsDirty)) {
-
-    TftpBufferSize = File->Size;
-    Status = EblMtftp (
-      EFI_PXE_BASE_CODE_TFTP_WRITE_FILE, 
-      File->Buffer, 
-      TRUE, 
-      &TftpBufferSize, 
-      NULL, 
-      &File->ServerIp, 
-      (UINT8 *)File->FileName, 
-      NULL, 
-      FALSE
-      );
-    if (EFI_ERROR(Status)) {
-      AsciiPrint("TFTP error during APPLE_NSP_TFTP_WRITE_FILE: %r\n", Status);
-      return Status;
-    }
-  }
-
-  if ((File->Type == EfiOpenLoadFile) || 
-    ((File->Type == EfiOpenTftp) && (File->IsBufferValid == TRUE)) ||
-    ((File->Type == EfiOpenFirmwareVolume) && (File->IsBufferValid == TRUE))) {
-    EblFreePool(File->Buffer);
-  }
-
-  EblFreePool (File->DevicePath);
-  EblFreePool (File->DeviceName);
-  EblFreePool (File->FsFileInfo);
-  EblFreePool (File->FsInfo);
-
-  if (File->FsFileHandle != NULL) {
-    File->FsFileHandle->Close (File->FsFileHandle);
-  }
-
-  // Need to free File and it's Guard structures
-  EblFreePool (BASE_CR (File, EFI_OPEN_FILE_GUARD, File));
-  return EFI_SUCCESS;
-}
-
-
-/**
-Return the size of the file represented by Stream. Also return the current 
-Seek position. Opening a file will enable a valid file size to be returned.
-LoadFile is an exception as a load file size is set to zero. 
-
-@param  Stream    Open File Handle
-
-@return 0         Stream is not an Open File or a valid LoadFile handle
-
-**/
-UINTN
-EfiTell (
-  IN  EFI_OPEN_FILE     *File,
-  OUT EFI_LBA           *CurrentPosition    OPTIONAL
-  )
-{
-  EFI_STATUS Status;
-  UINT64     BufferSize = 0;
-
-  if (!FileHandleValid (File)) {
-    return 0;
-  }
-
-  if (CurrentPosition != NULL) {
-    *CurrentPosition = File->CurrentPosition;
-  }
-
-  if (File->Type == EfiOpenLoadFile) {
-    // Figure out the File->Size
-    File->Buffer = NULL;
-    File->Size   = 0;
-    Status = File->LoadFile->LoadFile (File->LoadFile, File->DevicePath, FALSE, &File->Size, File->Buffer);
-    if (Status != EFI_BUFFER_TOO_SMALL) {
-      return 0;
-    }
-
-    File->MaxPosition = (UINT64)File->Size;
-  } else if (File->Type == EfiOpenTftp) {
-
-    Status = EblMtftp (
-      EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE,
-      NULL,
-      FALSE,
-      &BufferSize,
-      NULL,
-      &File->ServerIp,
-      (UINT8 *)File->FileName,
-      NULL,
-      TRUE
-      );
-    if (EFI_ERROR(Status)) {
-      AsciiPrint("TFTP error during APPLE_NSP_TFTP_GET_FILE_SIZE: %r\n", Status);
-      return 0;
-    }
-
-    File->Size        = (UINTN)BufferSize;
-    File->MaxPosition = File->Size;
-  }
-
-  return File->Size;
-}
-
-
-/**
-Seek to the Offset location in the file. LoadFile and FV device types do
-not support EfiSeek(). It is not possible to grow the file size using 
-EfiSeek().
-
-SeekType defines how use Offset to calculate the new file position:
-EfiSeekStart  : Position = Offset
-EfiSeekCurrent: Position is Offset bytes from the current position
-EfiSeekEnd    : Only supported if Offset is zero to seek to end of file.
-
-@param  Stream    Open File Handle
-@param  Offset    Offset to seek too. 
-@param  SeekType  Type of seek to perform
-
-
-@return EFI_INVALID_PARAMETER  Stream is not an Open File
-@return EFI_UNSUPPORTED        LoadFile and FV do not support Seek
-@return EFI_NOT_FOUND          Seek past the end of the file.
-@return EFI_SUCCESS            Steam closed
-
-**/
-EFI_STATUS
-EfiSeek (
-  IN  EFI_OPEN_FILE     *File,
-  IN  EFI_LBA           Offset,
-  IN  EFI_SEEK_TYPE     SeekType
-  )
-{
-  EFI_STATUS    Status;
-  UINT64        CurrentPosition;
-
-  if (!FileHandleValid (File)) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  if (File->Type == EfiOpenLoadFile) {
-    // LoadFile does not support Seek
-    return EFI_UNSUPPORTED;
-  }
-
-  CurrentPosition = File->CurrentPosition;
-  switch (SeekType) {
-  case EfiSeekStart:
-    if (Offset > File->MaxPosition) {
-      return EFI_NOT_FOUND;
-    }
-    CurrentPosition = Offset;
-    break;
-
-  case EfiSeekCurrent:
-    if ((File->CurrentPosition + Offset) > File->MaxPosition) {
-      return EFI_NOT_FOUND;
-    }
-    CurrentPosition += Offset;
-    break;
-
-  case EfiSeekEnd:
-    if (Offset != 0) {
-      // We don't support growing file size via seeking past end of file
-      return EFI_UNSUPPORTED;
-    }
-    CurrentPosition = File->MaxPosition;
-    break;
-
-  default:
-    return EFI_NOT_FOUND;
-  }
-
-  Status = EFI_SUCCESS;
-  if (File->FsFileHandle != NULL) {
-    Status = File->FsFileHandle->SetPosition (File->FsFileHandle, CurrentPosition);
-  }
-
-  if (!EFI_ERROR (Status)) {
-    File->CurrentPosition = CurrentPosition;
-  }
-
-  return Status;
-}
-
-EFI_STATUS
-CacheTftpFile (
-  IN OUT  EFI_OPEN_FILE *File
-  )
-{
-  EFI_STATUS          Status;
-  UINT64              TftpBufferSize;
-
-  if (File->IsBufferValid) {
-    return EFI_SUCCESS;
-  }
-
-  // Make sure the file size is set.
-  EfiTell (File, NULL);
-
-  //Allocate a buffer to hold the whole file.
-  File->Buffer = AllocatePool(File->Size);
-  if (File->Buffer == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  TftpBufferSize = File->Size;
-
-  Status = EblMtftp (
-    EFI_PXE_BASE_CODE_TFTP_READ_FILE, 
-    File->Buffer, 
-    FALSE, 
-    &TftpBufferSize, 
-    NULL, 
-    &File->ServerIp, 
-    (UINT8 *)File->FileName, 
-    NULL, 
-    FALSE);
-  if (EFI_ERROR(Status)) {
-    AsciiPrint("TFTP error during APPLE_NSP_TFTP_READ_FILE: %r\n", Status);
-    FreePool(File->Buffer);
-    return Status;
-  }
-
-  // Set the buffer valid flag.
-  File->IsBufferValid = TRUE;
-
-  return Status;
-}
-
-/**
-Read BufferSize bytes from the current location in the file. For load file,
-FV, and TFTP case you must read the entire file. 
-
-@param  Stream      Open File Handle
-@param  Buffer      Caller allocated buffer. 
-@param  BufferSize  Size of buffer in bytes.
-
-
-@return EFI_SUCCESS           Stream is not an Open File
-@return EFI_END_OF_FILE Tried to read past the end of the file
-@return EFI_INVALID_PARAMETER Stream is not an open file handle
-@return EFI_BUFFER_TOO_SMALL  Buffer is not big enough to do the read
-@return "other"               Error returned from device read
-
-**/
-EFI_STATUS
-EfiRead (
-  IN  EFI_OPEN_FILE       *File,
-  OUT VOID                *Buffer,
-  OUT UINTN               *BufferSize
-  )
-{
-  EFI_STATUS            Status;
-  UINT32                AuthenticationStatus;
-  EFI_DISK_IO_PROTOCOL  *DiskIo;
-
-  if (!FileHandleValid (File)) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  // Don't read past the end of the file.
-  if ((File->CurrentPosition + *BufferSize) > File->MaxPosition) {
-    return EFI_END_OF_FILE;
-  }
-
-  switch (File->Type) {
-  case EfiOpenLoadFile:
-    // Figure out the File->Size
-    EfiTell (File, NULL);
-
-    Status = File->LoadFile->LoadFile (File->LoadFile, File->DevicePath, FALSE, BufferSize, Buffer);
-    break;
-
-  case EfiOpenFirmwareVolume:
-    if (CompareGuid (&File->FvNameGuid, &gZeroGuid)) {
-      // This is the entire FV device, so treat like a memory buffer 
-      CopyMem (Buffer, (VOID *)(UINTN)(File->FvStart + File->CurrentPosition), *BufferSize);
-      File->CurrentPosition += *BufferSize;
-      Status = EFI_SUCCESS;
-    } else {
-      if (File->Buffer == NULL) {
-        if (File->FvSectionType == EFI_SECTION_ALL) {
-          Status = File->Fv->ReadFile (
-            File->Fv,
-            &File->FvNameGuid,
-            (VOID **)&File->Buffer,
-            &File->Size,
-            &File->FvType,
-            &File->FvAttributes,
-            &AuthenticationStatus
-            );
-        } else {
-          Status = File->Fv->ReadSection (
-            File->Fv,
-            &File->FvNameGuid,
-            File->FvSectionType,
-            0,
-            (VOID **)&File->Buffer,
-            &File->Size,
-            &AuthenticationStatus
-            );
-        }
-        if (EFI_ERROR (Status)) {
-          return Status;
-        }
-        File->IsBufferValid = TRUE;
-      }
-      // Operate on the cached buffer so Seek will work
-      CopyMem (Buffer, File->Buffer + File->CurrentPosition, *BufferSize);
-      File->CurrentPosition += *BufferSize;
-      Status = EFI_SUCCESS;
-    }
-    break;
-
-  case EfiOpenMemoryBuffer:
-    CopyMem (Buffer, File->Buffer + File->CurrentPosition, *BufferSize);
-    File->CurrentPosition += *BufferSize;
-    Status = EFI_SUCCESS;
-    break;
-
-  case EfiOpenFileSystem:
-    Status = File->FsFileHandle->Read (File->FsFileHandle, BufferSize, Buffer);
-    File->CurrentPosition += *BufferSize;
-    break;
-
-  case EfiOpenBlockIo:
-    Status = gBS->HandleProtocol(File->EfiHandle, &gEfiDiskIoProtocolGuid, (VOID **)&DiskIo);
-    if (!EFI_ERROR(Status)) {
-      Status = DiskIo->ReadDisk(DiskIo, File->FsBlockIoMedia->MediaId, File->DiskOffset + File->CurrentPosition, *BufferSize, Buffer);
-    }
-    File->CurrentPosition += *BufferSize;
-    break;
-
-  case EfiOpenTftp:
-    // Cache the file if it hasn't been cached yet.
-    if (File->IsBufferValid == FALSE) {
-      Status = CacheTftpFile (File);
-      if (EFI_ERROR (Status)) {
-        return Status;
-      }
-    }
-
-    // Copy out the requested data
-    CopyMem (Buffer, File->Buffer + File->CurrentPosition, *BufferSize);
-    File->CurrentPosition += *BufferSize;
-
-    Status = EFI_SUCCESS;
-    break;
-
-  default:
-    return EFI_INVALID_PARAMETER;
-  };
-
-  return Status;
-}
-
-
-/**
-Read the entire file into a buffer. This routine allocates the buffer and
-returns it to the user full of the read data. 
-
-This is very useful for load file where it's hard to know how big the buffer
-must be.
-
-@param  Stream      Open File Handle
-@param  Buffer      Pointer to buffer to return. 
-@param  BufferSize  Pointer to Size of buffer return..
-
-
-@return EFI_SUCCESS           Stream is not an Open File
-@return EFI_END_OF_FILE       Tried to read past the end of the file
-@return EFI_INVALID_PARAMETER Stream is not an open file handle
-@return EFI_BUFFER_TOO_SMALL  Buffer is not big enough to do the read
-@return "other"               Error returned from device read
-
-**/
-EFI_STATUS
-EfiReadAllocatePool (
-  IN  EFI_OPEN_FILE     *File,
-  OUT VOID              **Buffer,
-  OUT UINTN             *BufferSize
-  )
-{
-  if (!FileHandleValid (File)) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  // Loadfile defers file size determination on Open so use tell to find it
-  EfiTell (File, NULL);
-
-  *BufferSize = File->Size;
-  *Buffer = AllocatePool (*BufferSize);
-  if (*Buffer == NULL) {
-    return EFI_NOT_FOUND;
-  }
-
-  return EfiRead (File, *Buffer, BufferSize);
-}
-
-
-/**
-Write data back to the file. For TFTP case you must write the entire file. 
-
-@param  Stream      Open File Handle
-@param  Buffer      Pointer to buffer to return. 
-@param  BufferSize  Pointer to Size of buffer return..
-
-
-@return EFI_SUCCESS           Stream is not an Open File
-@return EFI_END_OF_FILE       Tried to read past the end of the file
-@return EFI_INVALID_PARAMETER Stream is not an open file handle
-@return EFI_BUFFER_TOO_SMALL  Buffer is not big enough to do the read
-@return "other"               Error returned from device write
-
-**/
-EFI_STATUS
-EfiWrite (
-  IN  EFI_OPEN_FILE   *File,
-  OUT VOID            *Buffer,
-  OUT UINTN           *BufferSize
-  )
-{
-  EFI_STATUS              Status;
-  EFI_FV_WRITE_FILE_DATA  FileData;
-  EFI_DISK_IO_PROTOCOL    *DiskIo;  
-
-  if (!FileHandleValid (File)) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  switch (File->Type) {
-  case EfiOpenMemoryBuffer:
-    if ((File->CurrentPosition + *BufferSize) > File->MaxPosition) {
-      return EFI_END_OF_FILE;
-    }
-
-    CopyMem (File->Buffer + File->CurrentPosition, Buffer, *BufferSize);
-    File->CurrentPosition += *BufferSize;
-    Status = EFI_SUCCESS;
-
-  case EfiOpenLoadFile:
-    // LoadFile device is read only be definition
-    Status = EFI_UNSUPPORTED;
-
-  case EfiOpenFirmwareVolume:
-    if (File->FvSectionType != EFI_SECTION_ALL) {
-      // Writes not support to a specific section. You have to update entire file
-      return EFI_UNSUPPORTED;
-    }
-
-    FileData.NameGuid       = &(File->FvNameGuid);
-    FileData.Type           = File->FvType;
-    FileData.FileAttributes = File->FvAttributes;
-    FileData.Buffer         = Buffer;
-    FileData.BufferSize     = (UINT32)*BufferSize;
-    Status = File->Fv->WriteFile (File->Fv, 1, EFI_FV_UNRELIABLE_WRITE, &FileData);
-    break;
-
-  case EfiOpenFileSystem:
-    Status = File->FsFileHandle->Write (File->FsFileHandle, BufferSize, Buffer);
-    File->CurrentPosition += *BufferSize;
-    break;
-
-  case EfiOpenBlockIo:
-    if ((File->CurrentPosition + *BufferSize) > File->MaxPosition) {
-      return EFI_END_OF_FILE;
-    }
-
-    Status = gBS->HandleProtocol (File->EfiHandle, &gEfiDiskIoProtocolGuid, (VOID **)&DiskIo);
-    if (!EFI_ERROR(Status)) {
-      Status = DiskIo->WriteDisk (DiskIo, File->FsBlockIoMedia->MediaId, File->DiskOffset + File->CurrentPosition, *BufferSize, Buffer);
-    }
-    File->CurrentPosition += *BufferSize;
-    break;
-
-  case EfiOpenTftp:
-    // Cache the file if it hasn't been cached yet.
-    if (File->IsBufferValid == FALSE) {
-      Status = CacheTftpFile(File);
-      if (EFI_ERROR(Status)) {
-        return Status;
-      }
-    }
-
-    // Don't overwrite the buffer
-    if ((File->CurrentPosition + *BufferSize) > File->MaxPosition) {
-      UINT8 *TempBuffer;
-
-      TempBuffer = File->Buffer;
-
-      File->Buffer = AllocatePool ((UINTN)(File->CurrentPosition + *BufferSize));
-      if (File->Buffer == NULL) {
-        return EFI_OUT_OF_RESOURCES;
-      }
-
-      CopyMem (File->Buffer, TempBuffer, File->Size);
-
-      FreePool (TempBuffer);
-
-      File->Size = (UINTN)(File->CurrentPosition + *BufferSize);
-      File->MaxPosition = (UINT64)File->Size;
-    }
-
-    // Copy in the requested data
-    CopyMem (File->Buffer + File->CurrentPosition, Buffer, *BufferSize);
-    File->CurrentPosition += *BufferSize;
-
-    // Mark the file dirty
-    File->IsDirty = TRUE;
-
-    Status = EFI_SUCCESS;
-    break;
-
-  default:
-    Status = EFI_INVALID_PARAMETER;
-  };
-
-  return Status;
-}
-
-
-/**
-Given Cwd expand Path to remove .. and replace them with real 
-directory names.
-
-@param  Cwd     Current Working Directory
-@param  Path    Path to expand
-
-@return NULL     Cwd or Path are not valid
-@return 'other'  Path with .. expanded
-
-**/
-CHAR8 *
-ExpandPath (
-  IN CHAR8    *Cwd,
-  IN CHAR8    *Path
-  )
-{
-  CHAR8   *NewPath;
-  CHAR8   *Work, *Start, *End;
-  UINTN   StrLen;
-  INTN    i;
-
-  if (Cwd == NULL || Path == NULL) {
-    return NULL;
-  }
-
-  StrLen = AsciiStrSize (Cwd);
-  if (StrLen <= 2) {
-    // Smallest valid path is 1 char and a null
-    return NULL;
-  }
-
-  StrLen = AsciiStrSize (Path);
-  NewPath = AllocatePool (AsciiStrSize (Cwd) + StrLen + 1);
-  if (NewPath == NULL) {
-    return NULL;
-  }
-  AsciiStrCpy (NewPath, Cwd);
-
-  End = Path + StrLen;
-  for (Start = Path ;;) {
-    Work = AsciiStrStr (Start, "..") ;
-    if (Work == NULL) {
-      // Remaining part of Path contains no more ..
-      break;
-    } 
-
-    // append path prior to .. 
-    AsciiStrnCat (NewPath, Start, Work - Start);
-    StrLen = AsciiStrLen (NewPath);
-    for (i = StrLen; i >= 0; i--) {
-      if (NewPath[i] == ':') {
-        // too many ..
-        return NULL;
-      }
-      if (NewPath[i] == '/' || NewPath[i] == '\\') {
-        if ((i > 0) && (NewPath[i-1] == ':')) {
-          // leave the / before a :
-          NewPath[i+1] = '\0';
-        } else {
-          // replace / will Null to remove trailing file/dir reference
-          NewPath[i] = '\0';
-        }
-        break;
-      }
-    }
-
-    Start = Work + 3;
-  } 
-
-  // Handle the path that remains after the ..
-  AsciiStrnCat (NewPath, Start, End - Start);
-
-  return NewPath;
-}
-
-
-/**
-Set the Current Working Directory (CWD). If a call is made to EfiOpen () and
-the path does not contain a device name, The CWD is prepended to the path.
-
-@param  Cwd     Current Working Directory to set
-
-
-@return EFI_SUCCESS           CWD is set
-@return EFI_INVALID_PARAMETER Cwd is not a valid device:path
-
-**/
-EFI_STATUS
-EfiSetCwd (
-  IN  CHAR8   *Cwd
-  ) 
-{
-  EFI_OPEN_FILE *File;
-  UINTN         Len;
-  CHAR8         *Path;
-
-  if (Cwd == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  if (AsciiStrCmp (Cwd, ".") == 0) {
-    // cd . is a no-op
-    return EFI_SUCCESS;
-  }
-
-  Path = Cwd;
-  if (AsciiStrStr (Cwd, "..") != NULL) {
-    if (gCwd == NULL) {
-      // no parent 
-      return EFI_SUCCESS;
-    }
-
-    Len = AsciiStrLen (gCwd);
-    if ((gCwd[Len-2] == ':') && ((gCwd[Len-1] == '/') || (gCwd[Len-1] == '\\'))) {
-      // parent is device so nothing to do
-      return EFI_SUCCESS;
-    }
-
-    // Expand .. in Cwd, given we know current working directory
-    Path = ExpandPath (gCwd, Cwd);
-    if (Path == NULL) {
-      return EFI_NOT_FOUND;
-    }
-  }
-
-  File = EfiOpen (Path, EFI_FILE_MODE_READ, 0);
-  if (File == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  if (gCwd != NULL) {
-    FreePool (gCwd);
-  }
-
-  // Use the info returned from EfiOpen as it can add in CWD if needed. So Cwd could be
-  // relative to the current gCwd or not.
-  gCwd = AllocatePool (AsciiStrSize (File->DeviceName) + AsciiStrSize (File->FileName) + 10);
-  if (gCwd == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  AsciiStrCpy (gCwd, File->DeviceName);
-  if (File->FileName == NULL) {
-    AsciiStrCat (gCwd, ":\\");
-  } else {
-    AsciiStrCat (gCwd, ":");
-    AsciiStrCat (gCwd, File->FileName);
-  }
-
-
-  EfiClose (File);
-  if (Path != Cwd) {
-    FreePool (Path);
-  }
-  return EFI_SUCCESS;
-}
-
-
-/**
-Set the Current Working Directory (CWD). If a call is made to EfiOpen () and
-the path does not contain a device name, The CWD is prepended to the path.
-The CWD buffer is only valid until a new call is made to EfiSetCwd(). After
-a call to EfiSetCwd() it is not legal to use the pointer returned by 
-this function.
-
-@param  Cwd     Current Working Directory 
-
-
-@return ""      No CWD set
-@return 'other' Returns buffer that contains CWD.
-
-**/
-CHAR8 *
-EfiGetCwd (
-  VOID
-  )
-{
-  if (gCwd == NULL) {
-    return "";
-  }
-  return gCwd;
-}
-
-
+/** @file\r
+File IO routines inspired by Streams with an EFI flavor\r
+\r
+Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Basic support for opening files on different device types. The device string\r
+is in the form of DevType:Path. Current DevType is required as there is no\r
+current mounted device concept of current working directory concept implement\r
+by this library.\r
+\r
+Device names are case insensitive and only check the leading characters for\r
+unique matches. Thus the following are all the same:\r
+LoadFile0:\r
+l0:\r
+L0:\r
+Lo0:\r
+\r
+Supported Device Names:\r
+A0x1234:0x12 - A memory buffer starting at address 0x1234 for 0x12 bytes\r
+l1:          - EFI LoadFile device one.\r
+B0:          - EFI BlockIo zero.\r
+fs3:         - EFI Simple File System device 3\r
+Fv2:         - EFI Firmware VOlume device 2\r
+10.0.1.102:  - TFTP service IP followed by the file name\r
+**/\r
+\r
+#include <PiDxe.h>\r
+#include <Protocol/BlockIo.h>             \r
+#include <Protocol/DiskIo.h>             \r
+#include <Protocol/SimpleFileSystem.h>      \r
+#include <Protocol/FirmwareVolume2.h>        \r
+#include <Protocol/LoadFile.h>\r
+#include <Protocol/FirmwareVolumeBlock.h>  \r
+#include <Guid/FileInfo.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiLib.h>   \r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/EfiFileLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/EblNetworkLib.h>\r
+\r
+\r
+CHAR8 *gCwd = NULL;\r
+\r
+CONST EFI_GUID gZeroGuid  = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } };\r
+\r
+#define EFI_OPEN_FILE_GUARD_HEADER  0x4B4D4641\r
+#define EFI_OPEN_FILE_GUARD_FOOTER  0x444D5A56\r
+\r
+// Need to defend against this overflowing\r
+#define MAX_CMD_LINE  0x200\r
+\r
+typedef struct {\r
+  UINT32            Header;\r
+  EFI_OPEN_FILE     File;\r
+  UINT32            Footer;\r
+} EFI_OPEN_FILE_GUARD;\r
+\r
+\r
+// globals to store current open device info\r
+EFI_HANDLE            *mBlkIo = NULL;\r
+UINTN                 mBlkIoCount = 0;\r
+\r
+EFI_HANDLE            *mFs = NULL;\r
+UINTN                 mFsCount = 0;\r
+// mFsInfo[] array entries must match mFs[] handles\r
+EFI_FILE_SYSTEM_INFO  **mFsInfo = NULL;\r
+\r
+EFI_HANDLE            *mFv = NULL;\r
+UINTN                 mFvCount = 0;\r
+EFI_HANDLE            *mLoadFile = NULL;\r
+UINTN                 mLoadFileCount = 0;\r
+\r
+\r
+\r
+/**\r
+Internal worker function to validate a File handle.\r
+\r
+@param  File    Open File Handle\r
+\r
+@return TRUE    File is valid\r
+@return FALSE   File is not valid\r
+\r
+\r
+**/\r
+BOOLEAN\r
+FileHandleValid (\r
+  IN EFI_OPEN_FILE  *File\r
+  )\r
+{\r
+  EFI_OPEN_FILE_GUARD  *GuardFile;\r
+\r
+  // Look right before and after file structure for the correct signatures\r
+  GuardFile = BASE_CR (File, EFI_OPEN_FILE_GUARD, File);\r
+  if ((GuardFile->Header != EFI_OPEN_FILE_GUARD_HEADER) ||\r
+    (GuardFile->Footer != EFI_OPEN_FILE_GUARD_FOOTER) ) {\r
+      return FALSE;\r
+    }\r
+\r
+    return TRUE;\r
+}\r
+\r
+/**\r
+Internal worker function. If Buffer is not NULL free it.\r
+\r
+@param  Buffer    Buffer to FreePool()\r
+\r
+**/\r
+VOID\r
+EblFreePool (\r
+  IN  VOID  *Buffer\r
+  )\r
+{\r
+  if (Buffer != NULL) {\r
+    FreePool (Buffer);\r
+  }\r
+}\r
+\r
+/**\r
+Update Device List Global Variables\r
+\r
+**/\r
+VOID\r
+EblUpdateDeviceLists (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  UINTN                             Size;\r
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *Fs;\r
+  EFI_FILE_HANDLE                   Root;\r
+  UINTN                             Index;\r
+\r
+  if (mBlkIo != NULL) {\r
+    FreePool (mBlkIo);\r
+  }\r
+  gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &mBlkIoCount, &mBlkIo);\r
+\r
+\r
+\r
+  if (mFv != NULL) {\r
+    FreePool (mFv);\r
+  }\r
+  gBS->LocateHandleBuffer (ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &mFvCount, &mFv);\r
+\r
+  if (mLoadFile != NULL) {\r
+    FreePool (mLoadFile);\r
+  }\r
+  gBS->LocateHandleBuffer (ByProtocol, &gEfiLoadFileProtocolGuid, NULL, &mLoadFileCount, &mLoadFile);\r
+\r
+  if (mFs != NULL) {\r
+    FreePool (mFs);\r
+  }\r
+\r
+  if (&mFsInfo[0] != NULL) {\r
+    // Need to Free the mFsInfo prior to recalculating mFsCount so don't move this code\r
+    for (Index = 0; Index < mFsCount; Index++) {\r
+      if (mFsInfo[Index] != NULL) {\r
+        FreePool (mFsInfo[Index]);\r
+      }\r
+    }\r
+    FreePool (mFsInfo);\r
+  }\r
+\r
+  gBS->LocateHandleBuffer (ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &mFsCount, &mFs);\r
+\r
+\r
+  mFsInfo = AllocateZeroPool (mFsCount * sizeof (EFI_FILE_SYSTEM_INFO *));\r
+  if (mFsInfo == NULL) {\r
+    // If we can't do this then we can't support file system entries\r
+    mFsCount = 0;\r
+  } else {\r
+    // Loop through all the file system structures and cache the file system info data\r
+    for (Index =0; Index < mFsCount; Index++) {\r
+      Status = gBS->HandleProtocol (mFs[Index], &gEfiSimpleFileSystemProtocolGuid, (VOID **)&Fs);\r
+      if (!EFI_ERROR (Status)) {\r
+        Status = Fs->OpenVolume (Fs, &Root);\r
+        if (!EFI_ERROR (Status)) {\r
+          // Get information about the volume\r
+          Size = 0;\r
+          Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, mFsInfo[Index]);\r
+          if (Status == EFI_BUFFER_TOO_SMALL) {\r
+            mFsInfo[Index] = AllocatePool (Size);\r
+            Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, mFsInfo[Index]);\r
+          }\r
+\r
+          Root->Close (Root);\r
+        }\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+\r
+/**\r
+PathName is in the form <device name>:<path> for example fs1:\ or ROOT:\.\r
+Return TRUE if the <devce name> prefix of PathName matches a file system\r
+Volume Name. MatchIndex is the array  index in mFsInfo[] of the match, \r
+and it can be used with mFs[] to find the handle that needs to be opened\r
+\r
+@param  PathName      PathName to check\r
+@param  FileStart     Index of the first character of the <path>\r
+@param  MatchIndex    Index in mFsInfo[] that matches\r
+\r
+@return TRUE      PathName matches a Volume Label and MatchIndex is valid\r
+@return FALSE     PathName does not match a Volume Label MatchIndex undefined\r
+\r
+**/\r
+BOOLEAN\r
+EblMatchVolumeName (\r
+  IN  CHAR8   *PathName,\r
+  IN  UINTN   FileStart,\r
+  OUT UINTN   *MatchIndex\r
+  )\r
+{\r
+  UINTN   Index;\r
+  UINTN   Compare;\r
+  UINTN   VolStrLen;\r
+  BOOLEAN Match;\r
+\r
+  for (Index =0; Index < mFsCount; Index++) {\r
+    if (mFsInfo[Index] == NULL) {\r
+      // FsInfo is not valid so skip it\r
+      continue;\r
+    }\r
+    VolStrLen = StrLen (mFsInfo[Index]->VolumeLabel);\r
+    for (Compare = 0, Match = TRUE; Compare < (FileStart - 1); Compare++) {\r
+      if (Compare > VolStrLen) {\r
+        Match = FALSE;\r
+        break;\r
+      }\r
+      if (PathName[Compare] != (CHAR8)mFsInfo[Index]->VolumeLabel[Compare]) {\r
+        // If the VolumeLabel has a space allow a _ to match with it in addition to ' '\r
+        if (!((PathName[Compare] == '_') && (mFsInfo[Index]->VolumeLabel[Compare] == L' '))) {\r
+          Match = FALSE;\r
+          break;\r
+        }\r
+      }\r
+    }\r
+    if (Match) {\r
+      *MatchIndex = Index;\r
+      return TRUE;\r
+    }\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+\r
+/**\r
+Return the number of devices of the current type active in the system\r
+\r
+@param  Type      Device type to check\r
+\r
+@return 0         Invalid type\r
+\r
+**/\r
+UINTN\r
+EfiGetDeviceCounts (\r
+  IN  EFI_OPEN_FILE_TYPE     DeviceType\r
+  )\r
+{\r
+  switch (DeviceType) {\r
+  case EfiOpenLoadFile:\r
+    return mLoadFileCount;\r
+  case EfiOpenFirmwareVolume:\r
+    return mFvCount;\r
+  case EfiOpenFileSystem:\r
+    return mFsCount;\r
+  case EfiOpenBlockIo:\r
+    return mBlkIoCount;\r
+  default:\r
+    return 0;\r
+  }\r
+}\r
+\r
+EFI_STATUS\r
+ConvertIpStringToEfiIp (\r
+  IN  CHAR8           *PathName, \r
+  OUT EFI_IP_ADDRESS  *ServerIp\r
+  )\r
+{\r
+  CHAR8     *Str;\r
+\r
+  Str = PathName;\r
+  ServerIp->v4.Addr[0] = (UINT8)AsciiStrDecimalToUintn (Str);\r
+\r
+  Str = AsciiStrStr (Str, ".");\r
+  if (Str == NULL) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  ServerIp->v4.Addr[1] = (UINT8)AsciiStrDecimalToUintn (++Str);\r
+\r
+  Str = AsciiStrStr (Str, ".");\r
+  if (Str == NULL) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  ServerIp->v4.Addr[2] = (UINT8)AsciiStrDecimalToUintn (++Str);\r
+\r
+  Str = AsciiStrStr (Str, ".");\r
+  if (Str == NULL) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  ServerIp->v4.Addr[3] = (UINT8)AsciiStrDecimalToUintn (++Str);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+Internal work function to extract a device number from a string skipping \r
+text. Easy way to extract numbers from strings like blk7:.\r
+\r
+@param  Str   String to extract device number form\r
+\r
+@return -1    Device string is not valid\r
+@return       Device #\r
+\r
+**/\r
+UINTN\r
+EblConvertDevStringToNumber (\r
+  IN  CHAR8   *Str\r
+  )\r
+{\r
+  UINTN   Max;\r
+  UINTN   Index;\r
+\r
+\r
+  // Find the first digit \r
+  Max = AsciiStrLen (Str);\r
+  for  (Index = 0; !((*Str >= '0') && (*Str <= '9')) && (Index < Max); Index++) {\r
+    Str++;\r
+  }\r
+  if (Index == Max) {\r
+    return (UINTN)-1;\r
+  }\r
+\r
+  return AsciiStrDecimalToUintn (Str);\r
+}\r
+\r
+\r
+/**\r
+Internal work function to fill in EFI_OPEN_FILE information for the Fs and BlkIo\r
+\r
+@param  File        Open file handle\r
+@param  FileName    Name of file after device stripped off\r
+\r
+\r
+**/\r
+EFI_STATUS\r
+EblFileDevicePath (\r
+  IN OUT EFI_OPEN_FILE  *File,\r
+  IN  CHAR8             *FileName,\r
+  IN  CONST UINT64      OpenMode\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  UINTN                             Size;\r
+  FILEPATH_DEVICE_PATH              *FilePath;\r
+  EFI_DEVICE_PATH_PROTOCOL          *FileDevicePath;\r
+  CHAR16                            UnicodeFileName[MAX_PATHNAME];\r
+  EFI_BLOCK_IO_PROTOCOL             *BlkIo;\r
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *Fs;\r
+  EFI_FILE_HANDLE                   Root;\r
+\r
+\r
+  if ( *FileName != 0 ) {\r
+    AsciiStrToUnicodeStr (FileName, UnicodeFileName);\r
+  } else {\r
+    AsciiStrToUnicodeStr ("\\", UnicodeFileName);\r
+  }\r
+\r
+  Size = StrSize (UnicodeFileName);\r
+  FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + sizeof (EFI_DEVICE_PATH_PROTOCOL));\r
+  if (FileDevicePath != NULL) {\r
+    FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath;\r
+    FilePath->Header.Type    = MEDIA_DEVICE_PATH;\r
+    FilePath->Header.SubType = MEDIA_FILEPATH_DP;\r
+    CopyMem (&FilePath->PathName, UnicodeFileName, Size);\r
+    SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH);\r
+    SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header));\r
+\r
+    if (File->EfiHandle != NULL) {\r
+      File->DevicePath = DevicePathFromHandle (File->EfiHandle);\r
+    }\r
+\r
+    File->DevicePath = AppendDevicePath (File->DevicePath, FileDevicePath);\r
+    FreePool (FileDevicePath);\r
+  }\r
+\r
+  Status = gBS->HandleProtocol (File->EfiHandle, &gEfiBlockIoProtocolGuid, (VOID **)&BlkIo);\r
+  if (!EFI_ERROR (Status)) {\r
+    File->FsBlockIoMedia = BlkIo->Media;\r
+    File->FsBlockIo = BlkIo;\r
+\r
+    // If we are not opening the device this will get over written with file info\r
+    File->MaxPosition = MultU64x32 (BlkIo->Media->LastBlock + 1, BlkIo->Media->BlockSize);\r
+  }\r
+\r
+  if (File->Type == EfiOpenFileSystem) {\r
+    Status = gBS->HandleProtocol (File->EfiHandle, &gEfiSimpleFileSystemProtocolGuid, (VOID **)&Fs);\r
+    if (!EFI_ERROR (Status)) {\r
+      Status = Fs->OpenVolume (Fs, &Root);\r
+      if (!EFI_ERROR (Status)) {\r
+        // Get information about the volume\r
+        Size = 0;\r
+        Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, File->FsInfo);\r
+        if (Status == EFI_BUFFER_TOO_SMALL) {\r
+          File->FsInfo = AllocatePool (Size);\r
+          Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, File->FsInfo);\r
+        }\r
+\r
+        // Get information about the file\r
+        Status = Root->Open (Root, &File->FsFileHandle, UnicodeFileName, OpenMode, 0);\r
+        if (!EFI_ERROR (Status)) {\r
+          Size = 0;\r
+          Status = File->FsFileHandle->GetInfo (File->FsFileHandle, &gEfiFileInfoGuid, &Size, NULL);\r
+          if (Status == EFI_BUFFER_TOO_SMALL) {\r
+            File->FsFileInfo = AllocatePool (Size);\r
+            Status = File->FsFileHandle->GetInfo (File->FsFileHandle, &gEfiFileInfoGuid, &Size, File->FsFileInfo);\r
+            if (!EFI_ERROR (Status)) {\r
+              File->Size = (UINTN)File->FsFileInfo->FileSize;\r
+              File->MaxPosition = (UINT64)File->Size;\r
+            }\r
+          }\r
+        }\r
+\r
+        Root->Close (Root);\r
+      }\r
+    }\r
+  } else if (File->Type == EfiOpenBlockIo) {\r
+    File->Size = (UINTN)File->MaxPosition;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+#define ToUpper(a)  ((((a) >= 'a') && ((a) <= 'z')) ? ((a) - 'a' + 'A') : (a))\r
+\r
+EFI_STATUS\r
+CompareGuidToString (\r
+  IN  EFI_GUID    *Guid,\r
+  IN  CHAR8       *String\r
+  )\r
+{\r
+  CHAR8       AsciiGuid[64];\r
+  CHAR8       *StringPtr;\r
+  CHAR8       *GuidPtr;\r
+\r
+  AsciiSPrint (AsciiGuid, sizeof(AsciiGuid), "%g", Guid);\r
+\r
+  StringPtr = String;\r
+  GuidPtr   = AsciiGuid;\r
+\r
+  while ((*StringPtr != '\0') && (*GuidPtr != '\0')) {\r
+    // Skip dashes\r
+    if (*StringPtr == '-') {\r
+      StringPtr++;\r
+      continue;\r
+    }\r
+\r
+    if (*GuidPtr == '-') {\r
+      GuidPtr++;\r
+      continue;\r
+    }\r
+\r
+    if (ToUpper(*StringPtr) != ToUpper(*GuidPtr)) {\r
+      return EFI_NOT_FOUND;\r
+    }\r
+\r
+    StringPtr++;\r
+    GuidPtr++;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+Internal work function to fill in EFI_OPEN_FILE information for the FV\r
+\r
+@param  File        Open file handle\r
+@param  FileName    Name of file after device stripped off\r
+\r
+\r
+**/\r
+EFI_STATUS\r
+EblFvFileDevicePath (\r
+  IN OUT EFI_OPEN_FILE  *File,\r
+  IN  CHAR8             *FileName,\r
+  IN  CONST UINT64      OpenMode\r
+  )\r
+{\r
+  EFI_STATUS                          Status;\r
+  EFI_STATUS                          GetNextFileStatus;\r
+  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH   DevicePathNode;\r
+  EFI_DEVICE_PATH_PROTOCOL            *DevicePath;\r
+  UINTN                               Key;\r
+  UINT32                              AuthenticationStatus;\r
+  CHAR8                               AsciiSection[MAX_PATHNAME];\r
+  VOID                                *Section;\r
+  UINTN                               SectionSize;\r
+  EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *Fvb;\r
+  EFI_LBA                             Lba;\r
+  UINTN                               BlockSize;\r
+  UINTN                               NumberOfBlocks;\r
+  EFI_FIRMWARE_VOLUME_HEADER          *FvHeader = NULL;\r
+  UINTN                               Index;\r
+\r
+\r
+  Status = gBS->HandleProtocol (File->EfiHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **)&File->Fv);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  // Get FVB Info about the handle\r
+  Status = gBS->HandleProtocol (File->EfiHandle, &gEfiFirmwareVolumeBlockProtocolGuid, (VOID **)&Fvb);\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = Fvb->GetPhysicalAddress (Fvb, &File->FvStart);\r
+    if (!EFI_ERROR (Status)) {\r
+      FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)File->FvStart;\r
+      File->FvHeaderSize = sizeof (EFI_FIRMWARE_VOLUME_HEADER);\r
+      for (Index = 0; FvHeader->BlockMap[Index].Length !=0; Index++) {\r
+        File->FvHeaderSize += sizeof (EFI_FV_BLOCK_MAP_ENTRY);\r
+      }\r
+\r
+      for (Lba = 0, File->FvSize = 0, NumberOfBlocks = 0; ; File->FvSize += (BlockSize * NumberOfBlocks), Lba += NumberOfBlocks) {\r
+        Status = Fvb->GetBlockSize (Fvb, Lba, &BlockSize, &NumberOfBlocks);\r
+        if (EFI_ERROR (Status)) {\r
+          break;\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+\r
+  DevicePath = DevicePathFromHandle (File->EfiHandle);\r
+\r
+  if (*FileName == '\0') {\r
+    File->DevicePath = DuplicateDevicePath (DevicePath);\r
+    File->Size = File->FvSize;\r
+    File->MaxPosition = File->Size;\r
+  } else {\r
+    Key = 0;\r
+    do {\r
+      File->FvType = EFI_FV_FILETYPE_ALL;\r
+      GetNextFileStatus = File->Fv->GetNextFile (\r
+        File->Fv, \r
+        &Key,\r
+        &File->FvType,  \r
+        &File->FvNameGuid, \r
+        &File->FvAttributes, \r
+        &File->Size\r
+        );\r
+      if (!EFI_ERROR (GetNextFileStatus)) {\r
+        // Compare GUID first\r
+        Status = CompareGuidToString (&File->FvNameGuid, FileName);\r
+        if (!EFI_ERROR(Status)) {\r
+          break;\r
+        }\r
+\r
+        Section = NULL;\r
+        Status = File->Fv->ReadSection (\r
+          File->Fv,\r
+          &File->FvNameGuid,\r
+          EFI_SECTION_USER_INTERFACE,\r
+          0,\r
+          &Section,\r
+          &SectionSize,\r
+          &AuthenticationStatus\r
+          );\r
+        if (!EFI_ERROR (Status)) {\r
+          UnicodeStrToAsciiStr (Section, AsciiSection);\r
+          if (AsciiStriCmp (FileName, AsciiSection) == 0) {\r
+            FreePool (Section);\r
+            break;\r
+          }\r
+          FreePool (Section);\r
+        }\r
+      }\r
+    } while (!EFI_ERROR (GetNextFileStatus));\r
+\r
+    if (EFI_ERROR (GetNextFileStatus)) {\r
+      return GetNextFileStatus;\r
+    }\r
+\r
+    if (OpenMode != EFI_SECTION_ALL) {\r
+      // Calculate the size of the section we are targeting\r
+      Section = NULL;\r
+      File->Size = 0;\r
+      Status = File->Fv->ReadSection (\r
+        File->Fv,\r
+        &File->FvNameGuid,\r
+        (EFI_SECTION_TYPE)OpenMode,\r
+        0,\r
+        &Section,\r
+        &File->Size,\r
+        &AuthenticationStatus\r
+        );\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+    }\r
+\r
+    File->MaxPosition = File->Size;\r
+    EfiInitializeFwVolDevicepathNode (&DevicePathNode, &File->FvNameGuid);\r
+    File->DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&DevicePathNode);\r
+  }\r
+\r
+\r
+  // FVB not required if FV was soft loaded...\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+\r
+\r
+/**\r
+Open a device named by PathName. The PathName includes a device name and \r
+path separated by a :. See file header for more details on the PathName\r
+syntax. There is no checking to prevent a file from being opened more than\r
+one type. \r
+\r
+SectionType is only used to open an FV. Each file in an FV contains multiple\r
+sections and only the SectionType section is opened.\r
+\r
+For any file that is opened with EfiOpen() must be closed with EfiClose().\r
+\r
+@param  PathName    Path to parse to open \r
+@param  OpenMode    Same as EFI_FILE.Open()\r
+@param  SectionType Section in FV to open.\r
+\r
+@return NULL  Open failed\r
+@return Valid EFI_OPEN_FILE handle\r
+\r
+**/\r
+EFI_OPEN_FILE *\r
+EfiOpen (\r
+  IN        CHAR8               *PathName,\r
+  IN  CONST UINT64              OpenMode,\r
+  IN  CONST EFI_SECTION_TYPE    SectionType\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_OPEN_FILE             *File;\r
+  EFI_OPEN_FILE             FileData;\r
+  UINTN                     StrLen;\r
+  UINTN                     FileStart;\r
+  UINTN                     DevNumber = 0;\r
+  EFI_OPEN_FILE_GUARD       *GuardFile;\r
+  BOOLEAN                   VolumeNameMatch;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  UINTN                     Size;\r
+  EFI_IP_ADDRESS            Ip;\r
+  CHAR8                     *CwdPlusPathName;\r
+  UINTN                     Index;\r
+  EFI_SECTION_TYPE          ModifiedSectionType;\r
+\r
+  EblUpdateDeviceLists ();\r
+\r
+  File = &FileData;\r
+  ZeroMem (File, sizeof (EFI_OPEN_FILE));\r
+\r
+  StrLen = AsciiStrSize (PathName);\r
+  if (StrLen <= 1) {\r
+    // Smallest valid path is 1 char and a null\r
+    return NULL;\r
+  }\r
+\r
+  for (FileStart = 0; FileStart < StrLen; FileStart++) {\r
+    if (PathName[FileStart] == ':') {\r
+      FileStart++;\r
+      break;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Matching volume name has precedence over handle based names\r
+  //\r
+  VolumeNameMatch = EblMatchVolumeName (PathName, FileStart, &DevNumber);\r
+  if (!VolumeNameMatch) {\r
+    if (FileStart == StrLen) {\r
+      // No Volume name or device name, so try Current Working Directory\r
+      if (gCwd == NULL) {\r
+        // No CWD\r
+        return NULL;\r
+      }\r
+\r
+      // We could add a current working directory concept\r
+      CwdPlusPathName = AllocatePool (AsciiStrSize (gCwd) + AsciiStrSize (PathName));\r
+      if (CwdPlusPathName == NULL) {\r
+        return NULL;\r
+      }\r
+\r
+      if ((PathName[0] == '/') || (PathName[0] == '\\')) {\r
+        // PathName starts in / so this means we go to the root of the device in the CWD. \r
+        CwdPlusPathName[0] = '\0';\r
+        for (FileStart = 0; gCwd[FileStart] != '\0'; FileStart++) {\r
+          CwdPlusPathName[FileStart] = gCwd[FileStart];\r
+          if (gCwd[FileStart] == ':') {\r
+            FileStart++;\r
+            CwdPlusPathName[FileStart] = '\0';\r
+            break;\r
+          }\r
+        }\r
+      } else {\r
+        AsciiStrCpy (CwdPlusPathName, gCwd);\r
+        StrLen = AsciiStrLen (gCwd);\r
+        if ((*PathName != '/') && (*PathName != '\\') && (gCwd[StrLen-1] != '/') && (gCwd[StrLen-1] != '\\')) {\r
+          AsciiStrCat (CwdPlusPathName, "\\");\r
+        }\r
+      }\r
+\r
+      AsciiStrCat (CwdPlusPathName, PathName);\r
+      if (AsciiStrStr (CwdPlusPathName, ":") == NULL) {\r
+        // Extra error check to make sure we don't recurse and blow stack\r
+        return NULL;\r
+      }\r
+\r
+      File = EfiOpen (CwdPlusPathName, OpenMode, SectionType);\r
+      FreePool (CwdPlusPathName);\r
+      return File;\r
+    }\r
+\r
+    DevNumber = EblConvertDevStringToNumber ((CHAR8 *)PathName); \r
+  }\r
+\r
+  File->DeviceName = AllocatePool (StrLen);\r
+  AsciiStrCpy (File->DeviceName, PathName);\r
+  File->DeviceName[FileStart - 1] = '\0';\r
+  File->FileName = &File->DeviceName[FileStart];\r
+  if (File->FileName[0] == '\0') {\r
+    // if it is just a file name use / as root\r
+    File->FileName = "\\";\r
+  } \r
+\r
+  //\r
+  // Use best match algorithm on the dev names so we only need to look at the\r
+  // first few charters to match the full device name. Short name forms are \r
+  // legal from the caller.\r
+  //\r
+  Status = EFI_SUCCESS;\r
+  if (*PathName == 'f' || *PathName == 'F' || VolumeNameMatch) {\r
+    if (PathName[1] == 's' || PathName[1] == 'S' || VolumeNameMatch) {\r
+      if (DevNumber >= mFsCount) {\r
+        goto ErrorExit;\r
+      }\r
+      File->Type = EfiOpenFileSystem;\r
+      File->EfiHandle = mFs[DevNumber];\r
+      Status = EblFileDevicePath (File, &PathName[FileStart], OpenMode);\r
+\r
+    } else if (PathName[1] == 'v' || PathName[1] == 'V') { \r
+      if (DevNumber >= mFvCount) {\r
+        goto ErrorExit;\r
+      }\r
+      File->Type = EfiOpenFirmwareVolume;\r
+      File->EfiHandle = mFv[DevNumber];\r
+\r
+      if ((PathName[FileStart] == '/') || (PathName[FileStart] == '\\')) {\r
+        // Skip leading / as its not really needed for the FV since no directories are supported\r
+        FileStart++;\r
+      }\r
+\r
+      // Check for 2nd :\r
+      ModifiedSectionType = SectionType;\r
+      for (Index = FileStart; PathName[Index] != '\0'; Index++) {\r
+        if (PathName[Index] == ':') {\r
+          // Support fv0:\DxeCore:0x10\r
+          // This means open the PE32 Section of the file \r
+          ModifiedSectionType = (EFI_SECTION_TYPE)AsciiStrHexToUintn (&PathName[Index + 1]);\r
+          PathName[Index] = '\0';\r
+        }\r
+      }\r
+      File->FvSectionType = ModifiedSectionType;\r
+      Status = EblFvFileDevicePath (File, &PathName[FileStart], ModifiedSectionType);\r
+    }\r
+  } else if ((*PathName == 'A') || (*PathName == 'a')) {\r
+    // Handle a:0x10000000:0x1234 address form a:ADDRESS:SIZE\r
+    File->Type = EfiOpenMemoryBuffer;\r
+    // 1st colon is at PathName[FileStart - 1]\r
+    File->Buffer = (VOID *)AsciiStrHexToUintn (&PathName[FileStart]);\r
+\r
+    // Find 2nd colon\r
+    while ((PathName[FileStart] != ':') && (PathName[FileStart] != '\0')) {\r
+      FileStart++;\r
+    }\r
+\r
+    // If we ran out of string, there's no extra data\r
+    if (PathName[FileStart] == '\0') {\r
+      File->Size = 0;\r
+    } else {\r
+      File->Size = AsciiStrHexToUintn (&PathName[FileStart + 1]);\r
+    }\r
+\r
+    // if there's no number after the second colon, default\r
+    // the end of memory\r
+    if (File->Size == 0) {\r
+      File->Size =  (UINTN)(0 - (UINTN)File->Buffer);\r
+    }\r
+\r
+    File->MaxPosition = File->Size;\r
+    File->BaseOffset = (UINTN)File->Buffer;\r
+\r
+  } else if (*PathName== 'l' || *PathName == 'L') {\r
+    if (DevNumber >= mLoadFileCount) {\r
+      goto ErrorExit;\r
+    }\r
+    File->Type = EfiOpenLoadFile;\r
+    File->EfiHandle = mLoadFile[DevNumber];\r
+\r
+    Status = gBS->HandleProtocol (File->EfiHandle, &gEfiLoadFileProtocolGuid, (VOID **)&File->LoadFile);\r
+    if (EFI_ERROR (Status)) {\r
+      goto ErrorExit;\r
+    }\r
+\r
+    Status = gBS->HandleProtocol (File->EfiHandle, &gEfiDevicePathProtocolGuid, (VOID **)&DevicePath);\r
+    if (EFI_ERROR (Status)) {\r
+      goto ErrorExit;\r
+    }\r
+    File->DevicePath = DuplicateDevicePath (DevicePath);\r
+\r
+  } else if (*PathName == 'b' || *PathName == 'B') {\r
+    // Handle b#:0x10000000:0x1234 address form b#:ADDRESS:SIZE\r
+    if (DevNumber >= mBlkIoCount) {\r
+      goto ErrorExit;\r
+    }\r
+    File->Type = EfiOpenBlockIo;\r
+    File->EfiHandle = mBlkIo[DevNumber];\r
+    EblFileDevicePath (File, "", OpenMode);\r
+\r
+    // 1st colon is at PathName[FileStart - 1]\r
+    File->DiskOffset = AsciiStrHexToUintn (&PathName[FileStart]);\r
+\r
+    // Find 2nd colon\r
+    while ((PathName[FileStart] != ':') && (PathName[FileStart] != '\0')) {\r
+      FileStart++;\r
+    }\r
+\r
+    // If we ran out of string, there's no extra data\r
+    if (PathName[FileStart] == '\0') {\r
+      Size = 0;\r
+    } else {\r
+      Size = AsciiStrHexToUintn (&PathName[FileStart + 1]);\r
+    }\r
+\r
+    // if a zero size is passed in (or the size is left out entirely),\r
+    // go to the end of the device.\r
+    if (Size == 0) {\r
+      File->Size = File->Size - File->DiskOffset;\r
+    } else {\r
+      File->Size = Size;\r
+    }\r
+\r
+    File->MaxPosition = File->Size;\r
+    File->BaseOffset = File->DiskOffset;\r
+  } else if ((*PathName) >= '0' && (*PathName <= '9')) {\r
+\r
+    // Get current IP address\r
+    Status = EblGetCurrentIpAddress (&Ip);\r
+    if (EFI_ERROR(Status)) {\r
+      AsciiPrint("Device IP Address is not configured.\n");\r
+      goto ErrorExit;\r
+    }\r
+\r
+\r
+    // Parse X.X.X.X:Filename, only support IPv4 TFTP for now...\r
+    File->Type = EfiOpenTftp;\r
+    File->IsDirty = FALSE;\r
+    File->IsBufferValid = FALSE;\r
+\r
+    Status = ConvertIpStringToEfiIp (PathName, &File->ServerIp);\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto ErrorExit;\r
+  }\r
+\r
+  GuardFile = (EFI_OPEN_FILE_GUARD *)AllocateZeroPool (sizeof (EFI_OPEN_FILE_GUARD));\r
+  if (GuardFile == NULL) {\r
+    goto ErrorExit;\r
+  }\r
+\r
+  GuardFile->Header = EFI_OPEN_FILE_GUARD_HEADER;\r
+  CopyMem (&(GuardFile->File), &FileData, sizeof (EFI_OPEN_FILE));\r
+  GuardFile->Footer = EFI_OPEN_FILE_GUARD_FOOTER;\r
+\r
+  return &(GuardFile->File);\r
+\r
+ErrorExit:\r
+  FreePool (File->DeviceName);\r
+  return NULL;\r
+}\r
+\r
+#define FILE_COPY_CHUNK 0x01000000\r
+\r
+EFI_STATUS\r
+EfiCopyFile (\r
+  IN        CHAR8               *DestinationFile,\r
+  IN        CHAR8               *SourceFile\r
+  )\r
+{\r
+  EFI_OPEN_FILE *Source      = NULL;\r
+  EFI_OPEN_FILE *Destination = NULL;\r
+  EFI_STATUS    Status       = EFI_SUCCESS;\r
+  VOID          *Buffer      = NULL;\r
+  UINTN         Size;\r
+  UINTN         Offset;\r
+  UINTN         Chunk = FILE_COPY_CHUNK;\r
+\r
+  Source = EfiOpen (SourceFile, EFI_FILE_MODE_READ, 0);\r
+  if (Source == NULL) {\r
+    AsciiPrint("Source file open error.\n");\r
+    Status = EFI_NOT_FOUND;\r
+    goto Exit;\r
+  }\r
+\r
+  Destination = EfiOpen (DestinationFile, EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0);\r
+  if (Destination == NULL) {\r
+    AsciiPrint("Destination file open error.\n");\r
+    Status = EFI_NOT_FOUND;\r
+    goto Exit;\r
+  }\r
+\r
+  Buffer = AllocatePool(FILE_COPY_CHUNK);\r
+  if (Buffer == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Exit;\r
+  }\r
+\r
+  Size = EfiTell(Source, NULL);\r
+\r
+  for (Offset = 0; Offset + FILE_COPY_CHUNK <= Size; Offset += Chunk) {\r
+    Chunk = FILE_COPY_CHUNK;\r
+\r
+    Status = EfiRead(Source, Buffer, &Chunk);\r
+    if (EFI_ERROR(Status)) {\r
+      AsciiPrint("Read file error %r\n", Status);\r
+      goto Exit;\r
+    }\r
+\r
+    Status = EfiWrite(Destination, Buffer, &Chunk);\r
+    if (EFI_ERROR(Status)) {\r
+      AsciiPrint("Write file error %r\n", Status);\r
+      goto Exit;\r
+    }    \r
+  }\r
+\r
+  // Any left over?\r
+  if (Offset < Size) {\r
+    Chunk = Size - Offset;\r
+\r
+    Status = EfiRead(Source, Buffer, &Chunk);\r
+    if (EFI_ERROR(Status)) {\r
+      AsciiPrint("Read file error\n");\r
+      goto Exit;\r
+    }\r
+\r
+    Status = EfiWrite(Destination, Buffer, &Chunk);\r
+    if (EFI_ERROR(Status)) {\r
+      AsciiPrint("Write file error\n");\r
+      goto Exit;\r
+    }    \r
+  }\r
+\r
+Exit:\r
+  if (Source != NULL) {\r
+    Status = EfiClose(Source);\r
+    if (EFI_ERROR(Status)) {\r
+      AsciiPrint("Source close error");\r
+    }\r
+  }\r
+\r
+  if (Destination != NULL) {\r
+    Status = EfiClose(Destination);\r
+    if (EFI_ERROR(Status)) {\r
+      AsciiPrint("Destination close error");\r
+    }\r
+  }\r
+\r
+  if (Buffer != NULL) {\r
+    FreePool(Buffer);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+Use DeviceType and Index to form a valid PathName and try and open it.\r
+\r
+@param  DeviceType  Device type to open\r
+@param  Index       Device Index to use. Zero relative.\r
+\r
+@return NULL  Open failed\r
+@return Valid EFI_OPEN_FILE handle\r
+\r
+**/\r
+EFI_OPEN_FILE  *\r
+EfiDeviceOpenByType (\r
+  IN  EFI_OPEN_FILE_TYPE    DeviceType,\r
+  IN  UINTN                 Index\r
+  )\r
+{\r
+  CHAR8   *DevStr;\r
+  CHAR8   Path[MAX_CMD_LINE];\r
+\r
+  switch (DeviceType) {\r
+  case EfiOpenLoadFile:\r
+    DevStr = "loadfile%d:";\r
+    break;\r
+  case EfiOpenFirmwareVolume:\r
+    DevStr = "fv%d:";    \r
+    break;\r
+  case EfiOpenFileSystem:\r
+    DevStr = "fs%d:";    \r
+    break;\r
+  case EfiOpenBlockIo:\r
+    DevStr = "blk%d:";    \r
+    break;\r
+  case EfiOpenMemoryBuffer:\r
+    DevStr = "a%d:";    \r
+    break;\r
+  default:\r
+    return NULL;\r
+  }\r
+\r
+  AsciiSPrint (Path, MAX_PATHNAME, DevStr, Index);\r
+\r
+  return EfiOpen (Path, EFI_FILE_MODE_READ, 0);\r
+}\r
+\r
+\r
+/**\r
+Close a file handle opened by EfiOpen() and free all resources allocated by\r
+EfiOpen().\r
+\r
+@param  Stream    Open File Handle\r
+\r
+@return EFI_INVALID_PARAMETER  Stream is not an Open File\r
+@return EFI_SUCCESS            Steam closed\r
+\r
+**/\r
+EFI_STATUS\r
+EfiClose (\r
+  IN  EFI_OPEN_FILE     *File\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  UINT64              TftpBufferSize;\r
+\r
+  if (!FileHandleValid (File)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //Write the buffer contents to TFTP file.\r
+  if ((File->Type == EfiOpenTftp) && (File->IsDirty)) {\r
+\r
+    TftpBufferSize = File->Size;\r
+    Status = EblMtftp (\r
+      EFI_PXE_BASE_CODE_TFTP_WRITE_FILE, \r
+      File->Buffer, \r
+      TRUE, \r
+      &TftpBufferSize, \r
+      NULL, \r
+      &File->ServerIp, \r
+      (UINT8 *)File->FileName, \r
+      NULL, \r
+      FALSE\r
+      );\r
+    if (EFI_ERROR(Status)) {\r
+      AsciiPrint("TFTP error during APPLE_NSP_TFTP_WRITE_FILE: %r\n", Status);\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  if ((File->Type == EfiOpenLoadFile) || \r
+    ((File->Type == EfiOpenTftp) && (File->IsBufferValid == TRUE)) ||\r
+    ((File->Type == EfiOpenFirmwareVolume) && (File->IsBufferValid == TRUE))) {\r
+    EblFreePool(File->Buffer);\r
+  }\r
+\r
+  EblFreePool (File->DevicePath);\r
+  EblFreePool (File->DeviceName);\r
+  EblFreePool (File->FsFileInfo);\r
+  EblFreePool (File->FsInfo);\r
+\r
+  if (File->FsFileHandle != NULL) {\r
+    File->FsFileHandle->Close (File->FsFileHandle);\r
+  }\r
+\r
+  // Need to free File and it's Guard structures\r
+  EblFreePool (BASE_CR (File, EFI_OPEN_FILE_GUARD, File));\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+Return the size of the file represented by Stream. Also return the current \r
+Seek position. Opening a file will enable a valid file size to be returned.\r
+LoadFile is an exception as a load file size is set to zero. \r
+\r
+@param  Stream    Open File Handle\r
+\r
+@return 0         Stream is not an Open File or a valid LoadFile handle\r
+\r
+**/\r
+UINTN\r
+EfiTell (\r
+  IN  EFI_OPEN_FILE     *File,\r
+  OUT EFI_LBA           *CurrentPosition    OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  UINT64     BufferSize = 0;\r
+\r
+  if (!FileHandleValid (File)) {\r
+    return 0;\r
+  }\r
+\r
+  if (CurrentPosition != NULL) {\r
+    *CurrentPosition = File->CurrentPosition;\r
+  }\r
+\r
+  if (File->Type == EfiOpenLoadFile) {\r
+    // Figure out the File->Size\r
+    File->Buffer = NULL;\r
+    File->Size   = 0;\r
+    Status = File->LoadFile->LoadFile (File->LoadFile, File->DevicePath, FALSE, &File->Size, File->Buffer);\r
+    if (Status != EFI_BUFFER_TOO_SMALL) {\r
+      return 0;\r
+    }\r
+\r
+    File->MaxPosition = (UINT64)File->Size;\r
+  } else if (File->Type == EfiOpenTftp) {\r
+\r
+    Status = EblMtftp (\r
+      EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE,\r
+      NULL,\r
+      FALSE,\r
+      &BufferSize,\r
+      NULL,\r
+      &File->ServerIp,\r
+      (UINT8 *)File->FileName,\r
+      NULL,\r
+      TRUE\r
+      );\r
+    if (EFI_ERROR(Status)) {\r
+      AsciiPrint("TFTP error during APPLE_NSP_TFTP_GET_FILE_SIZE: %r\n", Status);\r
+      return 0;\r
+    }\r
+\r
+    File->Size        = (UINTN)BufferSize;\r
+    File->MaxPosition = File->Size;\r
+  }\r
+\r
+  return File->Size;\r
+}\r
+\r
+\r
+/**\r
+Seek to the Offset location in the file. LoadFile and FV device types do\r
+not support EfiSeek(). It is not possible to grow the file size using \r
+EfiSeek().\r
+\r
+SeekType defines how use Offset to calculate the new file position:\r
+EfiSeekStart  : Position = Offset\r
+EfiSeekCurrent: Position is Offset bytes from the current position\r
+EfiSeekEnd    : Only supported if Offset is zero to seek to end of file.\r
+\r
+@param  Stream    Open File Handle\r
+@param  Offset    Offset to seek too. \r
+@param  SeekType  Type of seek to perform\r
+\r
+\r
+@return EFI_INVALID_PARAMETER  Stream is not an Open File\r
+@return EFI_UNSUPPORTED        LoadFile and FV do not support Seek\r
+@return EFI_NOT_FOUND          Seek past the end of the file.\r
+@return EFI_SUCCESS            Steam closed\r
+\r
+**/\r
+EFI_STATUS\r
+EfiSeek (\r
+  IN  EFI_OPEN_FILE     *File,\r
+  IN  EFI_LBA           Offset,\r
+  IN  EFI_SEEK_TYPE     SeekType\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  UINT64        CurrentPosition;\r
+\r
+  if (!FileHandleValid (File)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (File->Type == EfiOpenLoadFile) {\r
+    // LoadFile does not support Seek\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  CurrentPosition = File->CurrentPosition;\r
+  switch (SeekType) {\r
+  case EfiSeekStart:\r
+    if (Offset > File->MaxPosition) {\r
+      return EFI_NOT_FOUND;\r
+    }\r
+    CurrentPosition = Offset;\r
+    break;\r
+\r
+  case EfiSeekCurrent:\r
+    if ((File->CurrentPosition + Offset) > File->MaxPosition) {\r
+      return EFI_NOT_FOUND;\r
+    }\r
+    CurrentPosition += Offset;\r
+    break;\r
+\r
+  case EfiSeekEnd:\r
+    if (Offset != 0) {\r
+      // We don't support growing file size via seeking past end of file\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+    CurrentPosition = File->MaxPosition;\r
+    break;\r
+\r
+  default:\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  Status = EFI_SUCCESS;\r
+  if (File->FsFileHandle != NULL) {\r
+    Status = File->FsFileHandle->SetPosition (File->FsFileHandle, CurrentPosition);\r
+  }\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    File->CurrentPosition = CurrentPosition;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+CacheTftpFile (\r
+  IN OUT  EFI_OPEN_FILE *File\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  UINT64              TftpBufferSize;\r
+\r
+  if (File->IsBufferValid) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  // Make sure the file size is set.\r
+  EfiTell (File, NULL);\r
+\r
+  //Allocate a buffer to hold the whole file.\r
+  File->Buffer = AllocatePool(File->Size);\r
+  if (File->Buffer == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  TftpBufferSize = File->Size;\r
+\r
+  Status = EblMtftp (\r
+    EFI_PXE_BASE_CODE_TFTP_READ_FILE, \r
+    File->Buffer, \r
+    FALSE, \r
+    &TftpBufferSize, \r
+    NULL, \r
+    &File->ServerIp, \r
+    (UINT8 *)File->FileName, \r
+    NULL, \r
+    FALSE);\r
+  if (EFI_ERROR(Status)) {\r
+    AsciiPrint("TFTP error during APPLE_NSP_TFTP_READ_FILE: %r\n", Status);\r
+    FreePool(File->Buffer);\r
+    return Status;\r
+  }\r
+\r
+  // Set the buffer valid flag.\r
+  File->IsBufferValid = TRUE;\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+Read BufferSize bytes from the current location in the file. For load file,\r
+FV, and TFTP case you must read the entire file. \r
+\r
+@param  Stream      Open File Handle\r
+@param  Buffer      Caller allocated buffer. \r
+@param  BufferSize  Size of buffer in bytes.\r
+\r
+\r
+@return EFI_SUCCESS           Stream is not an Open File\r
+@return EFI_END_OF_FILE Tried to read past the end of the file\r
+@return EFI_INVALID_PARAMETER Stream is not an open file handle\r
+@return EFI_BUFFER_TOO_SMALL  Buffer is not big enough to do the read\r
+@return "other"               Error returned from device read\r
+\r
+**/\r
+EFI_STATUS\r
+EfiRead (\r
+  IN  EFI_OPEN_FILE       *File,\r
+  OUT VOID                *Buffer,\r
+  OUT UINTN               *BufferSize\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  UINT32                AuthenticationStatus;\r
+  EFI_DISK_IO_PROTOCOL  *DiskIo;\r
+\r
+  if (!FileHandleValid (File)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  // Don't read past the end of the file.\r
+  if ((File->CurrentPosition + *BufferSize) > File->MaxPosition) {\r
+    return EFI_END_OF_FILE;\r
+  }\r
+\r
+  switch (File->Type) {\r
+  case EfiOpenLoadFile:\r
+    // Figure out the File->Size\r
+    EfiTell (File, NULL);\r
+\r
+    Status = File->LoadFile->LoadFile (File->LoadFile, File->DevicePath, FALSE, BufferSize, Buffer);\r
+    break;\r
+\r
+  case EfiOpenFirmwareVolume:\r
+    if (CompareGuid (&File->FvNameGuid, &gZeroGuid)) {\r
+      // This is the entire FV device, so treat like a memory buffer \r
+      CopyMem (Buffer, (VOID *)(UINTN)(File->FvStart + File->CurrentPosition), *BufferSize);\r
+      File->CurrentPosition += *BufferSize;\r
+      Status = EFI_SUCCESS;\r
+    } else {\r
+      if (File->Buffer == NULL) {\r
+        if (File->FvSectionType == EFI_SECTION_ALL) {\r
+          Status = File->Fv->ReadFile (\r
+            File->Fv,\r
+            &File->FvNameGuid,\r
+            (VOID **)&File->Buffer,\r
+            &File->Size,\r
+            &File->FvType,\r
+            &File->FvAttributes,\r
+            &AuthenticationStatus\r
+            );\r
+        } else {\r
+          Status = File->Fv->ReadSection (\r
+            File->Fv,\r
+            &File->FvNameGuid,\r
+            File->FvSectionType,\r
+            0,\r
+            (VOID **)&File->Buffer,\r
+            &File->Size,\r
+            &AuthenticationStatus\r
+            );\r
+        }\r
+        if (EFI_ERROR (Status)) {\r
+          return Status;\r
+        }\r
+        File->IsBufferValid = TRUE;\r
+      }\r
+      // Operate on the cached buffer so Seek will work\r
+      CopyMem (Buffer, File->Buffer + File->CurrentPosition, *BufferSize);\r
+      File->CurrentPosition += *BufferSize;\r
+      Status = EFI_SUCCESS;\r
+    }\r
+    break;\r
+\r
+  case EfiOpenMemoryBuffer:\r
+    CopyMem (Buffer, File->Buffer + File->CurrentPosition, *BufferSize);\r
+    File->CurrentPosition += *BufferSize;\r
+    Status = EFI_SUCCESS;\r
+    break;\r
+\r
+  case EfiOpenFileSystem:\r
+    Status = File->FsFileHandle->Read (File->FsFileHandle, BufferSize, Buffer);\r
+    File->CurrentPosition += *BufferSize;\r
+    break;\r
+\r
+  case EfiOpenBlockIo:\r
+    Status = gBS->HandleProtocol(File->EfiHandle, &gEfiDiskIoProtocolGuid, (VOID **)&DiskIo);\r
+    if (!EFI_ERROR(Status)) {\r
+      Status = DiskIo->ReadDisk(DiskIo, File->FsBlockIoMedia->MediaId, File->DiskOffset + File->CurrentPosition, *BufferSize, Buffer);\r
+    }\r
+    File->CurrentPosition += *BufferSize;\r
+    break;\r
+\r
+  case EfiOpenTftp:\r
+    // Cache the file if it hasn't been cached yet.\r
+    if (File->IsBufferValid == FALSE) {\r
+      Status = CacheTftpFile (File);\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+    }\r
+\r
+    // Copy out the requested data\r
+    CopyMem (Buffer, File->Buffer + File->CurrentPosition, *BufferSize);\r
+    File->CurrentPosition += *BufferSize;\r
+\r
+    Status = EFI_SUCCESS;\r
+    break;\r
+\r
+  default:\r
+    return EFI_INVALID_PARAMETER;\r
+  };\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+Read the entire file into a buffer. This routine allocates the buffer and\r
+returns it to the user full of the read data. \r
+\r
+This is very useful for load file where it's hard to know how big the buffer\r
+must be.\r
+\r
+@param  Stream      Open File Handle\r
+@param  Buffer      Pointer to buffer to return. \r
+@param  BufferSize  Pointer to Size of buffer return..\r
+\r
+\r
+@return EFI_SUCCESS           Stream is not an Open File\r
+@return EFI_END_OF_FILE       Tried to read past the end of the file\r
+@return EFI_INVALID_PARAMETER Stream is not an open file handle\r
+@return EFI_BUFFER_TOO_SMALL  Buffer is not big enough to do the read\r
+@return "other"               Error returned from device read\r
+\r
+**/\r
+EFI_STATUS\r
+EfiReadAllocatePool (\r
+  IN  EFI_OPEN_FILE     *File,\r
+  OUT VOID              **Buffer,\r
+  OUT UINTN             *BufferSize\r
+  )\r
+{\r
+  if (!FileHandleValid (File)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  // Loadfile defers file size determination on Open so use tell to find it\r
+  EfiTell (File, NULL);\r
+\r
+  *BufferSize = File->Size;\r
+  *Buffer = AllocatePool (*BufferSize);\r
+  if (*Buffer == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  return EfiRead (File, *Buffer, BufferSize);\r
+}\r
+\r
+\r
+/**\r
+Write data back to the file. For TFTP case you must write the entire file. \r
+\r
+@param  Stream      Open File Handle\r
+@param  Buffer      Pointer to buffer to return. \r
+@param  BufferSize  Pointer to Size of buffer return..\r
+\r
+\r
+@return EFI_SUCCESS           Stream is not an Open File\r
+@return EFI_END_OF_FILE       Tried to read past the end of the file\r
+@return EFI_INVALID_PARAMETER Stream is not an open file handle\r
+@return EFI_BUFFER_TOO_SMALL  Buffer is not big enough to do the read\r
+@return "other"               Error returned from device write\r
+\r
+**/\r
+EFI_STATUS\r
+EfiWrite (\r
+  IN  EFI_OPEN_FILE   *File,\r
+  OUT VOID            *Buffer,\r
+  OUT UINTN           *BufferSize\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_FV_WRITE_FILE_DATA  FileData;\r
+  EFI_DISK_IO_PROTOCOL    *DiskIo;  \r
+\r
+  if (!FileHandleValid (File)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  switch (File->Type) {\r
+  case EfiOpenMemoryBuffer:\r
+    if ((File->CurrentPosition + *BufferSize) > File->MaxPosition) {\r
+      return EFI_END_OF_FILE;\r
+    }\r
+\r
+    CopyMem (File->Buffer + File->CurrentPosition, Buffer, *BufferSize);\r
+    File->CurrentPosition += *BufferSize;\r
+    Status = EFI_SUCCESS;\r
+\r
+  case EfiOpenLoadFile:\r
+    // LoadFile device is read only be definition\r
+    Status = EFI_UNSUPPORTED;\r
+\r
+  case EfiOpenFirmwareVolume:\r
+    if (File->FvSectionType != EFI_SECTION_ALL) {\r
+      // Writes not support to a specific section. You have to update entire file\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+\r
+    FileData.NameGuid       = &(File->FvNameGuid);\r
+    FileData.Type           = File->FvType;\r
+    FileData.FileAttributes = File->FvAttributes;\r
+    FileData.Buffer         = Buffer;\r
+    FileData.BufferSize     = (UINT32)*BufferSize;\r
+    Status = File->Fv->WriteFile (File->Fv, 1, EFI_FV_UNRELIABLE_WRITE, &FileData);\r
+    break;\r
+\r
+  case EfiOpenFileSystem:\r
+    Status = File->FsFileHandle->Write (File->FsFileHandle, BufferSize, Buffer);\r
+    File->CurrentPosition += *BufferSize;\r
+    break;\r
+\r
+  case EfiOpenBlockIo:\r
+    if ((File->CurrentPosition + *BufferSize) > File->MaxPosition) {\r
+      return EFI_END_OF_FILE;\r
+    }\r
+\r
+    Status = gBS->HandleProtocol (File->EfiHandle, &gEfiDiskIoProtocolGuid, (VOID **)&DiskIo);\r
+    if (!EFI_ERROR(Status)) {\r
+      Status = DiskIo->WriteDisk (DiskIo, File->FsBlockIoMedia->MediaId, File->DiskOffset + File->CurrentPosition, *BufferSize, Buffer);\r
+    }\r
+    File->CurrentPosition += *BufferSize;\r
+    break;\r
+\r
+  case EfiOpenTftp:\r
+    // Cache the file if it hasn't been cached yet.\r
+    if (File->IsBufferValid == FALSE) {\r
+      Status = CacheTftpFile(File);\r
+      if (EFI_ERROR(Status)) {\r
+        return Status;\r
+      }\r
+    }\r
+\r
+    // Don't overwrite the buffer\r
+    if ((File->CurrentPosition + *BufferSize) > File->MaxPosition) {\r
+      UINT8 *TempBuffer;\r
+\r
+      TempBuffer = File->Buffer;\r
+\r
+      File->Buffer = AllocatePool ((UINTN)(File->CurrentPosition + *BufferSize));\r
+      if (File->Buffer == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+\r
+      CopyMem (File->Buffer, TempBuffer, File->Size);\r
+\r
+      FreePool (TempBuffer);\r
+\r
+      File->Size = (UINTN)(File->CurrentPosition + *BufferSize);\r
+      File->MaxPosition = (UINT64)File->Size;\r
+    }\r
+\r
+    // Copy in the requested data\r
+    CopyMem (File->Buffer + File->CurrentPosition, Buffer, *BufferSize);\r
+    File->CurrentPosition += *BufferSize;\r
+\r
+    // Mark the file dirty\r
+    File->IsDirty = TRUE;\r
+\r
+    Status = EFI_SUCCESS;\r
+    break;\r
+\r
+  default:\r
+    Status = EFI_INVALID_PARAMETER;\r
+  };\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+Given Cwd expand Path to remove .. and replace them with real \r
+directory names.\r
+\r
+@param  Cwd     Current Working Directory\r
+@param  Path    Path to expand\r
+\r
+@return NULL     Cwd or Path are not valid\r
+@return 'other'  Path with .. expanded\r
+\r
+**/\r
+CHAR8 *\r
+ExpandPath (\r
+  IN CHAR8    *Cwd,\r
+  IN CHAR8    *Path\r
+  )\r
+{\r
+  CHAR8   *NewPath;\r
+  CHAR8   *Work, *Start, *End;\r
+  UINTN   StrLen;\r
+  INTN    i;\r
+\r
+  if (Cwd == NULL || Path == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  StrLen = AsciiStrSize (Cwd);\r
+  if (StrLen <= 2) {\r
+    // Smallest valid path is 1 char and a null\r
+    return NULL;\r
+  }\r
+\r
+  StrLen = AsciiStrSize (Path);\r
+  NewPath = AllocatePool (AsciiStrSize (Cwd) + StrLen + 1);\r
+  if (NewPath == NULL) {\r
+    return NULL;\r
+  }\r
+  AsciiStrCpy (NewPath, Cwd);\r
+\r
+  End = Path + StrLen;\r
+  for (Start = Path ;;) {\r
+    Work = AsciiStrStr (Start, "..") ;\r
+    if (Work == NULL) {\r
+      // Remaining part of Path contains no more ..\r
+      break;\r
+    } \r
+\r
+    // append path prior to .. \r
+    AsciiStrnCat (NewPath, Start, Work - Start);\r
+    StrLen = AsciiStrLen (NewPath);\r
+    for (i = StrLen; i >= 0; i--) {\r
+      if (NewPath[i] == ':') {\r
+        // too many ..\r
+        return NULL;\r
+      }\r
+      if (NewPath[i] == '/' || NewPath[i] == '\\') {\r
+        if ((i > 0) && (NewPath[i-1] == ':')) {\r
+          // leave the / before a :\r
+          NewPath[i+1] = '\0';\r
+        } else {\r
+          // replace / will Null to remove trailing file/dir reference\r
+          NewPath[i] = '\0';\r
+        }\r
+        break;\r
+      }\r
+    }\r
+\r
+    Start = Work + 3;\r
+  } \r
+\r
+  // Handle the path that remains after the ..\r
+  AsciiStrnCat (NewPath, Start, End - Start);\r
+\r
+  return NewPath;\r
+}\r
+\r
+\r
+/**\r
+Set the Current Working Directory (CWD). If a call is made to EfiOpen () and\r
+the path does not contain a device name, The CWD is prepended to the path.\r
+\r
+@param  Cwd     Current Working Directory to set\r
+\r
+\r
+@return EFI_SUCCESS           CWD is set\r
+@return EFI_INVALID_PARAMETER Cwd is not a valid device:path\r
+\r
+**/\r
+EFI_STATUS\r
+EfiSetCwd (\r
+  IN  CHAR8   *Cwd\r
+  ) \r
+{\r
+  EFI_OPEN_FILE *File;\r
+  UINTN         Len;\r
+  CHAR8         *Path;\r
+\r
+  if (Cwd == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (AsciiStrCmp (Cwd, ".") == 0) {\r
+    // cd . is a no-op\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  Path = Cwd;\r
+  if (AsciiStrStr (Cwd, "..") != NULL) {\r
+    if (gCwd == NULL) {\r
+      // no parent \r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    Len = AsciiStrLen (gCwd);\r
+    if ((gCwd[Len-2] == ':') && ((gCwd[Len-1] == '/') || (gCwd[Len-1] == '\\'))) {\r
+      // parent is device so nothing to do\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    // Expand .. in Cwd, given we know current working directory\r
+    Path = ExpandPath (gCwd, Cwd);\r
+    if (Path == NULL) {\r
+      return EFI_NOT_FOUND;\r
+    }\r
+  }\r
+\r
+  File = EfiOpen (Path, EFI_FILE_MODE_READ, 0);\r
+  if (File == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (gCwd != NULL) {\r
+    FreePool (gCwd);\r
+  }\r
+\r
+  // Use the info returned from EfiOpen as it can add in CWD if needed. So Cwd could be\r
+  // relative to the current gCwd or not.\r
+  gCwd = AllocatePool (AsciiStrSize (File->DeviceName) + AsciiStrSize (File->FileName) + 10);\r
+  if (gCwd == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  AsciiStrCpy (gCwd, File->DeviceName);\r
+  if (File->FileName == NULL) {\r
+    AsciiStrCat (gCwd, ":\\");\r
+  } else {\r
+    AsciiStrCat (gCwd, ":");\r
+    AsciiStrCat (gCwd, File->FileName);\r
+  }\r
+\r
+\r
+  EfiClose (File);\r
+  if (Path != Cwd) {\r
+    FreePool (Path);\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+Set the Current Working Directory (CWD). If a call is made to EfiOpen () and\r
+the path does not contain a device name, The CWD is prepended to the path.\r
+The CWD buffer is only valid until a new call is made to EfiSetCwd(). After\r
+a call to EfiSetCwd() it is not legal to use the pointer returned by \r
+this function.\r
+\r
+@param  Cwd     Current Working Directory \r
+\r
+\r
+@return ""      No CWD set\r
+@return 'other' Returns buffer that contains CWD.\r
+\r
+**/\r
+CHAR8 *\r
+EfiGetCwd (\r
+  VOID\r
+  )\r
+{\r
+  if (gCwd == NULL) {\r
+    return "";\r
+  }\r
+  return gCwd;\r
+}\r
+\r
+\r
index e56833ae9b6ffaee67281dc959b0c263ccc24c15..151fcb2ab0475f84e8fdb61d249abfa2bb5094f9 100644 (file)
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2006 David Gibson, IBM Corporation.
- *
- * libfdt is dual licensed: you can use it either under the terms of
- * the GPL, or the BSD license, at your option.
- *
- *  a) This library is free software; you can redistribute it and/or
- *     modify it under the terms of the GNU General Public License as
- *     published by the Free Software Foundation; either version 2 of the
- *     License, or (at your option) any later version.
- *
- *     This library is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- *
- *     You should have received a copy of the GNU General Public
- *     License along with this library; if not, write to the Free
- *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
- *     MA 02110-1301 USA
- *
- * Alternatively,
- *
- *  b) Redistribution and use in source and binary forms, with or
- *     without modification, are permitted provided that the following
- *     conditions are met:
- *
- *     1. Redistributions of source code must retain the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer.
- *     2. Redistributions in binary form must reproduce the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer in the documentation and/or other materials
- *        provided with the distribution.
- *
- *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "libfdt_env.h"
-
-#include <fdt.h>
-#include <libfdt.h>
-
-#include "libfdt_internal.h"
-
-int fdt_check_header(const void *fdt)
-{
-       if (fdt_magic(fdt) == FDT_MAGIC) {
-               /* Complete tree */
-               if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
-                       return -FDT_ERR_BADVERSION;
-               if (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION)
-                       return -FDT_ERR_BADVERSION;
-       } else if (fdt_magic(fdt) == FDT_SW_MAGIC) {
-               /* Unfinished sequential-write blob */
-               if (fdt_size_dt_struct(fdt) == 0)
-                       return -FDT_ERR_BADSTATE;
-       } else {
-               return -FDT_ERR_BADMAGIC;
-       }
-
-       return 0;
-}
-
-const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
-{
-       const char *p;
-
-       if (fdt_version(fdt) >= 0x11)
-               if (((offset + len) < offset)
-                   || ((offset + len) > fdt_size_dt_struct(fdt)))
-                       return NULL;
-
-       p = _fdt_offset_ptr(fdt, offset);
-
-       if (p + len < p)
-               return NULL;
-       return p;
-}
-
-uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
-{
-       const uint32_t *tagp, *lenp;
-       uint32_t tag;
-       int offset = startoffset;
-       const char *p;
-
-       *nextoffset = -FDT_ERR_TRUNCATED;
-       tagp = fdt_offset_ptr(fdt, offset, FDT_TAGSIZE);
-       if (!tagp)
-               return FDT_END; /* premature end */
-       tag = fdt32_to_cpu(*tagp);
-       offset += FDT_TAGSIZE;
-
-       *nextoffset = -FDT_ERR_BADSTRUCTURE;
-       switch (tag) {
-       case FDT_BEGIN_NODE:
-               /* skip name */
-               do {
-                       p = fdt_offset_ptr(fdt, offset++, 1);
-               } while (p && (*p != '\0'));
-               if (!p)
-                       return FDT_END; /* premature end */
-               break;
-
-       case FDT_PROP:
-               lenp = fdt_offset_ptr(fdt, offset, sizeof(*lenp));
-               if (!lenp)
-                       return FDT_END; /* premature end */
-               /* skip-name offset, length and value */
-               offset += sizeof(struct fdt_property) - FDT_TAGSIZE
-                       + fdt32_to_cpu(*lenp);
-               break;
-
-       case FDT_END:
-       case FDT_END_NODE:
-       case FDT_NOP:
-               break;
-
-       default:
-               return FDT_END;
-       }
-
-       if (!fdt_offset_ptr(fdt, startoffset, offset - startoffset))
-               return FDT_END; /* premature end */
-
-       *nextoffset = FDT_TAGALIGN(offset);
-       return tag;
-}
-
-int _fdt_check_node_offset(const void *fdt, int offset)
-{
-       if ((offset < 0) || (offset % FDT_TAGSIZE)
-           || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE))
-               return -FDT_ERR_BADOFFSET;
-
-       return offset;
-}
-
-int _fdt_check_prop_offset(const void *fdt, int offset)
-{
-       if ((offset < 0) || (offset % FDT_TAGSIZE)
-           || (fdt_next_tag(fdt, offset, &offset) != FDT_PROP))
-               return -FDT_ERR_BADOFFSET;
-
-       return offset;
-}
-
-int fdt_next_node(const void *fdt, int offset, int *depth)
-{
-       int nextoffset = 0;
-       uint32_t tag;
-
-       if (offset >= 0)
-               if ((nextoffset = _fdt_check_node_offset(fdt, offset)) < 0)
-                       return nextoffset;
-
-       do {
-               offset = nextoffset;
-               tag = fdt_next_tag(fdt, offset, &nextoffset);
-
-               switch (tag) {
-               case FDT_PROP:
-               case FDT_NOP:
-                       break;
-
-               case FDT_BEGIN_NODE:
-                       if (depth)
-                               (*depth)++;
-                       break;
-
-               case FDT_END_NODE:
-                       if (depth && ((--(*depth)) < 0))
-                               return nextoffset;
-                       break;
-
-               case FDT_END:
-                       if ((nextoffset >= 0)
-                           || ((nextoffset == -FDT_ERR_TRUNCATED) && !depth))
-                               return -FDT_ERR_NOTFOUND;
-                       else
-                               return nextoffset;
-               }
-       } while (tag != FDT_BEGIN_NODE);
-
-       return offset;
-}
-
-const char *_fdt_find_string(const char *strtab, int tabsize, const char *s)
-{
-       int len = strlen(s) + 1;
-       const char *last = strtab + tabsize - len;
-       const char *p;
-
-       for (p = strtab; p <= last; p++)
-               if (memcmp(p, s, len) == 0)
-                       return p;
-       return NULL;
-}
-
-int fdt_move(const void *fdt, void *buf, int bufsize)
-{
-       FDT_CHECK_HEADER(fdt);
-
-       if (fdt_totalsize(fdt) > bufsize)
-               return -FDT_ERR_NOSPACE;
-
-       memmove(buf, fdt, fdt_totalsize(fdt));
-       return 0;
-}
+/*\r
+ * libfdt - Flat Device Tree manipulation\r
+ * Copyright (C) 2006 David Gibson, IBM Corporation.\r
+ *\r
+ * libfdt is dual licensed: you can use it either under the terms of\r
+ * the GPL, or the BSD license, at your option.\r
+ *\r
+ *  a) This library is free software; you can redistribute it and/or\r
+ *     modify it under the terms of the GNU General Public License as\r
+ *     published by the Free Software Foundation; either version 2 of the\r
+ *     License, or (at your option) any later version.\r
+ *\r
+ *     This library is distributed in the hope that it will be useful,\r
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ *     GNU General Public License for more details.\r
+ *\r
+ *     You should have received a copy of the GNU General Public\r
+ *     License along with this library; if not, write to the Free\r
+ *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\r
+ *     MA 02110-1301 USA\r
+ *\r
+ * Alternatively,\r
+ *\r
+ *  b) Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *     1. Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *     2. Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\r
+ *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,\r
+ *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
+ *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+ *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
+ *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
+ *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
+ *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#include "libfdt_env.h"\r
+\r
+#include <fdt.h>\r
+#include <libfdt.h>\r
+\r
+#include "libfdt_internal.h"\r
+\r
+int fdt_check_header(const void *fdt)\r
+{\r
+       if (fdt_magic(fdt) == FDT_MAGIC) {\r
+               /* Complete tree */\r
+               if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)\r
+                       return -FDT_ERR_BADVERSION;\r
+               if (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION)\r
+                       return -FDT_ERR_BADVERSION;\r
+       } else if (fdt_magic(fdt) == FDT_SW_MAGIC) {\r
+               /* Unfinished sequential-write blob */\r
+               if (fdt_size_dt_struct(fdt) == 0)\r
+                       return -FDT_ERR_BADSTATE;\r
+       } else {\r
+               return -FDT_ERR_BADMAGIC;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)\r
+{\r
+       const char *p;\r
+\r
+       if (fdt_version(fdt) >= 0x11)\r
+               if (((offset + len) < offset)\r
+                   || ((offset + len) > fdt_size_dt_struct(fdt)))\r
+                       return NULL;\r
+\r
+       p = _fdt_offset_ptr(fdt, offset);\r
+\r
+       if (p + len < p)\r
+               return NULL;\r
+       return p;\r
+}\r
+\r
+uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)\r
+{\r
+       const uint32_t *tagp, *lenp;\r
+       uint32_t tag;\r
+       int offset = startoffset;\r
+       const char *p;\r
+\r
+       *nextoffset = -FDT_ERR_TRUNCATED;\r
+       tagp = fdt_offset_ptr(fdt, offset, FDT_TAGSIZE);\r
+       if (!tagp)\r
+               return FDT_END; /* premature end */\r
+       tag = fdt32_to_cpu(*tagp);\r
+       offset += FDT_TAGSIZE;\r
+\r
+       *nextoffset = -FDT_ERR_BADSTRUCTURE;\r
+       switch (tag) {\r
+       case FDT_BEGIN_NODE:\r
+               /* skip name */\r
+               do {\r
+                       p = fdt_offset_ptr(fdt, offset++, 1);\r
+               } while (p && (*p != '\0'));\r
+               if (!p)\r
+                       return FDT_END; /* premature end */\r
+               break;\r
+\r
+       case FDT_PROP:\r
+               lenp = fdt_offset_ptr(fdt, offset, sizeof(*lenp));\r
+               if (!lenp)\r
+                       return FDT_END; /* premature end */\r
+               /* skip-name offset, length and value */\r
+               offset += sizeof(struct fdt_property) - FDT_TAGSIZE\r
+                       + fdt32_to_cpu(*lenp);\r
+               break;\r
+\r
+       case FDT_END:\r
+       case FDT_END_NODE:\r
+       case FDT_NOP:\r
+               break;\r
+\r
+       default:\r
+               return FDT_END;\r
+       }\r
+\r
+       if (!fdt_offset_ptr(fdt, startoffset, offset - startoffset))\r
+               return FDT_END; /* premature end */\r
+\r
+       *nextoffset = FDT_TAGALIGN(offset);\r
+       return tag;\r
+}\r
+\r
+int _fdt_check_node_offset(const void *fdt, int offset)\r
+{\r
+       if ((offset < 0) || (offset % FDT_TAGSIZE)\r
+           || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE))\r
+               return -FDT_ERR_BADOFFSET;\r
+\r
+       return offset;\r
+}\r
+\r
+int _fdt_check_prop_offset(const void *fdt, int offset)\r
+{\r
+       if ((offset < 0) || (offset % FDT_TAGSIZE)\r
+           || (fdt_next_tag(fdt, offset, &offset) != FDT_PROP))\r
+               return -FDT_ERR_BADOFFSET;\r
+\r
+       return offset;\r
+}\r
+\r
+int fdt_next_node(const void *fdt, int offset, int *depth)\r
+{\r
+       int nextoffset = 0;\r
+       uint32_t tag;\r
+\r
+       if (offset >= 0)\r
+               if ((nextoffset = _fdt_check_node_offset(fdt, offset)) < 0)\r
+                       return nextoffset;\r
+\r
+       do {\r
+               offset = nextoffset;\r
+               tag = fdt_next_tag(fdt, offset, &nextoffset);\r
+\r
+               switch (tag) {\r
+               case FDT_PROP:\r
+               case FDT_NOP:\r
+                       break;\r
+\r
+               case FDT_BEGIN_NODE:\r
+                       if (depth)\r
+                               (*depth)++;\r
+                       break;\r
+\r
+               case FDT_END_NODE:\r
+                       if (depth && ((--(*depth)) < 0))\r
+                               return nextoffset;\r
+                       break;\r
+\r
+               case FDT_END:\r
+                       if ((nextoffset >= 0)\r
+                           || ((nextoffset == -FDT_ERR_TRUNCATED) && !depth))\r
+                               return -FDT_ERR_NOTFOUND;\r
+                       else\r
+                               return nextoffset;\r
+               }\r
+       } while (tag != FDT_BEGIN_NODE);\r
+\r
+       return offset;\r
+}\r
+\r
+const char *_fdt_find_string(const char *strtab, int tabsize, const char *s)\r
+{\r
+       int len = strlen(s) + 1;\r
+       const char *last = strtab + tabsize - len;\r
+       const char *p;\r
+\r
+       for (p = strtab; p <= last; p++)\r
+               if (memcmp(p, s, len) == 0)\r
+                       return p;\r
+       return NULL;\r
+}\r
+\r
+int fdt_move(const void *fdt, void *buf, int bufsize)\r
+{\r
+       FDT_CHECK_HEADER(fdt);\r
+\r
+       if (fdt_totalsize(fdt) > bufsize)\r
+               return -FDT_ERR_NOSPACE;\r
+\r
+       memmove(buf, fdt, fdt_totalsize(fdt));\r
+       return 0;\r
+}\r
index f72d13b1d19c0bce7a27658e18a5f9fe26b2453c..f00a8991d44f4cd9c4b0f719c65b5c7aa0bf9474 100644 (file)
@@ -1,84 +1,84 @@
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2012 David Gibson, IBM Corporation.
- *
- * libfdt is dual licensed: you can use it either under the terms of
- * the GPL, or the BSD license, at your option.
- *
- *  a) This library is free software; you can redistribute it and/or
- *     modify it under the terms of the GNU General Public License as
- *     published by the Free Software Foundation; either version 2 of the
- *     License, or (at your option) any later version.
- *
- *     This library is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- *
- *     You should have received a copy of the GNU General Public
- *     License along with this library; if not, write to the Free
- *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
- *     MA 02110-1301 USA
- *
- * Alternatively,
- *
- *  b) Redistribution and use in source and binary forms, with or
- *     without modification, are permitted provided that the following
- *     conditions are met:
- *
- *     1. Redistributions of source code must retain the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer.
- *     2. Redistributions in binary form must reproduce the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer in the documentation and/or other materials
- *        provided with the distribution.
- *
- *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "libfdt_env.h"
-
-#include <fdt.h>
-#include <libfdt.h>
-
-#include "libfdt_internal.h"
-
-int fdt_create_empty_tree(void *buf, int bufsize)
-{
-       int err;
-
-       err = fdt_create(buf, bufsize);
-       if (err)
-               return err;
-
-       err = fdt_finish_reservemap(buf);
-       if (err)
-               return err;
-
-       err = fdt_begin_node(buf, "");
-       if (err)
-               return err;
-
-       err =  fdt_end_node(buf);
-       if (err)
-               return err;
-
-       err = fdt_finish(buf);
-       if (err)
-               return err;
-
-       return fdt_open_into(buf, buf, bufsize);
-}
-
+/*\r
+ * libfdt - Flat Device Tree manipulation\r
+ * Copyright (C) 2012 David Gibson, IBM Corporation.\r
+ *\r
+ * libfdt is dual licensed: you can use it either under the terms of\r
+ * the GPL, or the BSD license, at your option.\r
+ *\r
+ *  a) This library is free software; you can redistribute it and/or\r
+ *     modify it under the terms of the GNU General Public License as\r
+ *     published by the Free Software Foundation; either version 2 of the\r
+ *     License, or (at your option) any later version.\r
+ *\r
+ *     This library is distributed in the hope that it will be useful,\r
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ *     GNU General Public License for more details.\r
+ *\r
+ *     You should have received a copy of the GNU General Public\r
+ *     License along with this library; if not, write to the Free\r
+ *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\r
+ *     MA 02110-1301 USA\r
+ *\r
+ * Alternatively,\r
+ *\r
+ *  b) Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *     1. Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *     2. Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\r
+ *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,\r
+ *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
+ *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+ *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
+ *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
+ *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
+ *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#include "libfdt_env.h"\r
+\r
+#include <fdt.h>\r
+#include <libfdt.h>\r
+\r
+#include "libfdt_internal.h"\r
+\r
+int fdt_create_empty_tree(void *buf, int bufsize)\r
+{\r
+       int err;\r
+\r
+       err = fdt_create(buf, bufsize);\r
+       if (err)\r
+               return err;\r
+\r
+       err = fdt_finish_reservemap(buf);\r
+       if (err)\r
+               return err;\r
+\r
+       err = fdt_begin_node(buf, "");\r
+       if (err)\r
+               return err;\r
+\r
+       err =  fdt_end_node(buf);\r
+       if (err)\r
+               return err;\r
+\r
+       err = fdt_finish(buf);\r
+       if (err)\r
+               return err;\r
+\r
+       return fdt_open_into(buf, buf, bufsize);\r
+}\r
+\r
index 95fdbeadd4c3017ed1fa15dc50e4eda2b70b4f23..9ae6b5ecc55626c943f9e12a61810e05cfdf5a3b 100644 (file)
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2006 David Gibson, IBM Corporation.
- *
- * libfdt is dual licensed: you can use it either under the terms of
- * the GPL, or the BSD license, at your option.
- *
- *  a) This library is free software; you can redistribute it and/or
- *     modify it under the terms of the GNU General Public License as
- *     published by the Free Software Foundation; either version 2 of the
- *     License, or (at your option) any later version.
- *
- *     This library is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- *
- *     You should have received a copy of the GNU General Public
- *     License along with this library; if not, write to the Free
- *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
- *     MA 02110-1301 USA
- *
- * Alternatively,
- *
- *  b) Redistribution and use in source and binary forms, with or
- *     without modification, are permitted provided that the following
- *     conditions are met:
- *
- *     1. Redistributions of source code must retain the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer.
- *     2. Redistributions in binary form must reproduce the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer in the documentation and/or other materials
- *        provided with the distribution.
- *
- *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "libfdt_env.h"
-
-#include <fdt.h>
-#include <libfdt.h>
-
-#include "libfdt_internal.h"
-
-static int _fdt_nodename_eq(const void *fdt, int offset,
-                           const char *s, int len)
-{
-       const char *p = fdt_offset_ptr(fdt, offset + FDT_TAGSIZE, len+1);
-
-       if (! p)
-               /* short match */
-               return 0;
-
-       if (memcmp(p, s, len) != 0)
-               return 0;
-
-       if (p[len] == '\0')
-               return 1;
-       else if (!memchr(s, '@', len) && (p[len] == '@'))
-               return 1;
-       else
-               return 0;
-}
-
-const char *fdt_string(const void *fdt, int stroffset)
-{
-       return (const char *)fdt + fdt_off_dt_strings(fdt) + stroffset;
-}
-
-static int _fdt_string_eq(const void *fdt, int stroffset,
-                         const char *s, int len)
-{
-       const char *p = fdt_string(fdt, stroffset);
-
-       return (strlen(p) == len) && (memcmp(p, s, len) == 0);
-}
-
-int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size)
-{
-       FDT_CHECK_HEADER(fdt);
-       *address = fdt64_to_cpu(_fdt_mem_rsv(fdt, n)->address);
-       *size = fdt64_to_cpu(_fdt_mem_rsv(fdt, n)->size);
-       return 0;
-}
-
-int fdt_num_mem_rsv(const void *fdt)
-{
-       int i = 0;
-
-       while (fdt64_to_cpu(_fdt_mem_rsv(fdt, i)->size) != 0)
-               i++;
-       return i;
-}
-
-static int _nextprop(const void *fdt, int offset)
-{
-       uint32_t tag;
-       int nextoffset;
-
-       do {
-               tag = fdt_next_tag(fdt, offset, &nextoffset);
-
-               switch (tag) {
-               case FDT_END:
-                       if (nextoffset >= 0)
-                               return -FDT_ERR_BADSTRUCTURE;
-                       else
-                               return nextoffset;
-
-               case FDT_PROP:
-                       return offset;
-               }
-               offset = nextoffset;
-       } while (tag == FDT_NOP);
-
-       return -FDT_ERR_NOTFOUND;
-}
-
-int fdt_subnode_offset_namelen(const void *fdt, int offset,
-                              const char *name, int namelen)
-{
-       int depth;
-
-       FDT_CHECK_HEADER(fdt);
-
-       for (depth = 0;
-            (offset >= 0) && (depth >= 0);
-            offset = fdt_next_node(fdt, offset, &depth))
-               if ((depth == 1)
-                   && _fdt_nodename_eq(fdt, offset, name, namelen))
-                       return offset;
-
-       if (depth < 0)
-               return -FDT_ERR_NOTFOUND;
-       return offset; /* error */
-}
-
-int fdt_subnode_offset(const void *fdt, int parentoffset,
-                      const char *name)
-{
-       return fdt_subnode_offset_namelen(fdt, parentoffset, name, strlen(name));
-}
-
-int fdt_path_offset(const void *fdt, const char *path)
-{
-       const char *end = path + strlen(path);
-       const char *p = path;
-       int offset = 0;
-
-       FDT_CHECK_HEADER(fdt);
-
-       /* see if we have an alias */
-       if (*path != '/') {
-               const char *q = strchr(path, '/');
-
-               if (!q)
-                       q = end;
-
-               p = fdt_get_alias_namelen(fdt, p, q - p);
-               if (!p)
-                       return -FDT_ERR_BADPATH;
-               offset = fdt_path_offset(fdt, p);
-
-               p = q;
-       }
-
-       while (*p) {
-               const char *q;
-
-               while (*p == '/')
-                       p++;
-               if (! *p)
-                       return offset;
-               q = strchr(p, '/');
-               if (! q)
-                       q = end;
-
-               offset = fdt_subnode_offset_namelen(fdt, offset, p, q-p);
-               if (offset < 0)
-                       return offset;
-
-               p = q;
-       }
-
-       return offset;
-}
-
-const char *fdt_get_name(const void *fdt, int nodeoffset, int *len)
-{
-       const struct fdt_node_header *nh = _fdt_offset_ptr(fdt, nodeoffset);
-       int err;
-
-       if (((err = fdt_check_header(fdt)) != 0)
-           || ((err = _fdt_check_node_offset(fdt, nodeoffset)) < 0))
-                       goto fail;
-
-       if (len)
-               *len = strlen(nh->name);
-
-       return nh->name;
-
- fail:
-       if (len)
-               *len = err;
-       return NULL;
-}
-
-int fdt_first_property_offset(const void *fdt, int nodeoffset)
-{
-       int offset;
-
-       if ((offset = _fdt_check_node_offset(fdt, nodeoffset)) < 0)
-               return offset;
-
-       return _nextprop(fdt, offset);
-}
-
-int fdt_next_property_offset(const void *fdt, int offset)
-{
-       if ((offset = _fdt_check_prop_offset(fdt, offset)) < 0)
-               return offset;
-
-       return _nextprop(fdt, offset);
-}
-
-const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
-                                                     int offset,
-                                                     int *lenp)
-{
-       int err;
-       const struct fdt_property *prop;
-
-       if ((err = _fdt_check_prop_offset(fdt, offset)) < 0) {
-               if (lenp)
-                       *lenp = err;
-               return NULL;
-       }
-
-       prop = _fdt_offset_ptr(fdt, offset);
-
-       if (lenp)
-               *lenp = fdt32_to_cpu(prop->len);
-
-       return prop;
-}
-
-const struct fdt_property *fdt_get_property_namelen(const void *fdt,
-                                                   int offset,
-                                                   const char *name,
-                                                   int namelen, int *lenp)
-{
-       for (offset = fdt_first_property_offset(fdt, offset);
-            (offset >= 0);
-            (offset = fdt_next_property_offset(fdt, offset))) {
-               const struct fdt_property *prop;
-
-               prop = fdt_get_property_by_offset(fdt, offset, lenp);
-               if (!prop) {
-                       offset = -FDT_ERR_INTERNAL;
-                       break;
-               }
-               if (_fdt_string_eq(fdt, fdt32_to_cpu(prop->nameoff),
-                                  name, namelen))
-                       return prop;
-       }
-
-       if (lenp)
-               *lenp = offset;
-       return NULL;
-}
-
-const struct fdt_property *fdt_get_property(const void *fdt,
-                                           int nodeoffset,
-                                           const char *name, int *lenp)
-{
-       return fdt_get_property_namelen(fdt, nodeoffset, name,
-                                       strlen(name), lenp);
-}
-
-const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
-                               const char *name, int namelen, int *lenp)
-{
-       const struct fdt_property *prop;
-
-       prop = fdt_get_property_namelen(fdt, nodeoffset, name, namelen, lenp);
-       if (! prop)
-               return NULL;
-
-       return prop->data;
-}
-
-const void *fdt_getprop_by_offset(const void *fdt, int offset,
-                                 const char **namep, int *lenp)
-{
-       const struct fdt_property *prop;
-
-       prop = fdt_get_property_by_offset(fdt, offset, lenp);
-       if (!prop)
-               return NULL;
-       if (namep)
-               *namep = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
-       return prop->data;
-}
-
-const void *fdt_getprop(const void *fdt, int nodeoffset,
-                       const char *name, int *lenp)
-{
-       return fdt_getprop_namelen(fdt, nodeoffset, name, strlen(name), lenp);
-}
-
-uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
-{
-       const uint32_t *php;
-       int len;
-
-       /* FIXME: This is a bit sub-optimal, since we potentially scan
-        * over all the properties twice. */
-       php = fdt_getprop(fdt, nodeoffset, "phandle", &len);
-       if (!php || (len != sizeof(*php))) {
-               php = fdt_getprop(fdt, nodeoffset, "linux,phandle", &len);
-               if (!php || (len != sizeof(*php)))
-                       return 0;
-       }
-
-       return fdt32_to_cpu(*php);
-}
-
-const char *fdt_get_alias_namelen(const void *fdt,
-                                 const char *name, int namelen)
-{
-       int aliasoffset;
-
-       aliasoffset = fdt_path_offset(fdt, "/aliases");
-       if (aliasoffset < 0)
-               return NULL;
-
-       return fdt_getprop_namelen(fdt, aliasoffset, name, namelen, NULL);
-}
-
-const char *fdt_get_alias(const void *fdt, const char *name)
-{
-       return fdt_get_alias_namelen(fdt, name, strlen(name));
-}
-
-int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)
-{
-       int pdepth = 0, p = 0;
-       int offset, depth, namelen;
-       const char *name;
-
-       FDT_CHECK_HEADER(fdt);
-
-       if (buflen < 2)
-               return -FDT_ERR_NOSPACE;
-
-       for (offset = 0, depth = 0;
-            (offset >= 0) && (offset <= nodeoffset);
-            offset = fdt_next_node(fdt, offset, &depth)) {
-               while (pdepth > depth) {
-                       do {
-                               p--;
-                       } while (buf[p-1] != '/');
-                       pdepth--;
-               }
-
-               if (pdepth >= depth) {
-                       name = fdt_get_name(fdt, offset, &namelen);
-                       if (!name)
-                               return namelen;
-                       if ((p + namelen + 1) <= buflen) {
-                               memcpy(buf + p, name, namelen);
-                               p += namelen;
-                               buf[p++] = '/';
-                               pdepth++;
-                       }
-               }
-
-               if (offset == nodeoffset) {
-                       if (pdepth < (depth + 1))
-                               return -FDT_ERR_NOSPACE;
-
-                       if (p > 1) /* special case so that root path is "/", not "" */
-                               p--;
-                       buf[p] = '\0';
-                       return 0;
-               }
-       }
-
-       if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0))
-               return -FDT_ERR_BADOFFSET;
-       else if (offset == -FDT_ERR_BADOFFSET)
-               return -FDT_ERR_BADSTRUCTURE;
-
-       return offset; /* error from fdt_next_node() */
-}
-
-int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
-                                int supernodedepth, int *nodedepth)
-{
-       int offset, depth;
-       int supernodeoffset = -FDT_ERR_INTERNAL;
-
-       FDT_CHECK_HEADER(fdt);
-
-       if (supernodedepth < 0)
-               return -FDT_ERR_NOTFOUND;
-
-       for (offset = 0, depth = 0;
-            (offset >= 0) && (offset <= nodeoffset);
-            offset = fdt_next_node(fdt, offset, &depth)) {
-               if (depth == supernodedepth)
-                       supernodeoffset = offset;
-
-               if (offset == nodeoffset) {
-                       if (nodedepth)
-                               *nodedepth = depth;
-
-                       if (supernodedepth > depth)
-                               return -FDT_ERR_NOTFOUND;
-                       else
-                               return supernodeoffset;
-               }
-       }
-
-       if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0))
-               return -FDT_ERR_BADOFFSET;
-       else if (offset == -FDT_ERR_BADOFFSET)
-               return -FDT_ERR_BADSTRUCTURE;
-
-       return offset; /* error from fdt_next_node() */
-}
-
-int fdt_node_depth(const void *fdt, int nodeoffset)
-{
-       int nodedepth;
-       int err;
-
-       err = fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, &nodedepth);
-       if (err)
-               return (err < 0) ? err : -FDT_ERR_INTERNAL;
-       return nodedepth;
-}
-
-int fdt_parent_offset(const void *fdt, int nodeoffset)
-{
-       int nodedepth = fdt_node_depth(fdt, nodeoffset);
-
-       if (nodedepth < 0)
-               return nodedepth;
-       return fdt_supernode_atdepth_offset(fdt, nodeoffset,
-                                           nodedepth - 1, NULL);
-}
-
-int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
-                                 const char *propname,
-                                 const void *propval, int proplen)
-{
-       int offset;
-       const void *val;
-       int len;
-
-       FDT_CHECK_HEADER(fdt);
-
-       /* FIXME: The algorithm here is pretty horrible: we scan each
-        * property of a node in fdt_getprop(), then if that didn't
-        * find what we want, we scan over them again making our way
-        * to the next node.  Still it's the easiest to implement
-        * approach; performance can come later. */
-       for (offset = fdt_next_node(fdt, startoffset, NULL);
-            offset >= 0;
-            offset = fdt_next_node(fdt, offset, NULL)) {
-               val = fdt_getprop(fdt, offset, propname, &len);
-               if (val && (len == proplen)
-                   && (memcmp(val, propval, len) == 0))
-                       return offset;
-       }
-
-       return offset; /* error from fdt_next_node() */
-}
-
-int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle)
-{
-       int offset;
-
-       if ((phandle == 0) || (phandle == (uint32_t)-1))
-               return -FDT_ERR_BADPHANDLE;
-
-       FDT_CHECK_HEADER(fdt);
-
-       /* FIXME: The algorithm here is pretty horrible: we
-        * potentially scan each property of a node in
-        * fdt_get_phandle(), then if that didn't find what
-        * we want, we scan over them again making our way to the next
-        * node.  Still it's the easiest to implement approach;
-        * performance can come later. */
-       for (offset = fdt_next_node(fdt, -1, NULL);
-            offset >= 0;
-            offset = fdt_next_node(fdt, offset, NULL)) {
-               if (fdt_get_phandle(fdt, offset) == phandle)
-                       return offset;
-       }
-
-       return offset; /* error from fdt_next_node() */
-}
-
-static int _fdt_stringlist_contains(const char *strlist, int listlen,
-                                   const char *str)
-{
-       int len = strlen(str);
-       const char *p;
-
-       while (listlen >= len) {
-               if (memcmp(str, strlist, len+1) == 0)
-                       return 1;
-               p = memchr(strlist, '\0', listlen);
-               if (!p)
-                       return 0; /* malformed strlist.. */
-               listlen -= (p-strlist) + 1;
-               strlist = p + 1;
-       }
-       return 0;
-}
-
-int fdt_node_check_compatible(const void *fdt, int nodeoffset,
-                             const char *compatible)
-{
-       const void *prop;
-       int len;
-
-       prop = fdt_getprop(fdt, nodeoffset, "compatible", &len);
-       if (!prop)
-               return len;
-       if (_fdt_stringlist_contains(prop, len, compatible))
-               return 0;
-       else
-               return 1;
-}
-
-int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
-                                 const char *compatible)
-{
-       int offset, err;
-
-       FDT_CHECK_HEADER(fdt);
-
-       /* FIXME: The algorithm here is pretty horrible: we scan each
-        * property of a node in fdt_node_check_compatible(), then if
-        * that didn't find what we want, we scan over them again
-        * making our way to the next node.  Still it's the easiest to
-        * implement approach; performance can come later. */
-       for (offset = fdt_next_node(fdt, startoffset, NULL);
-            offset >= 0;
-            offset = fdt_next_node(fdt, offset, NULL)) {
-               err = fdt_node_check_compatible(fdt, offset, compatible);
-               if ((err < 0) && (err != -FDT_ERR_NOTFOUND))
-                       return err;
-               else if (err == 0)
-                       return offset;
-       }
-
-       return offset; /* error from fdt_next_node() */
-}
+/*\r
+ * libfdt - Flat Device Tree manipulation\r
+ * Copyright (C) 2006 David Gibson, IBM Corporation.\r
+ *\r
+ * libfdt is dual licensed: you can use it either under the terms of\r
+ * the GPL, or the BSD license, at your option.\r
+ *\r
+ *  a) This library is free software; you can redistribute it and/or\r
+ *     modify it under the terms of the GNU General Public License as\r
+ *     published by the Free Software Foundation; either version 2 of the\r
+ *     License, or (at your option) any later version.\r
+ *\r
+ *     This library is distributed in the hope that it will be useful,\r
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ *     GNU General Public License for more details.\r
+ *\r
+ *     You should have received a copy of the GNU General Public\r
+ *     License along with this library; if not, write to the Free\r
+ *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\r
+ *     MA 02110-1301 USA\r
+ *\r
+ * Alternatively,\r
+ *\r
+ *  b) Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *     1. Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *     2. Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\r
+ *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,\r
+ *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
+ *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+ *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
+ *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
+ *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
+ *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#include "libfdt_env.h"\r
+\r
+#include <fdt.h>\r
+#include <libfdt.h>\r
+\r
+#include "libfdt_internal.h"\r
+\r
+static int _fdt_nodename_eq(const void *fdt, int offset,\r
+                           const char *s, int len)\r
+{\r
+       const char *p = fdt_offset_ptr(fdt, offset + FDT_TAGSIZE, len+1);\r
+\r
+       if (! p)\r
+               /* short match */\r
+               return 0;\r
+\r
+       if (memcmp(p, s, len) != 0)\r
+               return 0;\r
+\r
+       if (p[len] == '\0')\r
+               return 1;\r
+       else if (!memchr(s, '@', len) && (p[len] == '@'))\r
+               return 1;\r
+       else\r
+               return 0;\r
+}\r
+\r
+const char *fdt_string(const void *fdt, int stroffset)\r
+{\r
+       return (const char *)fdt + fdt_off_dt_strings(fdt) + stroffset;\r
+}\r
+\r
+static int _fdt_string_eq(const void *fdt, int stroffset,\r
+                         const char *s, int len)\r
+{\r
+       const char *p = fdt_string(fdt, stroffset);\r
+\r
+       return (strlen(p) == len) && (memcmp(p, s, len) == 0);\r
+}\r
+\r
+int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size)\r
+{\r
+       FDT_CHECK_HEADER(fdt);\r
+       *address = fdt64_to_cpu(_fdt_mem_rsv(fdt, n)->address);\r
+       *size = fdt64_to_cpu(_fdt_mem_rsv(fdt, n)->size);\r
+       return 0;\r
+}\r
+\r
+int fdt_num_mem_rsv(const void *fdt)\r
+{\r
+       int i = 0;\r
+\r
+       while (fdt64_to_cpu(_fdt_mem_rsv(fdt, i)->size) != 0)\r
+               i++;\r
+       return i;\r
+}\r
+\r
+static int _nextprop(const void *fdt, int offset)\r
+{\r
+       uint32_t tag;\r
+       int nextoffset;\r
+\r
+       do {\r
+               tag = fdt_next_tag(fdt, offset, &nextoffset);\r
+\r
+               switch (tag) {\r
+               case FDT_END:\r
+                       if (nextoffset >= 0)\r
+                               return -FDT_ERR_BADSTRUCTURE;\r
+                       else\r
+                               return nextoffset;\r
+\r
+               case FDT_PROP:\r
+                       return offset;\r
+               }\r
+               offset = nextoffset;\r
+       } while (tag == FDT_NOP);\r
+\r
+       return -FDT_ERR_NOTFOUND;\r
+}\r
+\r
+int fdt_subnode_offset_namelen(const void *fdt, int offset,\r
+                              const char *name, int namelen)\r
+{\r
+       int depth;\r
+\r
+       FDT_CHECK_HEADER(fdt);\r
+\r
+       for (depth = 0;\r
+            (offset >= 0) && (depth >= 0);\r
+            offset = fdt_next_node(fdt, offset, &depth))\r
+               if ((depth == 1)\r
+                   && _fdt_nodename_eq(fdt, offset, name, namelen))\r
+                       return offset;\r
+\r
+       if (depth < 0)\r
+               return -FDT_ERR_NOTFOUND;\r
+       return offset; /* error */\r
+}\r
+\r
+int fdt_subnode_offset(const void *fdt, int parentoffset,\r
+                      const char *name)\r
+{\r
+       return fdt_subnode_offset_namelen(fdt, parentoffset, name, strlen(name));\r
+}\r
+\r
+int fdt_path_offset(const void *fdt, const char *path)\r
+{\r
+       const char *end = path + strlen(path);\r
+       const char *p = path;\r
+       int offset = 0;\r
+\r
+       FDT_CHECK_HEADER(fdt);\r
+\r
+       /* see if we have an alias */\r
+       if (*path != '/') {\r
+               const char *q = strchr(path, '/');\r
+\r
+               if (!q)\r
+                       q = end;\r
+\r
+               p = fdt_get_alias_namelen(fdt, p, q - p);\r
+               if (!p)\r
+                       return -FDT_ERR_BADPATH;\r
+               offset = fdt_path_offset(fdt, p);\r
+\r
+               p = q;\r
+       }\r
+\r
+       while (*p) {\r
+               const char *q;\r
+\r
+               while (*p == '/')\r
+                       p++;\r
+               if (! *p)\r
+                       return offset;\r
+               q = strchr(p, '/');\r
+               if (! q)\r
+                       q = end;\r
+\r
+               offset = fdt_subnode_offset_namelen(fdt, offset, p, q-p);\r
+               if (offset < 0)\r
+                       return offset;\r
+\r
+               p = q;\r
+       }\r
+\r
+       return offset;\r
+}\r
+\r
+const char *fdt_get_name(const void *fdt, int nodeoffset, int *len)\r
+{\r
+       const struct fdt_node_header *nh = _fdt_offset_ptr(fdt, nodeoffset);\r
+       int err;\r
+\r
+       if (((err = fdt_check_header(fdt)) != 0)\r
+           || ((err = _fdt_check_node_offset(fdt, nodeoffset)) < 0))\r
+                       goto fail;\r
+\r
+       if (len)\r
+               *len = strlen(nh->name);\r
+\r
+       return nh->name;\r
+\r
+ fail:\r
+       if (len)\r
+               *len = err;\r
+       return NULL;\r
+}\r
+\r
+int fdt_first_property_offset(const void *fdt, int nodeoffset)\r
+{\r
+       int offset;\r
+\r
+       if ((offset = _fdt_check_node_offset(fdt, nodeoffset)) < 0)\r
+               return offset;\r
+\r
+       return _nextprop(fdt, offset);\r
+}\r
+\r
+int fdt_next_property_offset(const void *fdt, int offset)\r
+{\r
+       if ((offset = _fdt_check_prop_offset(fdt, offset)) < 0)\r
+               return offset;\r
+\r
+       return _nextprop(fdt, offset);\r
+}\r
+\r
+const struct fdt_property *fdt_get_property_by_offset(const void *fdt,\r
+                                                     int offset,\r
+                                                     int *lenp)\r
+{\r
+       int err;\r
+       const struct fdt_property *prop;\r
+\r
+       if ((err = _fdt_check_prop_offset(fdt, offset)) < 0) {\r
+               if (lenp)\r
+                       *lenp = err;\r
+               return NULL;\r
+       }\r
+\r
+       prop = _fdt_offset_ptr(fdt, offset);\r
+\r
+       if (lenp)\r
+               *lenp = fdt32_to_cpu(prop->len);\r
+\r
+       return prop;\r
+}\r
+\r
+const struct fdt_property *fdt_get_property_namelen(const void *fdt,\r
+                                                   int offset,\r
+                                                   const char *name,\r
+                                                   int namelen, int *lenp)\r
+{\r
+       for (offset = fdt_first_property_offset(fdt, offset);\r
+            (offset >= 0);\r
+            (offset = fdt_next_property_offset(fdt, offset))) {\r
+               const struct fdt_property *prop;\r
+\r
+               prop = fdt_get_property_by_offset(fdt, offset, lenp);\r
+               if (!prop) {\r
+                       offset = -FDT_ERR_INTERNAL;\r
+                       break;\r
+               }\r
+               if (_fdt_string_eq(fdt, fdt32_to_cpu(prop->nameoff),\r
+                                  name, namelen))\r
+                       return prop;\r
+       }\r
+\r
+       if (lenp)\r
+               *lenp = offset;\r
+       return NULL;\r
+}\r
+\r
+const struct fdt_property *fdt_get_property(const void *fdt,\r
+                                           int nodeoffset,\r
+                                           const char *name, int *lenp)\r
+{\r
+       return fdt_get_property_namelen(fdt, nodeoffset, name,\r
+                                       strlen(name), lenp);\r
+}\r
+\r
+const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,\r
+                               const char *name, int namelen, int *lenp)\r
+{\r
+       const struct fdt_property *prop;\r
+\r
+       prop = fdt_get_property_namelen(fdt, nodeoffset, name, namelen, lenp);\r
+       if (! prop)\r
+               return NULL;\r
+\r
+       return prop->data;\r
+}\r
+\r
+const void *fdt_getprop_by_offset(const void *fdt, int offset,\r
+                                 const char **namep, int *lenp)\r
+{\r
+       const struct fdt_property *prop;\r
+\r
+       prop = fdt_get_property_by_offset(fdt, offset, lenp);\r
+       if (!prop)\r
+               return NULL;\r
+       if (namep)\r
+               *namep = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));\r
+       return prop->data;\r
+}\r
+\r
+const void *fdt_getprop(const void *fdt, int nodeoffset,\r
+                       const char *name, int *lenp)\r
+{\r
+       return fdt_getprop_namelen(fdt, nodeoffset, name, strlen(name), lenp);\r
+}\r
+\r
+uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)\r
+{\r
+       const uint32_t *php;\r
+       int len;\r
+\r
+       /* FIXME: This is a bit sub-optimal, since we potentially scan\r
+        * over all the properties twice. */\r
+       php = fdt_getprop(fdt, nodeoffset, "phandle", &len);\r
+       if (!php || (len != sizeof(*php))) {\r
+               php = fdt_getprop(fdt, nodeoffset, "linux,phandle", &len);\r
+               if (!php || (len != sizeof(*php)))\r
+                       return 0;\r
+       }\r
+\r
+       return fdt32_to_cpu(*php);\r
+}\r
+\r
+const char *fdt_get_alias_namelen(const void *fdt,\r
+                                 const char *name, int namelen)\r
+{\r
+       int aliasoffset;\r
+\r
+       aliasoffset = fdt_path_offset(fdt, "/aliases");\r
+       if (aliasoffset < 0)\r
+               return NULL;\r
+\r
+       return fdt_getprop_namelen(fdt, aliasoffset, name, namelen, NULL);\r
+}\r
+\r
+const char *fdt_get_alias(const void *fdt, const char *name)\r
+{\r
+       return fdt_get_alias_namelen(fdt, name, strlen(name));\r
+}\r
+\r
+int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)\r
+{\r
+       int pdepth = 0, p = 0;\r
+       int offset, depth, namelen;\r
+       const char *name;\r
+\r
+       FDT_CHECK_HEADER(fdt);\r
+\r
+       if (buflen < 2)\r
+               return -FDT_ERR_NOSPACE;\r
+\r
+       for (offset = 0, depth = 0;\r
+            (offset >= 0) && (offset <= nodeoffset);\r
+            offset = fdt_next_node(fdt, offset, &depth)) {\r
+               while (pdepth > depth) {\r
+                       do {\r
+                               p--;\r
+                       } while (buf[p-1] != '/');\r
+                       pdepth--;\r
+               }\r
+\r
+               if (pdepth >= depth) {\r
+                       name = fdt_get_name(fdt, offset, &namelen);\r
+                       if (!name)\r
+                               return namelen;\r
+                       if ((p + namelen + 1) <= buflen) {\r
+                               memcpy(buf + p, name, namelen);\r
+                               p += namelen;\r
+                               buf[p++] = '/';\r
+                               pdepth++;\r
+                       }\r
+               }\r
+\r
+               if (offset == nodeoffset) {\r
+                       if (pdepth < (depth + 1))\r
+                               return -FDT_ERR_NOSPACE;\r
+\r
+                       if (p > 1) /* special case so that root path is "/", not "" */\r
+                               p--;\r
+                       buf[p] = '\0';\r
+                       return 0;\r
+               }\r
+       }\r
+\r
+       if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0))\r
+               return -FDT_ERR_BADOFFSET;\r
+       else if (offset == -FDT_ERR_BADOFFSET)\r
+               return -FDT_ERR_BADSTRUCTURE;\r
+\r
+       return offset; /* error from fdt_next_node() */\r
+}\r
+\r
+int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,\r
+                                int supernodedepth, int *nodedepth)\r
+{\r
+       int offset, depth;\r
+       int supernodeoffset = -FDT_ERR_INTERNAL;\r
+\r
+       FDT_CHECK_HEADER(fdt);\r
+\r
+       if (supernodedepth < 0)\r
+               return -FDT_ERR_NOTFOUND;\r
+\r
+       for (offset = 0, depth = 0;\r
+            (offset >= 0) && (offset <= nodeoffset);\r
+            offset = fdt_next_node(fdt, offset, &depth)) {\r
+               if (depth == supernodedepth)\r
+                       supernodeoffset = offset;\r
+\r
+               if (offset == nodeoffset) {\r
+                       if (nodedepth)\r
+                               *nodedepth = depth;\r
+\r
+                       if (supernodedepth > depth)\r
+                               return -FDT_ERR_NOTFOUND;\r
+                       else\r
+                               return supernodeoffset;\r
+               }\r
+       }\r
+\r
+       if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0))\r
+               return -FDT_ERR_BADOFFSET;\r
+       else if (offset == -FDT_ERR_BADOFFSET)\r
+               return -FDT_ERR_BADSTRUCTURE;\r
+\r
+       return offset; /* error from fdt_next_node() */\r
+}\r
+\r
+int fdt_node_depth(const void *fdt, int nodeoffset)\r
+{\r
+       int nodedepth;\r
+       int err;\r
+\r
+       err = fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, &nodedepth);\r
+       if (err)\r
+               return (err < 0) ? err : -FDT_ERR_INTERNAL;\r
+       return nodedepth;\r
+}\r
+\r
+int fdt_parent_offset(const void *fdt, int nodeoffset)\r
+{\r
+       int nodedepth = fdt_node_depth(fdt, nodeoffset);\r
+\r
+       if (nodedepth < 0)\r
+               return nodedepth;\r
+       return fdt_supernode_atdepth_offset(fdt, nodeoffset,\r
+                                           nodedepth - 1, NULL);\r
+}\r
+\r
+int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,\r
+                                 const char *propname,\r
+                                 const void *propval, int proplen)\r
+{\r
+       int offset;\r
+       const void *val;\r
+       int len;\r
+\r
+       FDT_CHECK_HEADER(fdt);\r
+\r
+       /* FIXME: The algorithm here is pretty horrible: we scan each\r
+        * property of a node in fdt_getprop(), then if that didn't\r
+        * find what we want, we scan over them again making our way\r
+        * to the next node.  Still it's the easiest to implement\r
+        * approach; performance can come later. */\r
+       for (offset = fdt_next_node(fdt, startoffset, NULL);\r
+            offset >= 0;\r
+            offset = fdt_next_node(fdt, offset, NULL)) {\r
+               val = fdt_getprop(fdt, offset, propname, &len);\r
+               if (val && (len == proplen)\r
+                   && (memcmp(val, propval, len) == 0))\r
+                       return offset;\r
+       }\r
+\r
+       return offset; /* error from fdt_next_node() */\r
+}\r
+\r
+int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle)\r
+{\r
+       int offset;\r
+\r
+       if ((phandle == 0) || (phandle == (uint32_t)-1))\r
+               return -FDT_ERR_BADPHANDLE;\r
+\r
+       FDT_CHECK_HEADER(fdt);\r
+\r
+       /* FIXME: The algorithm here is pretty horrible: we\r
+        * potentially scan each property of a node in\r
+        * fdt_get_phandle(), then if that didn't find what\r
+        * we want, we scan over them again making our way to the next\r
+        * node.  Still it's the easiest to implement approach;\r
+        * performance can come later. */\r
+       for (offset = fdt_next_node(fdt, -1, NULL);\r
+            offset >= 0;\r
+            offset = fdt_next_node(fdt, offset, NULL)) {\r
+               if (fdt_get_phandle(fdt, offset) == phandle)\r
+                       return offset;\r
+       }\r
+\r
+       return offset; /* error from fdt_next_node() */\r
+}\r
+\r
+static int _fdt_stringlist_contains(const char *strlist, int listlen,\r
+                                   const char *str)\r
+{\r
+       int len = strlen(str);\r
+       const char *p;\r
+\r
+       while (listlen >= len) {\r
+               if (memcmp(str, strlist, len+1) == 0)\r
+                       return 1;\r
+               p = memchr(strlist, '\0', listlen);\r
+               if (!p)\r
+                       return 0; /* malformed strlist.. */\r
+               listlen -= (p-strlist) + 1;\r
+               strlist = p + 1;\r
+       }\r
+       return 0;\r
+}\r
+\r
+int fdt_node_check_compatible(const void *fdt, int nodeoffset,\r
+                             const char *compatible)\r
+{\r
+       const void *prop;\r
+       int len;\r
+\r
+       prop = fdt_getprop(fdt, nodeoffset, "compatible", &len);\r
+       if (!prop)\r
+               return len;\r
+       if (_fdt_stringlist_contains(prop, len, compatible))\r
+               return 0;\r
+       else\r
+               return 1;\r
+}\r
+\r
+int fdt_node_offset_by_compatible(const void *fdt, int startoffset,\r
+                                 const char *compatible)\r
+{\r
+       int offset, err;\r
+\r
+       FDT_CHECK_HEADER(fdt);\r
+\r
+       /* FIXME: The algorithm here is pretty horrible: we scan each\r
+        * property of a node in fdt_node_check_compatible(), then if\r
+        * that didn't find what we want, we scan over them again\r
+        * making our way to the next node.  Still it's the easiest to\r
+        * implement approach; performance can come later. */\r
+       for (offset = fdt_next_node(fdt, startoffset, NULL);\r
+            offset >= 0;\r
+            offset = fdt_next_node(fdt, offset, NULL)) {\r
+               err = fdt_node_check_compatible(fdt, offset, compatible);\r
+               if ((err < 0) && (err != -FDT_ERR_NOTFOUND))\r
+                       return err;\r
+               else if (err == 0)\r
+                       return offset;\r
+       }\r
+\r
+       return offset; /* error from fdt_next_node() */\r
+}\r
index 878a775a7b012d4e08ce2a3a8fd6a304f4e3bd26..1d95a73ec137d79aed229de064e614514abcbaaf 100644 (file)
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2006 David Gibson, IBM Corporation.
- *
- * libfdt is dual licensed: you can use it either under the terms of
- * the GPL, or the BSD license, at your option.
- *
- *  a) This library is free software; you can redistribute it and/or
- *     modify it under the terms of the GNU General Public License as
- *     published by the Free Software Foundation; either version 2 of the
- *     License, or (at your option) any later version.
- *
- *     This library is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- *
- *     You should have received a copy of the GNU General Public
- *     License along with this library; if not, write to the Free
- *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
- *     MA 02110-1301 USA
- *
- * Alternatively,
- *
- *  b) Redistribution and use in source and binary forms, with or
- *     without modification, are permitted provided that the following
- *     conditions are met:
- *
- *     1. Redistributions of source code must retain the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer.
- *     2. Redistributions in binary form must reproduce the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer in the documentation and/or other materials
- *        provided with the distribution.
- *
- *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "libfdt_env.h"
-
-#include <fdt.h>
-#include <libfdt.h>
-
-#include "libfdt_internal.h"
-
-static int _fdt_blocks_misordered(const void *fdt,
-                             int mem_rsv_size, int struct_size)
-{
-       return (fdt_off_mem_rsvmap(fdt) < FDT_ALIGN(sizeof(struct fdt_header), 8))
-               || (fdt_off_dt_struct(fdt) <
-                   (fdt_off_mem_rsvmap(fdt) + mem_rsv_size))
-               || (fdt_off_dt_strings(fdt) <
-                   (fdt_off_dt_struct(fdt) + struct_size))
-               || (fdt_totalsize(fdt) <
-                   (fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt)));
-}
-
-static int _fdt_rw_check_header(void *fdt)
-{
-       FDT_CHECK_HEADER(fdt);
-
-       if (fdt_version(fdt) < 17)
-               return -FDT_ERR_BADVERSION;
-       if (_fdt_blocks_misordered(fdt, sizeof(struct fdt_reserve_entry),
-                                  fdt_size_dt_struct(fdt)))
-               return -FDT_ERR_BADLAYOUT;
-       if (fdt_version(fdt) > 17)
-               fdt_set_version(fdt, 17);
-
-       return 0;
-}
-
-#define FDT_RW_CHECK_HEADER(fdt) \
-       { \
-               int err; \
-               if ((err = _fdt_rw_check_header(fdt)) != 0) \
-                       return err; \
-       }
-
-static inline int _fdt_data_size(void *fdt)
-{
-       return fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);
-}
-
-static int _fdt_splice(void *fdt, void *splicepoint, int oldlen, int newlen)
-{
-       char *p = splicepoint;
-       char *end = (char *)fdt + _fdt_data_size(fdt);
-
-       if (((p + oldlen) < p) || ((p + oldlen) > end))
-               return -FDT_ERR_BADOFFSET;
-       if ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize(fdt)))
-               return -FDT_ERR_NOSPACE;
-       memmove(p + newlen, p + oldlen, end - p - oldlen);
-       return 0;
-}
-
-static int _fdt_splice_mem_rsv(void *fdt, struct fdt_reserve_entry *p,
-                              int oldn, int newn)
-{
-       int delta = (newn - oldn) * sizeof(*p);
-       int err;
-       err = _fdt_splice(fdt, p, oldn * sizeof(*p), newn * sizeof(*p));
-       if (err)
-               return err;
-       fdt_set_off_dt_struct(fdt, fdt_off_dt_struct(fdt) + delta);
-       fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta);
-       return 0;
-}
-
-static int _fdt_splice_struct(void *fdt, void *p,
-                             int oldlen, int newlen)
-{
-       int delta = newlen - oldlen;
-       int err;
-
-       err = _fdt_splice(fdt, p, oldlen, newlen);
-       if (err)
-               return err;
-
-       fdt_set_size_dt_struct(fdt, fdt_size_dt_struct(fdt) + delta);
-       fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta);
-       return 0;
-}
-
-static int _fdt_splice_string(void *fdt, int newlen)
-{
-       void *p = (char *)fdt
-               + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);
-       int err;
-
-       err = _fdt_splice(fdt, p, 0, newlen);
-       if (err)
-               return err;
-
-       fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) + newlen);
-       return 0;
-}
-
-static int _fdt_find_add_string(void *fdt, const char *s)
-{
-       char *strtab = (char *)fdt + fdt_off_dt_strings(fdt);
-       const char *p;
-       char *new;
-       int len = strlen(s) + 1;
-       int err;
-
-       p = _fdt_find_string(strtab, fdt_size_dt_strings(fdt), s);
-       if (p)
-               /* found it */
-               return (p - strtab);
-
-       new = strtab + fdt_size_dt_strings(fdt);
-       err = _fdt_splice_string(fdt, len);
-       if (err)
-               return err;
-
-       memcpy(new, s, len);
-       return (new - strtab);
-}
-
-int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size)
-{
-       struct fdt_reserve_entry *re;
-       int err;
-
-       FDT_RW_CHECK_HEADER(fdt);
-
-       re = _fdt_mem_rsv_w(fdt, fdt_num_mem_rsv(fdt));
-       err = _fdt_splice_mem_rsv(fdt, re, 0, 1);
-       if (err)
-               return err;
-
-       re->address = cpu_to_fdt64(address);
-       re->size = cpu_to_fdt64(size);
-       return 0;
-}
-
-int fdt_del_mem_rsv(void *fdt, int n)
-{
-       struct fdt_reserve_entry *re = _fdt_mem_rsv_w(fdt, n);
-       int err;
-
-       FDT_RW_CHECK_HEADER(fdt);
-
-       if (n >= fdt_num_mem_rsv(fdt))
-               return -FDT_ERR_NOTFOUND;
-
-       err = _fdt_splice_mem_rsv(fdt, re, 1, 0);
-       if (err)
-               return err;
-       return 0;
-}
-
-static int _fdt_resize_property(void *fdt, int nodeoffset, const char *name,
-                               int len, struct fdt_property **prop)
-{
-       int oldlen;
-       int err;
-
-       *prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);
-       if (! (*prop))
-               return oldlen;
-
-       err = _fdt_splice_struct(fdt, (*prop)->data, FDT_TAGALIGN(oldlen),
-                     FDT_TAGALIGN(len));
-       if (err)
-               return err;
-
-       (*prop)->len = cpu_to_fdt32(len);
-       return 0;
-}
-
-static int _fdt_add_property(void *fdt, int nodeoffset, const char *name,
-                            int len, struct fdt_property **prop)
-{
-       int proplen;
-       int nextoffset;
-       int namestroff;
-       int err;
-
-       if ((nextoffset = _fdt_check_node_offset(fdt, nodeoffset)) < 0)
-               return nextoffset;
-
-       namestroff = _fdt_find_add_string(fdt, name);
-       if (namestroff < 0)
-               return namestroff;
-
-       *prop = _fdt_offset_ptr_w(fdt, nextoffset);
-       proplen = sizeof(**prop) + FDT_TAGALIGN(len);
-
-       err = _fdt_splice_struct(fdt, *prop, 0, proplen);
-       if (err)
-               return err;
-
-       (*prop)->tag = cpu_to_fdt32(FDT_PROP);
-       (*prop)->nameoff = cpu_to_fdt32(namestroff);
-       (*prop)->len = cpu_to_fdt32(len);
-       return 0;
-}
-
-int fdt_set_name(void *fdt, int nodeoffset, const char *name)
-{
-       char *namep;
-       int oldlen, newlen;
-       int err;
-
-       FDT_RW_CHECK_HEADER(fdt);
-
-       namep = (char *)(uintptr_t)fdt_get_name(fdt, nodeoffset, &oldlen);
-       if (!namep)
-               return oldlen;
-
-       newlen = strlen(name);
-
-       err = _fdt_splice_struct(fdt, namep, FDT_TAGALIGN(oldlen+1),
-                                FDT_TAGALIGN(newlen+1));
-       if (err)
-               return err;
-
-       memcpy(namep, name, newlen+1);
-       return 0;
-}
-
-int fdt_setprop(void *fdt, int nodeoffset, const char *name,
-               const void *val, int len)
-{
-       struct fdt_property *prop;
-       int err;
-
-       FDT_RW_CHECK_HEADER(fdt);
-
-       err = _fdt_resize_property(fdt, nodeoffset, name, len, &prop);
-       if (err == -FDT_ERR_NOTFOUND)
-               err = _fdt_add_property(fdt, nodeoffset, name, len, &prop);
-       if (err)
-               return err;
-
-       memcpy(prop->data, val, len);
-       return 0;
-}
-
-int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
-                  const void *val, int len)
-{
-       struct fdt_property *prop;
-       int err, oldlen, newlen;
-
-       FDT_RW_CHECK_HEADER(fdt);
-
-       prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);
-       if (prop) {
-               newlen = len + oldlen;
-               err = _fdt_splice_struct(fdt, prop->data,
-                                        FDT_TAGALIGN(oldlen),
-                                        FDT_TAGALIGN(newlen));
-               if (err)
-                       return err;
-               prop->len = cpu_to_fdt32(newlen);
-               memcpy(prop->data + oldlen, val, len);
-       } else {
-               err = _fdt_add_property(fdt, nodeoffset, name, len, &prop);
-               if (err)
-                       return err;
-               memcpy(prop->data, val, len);
-       }
-       return 0;
-}
-
-int fdt_delprop(void *fdt, int nodeoffset, const char *name)
-{
-       struct fdt_property *prop;
-       int len, proplen;
-
-       FDT_RW_CHECK_HEADER(fdt);
-
-       prop = fdt_get_property_w(fdt, nodeoffset, name, &len);
-       if (! prop)
-               return len;
-
-       proplen = sizeof(*prop) + FDT_TAGALIGN(len);
-       return _fdt_splice_struct(fdt, prop, proplen, 0);
-}
-
-int fdt_add_subnode_namelen(void *fdt, int parentoffset,
-                           const char *name, int namelen)
-{
-       struct fdt_node_header *nh;
-       int offset, nextoffset;
-       int nodelen;
-       int err;
-       uint32_t tag;
-       uint32_t *endtag;
-
-       FDT_RW_CHECK_HEADER(fdt);
-
-       offset = fdt_subnode_offset_namelen(fdt, parentoffset, name, namelen);
-       if (offset >= 0)
-               return -FDT_ERR_EXISTS;
-       else if (offset != -FDT_ERR_NOTFOUND)
-               return offset;
-
-       /* Try to place the new node after the parent's properties */
-       fdt_next_tag(fdt, parentoffset, &nextoffset); /* skip the BEGIN_NODE */
-       do {
-               offset = nextoffset;
-               tag = fdt_next_tag(fdt, offset, &nextoffset);
-       } while ((tag == FDT_PROP) || (tag == FDT_NOP));
-
-       nh = _fdt_offset_ptr_w(fdt, offset);
-       nodelen = sizeof(*nh) + FDT_TAGALIGN(namelen+1) + FDT_TAGSIZE;
-
-       err = _fdt_splice_struct(fdt, nh, 0, nodelen);
-       if (err)
-               return err;
-
-       nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);
-       memset(nh->name, 0, FDT_TAGALIGN(namelen+1));
-       memcpy(nh->name, name, namelen);
-       endtag = (uint32_t *)((char *)nh + nodelen - FDT_TAGSIZE);
-       *endtag = cpu_to_fdt32(FDT_END_NODE);
-
-       return offset;
-}
-
-int fdt_add_subnode(void *fdt, int parentoffset, const char *name)
-{
-       return fdt_add_subnode_namelen(fdt, parentoffset, name, strlen(name));
-}
-
-int fdt_del_node(void *fdt, int nodeoffset)
-{
-       int endoffset;
-
-       FDT_RW_CHECK_HEADER(fdt);
-
-       endoffset = _fdt_node_end_offset(fdt, nodeoffset);
-       if (endoffset < 0)
-               return endoffset;
-
-       return _fdt_splice_struct(fdt, _fdt_offset_ptr_w(fdt, nodeoffset),
-                                 endoffset - nodeoffset, 0);
-}
-
-static void _fdt_packblocks(const char *old, char *new,
-                           int mem_rsv_size, int struct_size)
-{
-       int mem_rsv_off, struct_off, strings_off;
-
-       mem_rsv_off = FDT_ALIGN(sizeof(struct fdt_header), 8);
-       struct_off = mem_rsv_off + mem_rsv_size;
-       strings_off = struct_off + struct_size;
-
-       memmove(new + mem_rsv_off, old + fdt_off_mem_rsvmap(old), mem_rsv_size);
-       fdt_set_off_mem_rsvmap(new, mem_rsv_off);
-
-       memmove(new + struct_off, old + fdt_off_dt_struct(old), struct_size);
-       fdt_set_off_dt_struct(new, struct_off);
-       fdt_set_size_dt_struct(new, struct_size);
-
-       memmove(new + strings_off, old + fdt_off_dt_strings(old),
-               fdt_size_dt_strings(old));
-       fdt_set_off_dt_strings(new, strings_off);
-       fdt_set_size_dt_strings(new, fdt_size_dt_strings(old));
-}
-
-int fdt_open_into(const void *fdt, void *buf, int bufsize)
-{
-       int err;
-       int mem_rsv_size, struct_size;
-       int newsize;
-       const char *fdtstart = fdt;
-       const char *fdtend = fdtstart + fdt_totalsize(fdt);
-       char *tmp;
-
-       FDT_CHECK_HEADER(fdt);
-
-       mem_rsv_size = (fdt_num_mem_rsv(fdt)+1)
-               * sizeof(struct fdt_reserve_entry);
-
-       if (fdt_version(fdt) >= 17) {
-               struct_size = fdt_size_dt_struct(fdt);
-       } else {
-               struct_size = 0;
-               while (fdt_next_tag(fdt, struct_size, &struct_size) != FDT_END)
-                       ;
-               if (struct_size < 0)
-                       return struct_size;
-       }
-
-       if (!_fdt_blocks_misordered(fdt, mem_rsv_size, struct_size)) {
-               /* no further work necessary */
-               err = fdt_move(fdt, buf, bufsize);
-               if (err)
-                       return err;
-               fdt_set_version(buf, 17);
-               fdt_set_size_dt_struct(buf, struct_size);
-               fdt_set_totalsize(buf, bufsize);
-               return 0;
-       }
-
-       /* Need to reorder */
-       newsize = FDT_ALIGN(sizeof(struct fdt_header), 8) + mem_rsv_size
-               + struct_size + fdt_size_dt_strings(fdt);
-
-       if (bufsize < newsize)
-               return -FDT_ERR_NOSPACE;
-
-       /* First attempt to build converted tree at beginning of buffer */
-       tmp = buf;
-       /* But if that overlaps with the old tree... */
-       if (((tmp + newsize) > fdtstart) && (tmp < fdtend)) {
-               /* Try right after the old tree instead */
-               tmp = (char *)(uintptr_t)fdtend;
-               if ((tmp + newsize) > ((char *)buf + bufsize))
-                       return -FDT_ERR_NOSPACE;
-       }
-
-       _fdt_packblocks(fdt, tmp, mem_rsv_size, struct_size);
-       memmove(buf, tmp, newsize);
-
-       fdt_set_magic(buf, FDT_MAGIC);
-       fdt_set_totalsize(buf, bufsize);
-       fdt_set_version(buf, 17);
-       fdt_set_last_comp_version(buf, 16);
-       fdt_set_boot_cpuid_phys(buf, fdt_boot_cpuid_phys(fdt));
-
-       return 0;
-}
-
-int fdt_pack(void *fdt)
-{
-       int mem_rsv_size;
-
-       FDT_RW_CHECK_HEADER(fdt);
-
-       mem_rsv_size = (fdt_num_mem_rsv(fdt)+1)
-               * sizeof(struct fdt_reserve_entry);
-       _fdt_packblocks(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt));
-       fdt_set_totalsize(fdt, _fdt_data_size(fdt));
-
-       return 0;
-}
+/*\r
+ * libfdt - Flat Device Tree manipulation\r
+ * Copyright (C) 2006 David Gibson, IBM Corporation.\r
+ *\r
+ * libfdt is dual licensed: you can use it either under the terms of\r
+ * the GPL, or the BSD license, at your option.\r
+ *\r
+ *  a) This library is free software; you can redistribute it and/or\r
+ *     modify it under the terms of the GNU General Public License as\r
+ *     published by the Free Software Foundation; either version 2 of the\r
+ *     License, or (at your option) any later version.\r
+ *\r
+ *     This library is distributed in the hope that it will be useful,\r
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ *     GNU General Public License for more details.\r
+ *\r
+ *     You should have received a copy of the GNU General Public\r
+ *     License along with this library; if not, write to the Free\r
+ *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\r
+ *     MA 02110-1301 USA\r
+ *\r
+ * Alternatively,\r
+ *\r
+ *  b) Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *     1. Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *     2. Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\r
+ *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,\r
+ *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
+ *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+ *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
+ *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
+ *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
+ *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#include "libfdt_env.h"\r
+\r
+#include <fdt.h>\r
+#include <libfdt.h>\r
+\r
+#include "libfdt_internal.h"\r
+\r
+static int _fdt_blocks_misordered(const void *fdt,\r
+                             int mem_rsv_size, int struct_size)\r
+{\r
+       return (fdt_off_mem_rsvmap(fdt) < FDT_ALIGN(sizeof(struct fdt_header), 8))\r
+               || (fdt_off_dt_struct(fdt) <\r
+                   (fdt_off_mem_rsvmap(fdt) + mem_rsv_size))\r
+               || (fdt_off_dt_strings(fdt) <\r
+                   (fdt_off_dt_struct(fdt) + struct_size))\r
+               || (fdt_totalsize(fdt) <\r
+                   (fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt)));\r
+}\r
+\r
+static int _fdt_rw_check_header(void *fdt)\r
+{\r
+       FDT_CHECK_HEADER(fdt);\r
+\r
+       if (fdt_version(fdt) < 17)\r
+               return -FDT_ERR_BADVERSION;\r
+       if (_fdt_blocks_misordered(fdt, sizeof(struct fdt_reserve_entry),\r
+                                  fdt_size_dt_struct(fdt)))\r
+               return -FDT_ERR_BADLAYOUT;\r
+       if (fdt_version(fdt) > 17)\r
+               fdt_set_version(fdt, 17);\r
+\r
+       return 0;\r
+}\r
+\r
+#define FDT_RW_CHECK_HEADER(fdt) \\r
+       { \\r
+               int err; \\r
+               if ((err = _fdt_rw_check_header(fdt)) != 0) \\r
+                       return err; \\r
+       }\r
+\r
+static inline int _fdt_data_size(void *fdt)\r
+{\r
+       return fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);\r
+}\r
+\r
+static int _fdt_splice(void *fdt, void *splicepoint, int oldlen, int newlen)\r
+{\r
+       char *p = splicepoint;\r
+       char *end = (char *)fdt + _fdt_data_size(fdt);\r
+\r
+       if (((p + oldlen) < p) || ((p + oldlen) > end))\r
+               return -FDT_ERR_BADOFFSET;\r
+       if ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize(fdt)))\r
+               return -FDT_ERR_NOSPACE;\r
+       memmove(p + newlen, p + oldlen, end - p - oldlen);\r
+       return 0;\r
+}\r
+\r
+static int _fdt_splice_mem_rsv(void *fdt, struct fdt_reserve_entry *p,\r
+                              int oldn, int newn)\r
+{\r
+       int delta = (newn - oldn) * sizeof(*p);\r
+       int err;\r
+       err = _fdt_splice(fdt, p, oldn * sizeof(*p), newn * sizeof(*p));\r
+       if (err)\r
+               return err;\r
+       fdt_set_off_dt_struct(fdt, fdt_off_dt_struct(fdt) + delta);\r
+       fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta);\r
+       return 0;\r
+}\r
+\r
+static int _fdt_splice_struct(void *fdt, void *p,\r
+                             int oldlen, int newlen)\r
+{\r
+       int delta = newlen - oldlen;\r
+       int err;\r
+\r
+       err = _fdt_splice(fdt, p, oldlen, newlen);\r
+       if (err)\r
+               return err;\r
+\r
+       fdt_set_size_dt_struct(fdt, fdt_size_dt_struct(fdt) + delta);\r
+       fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta);\r
+       return 0;\r
+}\r
+\r
+static int _fdt_splice_string(void *fdt, int newlen)\r
+{\r
+       void *p = (char *)fdt\r
+               + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);\r
+       int err;\r
+\r
+       err = _fdt_splice(fdt, p, 0, newlen);\r
+       if (err)\r
+               return err;\r
+\r
+       fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) + newlen);\r
+       return 0;\r
+}\r
+\r
+static int _fdt_find_add_string(void *fdt, const char *s)\r
+{\r
+       char *strtab = (char *)fdt + fdt_off_dt_strings(fdt);\r
+       const char *p;\r
+       char *new;\r
+       int len = strlen(s) + 1;\r
+       int err;\r
+\r
+       p = _fdt_find_string(strtab, fdt_size_dt_strings(fdt), s);\r
+       if (p)\r
+               /* found it */\r
+               return (p - strtab);\r
+\r
+       new = strtab + fdt_size_dt_strings(fdt);\r
+       err = _fdt_splice_string(fdt, len);\r
+       if (err)\r
+               return err;\r
+\r
+       memcpy(new, s, len);\r
+       return (new - strtab);\r
+}\r
+\r
+int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size)\r
+{\r
+       struct fdt_reserve_entry *re;\r
+       int err;\r
+\r
+       FDT_RW_CHECK_HEADER(fdt);\r
+\r
+       re = _fdt_mem_rsv_w(fdt, fdt_num_mem_rsv(fdt));\r
+       err = _fdt_splice_mem_rsv(fdt, re, 0, 1);\r
+       if (err)\r
+               return err;\r
+\r
+       re->address = cpu_to_fdt64(address);\r
+       re->size = cpu_to_fdt64(size);\r
+       return 0;\r
+}\r
+\r
+int fdt_del_mem_rsv(void *fdt, int n)\r
+{\r
+       struct fdt_reserve_entry *re = _fdt_mem_rsv_w(fdt, n);\r
+       int err;\r
+\r
+       FDT_RW_CHECK_HEADER(fdt);\r
+\r
+       if (n >= fdt_num_mem_rsv(fdt))\r
+               return -FDT_ERR_NOTFOUND;\r
+\r
+       err = _fdt_splice_mem_rsv(fdt, re, 1, 0);\r
+       if (err)\r
+               return err;\r
+       return 0;\r
+}\r
+\r
+static int _fdt_resize_property(void *fdt, int nodeoffset, const char *name,\r
+                               int len, struct fdt_property **prop)\r
+{\r
+       int oldlen;\r
+       int err;\r
+\r
+       *prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);\r
+       if (! (*prop))\r
+               return oldlen;\r
+\r
+       err = _fdt_splice_struct(fdt, (*prop)->data, FDT_TAGALIGN(oldlen),\r
+                     FDT_TAGALIGN(len));\r
+       if (err)\r
+               return err;\r
+\r
+       (*prop)->len = cpu_to_fdt32(len);\r
+       return 0;\r
+}\r
+\r
+static int _fdt_add_property(void *fdt, int nodeoffset, const char *name,\r
+                            int len, struct fdt_property **prop)\r
+{\r
+       int proplen;\r
+       int nextoffset;\r
+       int namestroff;\r
+       int err;\r
+\r
+       if ((nextoffset = _fdt_check_node_offset(fdt, nodeoffset)) < 0)\r
+               return nextoffset;\r
+\r
+       namestroff = _fdt_find_add_string(fdt, name);\r
+       if (namestroff < 0)\r
+               return namestroff;\r
+\r
+       *prop = _fdt_offset_ptr_w(fdt, nextoffset);\r
+       proplen = sizeof(**prop) + FDT_TAGALIGN(len);\r
+\r
+       err = _fdt_splice_struct(fdt, *prop, 0, proplen);\r
+       if (err)\r
+               return err;\r
+\r
+       (*prop)->tag = cpu_to_fdt32(FDT_PROP);\r
+       (*prop)->nameoff = cpu_to_fdt32(namestroff);\r
+       (*prop)->len = cpu_to_fdt32(len);\r
+       return 0;\r
+}\r
+\r
+int fdt_set_name(void *fdt, int nodeoffset, const char *name)\r
+{\r
+       char *namep;\r
+       int oldlen, newlen;\r
+       int err;\r
+\r
+       FDT_RW_CHECK_HEADER(fdt);\r
+\r
+       namep = (char *)(uintptr_t)fdt_get_name(fdt, nodeoffset, &oldlen);\r
+       if (!namep)\r
+               return oldlen;\r
+\r
+       newlen = strlen(name);\r
+\r
+       err = _fdt_splice_struct(fdt, namep, FDT_TAGALIGN(oldlen+1),\r
+                                FDT_TAGALIGN(newlen+1));\r
+       if (err)\r
+               return err;\r
+\r
+       memcpy(namep, name, newlen+1);\r
+       return 0;\r
+}\r
+\r
+int fdt_setprop(void *fdt, int nodeoffset, const char *name,\r
+               const void *val, int len)\r
+{\r
+       struct fdt_property *prop;\r
+       int err;\r
+\r
+       FDT_RW_CHECK_HEADER(fdt);\r
+\r
+       err = _fdt_resize_property(fdt, nodeoffset, name, len, &prop);\r
+       if (err == -FDT_ERR_NOTFOUND)\r
+               err = _fdt_add_property(fdt, nodeoffset, name, len, &prop);\r
+       if (err)\r
+               return err;\r
+\r
+       memcpy(prop->data, val, len);\r
+       return 0;\r
+}\r
+\r
+int fdt_appendprop(void *fdt, int nodeoffset, const char *name,\r
+                  const void *val, int len)\r
+{\r
+       struct fdt_property *prop;\r
+       int err, oldlen, newlen;\r
+\r
+       FDT_RW_CHECK_HEADER(fdt);\r
+\r
+       prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);\r
+       if (prop) {\r
+               newlen = len + oldlen;\r
+               err = _fdt_splice_struct(fdt, prop->data,\r
+                                        FDT_TAGALIGN(oldlen),\r
+                                        FDT_TAGALIGN(newlen));\r
+               if (err)\r
+                       return err;\r
+               prop->len = cpu_to_fdt32(newlen);\r
+               memcpy(prop->data + oldlen, val, len);\r
+       } else {\r
+               err = _fdt_add_property(fdt, nodeoffset, name, len, &prop);\r
+               if (err)\r
+                       return err;\r
+               memcpy(prop->data, val, len);\r
+       }\r
+       return 0;\r
+}\r
+\r
+int fdt_delprop(void *fdt, int nodeoffset, const char *name)\r
+{\r
+       struct fdt_property *prop;\r
+       int len, proplen;\r
+\r
+       FDT_RW_CHECK_HEADER(fdt);\r
+\r
+       prop = fdt_get_property_w(fdt, nodeoffset, name, &len);\r
+       if (! prop)\r
+               return len;\r
+\r
+       proplen = sizeof(*prop) + FDT_TAGALIGN(len);\r
+       return _fdt_splice_struct(fdt, prop, proplen, 0);\r
+}\r
+\r
+int fdt_add_subnode_namelen(void *fdt, int parentoffset,\r
+                           const char *name, int namelen)\r
+{\r
+       struct fdt_node_header *nh;\r
+       int offset, nextoffset;\r
+       int nodelen;\r
+       int err;\r
+       uint32_t tag;\r
+       uint32_t *endtag;\r
+\r
+       FDT_RW_CHECK_HEADER(fdt);\r
+\r
+       offset = fdt_subnode_offset_namelen(fdt, parentoffset, name, namelen);\r
+       if (offset >= 0)\r
+               return -FDT_ERR_EXISTS;\r
+       else if (offset != -FDT_ERR_NOTFOUND)\r
+               return offset;\r
+\r
+       /* Try to place the new node after the parent's properties */\r
+       fdt_next_tag(fdt, parentoffset, &nextoffset); /* skip the BEGIN_NODE */\r
+       do {\r
+               offset = nextoffset;\r
+               tag = fdt_next_tag(fdt, offset, &nextoffset);\r
+       } while ((tag == FDT_PROP) || (tag == FDT_NOP));\r
+\r
+       nh = _fdt_offset_ptr_w(fdt, offset);\r
+       nodelen = sizeof(*nh) + FDT_TAGALIGN(namelen+1) + FDT_TAGSIZE;\r
+\r
+       err = _fdt_splice_struct(fdt, nh, 0, nodelen);\r
+       if (err)\r
+               return err;\r
+\r
+       nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);\r
+       memset(nh->name, 0, FDT_TAGALIGN(namelen+1));\r
+       memcpy(nh->name, name, namelen);\r
+       endtag = (uint32_t *)((char *)nh + nodelen - FDT_TAGSIZE);\r
+       *endtag = cpu_to_fdt32(FDT_END_NODE);\r
+\r
+       return offset;\r
+}\r
+\r
+int fdt_add_subnode(void *fdt, int parentoffset, const char *name)\r
+{\r
+       return fdt_add_subnode_namelen(fdt, parentoffset, name, strlen(name));\r
+}\r
+\r
+int fdt_del_node(void *fdt, int nodeoffset)\r
+{\r
+       int endoffset;\r
+\r
+       FDT_RW_CHECK_HEADER(fdt);\r
+\r
+       endoffset = _fdt_node_end_offset(fdt, nodeoffset);\r
+       if (endoffset < 0)\r
+               return endoffset;\r
+\r
+       return _fdt_splice_struct(fdt, _fdt_offset_ptr_w(fdt, nodeoffset),\r
+                                 endoffset - nodeoffset, 0);\r
+}\r
+\r
+static void _fdt_packblocks(const char *old, char *new,\r
+                           int mem_rsv_size, int struct_size)\r
+{\r
+       int mem_rsv_off, struct_off, strings_off;\r
+\r
+       mem_rsv_off = FDT_ALIGN(sizeof(struct fdt_header), 8);\r
+       struct_off = mem_rsv_off + mem_rsv_size;\r
+       strings_off = struct_off + struct_size;\r
+\r
+       memmove(new + mem_rsv_off, old + fdt_off_mem_rsvmap(old), mem_rsv_size);\r
+       fdt_set_off_mem_rsvmap(new, mem_rsv_off);\r
+\r
+       memmove(new + struct_off, old + fdt_off_dt_struct(old), struct_size);\r
+       fdt_set_off_dt_struct(new, struct_off);\r
+       fdt_set_size_dt_struct(new, struct_size);\r
+\r
+       memmove(new + strings_off, old + fdt_off_dt_strings(old),\r
+               fdt_size_dt_strings(old));\r
+       fdt_set_off_dt_strings(new, strings_off);\r
+       fdt_set_size_dt_strings(new, fdt_size_dt_strings(old));\r
+}\r
+\r
+int fdt_open_into(const void *fdt, void *buf, int bufsize)\r
+{\r
+       int err;\r
+       int mem_rsv_size, struct_size;\r
+       int newsize;\r
+       const char *fdtstart = fdt;\r
+       const char *fdtend = fdtstart + fdt_totalsize(fdt);\r
+       char *tmp;\r
+\r
+       FDT_CHECK_HEADER(fdt);\r
+\r
+       mem_rsv_size = (fdt_num_mem_rsv(fdt)+1)\r
+               * sizeof(struct fdt_reserve_entry);\r
+\r
+       if (fdt_version(fdt) >= 17) {\r
+               struct_size = fdt_size_dt_struct(fdt);\r
+       } else {\r
+               struct_size = 0;\r
+               while (fdt_next_tag(fdt, struct_size, &struct_size) != FDT_END)\r
+                       ;\r
+               if (struct_size < 0)\r
+                       return struct_size;\r
+       }\r
+\r
+       if (!_fdt_blocks_misordered(fdt, mem_rsv_size, struct_size)) {\r
+               /* no further work necessary */\r
+               err = fdt_move(fdt, buf, bufsize);\r
+               if (err)\r
+                       return err;\r
+               fdt_set_version(buf, 17);\r
+               fdt_set_size_dt_struct(buf, struct_size);\r
+               fdt_set_totalsize(buf, bufsize);\r
+               return 0;\r
+       }\r
+\r
+       /* Need to reorder */\r
+       newsize = FDT_ALIGN(sizeof(struct fdt_header), 8) + mem_rsv_size\r
+               + struct_size + fdt_size_dt_strings(fdt);\r
+\r
+       if (bufsize < newsize)\r
+               return -FDT_ERR_NOSPACE;\r
+\r
+       /* First attempt to build converted tree at beginning of buffer */\r
+       tmp = buf;\r
+       /* But if that overlaps with the old tree... */\r
+       if (((tmp + newsize) > fdtstart) && (tmp < fdtend)) {\r
+               /* Try right after the old tree instead */\r
+               tmp = (char *)(uintptr_t)fdtend;\r
+               if ((tmp + newsize) > ((char *)buf + bufsize))\r
+                       return -FDT_ERR_NOSPACE;\r
+       }\r
+\r
+       _fdt_packblocks(fdt, tmp, mem_rsv_size, struct_size);\r
+       memmove(buf, tmp, newsize);\r
+\r
+       fdt_set_magic(buf, FDT_MAGIC);\r
+       fdt_set_totalsize(buf, bufsize);\r
+       fdt_set_version(buf, 17);\r
+       fdt_set_last_comp_version(buf, 16);\r
+       fdt_set_boot_cpuid_phys(buf, fdt_boot_cpuid_phys(fdt));\r
+\r
+       return 0;\r
+}\r
+\r
+int fdt_pack(void *fdt)\r
+{\r
+       int mem_rsv_size;\r
+\r
+       FDT_RW_CHECK_HEADER(fdt);\r
+\r
+       mem_rsv_size = (fdt_num_mem_rsv(fdt)+1)\r
+               * sizeof(struct fdt_reserve_entry);\r
+       _fdt_packblocks(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt));\r
+       fdt_set_totalsize(fdt, _fdt_data_size(fdt));\r
+\r
+       return 0;\r
+}\r
index e6c3ceee8c58c56beee386e6ed730e32c4ff646b..a49793d9361b0185b4b605320b944435e5aa40f9 100644 (file)
@@ -1,96 +1,96 @@
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2006 David Gibson, IBM Corporation.
- *
- * libfdt is dual licensed: you can use it either under the terms of
- * the GPL, or the BSD license, at your option.
- *
- *  a) This library is free software; you can redistribute it and/or
- *     modify it under the terms of the GNU General Public License as
- *     published by the Free Software Foundation; either version 2 of the
- *     License, or (at your option) any later version.
- *
- *     This library is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- *
- *     You should have received a copy of the GNU General Public
- *     License along with this library; if not, write to the Free
- *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
- *     MA 02110-1301 USA
- *
- * Alternatively,
- *
- *  b) Redistribution and use in source and binary forms, with or
- *     without modification, are permitted provided that the following
- *     conditions are met:
- *
- *     1. Redistributions of source code must retain the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer.
- *     2. Redistributions in binary form must reproduce the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer in the documentation and/or other materials
- *        provided with the distribution.
- *
- *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "libfdt_env.h"
-
-#include <fdt.h>
-#include <libfdt.h>
-
-#include "libfdt_internal.h"
-
-struct fdt_errtabent {
-       const char *str;
-};
-
-#define FDT_ERRTABENT(val) \
-       [(val)] = { .str = #val, }
-
-static struct fdt_errtabent fdt_errtable[] = {
-       FDT_ERRTABENT(FDT_ERR_NOTFOUND),
-       FDT_ERRTABENT(FDT_ERR_EXISTS),
-       FDT_ERRTABENT(FDT_ERR_NOSPACE),
-
-       FDT_ERRTABENT(FDT_ERR_BADOFFSET),
-       FDT_ERRTABENT(FDT_ERR_BADPATH),
-       FDT_ERRTABENT(FDT_ERR_BADSTATE),
-
-       FDT_ERRTABENT(FDT_ERR_TRUNCATED),
-       FDT_ERRTABENT(FDT_ERR_BADMAGIC),
-       FDT_ERRTABENT(FDT_ERR_BADVERSION),
-       FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE),
-       FDT_ERRTABENT(FDT_ERR_BADLAYOUT),
-};
-#define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))
-
-const char *fdt_strerror(int errval)
-{
-       if (errval > 0)
-               return "<valid offset/length>";
-       else if (errval == 0)
-               return "<no error>";
-       else if (errval > -FDT_ERRTABSIZE) {
-               const char *s = fdt_errtable[-errval].str;
-
-               if (s)
-                       return s;
-       }
-
-       return "<unknown error>";
-}
+/*\r
+ * libfdt - Flat Device Tree manipulation\r
+ * Copyright (C) 2006 David Gibson, IBM Corporation.\r
+ *\r
+ * libfdt is dual licensed: you can use it either under the terms of\r
+ * the GPL, or the BSD license, at your option.\r
+ *\r
+ *  a) This library is free software; you can redistribute it and/or\r
+ *     modify it under the terms of the GNU General Public License as\r
+ *     published by the Free Software Foundation; either version 2 of the\r
+ *     License, or (at your option) any later version.\r
+ *\r
+ *     This library is distributed in the hope that it will be useful,\r
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ *     GNU General Public License for more details.\r
+ *\r
+ *     You should have received a copy of the GNU General Public\r
+ *     License along with this library; if not, write to the Free\r
+ *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\r
+ *     MA 02110-1301 USA\r
+ *\r
+ * Alternatively,\r
+ *\r
+ *  b) Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *     1. Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *     2. Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\r
+ *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,\r
+ *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
+ *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+ *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
+ *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
+ *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
+ *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#include "libfdt_env.h"\r
+\r
+#include <fdt.h>\r
+#include <libfdt.h>\r
+\r
+#include "libfdt_internal.h"\r
+\r
+struct fdt_errtabent {\r
+       const char *str;\r
+};\r
+\r
+#define FDT_ERRTABENT(val) \\r
+       [(val)] = { .str = #val, }\r
+\r
+static struct fdt_errtabent fdt_errtable[] = {\r
+       FDT_ERRTABENT(FDT_ERR_NOTFOUND),\r
+       FDT_ERRTABENT(FDT_ERR_EXISTS),\r
+       FDT_ERRTABENT(FDT_ERR_NOSPACE),\r
+\r
+       FDT_ERRTABENT(FDT_ERR_BADOFFSET),\r
+       FDT_ERRTABENT(FDT_ERR_BADPATH),\r
+       FDT_ERRTABENT(FDT_ERR_BADSTATE),\r
+\r
+       FDT_ERRTABENT(FDT_ERR_TRUNCATED),\r
+       FDT_ERRTABENT(FDT_ERR_BADMAGIC),\r
+       FDT_ERRTABENT(FDT_ERR_BADVERSION),\r
+       FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE),\r
+       FDT_ERRTABENT(FDT_ERR_BADLAYOUT),\r
+};\r
+#define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))\r
+\r
+const char *fdt_strerror(int errval)\r
+{\r
+       if (errval > 0)\r
+               return "<valid offset/length>";\r
+       else if (errval == 0)\r
+               return "<no error>";\r
+       else if (errval > -FDT_ERRTABSIZE) {\r
+               const char *s = fdt_errtable[-errval].str;\r
+\r
+               if (s)\r
+                       return s;\r
+       }\r
+\r
+       return "<unknown error>";\r
+}\r
index 55ebebf1eb20e8c7f9200881f99ecf03632db9a3..240fabc554248ebb085d38751624b79726e50f7c 100644 (file)
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2006 David Gibson, IBM Corporation.
- *
- * libfdt is dual licensed: you can use it either under the terms of
- * the GPL, or the BSD license, at your option.
- *
- *  a) This library is free software; you can redistribute it and/or
- *     modify it under the terms of the GNU General Public License as
- *     published by the Free Software Foundation; either version 2 of the
- *     License, or (at your option) any later version.
- *
- *     This library is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- *
- *     You should have received a copy of the GNU General Public
- *     License along with this library; if not, write to the Free
- *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
- *     MA 02110-1301 USA
- *
- * Alternatively,
- *
- *  b) Redistribution and use in source and binary forms, with or
- *     without modification, are permitted provided that the following
- *     conditions are met:
- *
- *     1. Redistributions of source code must retain the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer.
- *     2. Redistributions in binary form must reproduce the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer in the documentation and/or other materials
- *        provided with the distribution.
- *
- *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "libfdt_env.h"
-
-#include <fdt.h>
-#include <libfdt.h>
-
-#include "libfdt_internal.h"
-
-static int _fdt_sw_check_header(void *fdt)
-{
-       if (fdt_magic(fdt) != FDT_SW_MAGIC)
-               return -FDT_ERR_BADMAGIC;
-       /* FIXME: should check more details about the header state */
-       return 0;
-}
-
-#define FDT_SW_CHECK_HEADER(fdt) \
-       { \
-               int err; \
-               if ((err = _fdt_sw_check_header(fdt)) != 0) \
-                       return err; \
-       }
-
-static void *_fdt_grab_space(void *fdt, size_t len)
-{
-       int offset = fdt_size_dt_struct(fdt);
-       int spaceleft;
-
-       spaceleft = fdt_totalsize(fdt) - fdt_off_dt_struct(fdt)
-               - fdt_size_dt_strings(fdt);
-
-       if ((offset + len < offset) || (offset + len > spaceleft))
-               return NULL;
-
-       fdt_set_size_dt_struct(fdt, offset + len);
-       return _fdt_offset_ptr_w(fdt, offset);
-}
-
-int fdt_create(void *buf, int bufsize)
-{
-       void *fdt = buf;
-
-       if (bufsize < sizeof(struct fdt_header))
-               return -FDT_ERR_NOSPACE;
-
-       memset(buf, 0, bufsize);
-
-       fdt_set_magic(fdt, FDT_SW_MAGIC);
-       fdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION);
-       fdt_set_last_comp_version(fdt, FDT_FIRST_SUPPORTED_VERSION);
-       fdt_set_totalsize(fdt,  bufsize);
-
-       fdt_set_off_mem_rsvmap(fdt, FDT_ALIGN(sizeof(struct fdt_header),
-                                             sizeof(struct fdt_reserve_entry)));
-       fdt_set_off_dt_struct(fdt, fdt_off_mem_rsvmap(fdt));
-       fdt_set_off_dt_strings(fdt, bufsize);
-
-       return 0;
-}
-
-int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size)
-{
-       struct fdt_reserve_entry *re;
-       int offset;
-
-       FDT_SW_CHECK_HEADER(fdt);
-
-       if (fdt_size_dt_struct(fdt))
-               return -FDT_ERR_BADSTATE;
-
-       offset = fdt_off_dt_struct(fdt);
-       if ((offset + sizeof(*re)) > fdt_totalsize(fdt))
-               return -FDT_ERR_NOSPACE;
-
-       re = (struct fdt_reserve_entry *)((char *)fdt + offset);
-       re->address = cpu_to_fdt64(addr);
-       re->size = cpu_to_fdt64(size);
-
-       fdt_set_off_dt_struct(fdt, offset + sizeof(*re));
-
-       return 0;
-}
-
-int fdt_finish_reservemap(void *fdt)
-{
-       return fdt_add_reservemap_entry(fdt, 0, 0);
-}
-
-int fdt_begin_node(void *fdt, const char *name)
-{
-       struct fdt_node_header *nh;
-       int namelen = strlen(name) + 1;
-
-       FDT_SW_CHECK_HEADER(fdt);
-
-       nh = _fdt_grab_space(fdt, sizeof(*nh) + FDT_TAGALIGN(namelen));
-       if (! nh)
-               return -FDT_ERR_NOSPACE;
-
-       nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);
-       memcpy(nh->name, name, namelen);
-       return 0;
-}
-
-int fdt_end_node(void *fdt)
-{
-       uint32_t *en;
-
-       FDT_SW_CHECK_HEADER(fdt);
-
-       en = _fdt_grab_space(fdt, FDT_TAGSIZE);
-       if (! en)
-               return -FDT_ERR_NOSPACE;
-
-       *en = cpu_to_fdt32(FDT_END_NODE);
-       return 0;
-}
-
-static int _fdt_find_add_string(void *fdt, const char *s)
-{
-       char *strtab = (char *)fdt + fdt_totalsize(fdt);
-       const char *p;
-       int strtabsize = fdt_size_dt_strings(fdt);
-       int len = strlen(s) + 1;
-       int struct_top, offset;
-
-       p = _fdt_find_string(strtab - strtabsize, strtabsize, s);
-       if (p)
-               return p - strtab;
-
-       /* Add it */
-       offset = -strtabsize - len;
-       struct_top = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);
-       if (fdt_totalsize(fdt) + offset < struct_top)
-               return 0; /* no more room :( */
-
-       memcpy(strtab + offset, s, len);
-       fdt_set_size_dt_strings(fdt, strtabsize + len);
-       return offset;
-}
-
-int fdt_property(void *fdt, const char *name, const void *val, int len)
-{
-       struct fdt_property *prop;
-       int nameoff;
-
-       FDT_SW_CHECK_HEADER(fdt);
-
-       nameoff = _fdt_find_add_string(fdt, name);
-       if (nameoff == 0)
-               return -FDT_ERR_NOSPACE;
-
-       prop = _fdt_grab_space(fdt, sizeof(*prop) + FDT_TAGALIGN(len));
-       if (! prop)
-               return -FDT_ERR_NOSPACE;
-
-       prop->tag = cpu_to_fdt32(FDT_PROP);
-       prop->nameoff = cpu_to_fdt32(nameoff);
-       prop->len = cpu_to_fdt32(len);
-       memcpy(prop->data, val, len);
-       return 0;
-}
-
-int fdt_finish(void *fdt)
-{
-       char *p = (char *)fdt;
-       uint32_t *end;
-       int oldstroffset, newstroffset;
-       uint32_t tag;
-       int offset, nextoffset;
-
-       FDT_SW_CHECK_HEADER(fdt);
-
-       /* Add terminator */
-       end = _fdt_grab_space(fdt, sizeof(*end));
-       if (! end)
-               return -FDT_ERR_NOSPACE;
-       *end = cpu_to_fdt32(FDT_END);
-
-       /* Relocate the string table */
-       oldstroffset = fdt_totalsize(fdt) - fdt_size_dt_strings(fdt);
-       newstroffset = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);
-       memmove(p + newstroffset, p + oldstroffset, fdt_size_dt_strings(fdt));
-       fdt_set_off_dt_strings(fdt, newstroffset);
-
-       /* Walk the structure, correcting string offsets */
-       offset = 0;
-       while ((tag = fdt_next_tag(fdt, offset, &nextoffset)) != FDT_END) {
-               if (tag == FDT_PROP) {
-                       struct fdt_property *prop =
-                               _fdt_offset_ptr_w(fdt, offset);
-                       int nameoff;
-
-                       nameoff = fdt32_to_cpu(prop->nameoff);
-                       nameoff += fdt_size_dt_strings(fdt);
-                       prop->nameoff = cpu_to_fdt32(nameoff);
-               }
-               offset = nextoffset;
-       }
-       if (nextoffset < 0)
-               return nextoffset;
-
-       /* Finally, adjust the header */
-       fdt_set_totalsize(fdt, newstroffset + fdt_size_dt_strings(fdt));
-       fdt_set_magic(fdt, FDT_MAGIC);
-       return 0;
-}
+/*\r
+ * libfdt - Flat Device Tree manipulation\r
+ * Copyright (C) 2006 David Gibson, IBM Corporation.\r
+ *\r
+ * libfdt is dual licensed: you can use it either under the terms of\r
+ * the GPL, or the BSD license, at your option.\r
+ *\r
+ *  a) This library is free software; you can redistribute it and/or\r
+ *     modify it under the terms of the GNU General Public License as\r
+ *     published by the Free Software Foundation; either version 2 of the\r
+ *     License, or (at your option) any later version.\r
+ *\r
+ *     This library is distributed in the hope that it will be useful,\r
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ *     GNU General Public License for more details.\r
+ *\r
+ *     You should have received a copy of the GNU General Public\r
+ *     License along with this library; if not, write to the Free\r
+ *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\r
+ *     MA 02110-1301 USA\r
+ *\r
+ * Alternatively,\r
+ *\r
+ *  b) Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *     1. Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *     2. Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\r
+ *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,\r
+ *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
+ *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+ *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
+ *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
+ *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
+ *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#include "libfdt_env.h"\r
+\r
+#include <fdt.h>\r
+#include <libfdt.h>\r
+\r
+#include "libfdt_internal.h"\r
+\r
+static int _fdt_sw_check_header(void *fdt)\r
+{\r
+       if (fdt_magic(fdt) != FDT_SW_MAGIC)\r
+               return -FDT_ERR_BADMAGIC;\r
+       /* FIXME: should check more details about the header state */\r
+       return 0;\r
+}\r
+\r
+#define FDT_SW_CHECK_HEADER(fdt) \\r
+       { \\r
+               int err; \\r
+               if ((err = _fdt_sw_check_header(fdt)) != 0) \\r
+                       return err; \\r
+       }\r
+\r
+static void *_fdt_grab_space(void *fdt, size_t len)\r
+{\r
+       int offset = fdt_size_dt_struct(fdt);\r
+       int spaceleft;\r
+\r
+       spaceleft = fdt_totalsize(fdt) - fdt_off_dt_struct(fdt)\r
+               - fdt_size_dt_strings(fdt);\r
+\r
+       if ((offset + len < offset) || (offset + len > spaceleft))\r
+               return NULL;\r
+\r
+       fdt_set_size_dt_struct(fdt, offset + len);\r
+       return _fdt_offset_ptr_w(fdt, offset);\r
+}\r
+\r
+int fdt_create(void *buf, int bufsize)\r
+{\r
+       void *fdt = buf;\r
+\r
+       if (bufsize < sizeof(struct fdt_header))\r
+               return -FDT_ERR_NOSPACE;\r
+\r
+       memset(buf, 0, bufsize);\r
+\r
+       fdt_set_magic(fdt, FDT_SW_MAGIC);\r
+       fdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION);\r
+       fdt_set_last_comp_version(fdt, FDT_FIRST_SUPPORTED_VERSION);\r
+       fdt_set_totalsize(fdt,  bufsize);\r
+\r
+       fdt_set_off_mem_rsvmap(fdt, FDT_ALIGN(sizeof(struct fdt_header),\r
+                                             sizeof(struct fdt_reserve_entry)));\r
+       fdt_set_off_dt_struct(fdt, fdt_off_mem_rsvmap(fdt));\r
+       fdt_set_off_dt_strings(fdt, bufsize);\r
+\r
+       return 0;\r
+}\r
+\r
+int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size)\r
+{\r
+       struct fdt_reserve_entry *re;\r
+       int offset;\r
+\r
+       FDT_SW_CHECK_HEADER(fdt);\r
+\r
+       if (fdt_size_dt_struct(fdt))\r
+               return -FDT_ERR_BADSTATE;\r
+\r
+       offset = fdt_off_dt_struct(fdt);\r
+       if ((offset + sizeof(*re)) > fdt_totalsize(fdt))\r
+               return -FDT_ERR_NOSPACE;\r
+\r
+       re = (struct fdt_reserve_entry *)((char *)fdt + offset);\r
+       re->address = cpu_to_fdt64(addr);\r
+       re->size = cpu_to_fdt64(size);\r
+\r
+       fdt_set_off_dt_struct(fdt, offset + sizeof(*re));\r
+\r
+       return 0;\r
+}\r
+\r
+int fdt_finish_reservemap(void *fdt)\r
+{\r
+       return fdt_add_reservemap_entry(fdt, 0, 0);\r
+}\r
+\r
+int fdt_begin_node(void *fdt, const char *name)\r
+{\r
+       struct fdt_node_header *nh;\r
+       int namelen = strlen(name) + 1;\r
+\r
+       FDT_SW_CHECK_HEADER(fdt);\r
+\r
+       nh = _fdt_grab_space(fdt, sizeof(*nh) + FDT_TAGALIGN(namelen));\r
+       if (! nh)\r
+               return -FDT_ERR_NOSPACE;\r
+\r
+       nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);\r
+       memcpy(nh->name, name, namelen);\r
+       return 0;\r
+}\r
+\r
+int fdt_end_node(void *fdt)\r
+{\r
+       uint32_t *en;\r
+\r
+       FDT_SW_CHECK_HEADER(fdt);\r
+\r
+       en = _fdt_grab_space(fdt, FDT_TAGSIZE);\r
+       if (! en)\r
+               return -FDT_ERR_NOSPACE;\r
+\r
+       *en = cpu_to_fdt32(FDT_END_NODE);\r
+       return 0;\r
+}\r
+\r
+static int _fdt_find_add_string(void *fdt, const char *s)\r
+{\r
+       char *strtab = (char *)fdt + fdt_totalsize(fdt);\r
+       const char *p;\r
+       int strtabsize = fdt_size_dt_strings(fdt);\r
+       int len = strlen(s) + 1;\r
+       int struct_top, offset;\r
+\r
+       p = _fdt_find_string(strtab - strtabsize, strtabsize, s);\r
+       if (p)\r
+               return p - strtab;\r
+\r
+       /* Add it */\r
+       offset = -strtabsize - len;\r
+       struct_top = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);\r
+       if (fdt_totalsize(fdt) + offset < struct_top)\r
+               return 0; /* no more room :( */\r
+\r
+       memcpy(strtab + offset, s, len);\r
+       fdt_set_size_dt_strings(fdt, strtabsize + len);\r
+       return offset;\r
+}\r
+\r
+int fdt_property(void *fdt, const char *name, const void *val, int len)\r
+{\r
+       struct fdt_property *prop;\r
+       int nameoff;\r
+\r
+       FDT_SW_CHECK_HEADER(fdt);\r
+\r
+       nameoff = _fdt_find_add_string(fdt, name);\r
+       if (nameoff == 0)\r
+               return -FDT_ERR_NOSPACE;\r
+\r
+       prop = _fdt_grab_space(fdt, sizeof(*prop) + FDT_TAGALIGN(len));\r
+       if (! prop)\r
+               return -FDT_ERR_NOSPACE;\r
+\r
+       prop->tag = cpu_to_fdt32(FDT_PROP);\r
+       prop->nameoff = cpu_to_fdt32(nameoff);\r
+       prop->len = cpu_to_fdt32(len);\r
+       memcpy(prop->data, val, len);\r
+       return 0;\r
+}\r
+\r
+int fdt_finish(void *fdt)\r
+{\r
+       char *p = (char *)fdt;\r
+       uint32_t *end;\r
+       int oldstroffset, newstroffset;\r
+       uint32_t tag;\r
+       int offset, nextoffset;\r
+\r
+       FDT_SW_CHECK_HEADER(fdt);\r
+\r
+       /* Add terminator */\r
+       end = _fdt_grab_space(fdt, sizeof(*end));\r
+       if (! end)\r
+               return -FDT_ERR_NOSPACE;\r
+       *end = cpu_to_fdt32(FDT_END);\r
+\r
+       /* Relocate the string table */\r
+       oldstroffset = fdt_totalsize(fdt) - fdt_size_dt_strings(fdt);\r
+       newstroffset = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);\r
+       memmove(p + newstroffset, p + oldstroffset, fdt_size_dt_strings(fdt));\r
+       fdt_set_off_dt_strings(fdt, newstroffset);\r
+\r
+       /* Walk the structure, correcting string offsets */\r
+       offset = 0;\r
+       while ((tag = fdt_next_tag(fdt, offset, &nextoffset)) != FDT_END) {\r
+               if (tag == FDT_PROP) {\r
+                       struct fdt_property *prop =\r
+                               _fdt_offset_ptr_w(fdt, offset);\r
+                       int nameoff;\r
+\r
+                       nameoff = fdt32_to_cpu(prop->nameoff);\r
+                       nameoff += fdt_size_dt_strings(fdt);\r
+                       prop->nameoff = cpu_to_fdt32(nameoff);\r
+               }\r
+               offset = nextoffset;\r
+       }\r
+       if (nextoffset < 0)\r
+               return nextoffset;\r
+\r
+       /* Finally, adjust the header */\r
+       fdt_set_totalsize(fdt, newstroffset + fdt_size_dt_strings(fdt));\r
+       fdt_set_magic(fdt, FDT_MAGIC);\r
+       return 0;\r
+}\r
index 6025fa1fe8feeb046a68605776d0d1ecac1efe9f..e009a88f5112d7c14403474852bb2cdee0f266f3 100644 (file)
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2006 David Gibson, IBM Corporation.
- *
- * libfdt is dual licensed: you can use it either under the terms of
- * the GPL, or the BSD license, at your option.
- *
- *  a) This library is free software; you can redistribute it and/or
- *     modify it under the terms of the GNU General Public License as
- *     published by the Free Software Foundation; either version 2 of the
- *     License, or (at your option) any later version.
- *
- *     This library is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- *
- *     You should have received a copy of the GNU General Public
- *     License along with this library; if not, write to the Free
- *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
- *     MA 02110-1301 USA
- *
- * Alternatively,
- *
- *  b) Redistribution and use in source and binary forms, with or
- *     without modification, are permitted provided that the following
- *     conditions are met:
- *
- *     1. Redistributions of source code must retain the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer.
- *     2. Redistributions in binary form must reproduce the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer in the documentation and/or other materials
- *        provided with the distribution.
- *
- *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "libfdt_env.h"
-
-#include <fdt.h>
-#include <libfdt.h>
-
-#include "libfdt_internal.h"
-
-int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
-                       const void *val, int len)
-{
-       void *propval;
-       int proplen;
-
-       propval = fdt_getprop_w(fdt, nodeoffset, name, &proplen);
-       if (! propval)
-               return proplen;
-
-       if (proplen != len)
-               return -FDT_ERR_NOSPACE;
-
-       memcpy(propval, val, len);
-       return 0;
-}
-
-static void _fdt_nop_region(void *start, int len)
-{
-       uint32_t *p;
-
-       for (p = start; (char *)p < ((char *)start + len); p++)
-               *p = cpu_to_fdt32(FDT_NOP);
-}
-
-int fdt_nop_property(void *fdt, int nodeoffset, const char *name)
-{
-       struct fdt_property *prop;
-       int len;
-
-       prop = fdt_get_property_w(fdt, nodeoffset, name, &len);
-       if (! prop)
-               return len;
-
-       _fdt_nop_region(prop, len + sizeof(*prop));
-
-       return 0;
-}
-
-int _fdt_node_end_offset(void *fdt, int offset)
-{
-       int depth = 0;
-
-       while ((offset >= 0) && (depth >= 0))
-               offset = fdt_next_node(fdt, offset, &depth);
-
-       return offset;
-}
-
-int fdt_nop_node(void *fdt, int nodeoffset)
-{
-       int endoffset;
-
-       endoffset = _fdt_node_end_offset(fdt, nodeoffset);
-       if (endoffset < 0)
-               return endoffset;
-
-       _fdt_nop_region(fdt_offset_ptr_w(fdt, nodeoffset, 0),
-                       endoffset - nodeoffset);
-       return 0;
-}
+/*\r
+ * libfdt - Flat Device Tree manipulation\r
+ * Copyright (C) 2006 David Gibson, IBM Corporation.\r
+ *\r
+ * libfdt is dual licensed: you can use it either under the terms of\r
+ * the GPL, or the BSD license, at your option.\r
+ *\r
+ *  a) This library is free software; you can redistribute it and/or\r
+ *     modify it under the terms of the GNU General Public License as\r
+ *     published by the Free Software Foundation; either version 2 of the\r
+ *     License, or (at your option) any later version.\r
+ *\r
+ *     This library is distributed in the hope that it will be useful,\r
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ *     GNU General Public License for more details.\r
+ *\r
+ *     You should have received a copy of the GNU General Public\r
+ *     License along with this library; if not, write to the Free\r
+ *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\r
+ *     MA 02110-1301 USA\r
+ *\r
+ * Alternatively,\r
+ *\r
+ *  b) Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *     1. Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *     2. Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\r
+ *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,\r
+ *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
+ *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+ *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
+ *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
+ *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
+ *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#include "libfdt_env.h"\r
+\r
+#include <fdt.h>\r
+#include <libfdt.h>\r
+\r
+#include "libfdt_internal.h"\r
+\r
+int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,\r
+                       const void *val, int len)\r
+{\r
+       void *propval;\r
+       int proplen;\r
+\r
+       propval = fdt_getprop_w(fdt, nodeoffset, name, &proplen);\r
+       if (! propval)\r
+               return proplen;\r
+\r
+       if (proplen != len)\r
+               return -FDT_ERR_NOSPACE;\r
+\r
+       memcpy(propval, val, len);\r
+       return 0;\r
+}\r
+\r
+static void _fdt_nop_region(void *start, int len)\r
+{\r
+       uint32_t *p;\r
+\r
+       for (p = start; (char *)p < ((char *)start + len); p++)\r
+               *p = cpu_to_fdt32(FDT_NOP);\r
+}\r
+\r
+int fdt_nop_property(void *fdt, int nodeoffset, const char *name)\r
+{\r
+       struct fdt_property *prop;\r
+       int len;\r
+\r
+       prop = fdt_get_property_w(fdt, nodeoffset, name, &len);\r
+       if (! prop)\r
+               return len;\r
+\r
+       _fdt_nop_region(prop, len + sizeof(*prop));\r
+\r
+       return 0;\r
+}\r
+\r
+int _fdt_node_end_offset(void *fdt, int offset)\r
+{\r
+       int depth = 0;\r
+\r
+       while ((offset >= 0) && (depth >= 0))\r
+               offset = fdt_next_node(fdt, offset, &depth);\r
+\r
+       return offset;\r
+}\r
+\r
+int fdt_nop_node(void *fdt, int nodeoffset)\r
+{\r
+       int endoffset;\r
+\r
+       endoffset = _fdt_node_end_offset(fdt, nodeoffset);\r
+       if (endoffset < 0)\r
+               return endoffset;\r
+\r
+       _fdt_nop_region(fdt_offset_ptr_w(fdt, nodeoffset, 0),\r
+                       endoffset - nodeoffset);\r
+       return 0;\r
+}\r
index 381133ba81df7d02c375d7a1462d650136abd6d1..15456110a34e18fff9870eb9657ef9c28e6b8176 100644 (file)
@@ -1,95 +1,95 @@
-#ifndef _LIBFDT_INTERNAL_H
-#define _LIBFDT_INTERNAL_H
-/*
- * libfdt - Flat Device Tree manipulation
- * Copyright (C) 2006 David Gibson, IBM Corporation.
- *
- * libfdt is dual licensed: you can use it either under the terms of
- * the GPL, or the BSD license, at your option.
- *
- *  a) This library is free software; you can redistribute it and/or
- *     modify it under the terms of the GNU General Public License as
- *     published by the Free Software Foundation; either version 2 of the
- *     License, or (at your option) any later version.
- *
- *     This library is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- *
- *     You should have received a copy of the GNU General Public
- *     License along with this library; if not, write to the Free
- *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
- *     MA 02110-1301 USA
- *
- * Alternatively,
- *
- *  b) Redistribution and use in source and binary forms, with or
- *     without modification, are permitted provided that the following
- *     conditions are met:
- *
- *     1. Redistributions of source code must retain the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer.
- *     2. Redistributions in binary form must reproduce the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer in the documentation and/or other materials
- *        provided with the distribution.
- *
- *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include <fdt.h>
-
-#define FDT_ALIGN(x, a)                (((x) + (a) - 1) & ~((a) - 1))
-#define FDT_TAGALIGN(x)                (FDT_ALIGN((x), FDT_TAGSIZE))
-
-#define FDT_CHECK_HEADER(fdt) \
-       { \
-               int err; \
-               if ((err = fdt_check_header(fdt)) != 0) \
-                       return err; \
-       }
-
-int _fdt_check_node_offset(const void *fdt, int offset);
-int _fdt_check_prop_offset(const void *fdt, int offset);
-const char *_fdt_find_string(const char *strtab, int tabsize, const char *s);
-int _fdt_node_end_offset(void *fdt, int nodeoffset);
-
-static inline const void *_fdt_offset_ptr(const void *fdt, int offset)
-{
-       return (const char *)fdt + fdt_off_dt_struct(fdt) + offset;
-}
-
-static inline void *_fdt_offset_ptr_w(void *fdt, int offset)
-{
-       return (void *)(uintptr_t)_fdt_offset_ptr(fdt, offset);
-}
-
-static inline const struct fdt_reserve_entry *_fdt_mem_rsv(const void *fdt, int n)
-{
-       const struct fdt_reserve_entry *rsv_table =
-               (const struct fdt_reserve_entry *)
-               ((const char *)fdt + fdt_off_mem_rsvmap(fdt));
-
-       return rsv_table + n;
-}
-static inline struct fdt_reserve_entry *_fdt_mem_rsv_w(void *fdt, int n)
-{
-       return (void *)(uintptr_t)_fdt_mem_rsv(fdt, n);
-}
-
-#define FDT_SW_MAGIC           (~FDT_MAGIC)
-
-#endif /* _LIBFDT_INTERNAL_H */
+#ifndef _LIBFDT_INTERNAL_H\r
+#define _LIBFDT_INTERNAL_H\r
+/*\r
+ * libfdt - Flat Device Tree manipulation\r
+ * Copyright (C) 2006 David Gibson, IBM Corporation.\r
+ *\r
+ * libfdt is dual licensed: you can use it either under the terms of\r
+ * the GPL, or the BSD license, at your option.\r
+ *\r
+ *  a) This library is free software; you can redistribute it and/or\r
+ *     modify it under the terms of the GNU General Public License as\r
+ *     published by the Free Software Foundation; either version 2 of the\r
+ *     License, or (at your option) any later version.\r
+ *\r
+ *     This library is distributed in the hope that it will be useful,\r
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ *     GNU General Public License for more details.\r
+ *\r
+ *     You should have received a copy of the GNU General Public\r
+ *     License along with this library; if not, write to the Free\r
+ *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\r
+ *     MA 02110-1301 USA\r
+ *\r
+ * Alternatively,\r
+ *\r
+ *  b) Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *     1. Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *     2. Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\r
+ *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,\r
+ *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
+ *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+ *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
+ *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
+ *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
+ *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#include <fdt.h>\r
+\r
+#define FDT_ALIGN(x, a)                (((x) + (a) - 1) & ~((a) - 1))\r
+#define FDT_TAGALIGN(x)                (FDT_ALIGN((x), FDT_TAGSIZE))\r
+\r
+#define FDT_CHECK_HEADER(fdt) \\r
+       { \\r
+               int err; \\r
+               if ((err = fdt_check_header(fdt)) != 0) \\r
+                       return err; \\r
+       }\r
+\r
+int _fdt_check_node_offset(const void *fdt, int offset);\r
+int _fdt_check_prop_offset(const void *fdt, int offset);\r
+const char *_fdt_find_string(const char *strtab, int tabsize, const char *s);\r
+int _fdt_node_end_offset(void *fdt, int nodeoffset);\r
+\r
+static inline const void *_fdt_offset_ptr(const void *fdt, int offset)\r
+{\r
+       return (const char *)fdt + fdt_off_dt_struct(fdt) + offset;\r
+}\r
+\r
+static inline void *_fdt_offset_ptr_w(void *fdt, int offset)\r
+{\r
+       return (void *)(uintptr_t)_fdt_offset_ptr(fdt, offset);\r
+}\r
+\r
+static inline const struct fdt_reserve_entry *_fdt_mem_rsv(const void *fdt, int n)\r
+{\r
+       const struct fdt_reserve_entry *rsv_table =\r
+               (const struct fdt_reserve_entry *)\r
+               ((const char *)fdt + fdt_off_mem_rsvmap(fdt));\r
+\r
+       return rsv_table + n;\r
+}\r
+static inline struct fdt_reserve_entry *_fdt_mem_rsv_w(void *fdt, int n)\r
+{\r
+       return (void *)(uintptr_t)_fdt_mem_rsv(fdt, n);\r
+}\r
+\r
+#define FDT_SW_MAGIC           (~FDT_MAGIC)\r
+\r
+#endif /* _LIBFDT_INTERNAL_H */\r
index f8c4e296ca354fdcaa0e6481617c41803a3d80a6..9c3cc3ce3c680f90931fe5f3fd875b6383b119c8 100755 (executable)
-#------------------------------------------------------------------------------ 
-#
-# Use ARMv6 instruction to operate on a single stack
-#
-# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#------------------------------------------------------------------------------
-
-/*
-
-This is the stack constructed by the exception handler (low address to high address)
-                # R0 - IFAR is EFI_SYSTEM_CONTEXT for ARM
-  Reg   Offset
-  ===   ======              
-  R0    0x00    # stmfd     SP!,{R0-R12}
-  R1    0x04
-  R2    0x08
-  R3    0x0c
-  R4    0x10
-  R5    0x14
-  R6    0x18
-  R7    0x1c
-  R8    0x20
-  R9    0x24
-  R10   0x28
-  R11   0x2c
-  R12   0x30
-  SP    0x34    # reserved via adding 0x20 (32) to the SP
-  LR    0x38
-  PC    0x3c
-  CPSR  0x40
-  DFSR  0x44
-  DFAR  0x48
-  IFSR  0x4c
-  IFAR  0x50
-  
-  LR    0x54    # SVC Link register (we need to restore it)
-  
-  LR    0x58    # pushed by srsfd    
-  CPSR  0x5c    
-
- */
-
-GCC_ASM_EXPORT(ExceptionHandlersStart)
-GCC_ASM_EXPORT(ExceptionHandlersEnd)
-GCC_ASM_EXPORT(CommonExceptionEntry)
-GCC_ASM_EXPORT(AsmCommonExceptionEntry)
-GCC_ASM_EXPORT(GdbExceptionHandler)
-
-.text
-.align 3
-
-
-//
-// This code gets copied to the ARM vector table
-// ExceptionHandlersStart - ExceptionHandlersEnd gets copied
-//
-ASM_PFX(ExceptionHandlersStart):
-
-ASM_PFX(Reset):
-  b ASM_PFX(Reset)
-
-ASM_PFX(UndefinedInstruction):
-  b ASM_PFX(UndefinedInstructionEntry)
-
-ASM_PFX(SoftwareInterrupt):
-  b ASM_PFX(SoftwareInterruptEntry)
-
-ASM_PFX(PrefetchAbort):
-  b ASM_PFX(PrefetchAbortEntry)
-
-ASM_PFX(DataAbort):
-  b ASM_PFX(DataAbortEntry)
-
-ASM_PFX(ReservedException):
-  b ASM_PFX(ReservedExceptionEntry)
-
-ASM_PFX(Irq):
-  b ASM_PFX(Irq)
-
-ASM_PFX(Fiq):
-  b ASM_PFX(FiqEntry)
-
-
-ASM_PFX(UndefinedInstructionEntry):
-  sub       LR, LR, #4                @ Only -2 for Thumb, adjust in CommonExceptionEntry
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cpsid     f,#0x13                   @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       R0,#1                     @ ExceptionType
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(SoftwareInterruptEntry):
-  sub       LR, LR, #4                @ Only -2 for Thumb, adjust in CommonExceptionEntry
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cpsid     f                         @ We are already in SVC mode
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       R0,#2                     @ ExceptionType
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(PrefetchAbortEntry):
-  sub       LR,LR,#4
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cpsid     f,#0x13                   @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       R0,#3                     @ ExceptionType
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(DataAbortEntry):
-  sub       LR,LR,#8
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cpsid     f,#0x13                   @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       R0,#4
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(ReservedExceptionEntry):
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cpsid     f,#0x13                   @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-
-  mov       R0,#5
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-ASM_PFX(FiqEntry):
-  sub       LR,LR,#4
-  srsdb     #0x13!                    @ Store return state on SVC stack
-  cps       #0x13                     @ Switch to SVC for common stack
-  stmfd     SP!,{LR}                  @ Store the link register for the current mode
-  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              @ Store the register state
-                                      @ Since we have already switch to SVC R8_fiq - R12_fiq
-                                      @ never get used or saved
-  mov       R0,#7                     @ ExceptionType
-  ldr       R1,ASM_PFX(CommonExceptionEntry)
-  bx        R1
-
-//
-// This gets patched by the C code that patches in the vector table
-//
-ASM_PFX(CommonExceptionEntry):
-  .byte       0x12
-  .byte       0x34
-  .byte       0x56
-  .byte       0x78
-
-ASM_PFX(ExceptionHandlersEnd):
-
-//
-// This code runs from CpuDxe driver loaded address. It is patched into 
-// CommonExceptionEntry.
-//
-ASM_PFX(AsmCommonExceptionEntry):
-  mrc       p15, 0, R1, c6, c0, 2   @ Read IFAR
-  str       R1, [SP, #0x50]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFAR 
-  
-  mrc       p15, 0, R1, c5, c0, 1   @ Read IFSR
-  str       R1, [SP, #0x4c]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFSR
-  
-  mrc       p15, 0, R1, c6, c0, 0   @ Read DFAR
-  str       R1, [SP, #0x48]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFAR
-  
-  mrc       p15, 0, R1, c5, c0, 0   @ Read DFSR
-  str       R1, [SP, #0x44]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFSR
-  
-  ldr       R1, [SP, #0x5c]         @ srsdb saved pre-exception CPSR on the stack 
-  str       R1, [SP, #0x40]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.CPSR
-
-  add       R2, SP, #0x38           @ Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR
-  and       R3, R1, #0x1f           @ Check CPSR to see if User or System Mode
-  cmp       R3, #0x1f               @ if ((CPSR == 0x10) || (CPSR == 0x1df))
-  cmpne     R3, #0x10               @   
-  stmeqed   R2, {lr}^               @   save unbanked lr
-                                    @ else 
-  stmneed   R2, {lr}                @   save SVC lr
-
-
-  ldr       R5, [SP, #0x58]         @ PC is the LR pushed by srsfd 
-                                    @ Check to see if we have to adjust for Thumb entry
-  sub       r4, r0, #1              @ if (ExceptionType == 1 || ExceptionType ==2)) {
-  cmp       r4, #1                  @   // UND & SVC have differnt LR adjust for Thumb 
-  bhi       NoAdjustNeeded
-  
-  tst       r1, #0x20               @   if ((CPSR & T)) == T) {  // Thumb Mode on entry 
-  addne     R5, R5, #2              @     PC += 2@
-  str       R5,[SP,#0x58]           @ Update LR value pused by srsfd 
-  
-NoAdjustNeeded:
-
-  str       R5, [SP, #0x3c]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.PC
-  
-  sub       R1, SP, #0x60           @ We pused 0x60 bytes on the stack 
-  str       R1, [SP, #0x34]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.SP
-  
-                                    @ R0 is ExceptionType 
-  mov       R1,SP                   @ R1 is SystemContext 
-
-/* 
-VOID
-EFIAPI
-GdbExceptionHandler (
-  IN     EFI_EXCEPTION_TYPE           ExceptionType,   R0
-  IN OUT EFI_SYSTEM_CONTEXT           SystemContext    R1
-  )
-
-*/  
-  blx       ASM_PFX(GdbExceptionHandler)  @ Call exception handler
-  
-  ldr       R1,[SP,#0x3c]           @ EFI_SYSTEM_CONTEXT_ARM.PC
-  str       R1,[SP,#0x58]           @ Store it back to srsfd stack slot so it can be restored 
-
-  ldr       R1,[SP,#0x40]           @ EFI_SYSTEM_CONTEXT_ARM.CPSR
-  str       R1,[SP,#0x5c]           @ Store it back to srsfd stack slot so it can be restored 
-  
-  add       R3, SP, #0x54           @ Make R3 point to SVC LR saved on entry
-  add       R2, SP, #0x38           @ Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR
-  and       R1, R1, #0x1f           @ Check to see if User or System Mode
-  cmp       R1, #0x1f               @ if ((CPSR == 0x10) || (CPSR == 0x1f))
-  cmpne     R1, #0x10               @   
-  ldmeqed   R2, {lr}^               @   restore unbanked lr
-                                    @ else
-  ldmneed   R3, {lr}                @   restore SVC lr, via ldmfd SP!, {LR}
-  
-  ldmfd     SP!,{R0-R12}            @ Restore general purpose registers
-                                    @ Exception handler can not change SP
-                                    
-  add       SP,SP,#0x20             @ Clear out the remaining stack space
-  ldmfd     SP!,{LR}                @ restore the link register for this context
-  rfefd     SP!                     @ return from exception via srsfd stack slot
-  
+#------------------------------------------------------------------------------ \r
+#\r
+# Use ARMv6 instruction to operate on a single stack\r
+#\r
+# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+/*\r
+\r
+This is the stack constructed by the exception handler (low address to high address)\r
+                # R0 - IFAR is EFI_SYSTEM_CONTEXT for ARM\r
+  Reg   Offset\r
+  ===   ======              \r
+  R0    0x00    # stmfd     SP!,{R0-R12}\r
+  R1    0x04\r
+  R2    0x08\r
+  R3    0x0c\r
+  R4    0x10\r
+  R5    0x14\r
+  R6    0x18\r
+  R7    0x1c\r
+  R8    0x20\r
+  R9    0x24\r
+  R10   0x28\r
+  R11   0x2c\r
+  R12   0x30\r
+  SP    0x34    # reserved via adding 0x20 (32) to the SP\r
+  LR    0x38\r
+  PC    0x3c\r
+  CPSR  0x40\r
+  DFSR  0x44\r
+  DFAR  0x48\r
+  IFSR  0x4c\r
+  IFAR  0x50\r
+  \r
+  LR    0x54    # SVC Link register (we need to restore it)\r
+  \r
+  LR    0x58    # pushed by srsfd    \r
+  CPSR  0x5c    \r
+\r
+ */\r
\r
+\r
+GCC_ASM_EXPORT(ExceptionHandlersStart)\r
+GCC_ASM_EXPORT(ExceptionHandlersEnd)\r
+GCC_ASM_EXPORT(CommonExceptionEntry)\r
+GCC_ASM_EXPORT(AsmCommonExceptionEntry)\r
+GCC_ASM_EXPORT(GdbExceptionHandler)\r
+\r
+.text\r
+.align 3\r
+\r
+\r
+//\r
+// This code gets copied to the ARM vector table\r
+// ExceptionHandlersStart - ExceptionHandlersEnd gets copied\r
+//\r
+ASM_PFX(ExceptionHandlersStart):\r
+\r
+ASM_PFX(Reset):\r
+  b ASM_PFX(Reset)\r
+\r
+ASM_PFX(UndefinedInstruction):\r
+  b ASM_PFX(UndefinedInstructionEntry)\r
+\r
+ASM_PFX(SoftwareInterrupt):\r
+  b ASM_PFX(SoftwareInterruptEntry)\r
+\r
+ASM_PFX(PrefetchAbort):\r
+  b ASM_PFX(PrefetchAbortEntry)\r
+\r
+ASM_PFX(DataAbort):\r
+  b ASM_PFX(DataAbortEntry)\r
+\r
+ASM_PFX(ReservedException):\r
+  b ASM_PFX(ReservedExceptionEntry)\r
+\r
+ASM_PFX(Irq):\r
+  b ASM_PFX(Irq)\r
+\r
+ASM_PFX(Fiq):\r
+  b ASM_PFX(FiqEntry)\r
+\r
+\r
+ASM_PFX(UndefinedInstructionEntry):\r
+  sub       LR, LR, #4                @ Only -2 for Thumb, adjust in CommonExceptionEntry\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cpsid     f,#0x13                   @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       R0,#1                     @ ExceptionType\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(SoftwareInterruptEntry):\r
+  sub       LR, LR, #4                @ Only -2 for Thumb, adjust in CommonExceptionEntry\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cpsid     f                         @ We are already in SVC mode\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       R0,#2                     @ ExceptionType\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(PrefetchAbortEntry):\r
+  sub       LR,LR,#4\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cpsid     f,#0x13                   @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       R0,#3                     @ ExceptionType\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(DataAbortEntry):\r
+  sub       LR,LR,#8\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cpsid     f,#0x13                   @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       R0,#4\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(ReservedExceptionEntry):\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cpsid     f,#0x13                   @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+\r
+  mov       R0,#5\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+ASM_PFX(FiqEntry):\r
+  sub       LR,LR,#4\r
+  srsdb     #0x13!                    @ Store return state on SVC stack\r
+  cps       #0x13                     @ Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  @ Store the link register for the current mode\r
+  sub       SP,SP,#0x20               @ Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              @ Store the register state\r
+                                      @ Since we have already switch to SVC R8_fiq - R12_fiq\r
+                                      @ never get used or saved\r
+  mov       R0,#7                     @ ExceptionType\r
+  ldr       R1,ASM_PFX(CommonExceptionEntry)\r
+  bx        R1\r
+\r
+//\r
+// This gets patched by the C code that patches in the vector table\r
+//\r
+ASM_PFX(CommonExceptionEntry):\r
+  .byte       0x12\r
+  .byte       0x34\r
+  .byte       0x56\r
+  .byte       0x78\r
+\r
+ASM_PFX(ExceptionHandlersEnd):\r
+\r
+//\r
+// This code runs from CpuDxe driver loaded address. It is patched into \r
+// CommonExceptionEntry.\r
+//\r
+ASM_PFX(AsmCommonExceptionEntry):\r
+  mrc       p15, 0, R1, c6, c0, 2   @ Read IFAR\r
+  str       R1, [SP, #0x50]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFAR \r
+  \r
+  mrc       p15, 0, R1, c5, c0, 1   @ Read IFSR\r
+  str       R1, [SP, #0x4c]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFSR\r
+  \r
+  mrc       p15, 0, R1, c6, c0, 0   @ Read DFAR\r
+  str       R1, [SP, #0x48]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFAR\r
+  \r
+  mrc       p15, 0, R1, c5, c0, 0   @ Read DFSR\r
+  str       R1, [SP, #0x44]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFSR\r
+  \r
+  ldr       R1, [SP, #0x5c]         @ srsdb saved pre-exception CPSR on the stack \r
+  str       R1, [SP, #0x40]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.CPSR\r
+\r
+  add       R2, SP, #0x38           @ Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR\r
+  and       R3, R1, #0x1f           @ Check CPSR to see if User or System Mode\r
+  cmp       R3, #0x1f               @ if ((CPSR == 0x10) || (CPSR == 0x1df))\r
+  cmpne     R3, #0x10               @   \r
+  stmeqed   R2, {lr}^               @   save unbanked lr\r
+                                    @ else \r
+  stmneed   R2, {lr}                @   save SVC lr\r
+\r
+\r
+  ldr       R5, [SP, #0x58]         @ PC is the LR pushed by srsfd \r
+                                    @ Check to see if we have to adjust for Thumb entry\r
+  sub       r4, r0, #1              @ if (ExceptionType == 1 || ExceptionType ==2)) {\r
+  cmp       r4, #1                  @   // UND & SVC have differnt LR adjust for Thumb \r
+  bhi       NoAdjustNeeded\r
+  \r
+  tst       r1, #0x20               @   if ((CPSR & T)) == T) {  // Thumb Mode on entry \r
+  addne     R5, R5, #2              @     PC += 2@\r
+  str       R5,[SP,#0x58]           @ Update LR value pused by srsfd \r
+  \r
+NoAdjustNeeded:\r
+\r
+  str       R5, [SP, #0x3c]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.PC\r
+  \r
+  sub       R1, SP, #0x60           @ We pused 0x60 bytes on the stack \r
+  str       R1, [SP, #0x34]         @ Store it in EFI_SYSTEM_CONTEXT_ARM.SP\r
+  \r
+                                    @ R0 is ExceptionType \r
+  mov       R1,SP                   @ R1 is SystemContext \r
+\r
+/* \r
+VOID\r
+EFIAPI\r
+GdbExceptionHandler (\r
+  IN     EFI_EXCEPTION_TYPE           ExceptionType,   R0\r
+  IN OUT EFI_SYSTEM_CONTEXT           SystemContext    R1\r
+  )\r
+\r
+*/  \r
+  blx       ASM_PFX(GdbExceptionHandler)  @ Call exception handler\r
+  \r
+  ldr       R1,[SP,#0x3c]           @ EFI_SYSTEM_CONTEXT_ARM.PC\r
+  str       R1,[SP,#0x58]           @ Store it back to srsfd stack slot so it can be restored \r
+\r
+  ldr       R1,[SP,#0x40]           @ EFI_SYSTEM_CONTEXT_ARM.CPSR\r
+  str       R1,[SP,#0x5c]           @ Store it back to srsfd stack slot so it can be restored \r
+  \r
+  add       R3, SP, #0x54           @ Make R3 point to SVC LR saved on entry\r
+  add       R2, SP, #0x38           @ Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR\r
+  and       R1, R1, #0x1f           @ Check to see if User or System Mode\r
+  cmp       R1, #0x1f               @ if ((CPSR == 0x10) || (CPSR == 0x1f))\r
+  cmpne     R1, #0x10               @   \r
+  ldmeqed   R2, {lr}^               @   restore unbanked lr\r
+                                    @ else\r
+  ldmneed   R3, {lr}                @   restore SVC lr, via ldmfd SP!, {LR}\r
+  \r
+  ldmfd     SP!,{R0-R12}            @ Restore general purpose registers\r
+                                    @ Exception handler can not change SP\r
+                                    \r
+  add       SP,SP,#0x20             @ Clear out the remaining stack space\r
+  ldmfd     SP!,{LR}                @ restore the link register for this context\r
+  rfefd     SP!                     @ return from exception via srsfd stack slot\r
+  \r
index c133073f4bc1cfd9dac8a53fc05ba7d064533d4c..c70fb924828ad7af24b352fee41aedc09a0445d0 100755 (executable)
-//------------------------------------------------------------------------------ 
-//
-// Use ARMv6 instruction to operate on a single stack
-//
-// Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-
-
-/*
-
-This is the stack constructed by the exception handler (low address to high address)
-                # R0 - IFAR is EFI_SYSTEM_CONTEXT for ARM
-  Reg   Offset
-  ===   ======              
-  R0    0x00    # stmfd     SP!,{R0-R12}
-  R1    0x04
-  R2    0x08
-  R3    0x0c
-  R4    0x10
-  R5    0x14
-  R6    0x18
-  R7    0x1c
-  R8    0x20
-  R9    0x24
-  R10   0x28
-  R11   0x2c
-  R12   0x30
-  SP    0x34    # reserved via adding 0x20 (32) to the SP
-  LR    0x38
-  PC    0x3c
-  CPSR  0x40
-  DFSR  0x44
-  DFAR  0x48
-  IFSR  0x4c
-  IFAR  0x50
-  
-  LR    0x54    # SVC Link register (we need to restore it)
-  
-  LR    0x58    # pushed by srsfd    
-  CPSR  0x5c    
-
- */
-  EXPORT  ExceptionHandlersStart
-  EXPORT  ExceptionHandlersEnd
-  EXPORT  CommonExceptionEntry
-  EXPORT  AsmCommonExceptionEntry
-  IMPORT  GdbExceptionHandler
-
-  PRESERVE8
-  AREA  DxeExceptionHandlers, CODE, READONLY
-  
-//
-// This code gets copied to the ARM vector table
-// ExceptionHandlersStart - ExceptionHandlersEnd gets copied
-//
-ExceptionHandlersStart
-
-Reset
-  b   Reset
-
-UndefinedInstruction
-  b   UndefinedInstructionEntry
-
-SoftwareInterrupt
-  b   SoftwareInterruptEntry
-
-PrefetchAbort
-  b   PrefetchAbortEntry
-
-DataAbort
-  b   DataAbortEntry
-
-ReservedException
-  b   ReservedExceptionEntry
-
-Irq
-  b   Irq
-
-Fiq
-  b   FiqEntry
-
-
-UndefinedInstructionEntry
-  sub       LR, LR, #4                ; Only -2 for Thumb, adjust in CommonExceptionEntry
-  srsfd     #0x13!                    ; Store return state on SVC stack
-  cpsid     f, #0x13                  ; Switch to SVC for common stack
-  stmfd     SP!,{LR}                  ; Store the link register for the current mode
-  sub       SP,SP,#0x20               ; Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              ; Store the register state
-
-  mov       R0,#1                     ; ExceptionType
-  ldr       R1,CommonExceptionEntry; 
-  bx        R1
-
-SoftwareInterruptEntry
-  sub       LR, LR, #4                ; Only -2 for Thumb, adjust in CommonExceptionEntry
-  srsfd     #0x13!                    ; Store return state on SVC stack
-  cpsid     f                         ; We are already in SVC mode
-  stmfd     SP!,{LR}                  ; Store the link register for the current mode
-  sub       SP,SP,#0x20               ; Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              ; Store the register state
-
-  mov       R0,#2                     ; ExceptionType
-  ldr       R1,CommonExceptionEntry
-  bx        R1
-
-PrefetchAbortEntry
-  sub       LR,LR,#4
-  srsfd     #0x13!                    ; Store return state on SVC stack
-  cpsid     f, #0x13                  ; Switch to SVC for common stack
-  stmfd     SP!,{LR}                  ; Store the link register for the current mode
-  sub       SP,SP,#0x20               ; Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              ; Store the register state
-
-  mov       R0,#3                     ; ExceptionType
-  ldr       R1,CommonExceptionEntry
-  bx        R1
-
-DataAbortEntry
-  sub       LR,LR,#8
-  srsfd     #0x13!                    ; Store return state on SVC stack
-  cpsid     f, #0x13                  ; Switch to SVC for common stack
-  stmfd     SP!,{LR}                  ; Store the link register for the current mode
-  sub       SP,SP,#0x20               ; Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              ; Store the register state
-
-  mov       R0,#4                     ; ExceptionType
-  ldr       R1,CommonExceptionEntry
-  bx        R1
-
-ReservedExceptionEntry
-  srsfd     #0x13!                    ; Store return state on SVC stack
-  cpsid     f, #0x13                  ; Switch to SVC for common stack
-  stmfd     SP!,{LR}                  ; Store the link register for the current mode
-  sub       SP,SP,#0x20               ; Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              ; Store the register state
-
-  mov       R0,#5                     ; ExceptionType
-  ldr       R1,CommonExceptionEntry
-  bx        R1
-
-FiqEntry
-  sub       LR,LR,#4
-  srsfd     #0x13!                    ; Store return state on SVC stack
-  cps       #0x13                     ; Switch to SVC for common stack
-  stmfd     SP!,{LR}                  ; Store the link register for the current mode
-  sub       SP,SP,#0x20               ; Save space for SP, LR, PC, IFAR - CPSR
-  stmfd     SP!,{R0-R12}              ; Store the register state
-                                      ; Since we have already switch to SVC R8_fiq - R12_fiq
-                                      ; never get used or saved
-  mov       R0,#7                     ; ExceptionType
-  ldr       R1,CommonExceptionEntry
-  bx        R1
-
-//
-// This gets patched by the C code that patches in the vector table
-//
-CommonExceptionEntry
-  dcd       0x12345678
-
-ExceptionHandlersEnd
-
-//
-// This code runs from CpuDxe driver loaded address. It is patched into 
-// CommonExceptionEntry.
-//
-AsmCommonExceptionEntry
-  mrc       p15, 0, R1, c6, c0, 2   ; Read IFAR
-  str       R1, [SP, #0x50]         ; Store it in EFI_SYSTEM_CONTEXT_ARM.IFAR 
-  
-  mrc       p15, 0, R1, c5, c0, 1   ; Read IFSR
-  str       R1, [SP, #0x4c]         ; Store it in EFI_SYSTEM_CONTEXT_ARM.IFSR
-  
-  mrc       p15, 0, R1, c6, c0, 0   ; Read DFAR
-  str       R1, [SP, #0x48]         ; Store it in EFI_SYSTEM_CONTEXT_ARM.DFAR
-  
-  mrc       p15, 0, R1, c5, c0, 0   ; Read DFSR
-  str       R1, [SP, #0x44]         ; Store it in EFI_SYSTEM_CONTEXT_ARM.DFSR
-  
-  ldr       R1, [SP, #0x5c]         ; srsfd saved pre-exception CPSR on the stack 
-  str       R1, [SP, #0x40]         ; Store it in EFI_SYSTEM_CONTEXT_ARM.CPSR
-
-  add       R2, SP, #0x38           ; Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR
-  and       R3, R1, #0x1f           ; Check CPSR to see if User or System Mode
-  cmp       R3, #0x1f               ; if ((CPSR == 0x10) || (CPSR == 0x1df))
-  cmpne     R3, #0x10               ;   
-  stmeqed   R2, {lr}^               ;   save unbanked lr
-                                    ; else 
-  stmneed   R2, {lr}                ;   save SVC lr
-
-
-  ldr       R5, [SP, #0x58]         ; PC is the LR pushed by srsfd 
-                                    ; Check to see if we have to adjust for Thumb entry
-  sub       r4, r0, #1              ; if (ExceptionType == 1 || ExceptionType ==2)) {
-  cmp       r4, #1                  ;   // UND & SVC have differnt LR adjust for Thumb 
-  bhi       NoAdjustNeeded
-  
-  tst       r1, #0x20               ;   if ((CPSR & T)) == T) {  // Thumb Mode on entry 
-  addne     R5, R5, #2              ;     PC += 2;
-  str       R5,[SP,#0x58]           ; Update LR value pused by srsfd 
-  
-NoAdjustNeeded
-
-  str       R5, [SP, #0x3c]         ; Store it in EFI_SYSTEM_CONTEXT_ARM.PC
-  
-  sub       R1, SP, #0x60           ; We pused 0x60 bytes on the stack 
-  str       R1, [SP, #0x34]         ; Store it in EFI_SYSTEM_CONTEXT_ARM.SP
-  
-                                    ; R0 is ExceptionType 
-  mov       R1,SP                   ; R1 is SystemContext 
-
-/* 
-VOID
-EFIAPI
-GdbExceptionHandler (
-  IN     EFI_EXCEPTION_TYPE           ExceptionType,   R0
-  IN OUT EFI_SYSTEM_CONTEXT           SystemContext    R1
-  )
-
-*/
-  blx       GdbExceptionHandler     ; Call exception handler
-  
-  ldr       R1,[SP,#0x3c]           ; EFI_SYSTEM_CONTEXT_ARM.PC
-  str       R1,[SP,#0x58]           ; Store it back to srsfd stack slot so it can be restored 
-
-  ldr       R1,[SP,#0x40]           ; EFI_SYSTEM_CONTEXT_ARM.CPSR
-  str       R1,[SP,#0x5c]           ; Store it back to srsfd stack slot so it can be restored 
-  
-  add       R3, SP, #0x54           ; Make R3 point to SVC LR saved on entry
-  add       R2, SP, #0x38           ; Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR
-  and       R1, R1, #0x1f           ; Check to see if User or System Mode
-  cmp       R1, #0x1f               ; if ((CPSR == 0x10) || (CPSR == 0x1f))
-  cmpne     R1, #0x10               ;   
-  ldmeqed   R2, {lr}^               ;   restore unbanked lr
-                                    ; else
-  ldmneed   R3, {lr}                ;   restore SVC lr, via ldmfd SP!, {LR}
-  
-  ldmfd     SP!,{R0-R12}            ; Restore general purpose registers
-                                    ; Exception handler can not change SP
-                                    
-  add       SP,SP,#0x20             ; Clear out the remaining stack space
-  ldmfd     SP!,{LR}                ; restore the link register for this context
-  rfefd     SP!                     ; return from exception via srsfd stack slot
-  
-  END
-
-
+//------------------------------------------------------------------------------ \r
+//\r
+// Use ARMv6 instruction to operate on a single stack\r
+//\r
+// Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+\r
+\r
+/*\r
+\r
+This is the stack constructed by the exception handler (low address to high address)\r
+                # R0 - IFAR is EFI_SYSTEM_CONTEXT for ARM\r
+  Reg   Offset\r
+  ===   ======              \r
+  R0    0x00    # stmfd     SP!,{R0-R12}\r
+  R1    0x04\r
+  R2    0x08\r
+  R3    0x0c\r
+  R4    0x10\r
+  R5    0x14\r
+  R6    0x18\r
+  R7    0x1c\r
+  R8    0x20\r
+  R9    0x24\r
+  R10   0x28\r
+  R11   0x2c\r
+  R12   0x30\r
+  SP    0x34    # reserved via adding 0x20 (32) to the SP\r
+  LR    0x38\r
+  PC    0x3c\r
+  CPSR  0x40\r
+  DFSR  0x44\r
+  DFAR  0x48\r
+  IFSR  0x4c\r
+  IFAR  0x50\r
+  \r
+  LR    0x54    # SVC Link register (we need to restore it)\r
+  \r
+  LR    0x58    # pushed by srsfd    \r
+  CPSR  0x5c    \r
+\r
+ */\r
\r
\r
+  EXPORT  ExceptionHandlersStart\r
+  EXPORT  ExceptionHandlersEnd\r
+  EXPORT  CommonExceptionEntry\r
+  EXPORT  AsmCommonExceptionEntry\r
+  IMPORT  GdbExceptionHandler\r
+\r
+  PRESERVE8\r
+  AREA  DxeExceptionHandlers, CODE, READONLY\r
+  \r
+//\r
+// This code gets copied to the ARM vector table\r
+// ExceptionHandlersStart - ExceptionHandlersEnd gets copied\r
+//\r
+ExceptionHandlersStart\r
+\r
+Reset\r
+  b   Reset\r
+\r
+UndefinedInstruction\r
+  b   UndefinedInstructionEntry\r
+\r
+SoftwareInterrupt\r
+  b   SoftwareInterruptEntry\r
+\r
+PrefetchAbort\r
+  b   PrefetchAbortEntry\r
+\r
+DataAbort\r
+  b   DataAbortEntry\r
+\r
+ReservedException\r
+  b   ReservedExceptionEntry\r
+\r
+Irq\r
+  b   Irq\r
+\r
+Fiq\r
+  b   FiqEntry\r
+\r
+\r
+UndefinedInstructionEntry\r
+  sub       LR, LR, #4                ; Only -2 for Thumb, adjust in CommonExceptionEntry\r
+  srsfd     #0x13!                    ; Store return state on SVC stack\r
+  cpsid     f, #0x13                  ; Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  ; Store the link register for the current mode\r
+  sub       SP,SP,#0x20               ; Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              ; Store the register state\r
+\r
+  mov       R0,#1                     ; ExceptionType\r
+  ldr       R1,CommonExceptionEntry; \r
+  bx        R1\r
+\r
+SoftwareInterruptEntry\r
+  sub       LR, LR, #4                ; Only -2 for Thumb, adjust in CommonExceptionEntry\r
+  srsfd     #0x13!                    ; Store return state on SVC stack\r
+  cpsid     f                         ; We are already in SVC mode\r
+  stmfd     SP!,{LR}                  ; Store the link register for the current mode\r
+  sub       SP,SP,#0x20               ; Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              ; Store the register state\r
+\r
+  mov       R0,#2                     ; ExceptionType\r
+  ldr       R1,CommonExceptionEntry\r
+  bx        R1\r
+\r
+PrefetchAbortEntry\r
+  sub       LR,LR,#4\r
+  srsfd     #0x13!                    ; Store return state on SVC stack\r
+  cpsid     f, #0x13                  ; Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  ; Store the link register for the current mode\r
+  sub       SP,SP,#0x20               ; Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              ; Store the register state\r
+\r
+  mov       R0,#3                     ; ExceptionType\r
+  ldr       R1,CommonExceptionEntry\r
+  bx        R1\r
+\r
+DataAbortEntry\r
+  sub       LR,LR,#8\r
+  srsfd     #0x13!                    ; Store return state on SVC stack\r
+  cpsid     f, #0x13                  ; Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  ; Store the link register for the current mode\r
+  sub       SP,SP,#0x20               ; Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              ; Store the register state\r
+\r
+  mov       R0,#4                     ; ExceptionType\r
+  ldr       R1,CommonExceptionEntry\r
+  bx        R1\r
+\r
+ReservedExceptionEntry\r
+  srsfd     #0x13!                    ; Store return state on SVC stack\r
+  cpsid     f, #0x13                  ; Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  ; Store the link register for the current mode\r
+  sub       SP,SP,#0x20               ; Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              ; Store the register state\r
+\r
+  mov       R0,#5                     ; ExceptionType\r
+  ldr       R1,CommonExceptionEntry\r
+  bx        R1\r
+\r
+FiqEntry\r
+  sub       LR,LR,#4\r
+  srsfd     #0x13!                    ; Store return state on SVC stack\r
+  cps       #0x13                     ; Switch to SVC for common stack\r
+  stmfd     SP!,{LR}                  ; Store the link register for the current mode\r
+  sub       SP,SP,#0x20               ; Save space for SP, LR, PC, IFAR - CPSR\r
+  stmfd     SP!,{R0-R12}              ; Store the register state\r
+                                      ; Since we have already switch to SVC R8_fiq - R12_fiq\r
+                                      ; never get used or saved\r
+  mov       R0,#7                     ; ExceptionType\r
+  ldr       R1,CommonExceptionEntry\r
+  bx        R1\r
+\r
+//\r
+// This gets patched by the C code that patches in the vector table\r
+//\r
+CommonExceptionEntry\r
+  dcd       0x12345678\r
+\r
+ExceptionHandlersEnd\r
+\r
+//\r
+// This code runs from CpuDxe driver loaded address. It is patched into \r
+// CommonExceptionEntry.\r
+//\r
+AsmCommonExceptionEntry\r
+  mrc       p15, 0, R1, c6, c0, 2   ; Read IFAR\r
+  str       R1, [SP, #0x50]         ; Store it in EFI_SYSTEM_CONTEXT_ARM.IFAR \r
+  \r
+  mrc       p15, 0, R1, c5, c0, 1   ; Read IFSR\r
+  str       R1, [SP, #0x4c]         ; Store it in EFI_SYSTEM_CONTEXT_ARM.IFSR\r
+  \r
+  mrc       p15, 0, R1, c6, c0, 0   ; Read DFAR\r
+  str       R1, [SP, #0x48]         ; Store it in EFI_SYSTEM_CONTEXT_ARM.DFAR\r
+  \r
+  mrc       p15, 0, R1, c5, c0, 0   ; Read DFSR\r
+  str       R1, [SP, #0x44]         ; Store it in EFI_SYSTEM_CONTEXT_ARM.DFSR\r
+  \r
+  ldr       R1, [SP, #0x5c]         ; srsfd saved pre-exception CPSR on the stack \r
+  str       R1, [SP, #0x40]         ; Store it in EFI_SYSTEM_CONTEXT_ARM.CPSR\r
+\r
+  add       R2, SP, #0x38           ; Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR\r
+  and       R3, R1, #0x1f           ; Check CPSR to see if User or System Mode\r
+  cmp       R3, #0x1f               ; if ((CPSR == 0x10) || (CPSR == 0x1df))\r
+  cmpne     R3, #0x10               ;   \r
+  stmeqed   R2, {lr}^               ;   save unbanked lr\r
+                                    ; else \r
+  stmneed   R2, {lr}                ;   save SVC lr\r
+\r
+\r
+  ldr       R5, [SP, #0x58]         ; PC is the LR pushed by srsfd \r
+                                    ; Check to see if we have to adjust for Thumb entry\r
+  sub       r4, r0, #1              ; if (ExceptionType == 1 || ExceptionType ==2)) {\r
+  cmp       r4, #1                  ;   // UND & SVC have differnt LR adjust for Thumb \r
+  bhi       NoAdjustNeeded\r
+  \r
+  tst       r1, #0x20               ;   if ((CPSR & T)) == T) {  // Thumb Mode on entry \r
+  addne     R5, R5, #2              ;     PC += 2;\r
+  str       R5,[SP,#0x58]           ; Update LR value pused by srsfd \r
+  \r
+NoAdjustNeeded\r
+\r
+  str       R5, [SP, #0x3c]         ; Store it in EFI_SYSTEM_CONTEXT_ARM.PC\r
+  \r
+  sub       R1, SP, #0x60           ; We pused 0x60 bytes on the stack \r
+  str       R1, [SP, #0x34]         ; Store it in EFI_SYSTEM_CONTEXT_ARM.SP\r
+  \r
+                                    ; R0 is ExceptionType \r
+  mov       R1,SP                   ; R1 is SystemContext \r
+\r
+/* \r
+VOID\r
+EFIAPI\r
+GdbExceptionHandler (\r
+  IN     EFI_EXCEPTION_TYPE           ExceptionType,   R0\r
+  IN OUT EFI_SYSTEM_CONTEXT           SystemContext    R1\r
+  )\r
+\r
+*/\r
+  blx       GdbExceptionHandler     ; Call exception handler\r
+  \r
+  ldr       R1,[SP,#0x3c]           ; EFI_SYSTEM_CONTEXT_ARM.PC\r
+  str       R1,[SP,#0x58]           ; Store it back to srsfd stack slot so it can be restored \r
+\r
+  ldr       R1,[SP,#0x40]           ; EFI_SYSTEM_CONTEXT_ARM.CPSR\r
+  str       R1,[SP,#0x5c]           ; Store it back to srsfd stack slot so it can be restored \r
+  \r
+  add       R3, SP, #0x54           ; Make R3 point to SVC LR saved on entry\r
+  add       R2, SP, #0x38           ; Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR\r
+  and       R1, R1, #0x1f           ; Check to see if User or System Mode\r
+  cmp       R1, #0x1f               ; if ((CPSR == 0x10) || (CPSR == 0x1f))\r
+  cmpne     R1, #0x10               ;   \r
+  ldmeqed   R2, {lr}^               ;   restore unbanked lr\r
+                                    ; else\r
+  ldmneed   R3, {lr}                ;   restore SVC lr, via ldmfd SP!, {LR}\r
+  \r
+  ldmfd     SP!,{R0-R12}            ; Restore general purpose registers\r
+                                    ; Exception handler can not change SP\r
+                                    \r
+  add       SP,SP,#0x20             ; Clear out the remaining stack space\r
+  ldmfd     SP!,{LR}                ; restore the link register for this context\r
+  rfefd     SP!                     ; return from exception via srsfd stack slot\r
+  \r
+  END\r
+\r
+\r
index e6aabf940a9bf07dceb1bff2450e6408a637eabb..f22a19dded8760ce93f782b83d6df88c5a5531a4 100755 (executable)
@@ -447,23 +447,23 @@ RemoveBreakPoint (
 }\r
 \r
 \r
 }\r
 \r
 \r
-/**
- Send the T signal with the given exception type (in gdb order) and possibly 
- with n:r pairs related to the watchpoints
- @param  SystemContext        Register content at time of the exception
- @param  GdbExceptionType     GDB exception type
- **/
-VOID
-ProcessorSendTSignal (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINT8               GdbExceptionType,
-  IN  OUT CHAR8           *TSignalPtr,
-  IN  UINTN               SizeOfBuffer
-  )
-{
-  *TSignalPtr = '\0';
-}
+/**\r
+ Send the T signal with the given exception type (in gdb order) and possibly \r
+ with n:r pairs related to the watchpoints\r
\r
+ @param  SystemContext        Register content at time of the exception\r
+ @param  GdbExceptionType     GDB exception type\r
+ **/\r
+VOID\r
+ProcessorSendTSignal (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINT8               GdbExceptionType,\r
+  IN  OUT CHAR8           *TSignalPtr,\r
+  IN  UINTN               SizeOfBuffer\r
+  )\r
+{\r
+  *TSignalPtr = '\0';\r
+}\r
 \r
 /**\r
  FIQ state is only changed by FIQ exception. We don't want to take FIQ\r
 \r
 /**\r
  FIQ state is only changed by FIQ exception. We don't want to take FIQ\r
@@ -475,21 +475,21 @@ ProcessorSendTSignal (
 \r
  @return  TRUE  We are in the GDB stub exception preamble \r
  @return  FALSE We are not in GDB stub code\r
 \r
  @return  TRUE  We are in the GDB stub exception preamble \r
  @return  FALSE We are not in GDB stub code\r
- **/
-BOOLEAN
-InFiqCrack (
-  IN UINT32 PC
-  )
-{
-  UINT32 VectorBase = PcdGet32 (PcdCpuVectorBaseAddress);
-  UINT32 Length     = (UINTN)ExceptionHandlersEnd - (UINTN)ExceptionHandlersStart;
-
-  if ((PC >= VectorBase) && (PC <= (VectorBase + Length))) {
-    return TRUE;
-  }
-
-  return FALSE;
-}
+ **/\r
+BOOLEAN\r
+InFiqCrack (\r
+  IN UINT32 PC\r
+  )\r
+{\r
+  UINT32 VectorBase = PcdGet32 (PcdCpuVectorBaseAddress);\r
+  UINT32 Length     = (UINTN)ExceptionHandlersEnd - (UINTN)ExceptionHandlersStart;\r
+\r
+  if ((PC >= VectorBase) && (PC <= (VectorBase + Length))) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r
 \r
 \r
 /**\r
 \r
 \r
 /**\r
@@ -526,24 +526,24 @@ ProcessorControlC (
     return FALSE;\r
   }\r
 \r
     return FALSE;\r
   }\r
 \r
-  while (TRUE) {
-    if (!GdbIsCharAvailable ()) {
-      //
-      // No characters are pending so exit the loop
-      //
-      Return = TRUE;
-      break;
-    }
-    
-    Char = GdbGetChar ();
-    if (Char == 0x03) {
-      //
-      // We have a ctrl-c so exit and process exception for ctrl-c
-      //
-      Return = FALSE;
-      break;
-    }
-  }
+  while (TRUE) {\r
+    if (!GdbIsCharAvailable ()) {\r
+      //\r
+      // No characters are pending so exit the loop\r
+      //\r
+      Return = TRUE;\r
+      break;\r
+    }\r
+    \r
+    Char = GdbGetChar ();\r
+    if (Char == 0x03) {\r
+      //\r
+      // We have a ctrl-c so exit and process exception for ctrl-c\r
+      //\r
+      Return = FALSE;\r
+      break;\r
+    }\r
+  }\r
 \r
   DebugAgentTimerEndOfInterrupt ();\r
 \r
 \r
   DebugAgentTimerEndOfInterrupt ();\r
 \r
@@ -622,13 +622,13 @@ InitializeDebugAgent (
   IN VOID                  *Context, OPTIONAL\r
   IN DEBUG_AGENT_CONTINUE  Function  OPTIONAL\r
   )\r
   IN VOID                  *Context, OPTIONAL\r
   IN DEBUG_AGENT_CONTINUE  Function  OPTIONAL\r
   )\r
-{  
+{  \r
   UINTN                Offset;\r
   UINTN                Length;\r
   BOOLEAN              IrqEnabled;\r
   UINT32               *VectorBase;\r
 \r
   UINTN                Offset;\r
   UINTN                Length;\r
   BOOLEAN              IrqEnabled;\r
   UINT32               *VectorBase;\r
 \r
-
+\r
   //\r
   // Disable interrupts\r
   //\r
   //\r
   // Disable interrupts\r
   //\r
index 2d0570e3dc472cb736db1f4af3b384453ed3956e..44c82f3472eeac8187ddbacc0e821a6bc8bd735c 100755 (executable)
-/** @file
-  Private include file for GDB stub
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __GCC_DEBUG_AGENT_INTERNAL__
-#define __GCC_DEBUG_AGENT_INTERNAL__
-
-#include <Uefi.h>
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/DebugLib.h>
-#include <Library/PcdLib.h>
-#include <Library/GdbSerialLib.h>
-#include <Library/PrintLib.h>
-#include <Library/CacheMaintenanceLib.h>
-#include <Library/DebugAgentTimerLib.h>
+/** @file\r
+  Private include file for GDB stub\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __GCC_DEBUG_AGENT_INTERNAL__\r
+#define __GCC_DEBUG_AGENT_INTERNAL__\r
+\r
+#include <Uefi.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/GdbSerialLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/CacheMaintenanceLib.h>\r
+#include <Library/DebugAgentTimerLib.h>\r
 #include <Library/DebugAgentLib.h>\r
 #include <Library/DebugAgentLib.h>\r
-
-#include <IndustryStandard/PeImage.h>
-#include <Protocol/DebugSupport.h>
-
-extern CONST CHAR8 mHexToStr[];
-
-// maximum size of input and output buffers
-// This value came from the show remote command of the gdb we tested against 
-#define MAX_BUF_SIZE 2000
-
-// maximum size of address buffer
-#define MAX_ADDR_SIZE 32
-
-// maximum size of register number buffer
-#define MAX_REG_NUM_BUF_SIZE 32
-
-// maximum size of length buffer
-#define MAX_LENGTH_SIZE 32
-
-// maximum size of T signal members
-#define MAX_T_SIGNAL_SIZE 64
-
-// the mask used to clear all the cache
-#define TF_BIT 0x00000100
-
-
-//
-// GDB Signal definitions - generic names for interrupts
-//
-#define GDB_SIGINT      2  // Interrupt process via ctrl-c
-#define GDB_SIGILL      4  // Illegal instruction       
-#define GDB_SIGTRAP     5  // Trace Trap (Breakpoint and SingleStep)
-#define GDB_SIGEMT      7  // Emulator Trap
-#define GDB_SIGFPE      8  // Floating point exception
-#define GDB_SIGSEGV     11 // Setgment violation, page fault 
-
-
-//
-// GDB File I/O Error values, zero means no error
-// Includes all general GDB Unix like error values
-//
-#define GDB_EBADMEMADDRBUFSIZE   11  // the buffer that stores memory Address to be read from/written to is not the right size
-#define GDB_EBADMEMLENGBUFSIZE   12  // the buffer that stores Length is not the right size 
-#define GDB_EBADMEMLENGTH        13  // Length, the given number of bytes to read or write, is not the right size
-#define GDB_EBADMEMDATA          14  // one of the bytes or nibbles of the memory is leess than 0 
-#define GDB_EBADMEMDATASIZE      15  // the memory data, 'XX..', is too short or too long
-#define GDB_EBADBUFSIZE          21  // the buffer created is not the correct size
-#define GDB_EINVALIDARG          31  // argument is invalid
-#define GDB_ENOSPACE             41  //
-#define GDB_EINVALIDBRKPOINTTYPE 51  // the breakpoint type is not recognized
-#define GDB_EINVALIDREGNUM       61  // given register number is not valid: either <0 or >=Number of Registers
-#define GDB_EUNKNOWN             255 // unknown
-
-
-//
-// These devices are open by GDB so we can just read and write to them
-//
-#define GDB_STDIN   0x00
-#define GDB_STDOUT  0x01
-#define GDB_STDERR  0x02
-
-//
-//Define Register size for different architectures
-//
-#if defined (MDE_CPU_IA32) 
-#define REG_SIZE  32
-#elif defined (MDE_CPU_X64)
-#define REG_SIZE  64
-#elif defined (MDE_CPU_ARM)
-#define REG_SIZE  32
-#endif
-
-
-typedef struct {
-  EFI_EXCEPTION_TYPE  Exception;
-  UINT8               SignalNo;
-} EFI_EXCEPTION_TYPE_ENTRY;
-
-
-#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
-
-//
-// Byte packed structure for DR6
-// 32-bits on IA-32
-// 64-bits on X64.  The upper 32-bits on X64 are reserved
-//
-typedef union {
-  struct {
-    UINT32  B0:1;           // Breakpoint condition detected
-    UINT32  B1:1;           // Breakpoint condition detected
-    UINT32  B2:1;           // Breakpoint condition detected
-    UINT32  B3:1;           // Breakpoint condition detected
-    UINT32  Reserved_1:9;   // Reserved 
-    UINT32  BD:1;           // Debug register access detected
-    UINT32  BS:1;           // Single step
-    UINT32  BT:1;           // Task switch
-    UINT32  Reserved_2:16;  // Reserved
-  } Bits;
-  UINTN     UintN;
-} IA32_DR6;
-
-//
-// Byte packed structure for DR7
-// 32-bits on IA-32
-// 64-bits on X64.  The upper 32-bits on X64 are reserved
-//
-typedef union {
-  struct {
-    UINT32  L0:1;           // Local breakpoint enable
-    UINT32  G0:1;           // Global breakpoint enable
-    UINT32  L1:1;           // Local breakpoint enable
-    UINT32  G1:1;           // Global breakpoint enable
-    UINT32  L2:1;           // Local breakpoint enable
-    UINT32  G2:1;           // Global breakpoint enable
-    UINT32  L3:1;           // Local breakpoint enable
-    UINT32  G3:1;           // Global breakpoint enable
-    UINT32  LE:1;           // Local exact breakpoint enable
-    UINT32  GE:1;           // Global exact breakpoint enable
-    UINT32  Reserved_1:3;   // Reserved
-    UINT32  GD:1;           // Global detect enable
-    UINT32  Reserved_2:2;   // Reserved
-    UINT32  RW0:2;          // Read/Write field
-    UINT32  LEN0:2;         // Length field
-    UINT32  RW1:2;          // Read/Write field
-    UINT32  LEN1:2;         // Length field
-    UINT32  RW2:2;          // Read/Write field
-    UINT32  LEN2:2;         // Length field
-    UINT32  RW3:2;          // Read/Write field
-    UINT32  LEN3:2;         // Length field
-  } Bits;
-  UINTN     UintN;
-} IA32_DR7;
-
-#endif /* if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) */
-
-typedef enum {
-  InstructionExecution,   //Hardware breakpoint
-  DataWrite,              //watch
-  DataRead,               //rwatch
-  DataReadWrite,          //awatch
-  SoftwareBreakpoint,     //Software breakpoint
-  NotSupported
-} BREAK_TYPE;
-
-//
-// Array of exception types that need to be hooked by the debugger
-//
-extern EFI_EXCEPTION_TYPE_ENTRY gExceptionType[];
-
-//
-// If the periodic callback is called while we are processing an F packet we need
-// to let the callback know to not read from the serail stream as it could steal
-// characters from the F reponse packet
-//
-extern BOOLEAN gProcessingFPacket;
-
-
-/**
- Return the number of entries in the gExceptionType[]
- @retval    UINTN, the number of entries in the gExceptionType[] array.    
- **/
-UINTN
-MaxEfiException (
-  VOID
-  );
-
-
-/**
- Check to see if the ISA is supported. 
- ISA = Instruction Set Architecture
- @retval    TRUE if Isa is supported,
- FALSE otherwise.
- **/
-BOOLEAN
-CheckIsa (
-  IN    EFI_INSTRUCTION_SET_ARCHITECTURE    Isa
-  );
-
-
-/**
- Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints
- @param  SystemContext        Register content at time of the exception
- @param  GdbExceptionType     GDB exception type
- **/
-
-VOID
-GdbSendTSignal (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINT8                  GdbExceptionType
-  );
-
-
-/**
- Translates the EFI mapping to GDB mapping
- @param     EFIExceptionType        EFI Exception that is being processed
- @retval    UINTN that corresponds to EFIExceptionType's GDB exception type number
- **/
-UINT8
-ConvertEFItoGDBtype ( 
-  IN  EFI_EXCEPTION_TYPE EFIExceptionType
-  );
-
-
-/**
- Empties the given buffer 
- @param *Buf pointer to the first element in buffer to be emptied
- **/
-VOID
-EmptyBuffer ( 
-  IN CHAR8  *Buf
-  );
-
-
-/**
- Converts an 8-bit Hex Char into a INTN.
- @param     Char  - the hex character to be converted into UINTN
- @retval    a INTN, from 0 to 15, that corressponds to Char
- -1 if Char is not a hex character
- **/
-INTN
-HexCharToInt (
-  IN  CHAR8 Char
-  );
-
-
-/** 'E NN'
- Send an error with the given error number after converting to hex.
- The error number is put into the buffer in hex. '255' is the biggest errno we can send.
- ex: 162 will be sent as A2.
- @param   errno    the error number that will be sent
- **/
-VOID
-EFIAPI
-SendError (
-  IN  UINT8     ErrorNum
-  );
-
-
-/**
- Send 'OK' when the function is done executing successfully.
- **/
-VOID
-SendSuccess (
-  VOID
-  );
-
-
-/**
- Send empty packet to specify that particular command/functionality is not supported.
- **/
-VOID
-SendNotSupported (
-  VOID
-  );
-
-/** â€˜p n’ 
- Reads the n-th register's value into an output buffer and sends it as a packet 
- @param     SystemContext       Register content at time of the exception
- @param     InBuffer            This is the input buffer received from gdb server
- **/
-VOID
-ReadNthRegister (
-  IN    EFI_SYSTEM_CONTEXT  SystemContext,
-  IN    CHAR8               *InBuffer
-  );
-
-
-/** â€˜g’ 
- Reads the general registers into an output buffer  and sends it as a packet 
- @param     SystemContext           Register content at time of the exception
- **/
-VOID
-ReadGeneralRegisters (  
-  IN    EFI_SYSTEM_CONTEXT  SystemContext
-  );
-
-
-/** â€˜P n...=r...’
- Writes the new value of n-th register received into the input buffer to the n-th register
- @param     SystemContext       Register content at time of the exception
- @param     InBuffer            This is the input buffer received from gdb server
- **/
-VOID
-WriteNthRegister (
-  IN    EFI_SYSTEM_CONTEXT  SystemContext,
-  IN    CHAR8               *InBuffer
-  );
-
-
-/** â€˜G XX...’
- Writes the new values received into the input buffer to the general registers
- @param     SystemContext               Register content at time of the exception
- @param     InBuffer                    Pointer to the input buffer received from gdb server
- **/
-
-VOID
-WriteGeneralRegisters (
-  IN    EFI_SYSTEM_CONTEXT  SystemContext,
-  IN    CHAR8               *InBuffer
-  );
-
-
-/** â€˜m addr,length â€™
- Find the Length of the area to read and the start addres. Finally, pass them to 
- another function, TransferFromMemToOutBufAndSend, that will read from that memory space and 
- send it as a packet.
- @param  *PacketData  Pointer to Payload data for the packet
- **/
-VOID
-ReadFromMemory (
-  IN  CHAR8  *PacketData
-  );
-
-
-/** â€˜M addr,length :XX...’
- Find the Length of the area in bytes to write and the start addres. Finally, pass them to 
- another function, TransferFromInBufToMem, that will write to that memory space the info in
- the input buffer.
- @param   PacketData     Pointer to Payload data for the packet
- **/
-VOID
-WriteToMemory (
-  IN CHAR8 *PacketData
-  );
-
-
-/** â€˜c [addr ]’ 
- Continue. addr is Address to resume. If addr is omitted, resume at current 
- Address.
- @param SystemContext Register content at time of the exception  
- @param *PacketData   Pointer to PacketData
- **/
-
-VOID
-ContinueAtAddress (
-  IN  EFI_SYSTEM_CONTEXT   SystemContext,
-  IN  CHAR8                *PacketData
-  );
-
-
-/** â€˜s [addr ]’
- Single step. addr is the Address at which to resume. If addr is omitted, resume 
- at same Address.
- @param SystemContext   Register content at time of the exception
- @param PacketData      Pointer to Payload data for the packet
- **/
-VOID
-SingleStep (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  CHAR8               *PacketData
-  );
-
-/** 
- Insert Single Step in the SystemContext
- @param SystemContext   Register content at time of the exception
- **/
-VOID
-AddSingleStep (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext
-  );
-  
-/** 
- Remove Single Step in the SystemContext
- @param SystemContext   Register content at time of the exception
- **/
-VOID
-RemoveSingleStep (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext
-  );
-  
-  
-/**
-  â€˜Z1, [addr], [length]’
-  â€˜Z2, [addr], [length]’
-  â€˜Z3, [addr], [length]’
-  â€˜Z4, [addr], [length]’
-
-  Insert hardware breakpoint/watchpoint at address addr of size length
-
-  @param SystemContext  Register content at time of the exception
-  @param *PacketData    Pointer to the Payload data for the packet
-
-**/
-VOID
-EFIAPI
-InsertBreakPoint(
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  CHAR8               *PacketData
-  );
-
-
-/**
-  â€˜z1, [addr], [length]’
-  â€˜z2, [addr], [length]’
-  â€˜z3, [addr], [length]’
-  â€˜z4, [addr], [length]’
-
-  Remove hardware breakpoint/watchpoint at address addr of size length
-
-  @param SystemContext  Register content at time of the exception
-  @param *PacketData    Pointer to the Payload data for the packet
-
-**/
-VOID
-EFIAPI
-RemoveBreakPoint(
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  CHAR8               *PacketData
-  );
-
-
-/**
- Exception Hanldler for GDB. It will be called for all exceptions
- registered via the gExceptionType[] array.
- @param ExceptionType   Exception that is being processed
- @param SystemContext   Register content at time of the exception  
- **/
-VOID
-EFIAPI
-GdbExceptionHandler ( 
-  IN     EFI_EXCEPTION_TYPE  ExceptionType, 
-  IN OUT EFI_SYSTEM_CONTEXT  SystemContext 
-  );
-
-
-/**
- Periodic callback for GDB. This function is used to catch a ctrl-c or other 
- break in type command from GDB.
- @param SystemContext           Register content at time of the call
- **/
-VOID
-EFIAPI
-GdbPeriodicCallBack ( 
-  IN OUT EFI_SYSTEM_CONTEXT  SystemContext 
-  );
-
-
-/**
-  Make two serail consoles: 1) StdIn and StdOut via GDB. 2) StdErr via GDB.
-  
-  These console show up on the remote system running GDB
-
-**/
-
-VOID
-GdbInitializeSerialConsole (
-  VOID
-  );
-
-
-/**
-  Send a GDB Remote Serial Protocol Packet
-  
-  $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', 
-  the packet teminating character '#' and the two digit checksum.
-  
-  If an ack '+' is not sent resend the packet, but timeout eventually so we don't end up 
-  in an infinit loop. This is so if you unplug the debugger code just keeps running
-
-  @param PacketData   Payload data for the packet  
-  
-  @retval             Number of bytes of packet data sent.
-
-**/
-UINTN
-SendPacket (
-  IN  CHAR8 *PacketData
-  );
-  
-
-/**
- Receive a GDB Remote Serial Protocol Packet
- $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', 
- the packet teminating character '#' and the two digit checksum.
- If host re-starts sending a packet without ending the previous packet, only the last valid packet is proccessed.
- (In other words, if received packet is '$12345$12345$123456#checksum', only '$123456#checksum' will be processed.)
- If an ack '+' is not sent resend the packet
- @param PacketData   Payload data for the packet  
- @retval             Number of bytes of packet data received.
-
- **/
-UINTN
-ReceivePacket (
- OUT  CHAR8 *PacketData,
- IN   UINTN PacketDataSize
- );
-  
-
-/**
-  Read data from a FileDescriptor. On success number of bytes read is returned. Zero indicates 
-  the end of a file. On error -1 is returned. If count is zero, GdbRead returns zero.
-
-  @param  FileDescriptor   Device to talk to.
-  @param  Buffer           Buffer to hold Count bytes that were read
-  @param  Count            Number of bytes to transfer. 
-
-  @retval -1               Error
-  @retval {other}          Number of bytes read.
-
-**/
-INTN
-GdbRead (
-  IN  INTN    FileDescriptor,
-  OUT VOID    *Buffer,
-  IN  UINTN   Count
-  );
-  
-
-/**
-  Write data to a FileDescriptor. On success number of bytes written is returned. Zero indicates 
-  nothing was written. On error -1 is returned. 
-
-  @param  FileDescriptor   Device to talk to.
-  @param  Buffer           Buffer to hold Count bytes that are to be written
-  @param  Count            Number of bytes to transfer. 
-
-  @retval -1               Error
-  @retval {other}          Number of bytes written.
-
-**/
-INTN
-GdbWrite (
-  IN  INTN          FileDescriptor,
-  OUT CONST VOID    *Buffer,
-  IN  UINTN         Count
-  );
-
-UINTN *  
-FindPointerToRegister (
-  IN  EFI_SYSTEM_CONTEXT    SystemContext,
-  IN  UINTN                 RegNumber  
-  );
-
-CHAR8 * 
-BasicReadRegister (
-  IN  EFI_SYSTEM_CONTEXT      SystemContext,
-  IN  UINTN                   RegNumber,
-  IN  CHAR8                   *OutBufPtr
-  );
-
-VOID
-TransferFromInBufToMem (
-  IN  UINTN   Length,
-  IN  UINT8   *Address,
-  IN  CHAR8   *NewData
-  );
-
-VOID
-TransferFromMemToOutBufAndSend (
-  IN  UINTN  Length,
-  IN  UINT8  *Address
-  );
-
-CHAR8 *
-BasicWriteRegister (
-  IN  EFI_SYSTEM_CONTEXT    SystemContext,
-  IN  UINTN                 RegNumber,
-  IN  CHAR8                 *InBufPtr
-  );
-
-VOID  
-PrintReg (
-  EFI_SYSTEM_CONTEXT SystemContext
-  );
-
-UINTN
-ParseBreakpointPacket (
-  IN  CHAR8 *PacketData,
-  OUT UINTN *Type,
-  OUT UINTN *Address,
-  OUT UINTN *Length
-  );
-
-UINTN
-GetBreakpointDataAddress (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINTN               BreakpointNumber 
-  );
-
-UINTN
-GetBreakpointDetected (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext
-  );
-
-BREAK_TYPE
-GetBreakpointType (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINTN               BreakpointNumber  
-  );
-
-UINTN
-ConvertLengthData (
-  IN  UINTN  Length
-  );
-
-EFI_STATUS
-FindNextFreeDebugRegister (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  OUT UINTN               *Register
-  );
-
-EFI_STATUS
-EnableDebugRegister (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINTN               Register,
-  IN  UINTN               Address,
-  IN  UINTN               Length,
-  IN  UINTN               Type
-  );
-
-EFI_STATUS
-FindMatchingDebugRegister (
- IN  EFI_SYSTEM_CONTEXT  SystemContext,
- IN  UINTN               Address,
- IN  UINTN               Length,
- IN  UINTN               Type,
- OUT UINTN               *Register
- );
-
-EFI_STATUS
-DisableDebugRegister (
- IN  EFI_SYSTEM_CONTEXT  SystemContext,
- IN  UINTN               Register
- );
-
-VOID
-InitializeProcessor (
-  VOID
-  );
-
-/**
- Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints
- @param  SystemContext        Register content at time of the exception
- @param  GdbExceptionType     GDB exception type
- **/
-VOID
-ProcessorSendTSignal (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINT8               GdbExceptionType,
-  IN  OUT CHAR8           *TSignalPtr,
-  IN  UINTN               SizeOfBuffer
-  );
-
+\r
+#include <IndustryStandard/PeImage.h>\r
+#include <Protocol/DebugSupport.h>\r
+\r
+extern CONST CHAR8 mHexToStr[];\r
+\r
+// maximum size of input and output buffers\r
+// This value came from the show remote command of the gdb we tested against \r
+#define MAX_BUF_SIZE 2000\r
+\r
+// maximum size of address buffer\r
+#define MAX_ADDR_SIZE 32\r
+\r
+// maximum size of register number buffer\r
+#define MAX_REG_NUM_BUF_SIZE 32\r
+\r
+// maximum size of length buffer\r
+#define MAX_LENGTH_SIZE 32\r
+\r
+// maximum size of T signal members\r
+#define MAX_T_SIGNAL_SIZE 64\r
+\r
+// the mask used to clear all the cache\r
+#define TF_BIT 0x00000100\r
+\r
+\r
+//\r
+// GDB Signal definitions - generic names for interrupts\r
+//\r
+#define GDB_SIGINT      2  // Interrupt process via ctrl-c\r
+#define GDB_SIGILL      4  // Illegal instruction       \r
+#define GDB_SIGTRAP     5  // Trace Trap (Breakpoint and SingleStep)\r
+#define GDB_SIGEMT      7  // Emulator Trap\r
+#define GDB_SIGFPE      8  // Floating point exception\r
+#define GDB_SIGSEGV     11 // Setgment violation, page fault \r
+\r
+\r
+//\r
+// GDB File I/O Error values, zero means no error\r
+// Includes all general GDB Unix like error values\r
+//\r
+#define GDB_EBADMEMADDRBUFSIZE   11  // the buffer that stores memory Address to be read from/written to is not the right size\r
+#define GDB_EBADMEMLENGBUFSIZE   12  // the buffer that stores Length is not the right size \r
+#define GDB_EBADMEMLENGTH        13  // Length, the given number of bytes to read or write, is not the right size\r
+#define GDB_EBADMEMDATA          14  // one of the bytes or nibbles of the memory is leess than 0 \r
+#define GDB_EBADMEMDATASIZE      15  // the memory data, 'XX..', is too short or too long\r
+#define GDB_EBADBUFSIZE          21  // the buffer created is not the correct size\r
+#define GDB_EINVALIDARG          31  // argument is invalid\r
+#define GDB_ENOSPACE             41  //\r
+#define GDB_EINVALIDBRKPOINTTYPE 51  // the breakpoint type is not recognized\r
+#define GDB_EINVALIDREGNUM       61  // given register number is not valid: either <0 or >=Number of Registers\r
+#define GDB_EUNKNOWN             255 // unknown\r
+\r
+\r
+//\r
+// These devices are open by GDB so we can just read and write to them\r
+//\r
+#define GDB_STDIN   0x00\r
+#define GDB_STDOUT  0x01\r
+#define GDB_STDERR  0x02\r
+\r
+//\r
+//Define Register size for different architectures\r
+//\r
+#if defined (MDE_CPU_IA32) \r
+#define REG_SIZE  32\r
+#elif defined (MDE_CPU_X64)\r
+#define REG_SIZE  64\r
+#elif defined (MDE_CPU_ARM)\r
+#define REG_SIZE  32\r
+#endif\r
+\r
+\r
+typedef struct {\r
+  EFI_EXCEPTION_TYPE  Exception;\r
+  UINT8               SignalNo;\r
+} EFI_EXCEPTION_TYPE_ENTRY;\r
+\r
+\r
+#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r
+\r
+//\r
+// Byte packed structure for DR6\r
+// 32-bits on IA-32\r
+// 64-bits on X64.  The upper 32-bits on X64 are reserved\r
+//\r
+typedef union {\r
+  struct {\r
+    UINT32  B0:1;           // Breakpoint condition detected\r
+    UINT32  B1:1;           // Breakpoint condition detected\r
+    UINT32  B2:1;           // Breakpoint condition detected\r
+    UINT32  B3:1;           // Breakpoint condition detected\r
+    UINT32  Reserved_1:9;   // Reserved \r
+    UINT32  BD:1;           // Debug register access detected\r
+    UINT32  BS:1;           // Single step\r
+    UINT32  BT:1;           // Task switch\r
+    UINT32  Reserved_2:16;  // Reserved\r
+  } Bits;\r
+  UINTN     UintN;\r
+} IA32_DR6;\r
+\r
+//\r
+// Byte packed structure for DR7\r
+// 32-bits on IA-32\r
+// 64-bits on X64.  The upper 32-bits on X64 are reserved\r
+//\r
+typedef union {\r
+  struct {\r
+    UINT32  L0:1;           // Local breakpoint enable\r
+    UINT32  G0:1;           // Global breakpoint enable\r
+    UINT32  L1:1;           // Local breakpoint enable\r
+    UINT32  G1:1;           // Global breakpoint enable\r
+    UINT32  L2:1;           // Local breakpoint enable\r
+    UINT32  G2:1;           // Global breakpoint enable\r
+    UINT32  L3:1;           // Local breakpoint enable\r
+    UINT32  G3:1;           // Global breakpoint enable\r
+    UINT32  LE:1;           // Local exact breakpoint enable\r
+    UINT32  GE:1;           // Global exact breakpoint enable\r
+    UINT32  Reserved_1:3;   // Reserved\r
+    UINT32  GD:1;           // Global detect enable\r
+    UINT32  Reserved_2:2;   // Reserved\r
+    UINT32  RW0:2;          // Read/Write field\r
+    UINT32  LEN0:2;         // Length field\r
+    UINT32  RW1:2;          // Read/Write field\r
+    UINT32  LEN1:2;         // Length field\r
+    UINT32  RW2:2;          // Read/Write field\r
+    UINT32  LEN2:2;         // Length field\r
+    UINT32  RW3:2;          // Read/Write field\r
+    UINT32  LEN3:2;         // Length field\r
+  } Bits;\r
+  UINTN     UintN;\r
+} IA32_DR7;\r
+\r
+#endif /* if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) */\r
+\r
+typedef enum {\r
+  InstructionExecution,   //Hardware breakpoint\r
+  DataWrite,              //watch\r
+  DataRead,               //rwatch\r
+  DataReadWrite,          //awatch\r
+  SoftwareBreakpoint,     //Software breakpoint\r
+  NotSupported\r
+} BREAK_TYPE;\r
+\r
+//\r
+// Array of exception types that need to be hooked by the debugger\r
+//\r
+extern EFI_EXCEPTION_TYPE_ENTRY gExceptionType[];\r
+\r
+//\r
+// If the periodic callback is called while we are processing an F packet we need\r
+// to let the callback know to not read from the serail stream as it could steal\r
+// characters from the F reponse packet\r
+//\r
+extern BOOLEAN gProcessingFPacket;\r
+\r
+\r
+/**\r
+ Return the number of entries in the gExceptionType[]\r
\r
+ @retval    UINTN, the number of entries in the gExceptionType[] array.    \r
+ **/\r
+UINTN\r
+MaxEfiException (\r
+  VOID\r
+  );\r
+\r
+\r
+/**\r
+ Check to see if the ISA is supported. \r
+ ISA = Instruction Set Architecture\r
\r
+ @retval    TRUE if Isa is supported,\r
+ FALSE otherwise.\r
+ **/\r
+BOOLEAN\r
+CheckIsa (\r
+  IN    EFI_INSTRUCTION_SET_ARCHITECTURE    Isa\r
+  );\r
+\r
+\r
+/**\r
+ Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints\r
\r
+ @param  SystemContext        Register content at time of the exception\r
+ @param  GdbExceptionType     GDB exception type\r
+ **/\r
+\r
+VOID\r
+GdbSendTSignal (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINT8                  GdbExceptionType\r
+  );\r
+\r
+\r
+/**\r
+ Translates the EFI mapping to GDB mapping\r
\r
+ @param     EFIExceptionType        EFI Exception that is being processed\r
+ @retval    UINTN that corresponds to EFIExceptionType's GDB exception type number\r
+ **/\r
+UINT8\r
+ConvertEFItoGDBtype ( \r
+  IN  EFI_EXCEPTION_TYPE EFIExceptionType\r
+  );\r
+\r
+\r
+/**\r
+ Empties the given buffer \r
+ @param *Buf pointer to the first element in buffer to be emptied\r
+ **/\r
+VOID\r
+EmptyBuffer ( \r
+  IN CHAR8  *Buf\r
+  );\r
+\r
+\r
+/**\r
+ Converts an 8-bit Hex Char into a INTN.\r
\r
+ @param     Char  - the hex character to be converted into UINTN\r
+ @retval    a INTN, from 0 to 15, that corressponds to Char\r
+ -1 if Char is not a hex character\r
+ **/\r
+INTN\r
+HexCharToInt (\r
+  IN  CHAR8 Char\r
+  );\r
+\r
+\r
+/** 'E NN'\r
+ Send an error with the given error number after converting to hex.\r
+ The error number is put into the buffer in hex. '255' is the biggest errno we can send.\r
+ ex: 162 will be sent as A2.\r
\r
+ @param   errno    the error number that will be sent\r
+ **/\r
+VOID\r
+EFIAPI\r
+SendError (\r
+  IN  UINT8     ErrorNum\r
+  );\r
+\r
+\r
+/**\r
+ Send 'OK' when the function is done executing successfully.\r
+ **/\r
+VOID\r
+SendSuccess (\r
+  VOID\r
+  );\r
+\r
+\r
+/**\r
+ Send empty packet to specify that particular command/functionality is not supported.\r
+ **/\r
+VOID\r
+SendNotSupported (\r
+  VOID\r
+  );\r
+\r
+/** â€˜p n’ \r
+ Reads the n-th register's value into an output buffer and sends it as a packet \r
+ @param     SystemContext       Register content at time of the exception\r
+ @param     InBuffer            This is the input buffer received from gdb server\r
+ **/\r
+VOID\r
+ReadNthRegister (\r
+  IN    EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN    CHAR8               *InBuffer\r
+  );\r
+\r
+\r
+/** â€˜g’ \r
+ Reads the general registers into an output buffer  and sends it as a packet \r
+ @param     SystemContext           Register content at time of the exception\r
+ **/\r
+VOID\r
+ReadGeneralRegisters (  \r
+  IN    EFI_SYSTEM_CONTEXT  SystemContext\r
+  );\r
+\r
+\r
+/** â€˜P n...=r...’\r
+ Writes the new value of n-th register received into the input buffer to the n-th register\r
+ @param     SystemContext       Register content at time of the exception\r
+ @param     InBuffer            This is the input buffer received from gdb server\r
+ **/\r
+VOID\r
+WriteNthRegister (\r
+  IN    EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN    CHAR8               *InBuffer\r
+  );\r
+\r
+\r
+/** â€˜G XX...’\r
+ Writes the new values received into the input buffer to the general registers\r
+ @param     SystemContext               Register content at time of the exception\r
+ @param     InBuffer                    Pointer to the input buffer received from gdb server\r
+ **/\r
+\r
+VOID\r
+WriteGeneralRegisters (\r
+  IN    EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN    CHAR8               *InBuffer\r
+  );\r
+\r
+\r
+/** â€˜m addr,length â€™\r
+ Find the Length of the area to read and the start addres. Finally, pass them to \r
+ another function, TransferFromMemToOutBufAndSend, that will read from that memory space and \r
+ send it as a packet.\r
\r
+ @param  *PacketData  Pointer to Payload data for the packet\r
+ **/\r
+VOID\r
+ReadFromMemory (\r
+  IN  CHAR8  *PacketData\r
+  );\r
+\r
+\r
+/** â€˜M addr,length :XX...’\r
+ Find the Length of the area in bytes to write and the start addres. Finally, pass them to \r
+ another function, TransferFromInBufToMem, that will write to that memory space the info in\r
+ the input buffer.\r
\r
+ @param   PacketData     Pointer to Payload data for the packet\r
+ **/\r
+VOID\r
+WriteToMemory (\r
+  IN CHAR8 *PacketData\r
+  );\r
+\r
+\r
+/** â€˜c [addr ]’ \r
+ Continue. addr is Address to resume. If addr is omitted, resume at current \r
+ Address.\r
\r
+ @param SystemContext Register content at time of the exception  \r
+ @param *PacketData   Pointer to PacketData\r
+ **/\r
+\r
+VOID\r
+ContinueAtAddress (\r
+  IN  EFI_SYSTEM_CONTEXT   SystemContext,\r
+  IN  CHAR8                *PacketData\r
+  );\r
+\r
+\r
+/** â€˜s [addr ]’\r
+ Single step. addr is the Address at which to resume. If addr is omitted, resume \r
+ at same Address.\r
\r
+ @param SystemContext   Register content at time of the exception\r
+ @param PacketData      Pointer to Payload data for the packet\r
+ **/\r
+VOID\r
+SingleStep (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  CHAR8               *PacketData\r
+  );\r
+\r
+/** \r
+ Insert Single Step in the SystemContext\r
\r
+ @param SystemContext   Register content at time of the exception\r
+ **/\r
+VOID\r
+AddSingleStep (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext\r
+  );\r
+  \r
+/** \r
+ Remove Single Step in the SystemContext\r
\r
+ @param SystemContext   Register content at time of the exception\r
+ **/\r
+VOID\r
+RemoveSingleStep (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext\r
+  );\r
+  \r
+  \r
+/**\r
+  â€˜Z1, [addr], [length]’\r
+  â€˜Z2, [addr], [length]’\r
+  â€˜Z3, [addr], [length]’\r
+  â€˜Z4, [addr], [length]’\r
+\r
+  Insert hardware breakpoint/watchpoint at address addr of size length\r
+\r
+  @param SystemContext  Register content at time of the exception\r
+  @param *PacketData    Pointer to the Payload data for the packet\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+InsertBreakPoint(\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  CHAR8               *PacketData\r
+  );\r
+\r
+\r
+/**\r
+  â€˜z1, [addr], [length]’\r
+  â€˜z2, [addr], [length]’\r
+  â€˜z3, [addr], [length]’\r
+  â€˜z4, [addr], [length]’\r
+\r
+  Remove hardware breakpoint/watchpoint at address addr of size length\r
+\r
+  @param SystemContext  Register content at time of the exception\r
+  @param *PacketData    Pointer to the Payload data for the packet\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+RemoveBreakPoint(\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  CHAR8               *PacketData\r
+  );\r
+\r
+\r
+/**\r
+ Exception Hanldler for GDB. It will be called for all exceptions\r
+ registered via the gExceptionType[] array.\r
\r
+ @param ExceptionType   Exception that is being processed\r
+ @param SystemContext   Register content at time of the exception  \r
\r
+ **/\r
+VOID\r
+EFIAPI\r
+GdbExceptionHandler ( \r
+  IN     EFI_EXCEPTION_TYPE  ExceptionType, \r
+  IN OUT EFI_SYSTEM_CONTEXT  SystemContext \r
+  );\r
+\r
+\r
+/**\r
+ Periodic callback for GDB. This function is used to catch a ctrl-c or other \r
+ break in type command from GDB.\r
\r
+ @param SystemContext           Register content at time of the call\r
\r
+ **/\r
+VOID\r
+EFIAPI\r
+GdbPeriodicCallBack ( \r
+  IN OUT EFI_SYSTEM_CONTEXT  SystemContext \r
+  );\r
+\r
+\r
+/**\r
+  Make two serail consoles: 1) StdIn and StdOut via GDB. 2) StdErr via GDB.\r
+  \r
+  These console show up on the remote system running GDB\r
+\r
+**/\r
+\r
+VOID\r
+GdbInitializeSerialConsole (\r
+  VOID\r
+  );\r
+\r
+\r
+/**\r
+  Send a GDB Remote Serial Protocol Packet\r
+  \r
+  $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', \r
+  the packet teminating character '#' and the two digit checksum.\r
+  \r
+  If an ack '+' is not sent resend the packet, but timeout eventually so we don't end up \r
+  in an infinit loop. This is so if you unplug the debugger code just keeps running\r
+\r
+  @param PacketData   Payload data for the packet  \r
+  \r
+  @retval             Number of bytes of packet data sent.\r
+\r
+**/\r
+UINTN\r
+SendPacket (\r
+  IN  CHAR8 *PacketData\r
+  );\r
+  \r
+\r
+/**\r
+ Receive a GDB Remote Serial Protocol Packet\r
\r
+ $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', \r
+ the packet teminating character '#' and the two digit checksum.\r
\r
+ If host re-starts sending a packet without ending the previous packet, only the last valid packet is proccessed.\r
+ (In other words, if received packet is '$12345$12345$123456#checksum', only '$123456#checksum' will be processed.)\r
\r
+ If an ack '+' is not sent resend the packet\r
\r
+ @param PacketData   Payload data for the packet  \r
\r
+ @retval             Number of bytes of packet data received.\r
+\r
+ **/\r
+UINTN\r
+ReceivePacket (\r
+ OUT  CHAR8 *PacketData,\r
+ IN   UINTN PacketDataSize\r
+ );\r
+  \r
+\r
+/**\r
+  Read data from a FileDescriptor. On success number of bytes read is returned. Zero indicates \r
+  the end of a file. On error -1 is returned. If count is zero, GdbRead returns zero.\r
+\r
+  @param  FileDescriptor   Device to talk to.\r
+  @param  Buffer           Buffer to hold Count bytes that were read\r
+  @param  Count            Number of bytes to transfer. \r
+\r
+  @retval -1               Error\r
+  @retval {other}          Number of bytes read.\r
+\r
+**/\r
+INTN\r
+GdbRead (\r
+  IN  INTN    FileDescriptor,\r
+  OUT VOID    *Buffer,\r
+  IN  UINTN   Count\r
+  );\r
+  \r
+\r
+/**\r
+  Write data to a FileDescriptor. On success number of bytes written is returned. Zero indicates \r
+  nothing was written. On error -1 is returned. \r
+\r
+  @param  FileDescriptor   Device to talk to.\r
+  @param  Buffer           Buffer to hold Count bytes that are to be written\r
+  @param  Count            Number of bytes to transfer. \r
+\r
+  @retval -1               Error\r
+  @retval {other}          Number of bytes written.\r
+\r
+**/\r
+INTN\r
+GdbWrite (\r
+  IN  INTN          FileDescriptor,\r
+  OUT CONST VOID    *Buffer,\r
+  IN  UINTN         Count\r
+  );\r
+\r
+UINTN *  \r
+FindPointerToRegister (\r
+  IN  EFI_SYSTEM_CONTEXT    SystemContext,\r
+  IN  UINTN                 RegNumber  \r
+  );\r
+\r
+CHAR8 * \r
+BasicReadRegister (\r
+  IN  EFI_SYSTEM_CONTEXT      SystemContext,\r
+  IN  UINTN                   RegNumber,\r
+  IN  CHAR8                   *OutBufPtr\r
+  );\r
+\r
+VOID\r
+TransferFromInBufToMem (\r
+  IN  UINTN   Length,\r
+  IN  UINT8   *Address,\r
+  IN  CHAR8   *NewData\r
+  );\r
+\r
+VOID\r
+TransferFromMemToOutBufAndSend (\r
+  IN  UINTN  Length,\r
+  IN  UINT8  *Address\r
+  );\r
+\r
+CHAR8 *\r
+BasicWriteRegister (\r
+  IN  EFI_SYSTEM_CONTEXT    SystemContext,\r
+  IN  UINTN                 RegNumber,\r
+  IN  CHAR8                 *InBufPtr\r
+  );\r
+\r
+VOID  \r
+PrintReg (\r
+  EFI_SYSTEM_CONTEXT SystemContext\r
+  );\r
+\r
+UINTN\r
+ParseBreakpointPacket (\r
+  IN  CHAR8 *PacketData,\r
+  OUT UINTN *Type,\r
+  OUT UINTN *Address,\r
+  OUT UINTN *Length\r
+  );\r
+\r
+UINTN\r
+GetBreakpointDataAddress (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINTN               BreakpointNumber \r
+  );\r
+\r
+UINTN\r
+GetBreakpointDetected (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext\r
+  );\r
+\r
+BREAK_TYPE\r
+GetBreakpointType (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINTN               BreakpointNumber  \r
+  );\r
+\r
+UINTN\r
+ConvertLengthData (\r
+  IN  UINTN  Length\r
+  );\r
+\r
+EFI_STATUS\r
+FindNextFreeDebugRegister (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  OUT UINTN               *Register\r
+  );\r
+\r
+EFI_STATUS\r
+EnableDebugRegister (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINTN               Register,\r
+  IN  UINTN               Address,\r
+  IN  UINTN               Length,\r
+  IN  UINTN               Type\r
+  );\r
+\r
+EFI_STATUS\r
+FindMatchingDebugRegister (\r
+ IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+ IN  UINTN               Address,\r
+ IN  UINTN               Length,\r
+ IN  UINTN               Type,\r
+ OUT UINTN               *Register\r
+ );\r
+\r
+EFI_STATUS\r
+DisableDebugRegister (\r
+ IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+ IN  UINTN               Register\r
+ );\r
+\r
+VOID\r
+InitializeProcessor (\r
+  VOID\r
+  );\r
+\r
+/**\r
+ Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints\r
\r
+ @param  SystemContext        Register content at time of the exception\r
+ @param  GdbExceptionType     GDB exception type\r
+ **/\r
+VOID\r
+ProcessorSendTSignal (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINT8               GdbExceptionType,\r
+  IN  OUT CHAR8           *TSignalPtr,\r
+  IN  UINTN               SizeOfBuffer\r
+  );\r
+\r
 /**\r
  Check to see if this exception is related to ctrl-c handling.\r
  \r
 /**\r
  Check to see if this exception is related to ctrl-c handling.\r
  \r
@@ -705,9 +705,9 @@ BOOLEAN
 ProcessorControlC ( \r
   IN  EFI_EXCEPTION_TYPE        ExceptionType, \r
   IN OUT EFI_SYSTEM_CONTEXT     SystemContext \r
 ProcessorControlC ( \r
   IN  EFI_EXCEPTION_TYPE        ExceptionType, \r
   IN OUT EFI_SYSTEM_CONTEXT     SystemContext \r
-  );
-
-
+  );\r
+\r
+\r
 /**\r
   Initialize debug agent.\r
 \r
 /**\r
   Initialize debug agent.\r
 \r
@@ -723,6 +723,6 @@ DebugAgentHookExceptions (
   IN UINT32                InitFlag,\r
   IN VOID                  *Context  OPTIONAL\r
   );\r
   IN UINT32                InitFlag,\r
   IN VOID                  *Context  OPTIONAL\r
   );\r
-
-
-#endif
+\r
+\r
+#endif\r
index 96a1a596f3aeb9a5441013aa5bbafc2515fbc342..4e4350a0f25c0adfdbbdfa4a49ac1b48bb04e26d 100755 (executable)
-/** @file
-  Processor specific parts of the GDB stub
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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.
-
-**/
-
+/** @file\r
+  Processor specific parts of the GDB stub\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
 #include <GdbDebugAgent.h>\r
 #include <GdbDebugAgent.h>\r
-
-//
-// Array of exception types that need to be hooked by the debugger
-// {EFI mapping, GDB mapping}
-//
-EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = {
-  { EXCEPT_IA32_DIVIDE_ERROR,     GDB_SIGFPE  }, 
-  { EXCEPT_IA32_DEBUG,            GDB_SIGTRAP },
-  { EXCEPT_IA32_NMI,              GDB_SIGEMT  },
-  { EXCEPT_IA32_BREAKPOINT,       GDB_SIGTRAP },
-  { EXCEPT_IA32_OVERFLOW,         GDB_SIGSEGV },
-  { EXCEPT_IA32_BOUND,            GDB_SIGSEGV },
-  { EXCEPT_IA32_INVALID_OPCODE,   GDB_SIGILL  },
-  { EXCEPT_IA32_DOUBLE_FAULT,     GDB_SIGEMT  },
-  { EXCEPT_IA32_STACK_FAULT,      GDB_SIGSEGV },
-  { EXCEPT_IA32_GP_FAULT,         GDB_SIGSEGV },
-  { EXCEPT_IA32_PAGE_FAULT,       GDB_SIGSEGV },
-  { EXCEPT_IA32_FP_ERROR,         GDB_SIGEMT  },
-  { EXCEPT_IA32_ALIGNMENT_CHECK,  GDB_SIGEMT  },
-  { EXCEPT_IA32_MACHINE_CHECK,    GDB_SIGEMT  }
-};
-
-
-// The offsets of registers SystemContext.
-// The fields in the array are in the gdb ordering.
-//
-//16 regs
-UINTN gRegisterOffsets[] = {
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eax),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ecx),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Edx),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ebx),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Esp),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ebp),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Esi),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Edi),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eip),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eflags),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Cs),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ss),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ds),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Es),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Fs),
-  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Gs)
-};
-
-
-//Debug only..
-VOID 
-PrintReg (
-  IN EFI_SYSTEM_CONTEXT SystemContext
-  )
-{
-  Print ((CHAR16 *)L"EAX: %x ", SystemContext.SystemContextIa32->Eax);
-  Print ((CHAR16 *)L"ECX: %x ", SystemContext.SystemContextIa32->Ecx);
-  Print ((CHAR16 *)L"EDX: %x ", SystemContext.SystemContextIa32->Edx);
-  Print ((CHAR16 *)L"EBX: %x ", SystemContext.SystemContextIa32->Ebx);
-  Print ((CHAR16 *)L"ESP: %x ", SystemContext.SystemContextIa32->Esp);
-  Print ((CHAR16 *)L"EBP: %x ", SystemContext.SystemContextIa32->Ebp);
-  Print ((CHAR16 *)L"ESI: %x ", SystemContext.SystemContextIa32->Esi);
-  Print ((CHAR16 *)L"EDI: %x ", SystemContext.SystemContextIa32->Edi);
-  Print ((CHAR16 *)L"EIP: %x\n", SystemContext.SystemContextIa32->Eip);
-  Print ((CHAR16 *)L"EFlags: %x\n", SystemContext.SystemContextIa32->Eflags);
-}
-
-//Debug only..
-VOID 
-PrintDRreg (
-  IN EFI_SYSTEM_CONTEXT SystemContext
-  )
-{
-  Print ((CHAR16 *)L"DR0: %x ", SystemContext.SystemContextIa32->Dr0);
-  Print ((CHAR16 *)L"DR1: %x ", SystemContext.SystemContextIa32->Dr1);
-  Print ((CHAR16 *)L"DR2: %x ", SystemContext.SystemContextIa32->Dr2);
-  Print ((CHAR16 *)L"DR3: %x ", SystemContext.SystemContextIa32->Dr3);
-  Print ((CHAR16 *)L"DR6: %x ", SystemContext.SystemContextIa32->Dr6);
-  Print ((CHAR16 *)L"DR7: %x\n", SystemContext.SystemContextIa32->Dr7);
-}
-
-
-/**
- Return the number of entries in the gExceptionType[]
- @retval  UINTN, the number of entries in the gExceptionType[] array.    
- **/
-UINTN
-MaxEfiException (
-  VOID
-  )
-{
-  return sizeof (gExceptionType)/sizeof (EFI_EXCEPTION_TYPE_ENTRY);
-}
-
-
-/**
-  Check to see if the ISA is supported. 
-  ISA = Instruction Set Architecture
-  @retval TRUE if Isa is supported,
-      FALSE otherwise.
-**/
-BOOLEAN
-CheckIsa (
-  IN  EFI_INSTRUCTION_SET_ARCHITECTURE  Isa
-  )
-{
-  return (BOOLEAN)(Isa == IsaIa32);
-}
-
-
-/**
- This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering
- It is, by default, set to find the register pointer of the IA32 member
-
- @param   SystemContext     Register content at time of the exception 
- @param   RegNumber       The register to which we want to find a pointer
- @retval  the pointer to the RegNumber-th pointer
- **/
-UINTN *
-FindPointerToRegister(
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINTN               RegNumber  
-  )
-{
-  UINT8 *TempPtr;
-  TempPtr = ((UINT8 *)SystemContext.SystemContextIa32) + gRegisterOffsets[RegNumber];
-  return (UINTN *)TempPtr;
-}
-
-
-/**
- Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr
-
- @param SystemContext     Register content at time of the exception
- @param   RegNumber       the number of the register that we want to read
- @param   OutBufPtr       pointer to the output buffer's end. the new data will be added from this point on.
- @retval  the pointer to the next character of the output buffer that is available to be written on.
- **/
-CHAR8 *
-BasicReadRegister (
-  IN  EFI_SYSTEM_CONTEXT      SystemContext,
-  IN  UINTN           RegNumber,
-  IN  CHAR8           *OutBufPtr
-  )
-{
-  UINTN RegSize;
-  
-  RegSize = 0;
-  while (RegSize < REG_SIZE) {
-    *OutBufPtr++ = mHexToStr[((*FindPointerToRegister(SystemContext, RegNumber) >> (RegSize+4)) & 0xf)];
-    *OutBufPtr++ = mHexToStr[((*FindPointerToRegister(SystemContext, RegNumber) >> RegSize) & 0xf)];
-    RegSize = RegSize + 8;
-  }
-  return OutBufPtr;
-}
-
-
-/** â€˜p n’ 
- Reads the n-th register's value into an output buffer and sends it as a packet 
-
- @param   SystemContext   Register content at time of the exception
- @param   InBuffer      Pointer to the input buffer received from gdb server
- **/
-VOID
-EFIAPI
-ReadNthRegister (
-  IN  EFI_SYSTEM_CONTEXT   SystemContext,
-  IN  CHAR8                *InBuffer
-  )
-{
-  UINTN RegNumber;
-  CHAR8 OutBuffer[9]; // 1 reg=8 hex chars, and the end '\0' (escape seq)
-  CHAR8 *OutBufPtr;   // pointer to the output buffer
-  
-  RegNumber = AsciiStrHexToUintn (&InBuffer[1]);
-
-  if ((RegNumber < 0) || (RegNumber >= sizeof (gRegisterOffsets)/sizeof (UINTN))) {
-    SendError (GDB_EINVALIDREGNUM);
-    return;
-  }
-
-  OutBufPtr = OutBuffer;
-  OutBufPtr = BasicReadRegister(SystemContext, RegNumber, OutBufPtr);
-
-  *OutBufPtr = '\0';  // the end of the buffer
-  SendPacket(OutBuffer);
-}
-
-
-/** â€˜g’ 
- Reads the general registers into an output buffer  and sends it as a packet 
-
- @param   SystemContext     Register content at time of the exception
- **/
-VOID
-EFIAPI
-ReadGeneralRegisters (  
-  IN  EFI_SYSTEM_CONTEXT      SystemContext
-  )
-{
-  UINTN   i;
-  CHAR8 OutBuffer[129]; // 16 regs, 8 hex chars each, and the end '\0' (escape seq)
-  CHAR8 *OutBufPtr;   // pointer to the output buffer
-
-  OutBufPtr = OutBuffer;
-  for(i = 0 ; i < sizeof (gRegisterOffsets)/sizeof (UINTN) ; i++) {  // there are only 16 registers to read   
-    OutBufPtr = BasicReadRegister(SystemContext, i, OutBufPtr);
-  }
-
-  *OutBufPtr = '\0';  // the end of the buffer
-  SendPacket(OutBuffer);
-}
-
-
-/**
- Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr
-
- @param   SystemContext       Register content at time of the exception
- @param   RegNumber         the number of the register that we want to write
- @param   InBufPtr          pointer to the output buffer. the new data will be extracted from the input buffer from this point on.
- @retval  the pointer to the next character of the input buffer that can be used
- **/
-CHAR8 *
-BasicWriteRegister (
-  IN  EFI_SYSTEM_CONTEXT      SystemContext,
-  IN  UINTN           RegNumber,
-  IN  CHAR8           *InBufPtr
-  )
-{
-  UINTN RegSize;
-  UINTN TempValue; // the value transferred from a hex char
-  UINT32 NewValue; // the new value of the RegNumber-th Register
-  
-  NewValue = 0;
-  RegSize = 0;
-  while (RegSize < REG_SIZE) {
-    TempValue = HexCharToInt(*InBufPtr++);
-    
-   if (TempValue < 0) {
-      SendError (GDB_EBADMEMDATA); 
-      return NULL;
-    }
-
-    NewValue += (TempValue << (RegSize+4));
-    TempValue = HexCharToInt(*InBufPtr++);
-    
-    if (TempValue < 0) {
-      SendError (GDB_EBADMEMDATA); 
-      return NULL;
-    }
-    
-    NewValue += (TempValue << RegSize); 
-    RegSize = RegSize + 8;
-  }
-  *(FindPointerToRegister(SystemContext, RegNumber)) = NewValue;
-  return InBufPtr;
-}
-
-
-/** â€˜P n...=r...’
- Writes the new value of n-th register received into the input buffer to the n-th register
-
- @param   SystemContext   Register content at time of the exception
- @param   InBuffer      Ponter to the input buffer received from gdb server
- **/
-VOID
-EFIAPI
-WriteNthRegister (
-  IN  EFI_SYSTEM_CONTEXT      SystemContext,
-  IN  CHAR8           *InBuffer
-  )
-{
-  UINTN RegNumber;
-  CHAR8 RegNumBuffer[MAX_REG_NUM_BUF_SIZE];  // put the 'n..' part of the message into this array
-  CHAR8 *RegNumBufPtr;
-  CHAR8 *InBufPtr; // pointer to the input buffer
-  
-  // find the register number to write
-  InBufPtr = &InBuffer[1];
-  RegNumBufPtr = RegNumBuffer;
-  while (*InBufPtr != '=') {
-    *RegNumBufPtr++ = *InBufPtr++;
-  } 
-  *RegNumBufPtr = '\0';
-  RegNumber = AsciiStrHexToUintn (RegNumBuffer); 
-
-  // check if this is a valid Register Number
-  if ((RegNumber < 0) || (RegNumber >= sizeof (gRegisterOffsets)/sizeof (UINTN))) {
-       SendError (GDB_EINVALIDREGNUM); 
-    return;
-  }
-  InBufPtr++;  // skips the '=' character
-  BasicWriteRegister (SystemContext, RegNumber, InBufPtr);
-  SendSuccess();
-}
-
-
-/** â€˜G XX...’
- Writes the new values received into the input buffer to the general registers
-
- @param   SystemContext       Register content at time of the exception
- @param   InBuffer          Pointer to the input buffer received from gdb server
- **/
-VOID
-EFIAPI
-WriteGeneralRegisters (
-  IN  EFI_SYSTEM_CONTEXT        SystemContext,
-  IN  CHAR8             *InBuffer
-  )
-{
-  UINTN  i;
-  CHAR8 *InBufPtr; /// pointer to the input buffer
-
-  // check to see if the buffer is the right size which is 
-  // 1 (for 'G') + 16 (for 16 registers) * 8 ( for 8 hex chars each) = 129 
-  if (AsciiStrLen(InBuffer) != 129) { // 16 regs, 8 hex chars each, and the end '\0' (escape seq)
-       //Bad message. Message is not the right length 
-    SendError (GDB_EBADBUFSIZE); 
-    return;
-  }
-
-  InBufPtr = &InBuffer[1];
-  
-  // Read the new values for the registers from the input buffer to an array, NewValueArray.
-  // The values in the array are in the gdb ordering
-  for(i=0; i < sizeof (gRegisterOffsets)/sizeof (UINTN); i++) {  // there are only 16 registers to write
-    InBufPtr = BasicWriteRegister(SystemContext, i, InBufPtr);
-  }
-
-  SendSuccess();
-}
-
-/** â€˜c [addr ]’ 
- Continue. addr is Address to resume. If addr is omitted, resume at current 
- Address.
- @param   SystemContext     Register content at time of the exception  
- **/
-VOID
-EFIAPI
-ContinueAtAddress (
-  IN  EFI_SYSTEM_CONTEXT      SystemContext,
-  IN    CHAR8                 *PacketData
-  )
-{
-  if (PacketData[1] != '\0') {
-    SystemContext.SystemContextIa32->Eip = AsciiStrHexToUintn (&PacketData[1]);
-  } 
-}
-
-
-/** â€˜s [addr ]’
- Single step. addr is the Address at which to resume. If addr is omitted, resume 
- at same Address.
- @param   SystemContext     Register content at time of the exception  
- **/
-VOID
-EFIAPI
-SingleStep (
-  IN  EFI_SYSTEM_CONTEXT      SystemContext,
-  IN    CHAR8                 *PacketData
-  )
-{
+\r
+//\r
+// Array of exception types that need to be hooked by the debugger\r
+// {EFI mapping, GDB mapping}\r
+//\r
+EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = {\r
+  { EXCEPT_IA32_DIVIDE_ERROR,     GDB_SIGFPE  }, \r
+  { EXCEPT_IA32_DEBUG,            GDB_SIGTRAP },\r
+  { EXCEPT_IA32_NMI,              GDB_SIGEMT  },\r
+  { EXCEPT_IA32_BREAKPOINT,       GDB_SIGTRAP },\r
+  { EXCEPT_IA32_OVERFLOW,         GDB_SIGSEGV },\r
+  { EXCEPT_IA32_BOUND,            GDB_SIGSEGV },\r
+  { EXCEPT_IA32_INVALID_OPCODE,   GDB_SIGILL  },\r
+  { EXCEPT_IA32_DOUBLE_FAULT,     GDB_SIGEMT  },\r
+  { EXCEPT_IA32_STACK_FAULT,      GDB_SIGSEGV },\r
+  { EXCEPT_IA32_GP_FAULT,         GDB_SIGSEGV },\r
+  { EXCEPT_IA32_PAGE_FAULT,       GDB_SIGSEGV },\r
+  { EXCEPT_IA32_FP_ERROR,         GDB_SIGEMT  },\r
+  { EXCEPT_IA32_ALIGNMENT_CHECK,  GDB_SIGEMT  },\r
+  { EXCEPT_IA32_MACHINE_CHECK,    GDB_SIGEMT  }\r
+};\r
+\r
+\r
+// The offsets of registers SystemContext.\r
+// The fields in the array are in the gdb ordering.\r
+//\r
+//16 regs\r
+UINTN gRegisterOffsets[] = {\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eax),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ecx),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Edx),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ebx),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Esp),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ebp),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Esi),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Edi),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eip),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eflags),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Cs),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ss),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ds),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Es),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Fs),\r
+  OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Gs)\r
+};\r
+\r
+\r
+//Debug only..\r
+VOID \r
+PrintReg (\r
+  IN EFI_SYSTEM_CONTEXT SystemContext\r
+  )\r
+{\r
+  Print ((CHAR16 *)L"EAX: %x ", SystemContext.SystemContextIa32->Eax);\r
+  Print ((CHAR16 *)L"ECX: %x ", SystemContext.SystemContextIa32->Ecx);\r
+  Print ((CHAR16 *)L"EDX: %x ", SystemContext.SystemContextIa32->Edx);\r
+  Print ((CHAR16 *)L"EBX: %x ", SystemContext.SystemContextIa32->Ebx);\r
+  Print ((CHAR16 *)L"ESP: %x ", SystemContext.SystemContextIa32->Esp);\r
+  Print ((CHAR16 *)L"EBP: %x ", SystemContext.SystemContextIa32->Ebp);\r
+  Print ((CHAR16 *)L"ESI: %x ", SystemContext.SystemContextIa32->Esi);\r
+  Print ((CHAR16 *)L"EDI: %x ", SystemContext.SystemContextIa32->Edi);\r
+  Print ((CHAR16 *)L"EIP: %x\n", SystemContext.SystemContextIa32->Eip);\r
+  Print ((CHAR16 *)L"EFlags: %x\n", SystemContext.SystemContextIa32->Eflags);\r
+}\r
+\r
+//Debug only..\r
+VOID \r
+PrintDRreg (\r
+  IN EFI_SYSTEM_CONTEXT SystemContext\r
+  )\r
+{\r
+  Print ((CHAR16 *)L"DR0: %x ", SystemContext.SystemContextIa32->Dr0);\r
+  Print ((CHAR16 *)L"DR1: %x ", SystemContext.SystemContextIa32->Dr1);\r
+  Print ((CHAR16 *)L"DR2: %x ", SystemContext.SystemContextIa32->Dr2);\r
+  Print ((CHAR16 *)L"DR3: %x ", SystemContext.SystemContextIa32->Dr3);\r
+  Print ((CHAR16 *)L"DR6: %x ", SystemContext.SystemContextIa32->Dr6);\r
+  Print ((CHAR16 *)L"DR7: %x\n", SystemContext.SystemContextIa32->Dr7);\r
+}\r
+\r
+\r
+/**\r
+ Return the number of entries in the gExceptionType[]\r
\r
+ @retval  UINTN, the number of entries in the gExceptionType[] array.    \r
+ **/\r
+UINTN\r
+MaxEfiException (\r
+  VOID\r
+  )\r
+{\r
+  return sizeof (gExceptionType)/sizeof (EFI_EXCEPTION_TYPE_ENTRY);\r
+}\r
+\r
+\r
+/**\r
+  Check to see if the ISA is supported. \r
+  ISA = Instruction Set Architecture\r
\r
+  @retval TRUE if Isa is supported,\r
+      FALSE otherwise.\r
+**/\r
+BOOLEAN\r
+CheckIsa (\r
+  IN  EFI_INSTRUCTION_SET_ARCHITECTURE  Isa\r
+  )\r
+{\r
+  return (BOOLEAN)(Isa == IsaIa32);\r
+}\r
+\r
+\r
+/**\r
+ This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering\r
+ It is, by default, set to find the register pointer of the IA32 member\r
+\r
+ @param   SystemContext     Register content at time of the exception \r
+ @param   RegNumber       The register to which we want to find a pointer\r
+ @retval  the pointer to the RegNumber-th pointer\r
+ **/\r
+UINTN *\r
+FindPointerToRegister(\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINTN               RegNumber  \r
+  )\r
+{\r
+  UINT8 *TempPtr;\r
+  TempPtr = ((UINT8 *)SystemContext.SystemContextIa32) + gRegisterOffsets[RegNumber];\r
+  return (UINTN *)TempPtr;\r
+}\r
+\r
+\r
+/**\r
+ Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr\r
+\r
+ @param SystemContext     Register content at time of the exception\r
+ @param   RegNumber       the number of the register that we want to read\r
+ @param   OutBufPtr       pointer to the output buffer's end. the new data will be added from this point on.\r
+ @retval  the pointer to the next character of the output buffer that is available to be written on.\r
+ **/\r
+CHAR8 *\r
+BasicReadRegister (\r
+  IN  EFI_SYSTEM_CONTEXT      SystemContext,\r
+  IN  UINTN           RegNumber,\r
+  IN  CHAR8           *OutBufPtr\r
+  )\r
+{\r
+  UINTN RegSize;\r
+  \r
+  RegSize = 0;\r
+  while (RegSize < REG_SIZE) {\r
+    *OutBufPtr++ = mHexToStr[((*FindPointerToRegister(SystemContext, RegNumber) >> (RegSize+4)) & 0xf)];\r
+    *OutBufPtr++ = mHexToStr[((*FindPointerToRegister(SystemContext, RegNumber) >> RegSize) & 0xf)];\r
+    RegSize = RegSize + 8;\r
+  }\r
+  return OutBufPtr;\r
+}\r
+\r
+\r
+/** â€˜p n’ \r
+ Reads the n-th register's value into an output buffer and sends it as a packet \r
+\r
+ @param   SystemContext   Register content at time of the exception\r
+ @param   InBuffer      Pointer to the input buffer received from gdb server\r
+ **/\r
+VOID\r
+EFIAPI\r
+ReadNthRegister (\r
+  IN  EFI_SYSTEM_CONTEXT   SystemContext,\r
+  IN  CHAR8                *InBuffer\r
+  )\r
+{\r
+  UINTN RegNumber;\r
+  CHAR8 OutBuffer[9]; // 1 reg=8 hex chars, and the end '\0' (escape seq)\r
+  CHAR8 *OutBufPtr;   // pointer to the output buffer\r
+  \r
+  RegNumber = AsciiStrHexToUintn (&InBuffer[1]);\r
+\r
+  if ((RegNumber < 0) || (RegNumber >= sizeof (gRegisterOffsets)/sizeof (UINTN))) {\r
+    SendError (GDB_EINVALIDREGNUM);\r
+    return;\r
+  }\r
+\r
+  OutBufPtr = OutBuffer;\r
+  OutBufPtr = BasicReadRegister(SystemContext, RegNumber, OutBufPtr);\r
+\r
+  *OutBufPtr = '\0';  // the end of the buffer\r
+  SendPacket(OutBuffer);\r
+}\r
+\r
+\r
+/** â€˜g’ \r
+ Reads the general registers into an output buffer  and sends it as a packet \r
+\r
+ @param   SystemContext     Register content at time of the exception\r
+ **/\r
+VOID\r
+EFIAPI\r
+ReadGeneralRegisters (  \r
+  IN  EFI_SYSTEM_CONTEXT      SystemContext\r
+  )\r
+{\r
+  UINTN   i;\r
+  CHAR8 OutBuffer[129]; // 16 regs, 8 hex chars each, and the end '\0' (escape seq)\r
+  CHAR8 *OutBufPtr;   // pointer to the output buffer\r
+\r
+  OutBufPtr = OutBuffer;\r
+  for(i = 0 ; i < sizeof (gRegisterOffsets)/sizeof (UINTN) ; i++) {  // there are only 16 registers to read   \r
+    OutBufPtr = BasicReadRegister(SystemContext, i, OutBufPtr);\r
+  }\r
+\r
+  *OutBufPtr = '\0';  // the end of the buffer\r
+  SendPacket(OutBuffer);\r
+}\r
+\r
+\r
+/**\r
+ Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr\r
+\r
+ @param   SystemContext       Register content at time of the exception\r
+ @param   RegNumber         the number of the register that we want to write\r
+ @param   InBufPtr          pointer to the output buffer. the new data will be extracted from the input buffer from this point on.\r
+ @retval  the pointer to the next character of the input buffer that can be used\r
+ **/\r
+CHAR8 *\r
+BasicWriteRegister (\r
+  IN  EFI_SYSTEM_CONTEXT      SystemContext,\r
+  IN  UINTN           RegNumber,\r
+  IN  CHAR8           *InBufPtr\r
+  )\r
+{\r
+  UINTN RegSize;\r
+  UINTN TempValue; // the value transferred from a hex char\r
+  UINT32 NewValue; // the new value of the RegNumber-th Register\r
+  \r
+  NewValue = 0;\r
+  RegSize = 0;\r
+  while (RegSize < REG_SIZE) {\r
+    TempValue = HexCharToInt(*InBufPtr++);\r
+    \r
+   if (TempValue < 0) {\r
+      SendError (GDB_EBADMEMDATA); \r
+      return NULL;\r
+    }\r
+\r
+    NewValue += (TempValue << (RegSize+4));\r
+    TempValue = HexCharToInt(*InBufPtr++);\r
+    \r
+    if (TempValue < 0) {\r
+      SendError (GDB_EBADMEMDATA); \r
+      return NULL;\r
+    }\r
+    \r
+    NewValue += (TempValue << RegSize); \r
+    RegSize = RegSize + 8;\r
+  }\r
+  *(FindPointerToRegister(SystemContext, RegNumber)) = NewValue;\r
+  return InBufPtr;\r
+}\r
+\r
+\r
+/** â€˜P n...=r...’\r
+ Writes the new value of n-th register received into the input buffer to the n-th register\r
+\r
+ @param   SystemContext   Register content at time of the exception\r
+ @param   InBuffer      Ponter to the input buffer received from gdb server\r
+ **/\r
+VOID\r
+EFIAPI\r
+WriteNthRegister (\r
+  IN  EFI_SYSTEM_CONTEXT      SystemContext,\r
+  IN  CHAR8           *InBuffer\r
+  )\r
+{\r
+  UINTN RegNumber;\r
+  CHAR8 RegNumBuffer[MAX_REG_NUM_BUF_SIZE];  // put the 'n..' part of the message into this array\r
+  CHAR8 *RegNumBufPtr;\r
+  CHAR8 *InBufPtr; // pointer to the input buffer\r
+  \r
+  // find the register number to write\r
+  InBufPtr = &InBuffer[1];\r
+  RegNumBufPtr = RegNumBuffer;\r
+  while (*InBufPtr != '=') {\r
+    *RegNumBufPtr++ = *InBufPtr++;\r
+  } \r
+  *RegNumBufPtr = '\0';\r
+  RegNumber = AsciiStrHexToUintn (RegNumBuffer); \r
+\r
+  // check if this is a valid Register Number\r
+  if ((RegNumber < 0) || (RegNumber >= sizeof (gRegisterOffsets)/sizeof (UINTN))) {\r
+       SendError (GDB_EINVALIDREGNUM); \r
+    return;\r
+  }\r
+  InBufPtr++;  // skips the '=' character\r
+  BasicWriteRegister (SystemContext, RegNumber, InBufPtr);\r
+  SendSuccess();\r
+}\r
+\r
+\r
+/** â€˜G XX...’\r
+ Writes the new values received into the input buffer to the general registers\r
+\r
+ @param   SystemContext       Register content at time of the exception\r
+ @param   InBuffer          Pointer to the input buffer received from gdb server\r
+ **/\r
+VOID\r
+EFIAPI\r
+WriteGeneralRegisters (\r
+  IN  EFI_SYSTEM_CONTEXT        SystemContext,\r
+  IN  CHAR8             *InBuffer\r
+  )\r
+{\r
+  UINTN  i;\r
+  CHAR8 *InBufPtr; /// pointer to the input buffer\r
+\r
+  // check to see if the buffer is the right size which is \r
+  // 1 (for 'G') + 16 (for 16 registers) * 8 ( for 8 hex chars each) = 129 \r
+  if (AsciiStrLen(InBuffer) != 129) { // 16 regs, 8 hex chars each, and the end '\0' (escape seq)\r
+       //Bad message. Message is not the right length \r
+    SendError (GDB_EBADBUFSIZE); \r
+    return;\r
+  }\r
+\r
+  InBufPtr = &InBuffer[1];\r
+  \r
+  // Read the new values for the registers from the input buffer to an array, NewValueArray.\r
+  // The values in the array are in the gdb ordering\r
+  for(i=0; i < sizeof (gRegisterOffsets)/sizeof (UINTN); i++) {  // there are only 16 registers to write\r
+    InBufPtr = BasicWriteRegister(SystemContext, i, InBufPtr);\r
+  }\r
+\r
+  SendSuccess();\r
+}\r
+\r
+/** â€˜c [addr ]’ \r
+ Continue. addr is Address to resume. If addr is omitted, resume at current \r
+ Address.\r
\r
+ @param   SystemContext     Register content at time of the exception  \r
+ **/\r
+VOID\r
+EFIAPI\r
+ContinueAtAddress (\r
+  IN  EFI_SYSTEM_CONTEXT      SystemContext,\r
+  IN    CHAR8                 *PacketData\r
+  )\r
+{\r
+  if (PacketData[1] != '\0') {\r
+    SystemContext.SystemContextIa32->Eip = AsciiStrHexToUintn (&PacketData[1]);\r
+  } \r
+}\r
+\r
+\r
+/** â€˜s [addr ]’\r
+ Single step. addr is the Address at which to resume. If addr is omitted, resume \r
+ at same Address.\r
\r
+ @param   SystemContext     Register content at time of the exception  \r
+ **/\r
+VOID\r
+EFIAPI\r
+SingleStep (\r
+  IN  EFI_SYSTEM_CONTEXT      SystemContext,\r
+  IN    CHAR8                 *PacketData\r
+  )\r
+{\r
   SendNotSupported();\r
   SendNotSupported();\r
-}
-
-
-/**
-  Returns breakpoint data address from DR0-DR3 based on the input breakpoint number
-
-  @param  SystemContext      Register content at time of the exception
-  @param  BreakpointNumber   Breakpoint number
-
-  @retval Address            Data address from DR0-DR3 based on the breakpoint number.
-
-**/
-UINTN
-GetBreakpointDataAddress (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINTN               BreakpointNumber
-  )
-{
-  UINTN Address;
-
-  if (BreakpointNumber == 1) {
-    Address = SystemContext.SystemContextIa32->Dr0;
-  } else if (BreakpointNumber == 2) {
-    Address = SystemContext.SystemContextIa32->Dr1;
-  } else if (BreakpointNumber == 3) {
-    Address = SystemContext.SystemContextIa32->Dr2;
-  } else if (BreakpointNumber == 4) {
-    Address = SystemContext.SystemContextIa32->Dr3;
-  } else {
-    Address = 0;
-  }
-
-  return Address;
-}
-
-
-/**
-  Returns currently detected breakpoint value based on the register DR6 B0-B3 field.
-  If no breakpoint is detected then it returns 0.
-
-  @param  SystemContext  Register content at time of the exception
-
-  @retval {1-4}          Currently detected breakpoint value   
-  @retval 0              No breakpoint detected.
-**/
-UINTN
-GetBreakpointDetected (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext
-  )
-{
-  IA32_DR6 Dr6;
-  UINTN BreakpointNumber;
-
-  Dr6.UintN = SystemContext.SystemContextIa32->Dr6;
-
-  if (Dr6.Bits.B0 == 1) {
-    BreakpointNumber = 1;
-  } else if (Dr6.Bits.B1 == 1) {
-    BreakpointNumber = 2;
-  } else if (Dr6.Bits.B2 == 1) {
-    BreakpointNumber = 3;
-  } else if (Dr6.Bits.B3 == 1) {
-    BreakpointNumber = 4;
-  } else {
-    BreakpointNumber = 0;  //No breakpoint detected 
-  }
-
-  return BreakpointNumber;
-}
-
-
-/**
-  Returns Breakpoint type (InstructionExecution, DataWrite, DataRead or DataReadWrite)
-  based on the Breakpoint number
-  
-  @param  SystemContext        Register content at time of the exception
-  @param  BreakpointNumber     Breakpoint number
-  
-  @retval BREAK_TYPE           Breakpoint type value read from register DR7 RWn field
-                               For unknown value, it returns NotSupported.
-  
-**/
-BREAK_TYPE
-GetBreakpointType (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINTN               BreakpointNumber
-  )
-{
-  IA32_DR7 Dr7;
-  BREAK_TYPE Type = NotSupported;  //Default is NotSupported type
-
-  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
-
-  if (BreakpointNumber == 1) {
-    Type = (BREAK_TYPE) Dr7.Bits.RW0;  
-  } else if (BreakpointNumber == 2) {
-    Type = (BREAK_TYPE) Dr7.Bits.RW1;  
-  } else if (BreakpointNumber == 3) {
-    Type = (BREAK_TYPE) Dr7.Bits.RW2;  
-  } else if (BreakpointNumber == 4) {
-    Type = (BREAK_TYPE) Dr7.Bits.RW3;  
-  }
-
-  return Type;
-}
-
-
-/** 
-  Parses Length and returns the length which DR7 LENn field accepts.
-  For example: If we receive 1-Byte length then we should return 0. 
-               Zero gets written to DR7 LENn field.
-
-  @param  Length  Breakpoint length in Bytes (1 byte, 2 byte, 4 byte)
-
-  @retval Length  Appropriate converted values which DR7 LENn field accepts.
-
-**/
-UINTN
-ConvertLengthData (
-  IN     UINTN   Length
-  )
-{
-  if (Length == 1) {         //1-Byte length 
-    return 0;
-  } else if (Length == 2) {  //2-Byte length
-    return 1;
-  } else if (Length == 4) {  //4-Byte length
-    return 3;
-  } else {                   //Undefined or 8-byte length
-    return 2;
-  }
-}
-
-
-/**
-  Finds the next free debug register. If all the registers are occupied then 
-  EFI_OUT_OF_RESOURCES is returned.  
-
-  @param  SystemContext   Register content at time of the exception
-  @param  Register        Register value (0 - 3 for the first free debug register)
-
-  @retval EFI_STATUS      Appropriate status value.
-
-**/
-EFI_STATUS
-FindNextFreeDebugRegister (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  OUT UINTN               *Register
-  )
-{
-  IA32_DR7 Dr7;
-
-  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
-
-  if (Dr7.Bits.G0 == 0) {
-    *Register = 0;
-  } else if (Dr7.Bits.G1 == 0) {
-    *Register = 1;
-  } else if (Dr7.Bits.G2 == 0) {
-    *Register = 2;
-  } else if (Dr7.Bits.G3 == 0) {
-    *Register = 3;
-  } else {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  return EFI_SUCCESS;
-}
-
-
-/**
-  Enables the debug register. Writes Address value to appropriate DR0-3 register.
-  Sets LENn, Gn, RWn bits in DR7 register.
-  @param  SystemContext   Register content at time of the exception
-  @param  Register        Register value (0 - 3) 
-  @param  Address         Breakpoint address value
-  @param  Type            Breakpoint type (Instruction, Data write, Data read 
-                          or write etc.)
-
-  @retval EFI_STATUS      Appropriate status value.
-
-**/
-EFI_STATUS
-EnableDebugRegister (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  UINTN               Register,
-  IN  UINTN               Address,
-  IN  UINTN               Length,
-  IN  UINTN               Type
-  )
-{
-  IA32_DR7  Dr7;
-
-  //Convert length data
-  Length = ConvertLengthData (Length);
-
-  //For Instruction execution, length should be 0 
-  //(Ref. Intel reference manual 18.2.4)
-  if ((Type == 0) && (Length != 0)) {
-    return EFI_INVALID_PARAMETER;
-  }
-  //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle
-  //software breakpoint. We should send empty packet in both these cases.
-  if ((Type == (BREAK_TYPE)DataRead) || 
-      (Type == (BREAK_TYPE)SoftwareBreakpoint)) {
-    return EFI_UNSUPPORTED;
-  }
-
-  //Read DR7 so appropriate Gn, RWn and LENn bits can be modified.
-  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
-
-  if (Register == 0) {
-    SystemContext.SystemContextIa32->Dr0 = Address;
-    Dr7.Bits.G0 = 1;
-    Dr7.Bits.RW0 = Type;
-    Dr7.Bits.LEN0 = Length;
-  } else if (Register == 1) {
-    SystemContext.SystemContextIa32->Dr1 = Address;
-    Dr7.Bits.G1 = 1;
-    Dr7.Bits.RW1 = Type;
-    Dr7.Bits.LEN1 = Length;
-  } else if (Register == 2) {
-    SystemContext.SystemContextIa32->Dr2 = Address;
-    Dr7.Bits.G2 = 1;
-    Dr7.Bits.RW2 = Type;
-    Dr7.Bits.LEN2 = Length;
-  } else if (Register == 3) {
-    SystemContext.SystemContextIa32->Dr3 = Address;
-    Dr7.Bits.G3 = 1;
-    Dr7.Bits.RW3 = Type;
-    Dr7.Bits.LEN3 = Length;
-  } else {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  //Update Dr7 with appropriate Gn, RWn and LENn bits 
-  SystemContext.SystemContextIa32->Dr7 = Dr7.UintN;
-
-  return EFI_SUCCESS;
-}
-
-
-/**
-  Returns register number 0 - 3 for the maching debug register.
-  This function compares incoming Address, Type, Length and
-  if there is a match then it returns the appropriate register number.
-  In case of mismatch, function returns EFI_NOT_FOUND message.
-
-  @param  SystemContext  Register content at time of the exception
-  @param  Address        Breakpoint address value
-  @param  Length         Breakpoint length value
-  @param  Type           Breakpoint type (Instruction, Data write, 
-                         Data read or write etc.)
-  @param  Register       Register value to be returned
-
-  @retval EFI_STATUS     Appropriate status value.
-
-**/
-EFI_STATUS
-FindMatchingDebugRegister (
- IN  EFI_SYSTEM_CONTEXT  SystemContext,
- IN  UINTN               Address,
- IN  UINTN               Length,
- IN  UINTN               Type,
- OUT UINTN               *Register
- )
-{
-  IA32_DR7 Dr7;
-
-  //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle
-  //software breakpoint. We should send empty packet in both these cases.
-  if ((Type == (BREAK_TYPE)DataRead) || 
-      (Type == (BREAK_TYPE)SoftwareBreakpoint)) {
-    return EFI_UNSUPPORTED;
-  }
-
-  //Convert length data
-  Length = ConvertLengthData(Length);
-
-  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
-
-  if ((Dr7.Bits.G0 == 1) && 
-      (Dr7.Bits.LEN0 == Length) &&
-      (Dr7.Bits.RW0 == Type) && 
-      (Address == SystemContext.SystemContextIa32->Dr0)) {
-    *Register = 0;
-  } else if ((Dr7.Bits.G1 == 1) && 
-             (Dr7.Bits.LEN1 == Length) &&
-             (Dr7.Bits.RW1 == Type) && 
-             (Address == SystemContext.SystemContextIa32->Dr1)) {
-    *Register = 1;
-  } else if ((Dr7.Bits.G2 == 1) && 
-             (Dr7.Bits.LEN2 == Length) &&
-             (Dr7.Bits.RW2 == Type) && 
-             (Address == SystemContext.SystemContextIa32->Dr2)) {
-    *Register = 2;
-  } else if ((Dr7.Bits.G3 == 1) && 
-             (Dr7.Bits.LEN3 == Length) &&
-             (Dr7.Bits.RW3 == Type) && 
-             (Address == SystemContext.SystemContextIa32->Dr3)) {
-    *Register = 3;
-  } else {
-    Print ((CHAR16 *)L"No match found..\n");
-    return EFI_NOT_FOUND;
-  }
-
-  return EFI_SUCCESS;
-}
-
-
-/**
-  Disables the particular debug register.
-
-  @param  SystemContext   Register content at time of the exception
-  @param  Register        Register to be disabled
-
-  @retval EFI_STATUS      Appropriate status value.
-
-**/
-EFI_STATUS
-DisableDebugRegister (
- IN  EFI_SYSTEM_CONTEXT  SystemContext,
- IN  UINTN               Register  
- )
-{
-  IA32_DR7  Dr7;
-  UINTN Address = 0;
-  //Read DR7 register so appropriate Gn, RWn and LENn bits can be turned off.
-  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
-
-  if (Register == 0) {
-    SystemContext.SystemContextIa32->Dr0 = Address;
-    Dr7.Bits.G0 = 0;
-    Dr7.Bits.RW0 = 0;
-    Dr7.Bits.LEN0 = 0;
-  } else if (Register == 1) {
-    SystemContext.SystemContextIa32->Dr1 = Address;
-    Dr7.Bits.G1 = 0;
-    Dr7.Bits.RW1 = 0;
-    Dr7.Bits.LEN1 = 0;
-  } else if (Register == 2) {
-    SystemContext.SystemContextIa32->Dr2 = Address;
-    Dr7.Bits.G2 = 0;
-    Dr7.Bits.RW2 = 0;
-    Dr7.Bits.LEN2 = 0;
-  } else if (Register == 3) {
-    SystemContext.SystemContextIa32->Dr3 = Address;
-    Dr7.Bits.G3 = 0;
-    Dr7.Bits.RW3 = 0;
-    Dr7.Bits.LEN3 = 0;
-  } else {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  //Update DR7 register so appropriate Gn, RWn and LENn bits can be turned off.
-  SystemContext.SystemContextIa32->Dr7 = Dr7.UintN;
-
-  return EFI_SUCCESS;
-}
-
-
-/**
-  â€˜Z1, [addr], [length]’
-  â€˜Z2, [addr], [length]’
-  â€˜Z3, [addr], [length]’
-  â€˜Z4, [addr], [length]’
-
-  Insert hardware breakpoint/watchpoint at address addr of size length
-
-  @param SystemContext  Register content at time of the exception
-  @param *PacketData    Pointer to the Payload data for the packet
-
-**/
-VOID
-EFIAPI
-InsertBreakPoint (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  CHAR8              *PacketData
-  )
-{
-  UINTN Type;
-  UINTN Address;
-  UINTN Length;
-  UINTN Register;
-  EFI_STATUS Status;
-  BREAK_TYPE BreakType = NotSupported;
-  UINTN ErrorCode;
-
-  ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length);
-  if (ErrorCode > 0) {
-    SendError ((UINT8)ErrorCode);
-    return;
-  }
-
-  switch (Type) {
-
-    case    0:   //Software breakpoint
-      BreakType = SoftwareBreakpoint;
-      break;
-
-    case    1:   //Hardware breakpoint
-      BreakType = InstructionExecution;
-      break;
-
-    case    2:   //Write watchpoint
-      BreakType = DataWrite;
-      break;
-
-    case    3:   //Read watchpoint
-      BreakType = DataRead;
-      break;
-
-    case    4:   //Access watchpoint
-      BreakType = DataReadWrite;
-      break;
-
-    default  :
-      Print ((CHAR16 *)L"Insert breakpoint default: %x\n", Type);
-      SendError (GDB_EINVALIDBRKPOINTTYPE);
-      return;
-  }
-
-  // Find next free debug register
-  Status = FindNextFreeDebugRegister (SystemContext, &Register);
-  if (EFI_ERROR(Status)) {
-    Print ((CHAR16 *)L"No space left on device\n");
-    SendError (GDB_ENOSPACE);
-    return;
-  }
-
-  // Write Address, length data at particular DR register
-  Status = EnableDebugRegister (SystemContext, Register, Address, Length, (UINTN)BreakType);
-  if (EFI_ERROR(Status)) {
-    if (Status == EFI_UNSUPPORTED) {
-      SendNotSupported();
-      return;
-    }
-
-    SendError (GDB_EINVALIDARG);
-    return;
-  }
-
-  SendSuccess ();
-}
-
-
-/**
-  â€˜z1, [addr], [length]’
-  â€˜z2, [addr], [length]’
-  â€˜z3, [addr], [length]’
-  â€˜z4, [addr], [length]’
-
-  Remove hardware breakpoint/watchpoint at address addr of size length
-
-  @param *PacketData    Pointer to the Payload data for the packet
-
-**/
-VOID
-EFIAPI
-RemoveBreakPoint (
-  IN  EFI_SYSTEM_CONTEXT  SystemContext,
-  IN  CHAR8               *PacketData
-  )
-{
-  UINTN      Type;
-  UINTN      Address;
-  UINTN      Length;
-  UINTN      Register;
-  BREAK_TYPE BreakType = NotSupported;
-  EFI_STATUS Status;
-  UINTN      ErrorCode;
-
-  //Parse breakpoint packet data
-  ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length);
-  if (ErrorCode > 0) {
-    SendError ((UINT8)ErrorCode);
-    return;
-  }
-
-  switch (Type) {
-  
-    case    0:   //Software breakpoint
-      BreakType = SoftwareBreakpoint;
-      break;
-      
-    case    1:   //Hardware breakpoint
-      BreakType = InstructionExecution;
-      break;
-      
-    case    2:   //Write watchpoint
-      BreakType = DataWrite;
-      break;
-
-    case    3:   //Read watchpoint
-      BreakType = DataRead;
-      break;
-
-    case    4:   //Access watchpoint
-      BreakType = DataReadWrite;
-      break;
-
-    default  :
-      SendError (GDB_EINVALIDBRKPOINTTYPE);
-      return;
-  }
-
-  //Find matching debug register
-  Status = FindMatchingDebugRegister (SystemContext, Address, Length, (UINTN)BreakType, &Register);
-  if (EFI_ERROR(Status)) {
-    if (Status == EFI_UNSUPPORTED) {
-      SendNotSupported();
-      return;
-    }
-
-    SendError (GDB_ENOSPACE);
-    return;
-  }
-
-  //Remove breakpoint
-  Status = DisableDebugRegister(SystemContext, Register);
-  if (EFI_ERROR(Status)) {
-    SendError (GDB_EINVALIDARG);
-    return;
-  }
-
-  SendSuccess ();
-}
-
-
+}\r
+\r
+\r
+/**\r
+  Returns breakpoint data address from DR0-DR3 based on the input breakpoint number\r
+\r
+  @param  SystemContext      Register content at time of the exception\r
+  @param  BreakpointNumber   Breakpoint number\r
+\r
+  @retval Address            Data address from DR0-DR3 based on the breakpoint number.\r
+\r
+**/\r
+UINTN\r
+GetBreakpointDataAddress (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINTN               BreakpointNumber\r
+  )\r
+{\r
+  UINTN Address;\r
+\r
+  if (BreakpointNumber == 1) {\r
+    Address = SystemContext.SystemContextIa32->Dr0;\r
+  } else if (BreakpointNumber == 2) {\r
+    Address = SystemContext.SystemContextIa32->Dr1;\r
+  } else if (BreakpointNumber == 3) {\r
+    Address = SystemContext.SystemContextIa32->Dr2;\r
+  } else if (BreakpointNumber == 4) {\r
+    Address = SystemContext.SystemContextIa32->Dr3;\r
+  } else {\r
+    Address = 0;\r
+  }\r
+\r
+  return Address;\r
+}\r
+\r
+\r
+/**\r
+  Returns currently detected breakpoint value based on the register DR6 B0-B3 field.\r
+  If no breakpoint is detected then it returns 0.\r
+\r
+  @param  SystemContext  Register content at time of the exception\r
+\r
+  @retval {1-4}          Currently detected breakpoint value   \r
+  @retval 0              No breakpoint detected.\r
\r
+**/\r
+UINTN\r
+GetBreakpointDetected (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext\r
+  )\r
+{\r
+  IA32_DR6 Dr6;\r
+  UINTN BreakpointNumber;\r
+\r
+  Dr6.UintN = SystemContext.SystemContextIa32->Dr6;\r
+\r
+  if (Dr6.Bits.B0 == 1) {\r
+    BreakpointNumber = 1;\r
+  } else if (Dr6.Bits.B1 == 1) {\r
+    BreakpointNumber = 2;\r
+  } else if (Dr6.Bits.B2 == 1) {\r
+    BreakpointNumber = 3;\r
+  } else if (Dr6.Bits.B3 == 1) {\r
+    BreakpointNumber = 4;\r
+  } else {\r
+    BreakpointNumber = 0;  //No breakpoint detected \r
+  }\r
+\r
+  return BreakpointNumber;\r
+}\r
+\r
+\r
+/**\r
+  Returns Breakpoint type (InstructionExecution, DataWrite, DataRead or DataReadWrite)\r
+  based on the Breakpoint number\r
+  \r
+  @param  SystemContext        Register content at time of the exception\r
+  @param  BreakpointNumber     Breakpoint number\r
+  \r
+  @retval BREAK_TYPE           Breakpoint type value read from register DR7 RWn field\r
+                               For unknown value, it returns NotSupported.\r
+  \r
+**/\r
+BREAK_TYPE\r
+GetBreakpointType (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINTN               BreakpointNumber\r
+  )\r
+{\r
+  IA32_DR7 Dr7;\r
+  BREAK_TYPE Type = NotSupported;  //Default is NotSupported type\r
+\r
+  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;\r
+\r
+  if (BreakpointNumber == 1) {\r
+    Type = (BREAK_TYPE) Dr7.Bits.RW0;  \r
+  } else if (BreakpointNumber == 2) {\r
+    Type = (BREAK_TYPE) Dr7.Bits.RW1;  \r
+  } else if (BreakpointNumber == 3) {\r
+    Type = (BREAK_TYPE) Dr7.Bits.RW2;  \r
+  } else if (BreakpointNumber == 4) {\r
+    Type = (BREAK_TYPE) Dr7.Bits.RW3;  \r
+  }\r
+\r
+  return Type;\r
+}\r
+\r
+\r
+/** \r
+  Parses Length and returns the length which DR7 LENn field accepts.\r
+  For example: If we receive 1-Byte length then we should return 0. \r
+               Zero gets written to DR7 LENn field.\r
+\r
+  @param  Length  Breakpoint length in Bytes (1 byte, 2 byte, 4 byte)\r
+\r
+  @retval Length  Appropriate converted values which DR7 LENn field accepts.\r
+\r
+**/\r
+UINTN\r
+ConvertLengthData (\r
+  IN     UINTN   Length\r
+  )\r
+{\r
+  if (Length == 1) {         //1-Byte length \r
+    return 0;\r
+  } else if (Length == 2) {  //2-Byte length\r
+    return 1;\r
+  } else if (Length == 4) {  //4-Byte length\r
+    return 3;\r
+  } else {                   //Undefined or 8-byte length\r
+    return 2;\r
+  }\r
+}\r
+\r
+\r
+/**\r
+  Finds the next free debug register. If all the registers are occupied then \r
+  EFI_OUT_OF_RESOURCES is returned.  \r
+\r
+  @param  SystemContext   Register content at time of the exception\r
+  @param  Register        Register value (0 - 3 for the first free debug register)\r
+\r
+  @retval EFI_STATUS      Appropriate status value.\r
+\r
+**/\r
+EFI_STATUS\r
+FindNextFreeDebugRegister (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  OUT UINTN               *Register\r
+  )\r
+{\r
+  IA32_DR7 Dr7;\r
+\r
+  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;\r
+\r
+  if (Dr7.Bits.G0 == 0) {\r
+    *Register = 0;\r
+  } else if (Dr7.Bits.G1 == 0) {\r
+    *Register = 1;\r
+  } else if (Dr7.Bits.G2 == 0) {\r
+    *Register = 2;\r
+  } else if (Dr7.Bits.G3 == 0) {\r
+    *Register = 3;\r
+  } else {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Enables the debug register. Writes Address value to appropriate DR0-3 register.\r
+  Sets LENn, Gn, RWn bits in DR7 register.\r
\r
+  @param  SystemContext   Register content at time of the exception\r
+  @param  Register        Register value (0 - 3) \r
+  @param  Address         Breakpoint address value\r
+  @param  Type            Breakpoint type (Instruction, Data write, Data read \r
+                          or write etc.)\r
+\r
+  @retval EFI_STATUS      Appropriate status value.\r
+\r
+**/\r
+EFI_STATUS\r
+EnableDebugRegister (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  UINTN               Register,\r
+  IN  UINTN               Address,\r
+  IN  UINTN               Length,\r
+  IN  UINTN               Type\r
+  )\r
+{\r
+  IA32_DR7  Dr7;\r
+\r
+  //Convert length data\r
+  Length = ConvertLengthData (Length);\r
+\r
+  //For Instruction execution, length should be 0 \r
+  //(Ref. Intel reference manual 18.2.4)\r
+  if ((Type == 0) && (Length != 0)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
\r
+  //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle\r
+  //software breakpoint. We should send empty packet in both these cases.\r
+  if ((Type == (BREAK_TYPE)DataRead) || \r
+      (Type == (BREAK_TYPE)SoftwareBreakpoint)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //Read DR7 so appropriate Gn, RWn and LENn bits can be modified.\r
+  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;\r
+\r
+  if (Register == 0) {\r
+    SystemContext.SystemContextIa32->Dr0 = Address;\r
+    Dr7.Bits.G0 = 1;\r
+    Dr7.Bits.RW0 = Type;\r
+    Dr7.Bits.LEN0 = Length;\r
+  } else if (Register == 1) {\r
+    SystemContext.SystemContextIa32->Dr1 = Address;\r
+    Dr7.Bits.G1 = 1;\r
+    Dr7.Bits.RW1 = Type;\r
+    Dr7.Bits.LEN1 = Length;\r
+  } else if (Register == 2) {\r
+    SystemContext.SystemContextIa32->Dr2 = Address;\r
+    Dr7.Bits.G2 = 1;\r
+    Dr7.Bits.RW2 = Type;\r
+    Dr7.Bits.LEN2 = Length;\r
+  } else if (Register == 3) {\r
+    SystemContext.SystemContextIa32->Dr3 = Address;\r
+    Dr7.Bits.G3 = 1;\r
+    Dr7.Bits.RW3 = Type;\r
+    Dr7.Bits.LEN3 = Length;\r
+  } else {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //Update Dr7 with appropriate Gn, RWn and LENn bits \r
+  SystemContext.SystemContextIa32->Dr7 = Dr7.UintN;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Returns register number 0 - 3 for the maching debug register.\r
+  This function compares incoming Address, Type, Length and\r
+  if there is a match then it returns the appropriate register number.\r
+  In case of mismatch, function returns EFI_NOT_FOUND message.\r
+\r
+  @param  SystemContext  Register content at time of the exception\r
+  @param  Address        Breakpoint address value\r
+  @param  Length         Breakpoint length value\r
+  @param  Type           Breakpoint type (Instruction, Data write, \r
+                         Data read or write etc.)\r
+  @param  Register       Register value to be returned\r
+\r
+  @retval EFI_STATUS     Appropriate status value.\r
+\r
+**/\r
+EFI_STATUS\r
+FindMatchingDebugRegister (\r
+ IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+ IN  UINTN               Address,\r
+ IN  UINTN               Length,\r
+ IN  UINTN               Type,\r
+ OUT UINTN               *Register\r
+ )\r
+{\r
+  IA32_DR7 Dr7;\r
+\r
+  //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle\r
+  //software breakpoint. We should send empty packet in both these cases.\r
+  if ((Type == (BREAK_TYPE)DataRead) || \r
+      (Type == (BREAK_TYPE)SoftwareBreakpoint)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //Convert length data\r
+  Length = ConvertLengthData(Length);\r
+\r
+  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;\r
+\r
+  if ((Dr7.Bits.G0 == 1) && \r
+      (Dr7.Bits.LEN0 == Length) &&\r
+      (Dr7.Bits.RW0 == Type) && \r
+      (Address == SystemContext.SystemContextIa32->Dr0)) {\r
+    *Register = 0;\r
+  } else if ((Dr7.Bits.G1 == 1) && \r
+             (Dr7.Bits.LEN1 == Length) &&\r
+             (Dr7.Bits.RW1 == Type) && \r
+             (Address == SystemContext.SystemContextIa32->Dr1)) {\r
+    *Register = 1;\r
+  } else if ((Dr7.Bits.G2 == 1) && \r
+             (Dr7.Bits.LEN2 == Length) &&\r
+             (Dr7.Bits.RW2 == Type) && \r
+             (Address == SystemContext.SystemContextIa32->Dr2)) {\r
+    *Register = 2;\r
+  } else if ((Dr7.Bits.G3 == 1) && \r
+             (Dr7.Bits.LEN3 == Length) &&\r
+             (Dr7.Bits.RW3 == Type) && \r
+             (Address == SystemContext.SystemContextIa32->Dr3)) {\r
+    *Register = 3;\r
+  } else {\r
+    Print ((CHAR16 *)L"No match found..\n");\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Disables the particular debug register.\r
+\r
+  @param  SystemContext   Register content at time of the exception\r
+  @param  Register        Register to be disabled\r
+\r
+  @retval EFI_STATUS      Appropriate status value.\r
+\r
+**/\r
+EFI_STATUS\r
+DisableDebugRegister (\r
+ IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+ IN  UINTN               Register  \r
+ )\r
+{\r
+  IA32_DR7  Dr7;\r
+  UINTN Address = 0;\r
\r
+  //Read DR7 register so appropriate Gn, RWn and LENn bits can be turned off.\r
+  Dr7.UintN = SystemContext.SystemContextIa32->Dr7;\r
+\r
+  if (Register == 0) {\r
+    SystemContext.SystemContextIa32->Dr0 = Address;\r
+    Dr7.Bits.G0 = 0;\r
+    Dr7.Bits.RW0 = 0;\r
+    Dr7.Bits.LEN0 = 0;\r
+  } else if (Register == 1) {\r
+    SystemContext.SystemContextIa32->Dr1 = Address;\r
+    Dr7.Bits.G1 = 0;\r
+    Dr7.Bits.RW1 = 0;\r
+    Dr7.Bits.LEN1 = 0;\r
+  } else if (Register == 2) {\r
+    SystemContext.SystemContextIa32->Dr2 = Address;\r
+    Dr7.Bits.G2 = 0;\r
+    Dr7.Bits.RW2 = 0;\r
+    Dr7.Bits.LEN2 = 0;\r
+  } else if (Register == 3) {\r
+    SystemContext.SystemContextIa32->Dr3 = Address;\r
+    Dr7.Bits.G3 = 0;\r
+    Dr7.Bits.RW3 = 0;\r
+    Dr7.Bits.LEN3 = 0;\r
+  } else {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //Update DR7 register so appropriate Gn, RWn and LENn bits can be turned off.\r
+  SystemContext.SystemContextIa32->Dr7 = Dr7.UintN;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  â€˜Z1, [addr], [length]’\r
+  â€˜Z2, [addr], [length]’\r
+  â€˜Z3, [addr], [length]’\r
+  â€˜Z4, [addr], [length]’\r
+\r
+  Insert hardware breakpoint/watchpoint at address addr of size length\r
+\r
+  @param SystemContext  Register content at time of the exception\r
+  @param *PacketData    Pointer to the Payload data for the packet\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+InsertBreakPoint (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  CHAR8              *PacketData\r
+  )\r
+{\r
+  UINTN Type;\r
+  UINTN Address;\r
+  UINTN Length;\r
+  UINTN Register;\r
+  EFI_STATUS Status;\r
+  BREAK_TYPE BreakType = NotSupported;\r
+  UINTN ErrorCode;\r
+\r
+  ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length);\r
+  if (ErrorCode > 0) {\r
+    SendError ((UINT8)ErrorCode);\r
+    return;\r
+  }\r
+\r
+  switch (Type) {\r
+\r
+    case    0:   //Software breakpoint\r
+      BreakType = SoftwareBreakpoint;\r
+      break;\r
+\r
+    case    1:   //Hardware breakpoint\r
+      BreakType = InstructionExecution;\r
+      break;\r
+\r
+    case    2:   //Write watchpoint\r
+      BreakType = DataWrite;\r
+      break;\r
+\r
+    case    3:   //Read watchpoint\r
+      BreakType = DataRead;\r
+      break;\r
+\r
+    case    4:   //Access watchpoint\r
+      BreakType = DataReadWrite;\r
+      break;\r
+\r
+    default  :\r
+      Print ((CHAR16 *)L"Insert breakpoint default: %x\n", Type);\r
+      SendError (GDB_EINVALIDBRKPOINTTYPE);\r
+      return;\r
+  }\r
+\r
+  // Find next free debug register\r
+  Status = FindNextFreeDebugRegister (SystemContext, &Register);\r
+  if (EFI_ERROR(Status)) {\r
+    Print ((CHAR16 *)L"No space left on device\n");\r
+    SendError (GDB_ENOSPACE);\r
+    return;\r
+  }\r
+\r
+  // Write Address, length data at particular DR register\r
+  Status = EnableDebugRegister (SystemContext, Register, Address, Length, (UINTN)BreakType);\r
+  if (EFI_ERROR(Status)) {\r
+    if (Status == EFI_UNSUPPORTED) {\r
+      SendNotSupported();\r
+      return;\r
+    }\r
+\r
+    SendError (GDB_EINVALIDARG);\r
+    return;\r
+  }\r
+\r
+  SendSuccess ();\r
+}\r
+\r
+\r
+/**\r
+  â€˜z1, [addr], [length]’\r
+  â€˜z2, [addr], [length]’\r
+  â€˜z3, [addr], [length]’\r
+  â€˜z4, [addr], [length]’\r
+\r
+  Remove hardware breakpoint/watchpoint at address addr of size length\r
+\r
+  @param *PacketData    Pointer to the Payload data for the packet\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+RemoveBreakPoint (\r
+  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
+  IN  CHAR8               *PacketData\r
+  )\r
+{\r
+  UINTN      Type;\r
+  UINTN      Address;\r
+  UINTN      Length;\r
+  UINTN      Register;\r
+  BREAK_TYPE BreakType = NotSupported;\r
+  EFI_STATUS Status;\r
+  UINTN      ErrorCode;\r
+\r
+  //Parse breakpoint packet data\r
+  ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length);\r
+  if (ErrorCode > 0) {\r
+    SendError ((UINT8)ErrorCode);\r
+    return;\r
+  }\r
+\r
+  switch (Type) {\r
+  \r
+    case    0:   //Software breakpoint\r
+      BreakType = SoftwareBreakpoint;\r
+      break;\r
+      \r
+    case    1:   //Hardware breakpoint\r
+      BreakType = InstructionExecution;\r
+      break;\r
+      \r
+    case    2:   //Write watchpoint\r
+      BreakType = DataWrite;\r
+      break;\r
+\r
+    case    3:   //Read watchpoint\r
+      BreakType = DataRead;\r
+      break;\r
+\r
+    case    4:   //Access watchpoint\r
+      BreakType = DataReadWrite;\r
+      break;\r
+\r
+    default  :\r
+      SendError (GDB_EINVALIDBRKPOINTTYPE);\r
+      return;\r
+  }\r
+\r
+  //Find matching debug register\r
+  Status = FindMatchingDebugRegister (SystemContext, Address, Length, (UINTN)BreakType, &Register);\r
+  if (EFI_ERROR(Status)) {\r
+    if (Status == EFI_UNSUPPORTED) {\r
+      SendNotSupported();\r
+      return;\r
+    }\r
+\r
+    SendError (GDB_ENOSPACE);\r
+    return;\r
+  }\r
+\r
+  //Remove breakpoint\r
+  Status = DisableDebugRegister(SystemContext, Register);\r
+  if (EFI_ERROR(Status)) {\r
+    SendError (GDB_EINVALIDARG);\r
+    return;\r
+  }\r
+\r
+  SendSuccess ();\r
+}\r
+\r
+\r
 /**\r
   Initialize debug agent.\r
 \r
 /**\r
   Initialize debug agent.\r
 \r
index 4897a8a969f2c5d7ed4e422b775ec8290e9b354a..8e8ccaee384aea8f220d898901287bee9b1b1224 100755 (executable)
@@ -38,4 +38,4 @@
 [Pcd]\r
 \r
 [Depex]\r
 [Pcd]\r
 \r
 [Depex]\r
-  TRUE
\ No newline at end of file
+  TRUE\r
\ No newline at end of file
index a92a1de52e986460da30e8b1c08b98b47b1247eb..320dddfc256aa876cfa251e4db2cc430af9959fb 100644 (file)
-/** @file
-
-  Copyright (c) 2010, Apple Inc. All rights reserved.<BR>
-  
-  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 <PiPei.h>
-
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/DebugLib.h>
-#include <Library/PeCoffLib.h>
-#include <Library/HobLib.h>
-#include <Library/PcdLib.h>
-#include <Library/PrePiHobListPointerLib.h>
-
-#include <Protocol/PeCoffLoader.h>
-#include <Guid/ExtractSection.h>
-#include <Guid/MemoryTypeInformation.h>
-#include <Guid/MemoryAllocationHob.h>
-
-VOID
-BuildMemoryTypeInformationHob (
-  VOID
-  );
-
-/**
-  Returns the pointer to the HOB list.
-
-  This function returns the pointer to first HOB in the list.
-
-  @return The pointer to the HOB list.
-
-**/
-VOID *
-EFIAPI
-GetHobList (
-  VOID
-  )
-{
-  return PrePeiGetHobList ();
-}
-
-
-
-/**
-  Updates the pointer to the HOB list.
-
-  @param  HobList       Hob list pointer to store
-
-**/
-EFI_STATUS
-EFIAPI
-SetHobList (
-  IN  VOID      *HobList
-  )
-{
-  return PrePeiSetHobList (HobList);
-}
-
-/**
-
-
-**/
-EFI_HOB_HANDOFF_INFO_TABLE*
-HobConstructor (
-  IN VOID   *EfiMemoryBegin,
-  IN UINTN  EfiMemoryLength,
-  IN VOID   *EfiFreeMemoryBottom,
-  IN VOID   *EfiFreeMemoryTop
-  )
-{
-  EFI_HOB_HANDOFF_INFO_TABLE  *Hob;
-  EFI_HOB_GENERIC_HEADER      *HobEnd;
-
-  Hob    = EfiFreeMemoryBottom;
-  HobEnd = (EFI_HOB_GENERIC_HEADER *)(Hob+1);
-
-  Hob->Header.HobType     = EFI_HOB_TYPE_HANDOFF;
-  Hob->Header.HobLength   = sizeof(EFI_HOB_HANDOFF_INFO_TABLE);
-  Hob->Header.Reserved    = 0;
-
-  HobEnd->HobType     = EFI_HOB_TYPE_END_OF_HOB_LIST;
-  HobEnd->HobLength   = sizeof(EFI_HOB_GENERIC_HEADER);
-  HobEnd->Reserved    = 0;
-
-  Hob->Version             = EFI_HOB_HANDOFF_TABLE_VERSION;
-  Hob->BootMode            = BOOT_WITH_FULL_CONFIGURATION;
-
-  Hob->EfiMemoryTop        = (UINTN)EfiMemoryBegin + EfiMemoryLength;
-  Hob->EfiMemoryBottom     = (UINTN)EfiMemoryBegin;
-  Hob->EfiFreeMemoryTop    = (UINTN)EfiFreeMemoryTop;
-  Hob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS)(UINTN)(HobEnd+1);
-  Hob->EfiEndOfHobList     = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd;
-
-  return Hob;
-}
-
-VOID *
-CreateHob (
-  IN  UINT16    HobType,
-  IN  UINT16    HobLength
-  )
-{
-  EFI_HOB_HANDOFF_INFO_TABLE  *HandOffHob;
-  EFI_HOB_GENERIC_HEADER      *HobEnd;
-  EFI_PHYSICAL_ADDRESS        FreeMemory;
-  VOID                        *Hob;
-
-  HandOffHob = GetHobList ();
-
-  HobLength = (UINT16)((HobLength + 0x7) & (~0x7));
-
-  FreeMemory = HandOffHob->EfiFreeMemoryTop - HandOffHob->EfiFreeMemoryBottom;
-
-  if (FreeMemory < HobLength) {
-      return NULL;
-  }
-
-  Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList;
-  ((EFI_HOB_GENERIC_HEADER*) Hob)->HobType = HobType;
-  ((EFI_HOB_GENERIC_HEADER*) Hob)->HobLength = HobLength;
-  ((EFI_HOB_GENERIC_HEADER*) Hob)->Reserved = 0;
-
-  HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN)Hob + HobLength);
-  HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
-
-  HobEnd->HobType   = EFI_HOB_TYPE_END_OF_HOB_LIST;
-  HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);
-  HobEnd->Reserved  = 0;
-  HobEnd++;
-  HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
-
-  return Hob;
-}
-
-/**
-  Builds a HOB that describes a chunk of system memory.
-
-  This function builds a HOB that describes a chunk of system memory.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  ResourceType        The type of resource described by this HOB.
-  @param  ResourceAttribute   The resource attributes of the memory described by this HOB.
-  @param  PhysicalStart       The 64 bit physical address of memory described by this HOB.
-  @param  NumberOfBytes       The length of the memory described by this HOB in bytes.
-
-**/
-VOID
-EFIAPI
-BuildResourceDescriptorHob (
-  IN EFI_RESOURCE_TYPE            ResourceType,
-  IN EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute,
-  IN EFI_PHYSICAL_ADDRESS         PhysicalStart,
-  IN UINT64                       NumberOfBytes
-  )
-{
-  EFI_HOB_RESOURCE_DESCRIPTOR  *Hob;
-
-  Hob = CreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));
-  ASSERT(Hob != NULL);
-
-  Hob->ResourceType      = ResourceType;
-  Hob->ResourceAttribute = ResourceAttribute;
-  Hob->PhysicalStart     = PhysicalStart;
-  Hob->ResourceLength    = NumberOfBytes;
-}
-
-/**
-
-
-**/
-VOID
-CreateHobList (
-  IN VOID   *MemoryBegin,
-  IN UINTN  MemoryLength,
-  IN VOID   *HobBase,
-  IN VOID   *StackBase
-  )
-{
-  EFI_HOB_HANDOFF_INFO_TABLE  *Hob;
-  EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;
-
-  Hob = HobConstructor (MemoryBegin,MemoryLength,HobBase,StackBase);
-  SetHobList (Hob);
-
-  BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));
-  
-  Attributes =(
-    EFI_RESOURCE_ATTRIBUTE_PRESENT |
-    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
-    EFI_RESOURCE_ATTRIBUTE_TESTED |
-    EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
-    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
-    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
-    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
-  );
-
-  BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, Attributes, (UINTN)MemoryBegin, MemoryLength);
-
-  BuildStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)StackBase, ((UINTN)MemoryBegin + MemoryLength) - (UINTN)StackBase);
-
-  if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {
-    // Optional feature that helps prevent EFI memory map fragmentation. 
-    BuildMemoryTypeInformationHob ();
-  }
-}  
-  
-
-VOID
-EFIAPI
-BuildFvHobs (  
-  IN EFI_PHYSICAL_ADDRESS         PhysicalStart,
-  IN UINT64                       NumberOfBytes,
-  IN EFI_RESOURCE_ATTRIBUTE_TYPE  *ResourceAttribute
-  ) 
-{
-
-  EFI_RESOURCE_ATTRIBUTE_TYPE Resource;
-  
-  BuildFvHob (PhysicalStart, NumberOfBytes);
-  
-  if (ResourceAttribute == NULL) {
-    Resource = (EFI_RESOURCE_ATTRIBUTE_PRESENT    |
-                EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
-                EFI_RESOURCE_ATTRIBUTE_TESTED |
-                EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE);
-  } else {
-    Resource = *ResourceAttribute;
-  }
-  
-  BuildResourceDescriptorHob (EFI_RESOURCE_FIRMWARE_DEVICE, Resource, PhysicalStart, NumberOfBytes);
-}
-
-/**
-  Returns the next instance of a HOB type from the starting HOB.
-
-  This function searches the first instance of a HOB type from the starting HOB pointer. 
-  If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
-  In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
-  unconditionally: it returns HobStart back if HobStart itself meets the requirement;
-  caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
-  If HobStart is NULL, then ASSERT().
-
-  @param  Type          The HOB type to return.
-  @param  HobStart      The starting HOB pointer to search from.
-
-  @return The next instance of a HOB type from the starting HOB.
-
-**/
-VOID *
-EFIAPI
-GetNextHob (
-  IN UINT16                 Type,
-  IN CONST VOID             *HobStart
-  )
-{
-  EFI_PEI_HOB_POINTERS  Hob;
-
-  ASSERT (HobStart != NULL);
-   
-  Hob.Raw = (UINT8 *) HobStart;
-  //
-  // Parse the HOB list until end of list or matching type is found.
-  //
-  while (!END_OF_HOB_LIST (Hob)) {
-    if (Hob.Header->HobType == Type) {
-      return Hob.Raw;
-    }
-    Hob.Raw = GET_NEXT_HOB (Hob);
-  }
-  return NULL;
-}
-  
-  
-
-/**
-  Returns the first instance of a HOB type among the whole HOB list.
-
-  This function searches the first instance of a HOB type among the whole HOB list. 
-  If there does not exist such HOB type in the HOB list, it will return NULL. 
-
-  @param  Type          The HOB type to return.
-
-  @return The next instance of a HOB type from the starting HOB.
-
-**/
-VOID *
-EFIAPI
-GetFirstHob (
-  IN UINT16                 Type
-  )
-{
-  VOID      *HobList;
-
-  HobList = GetHobList ();
-  return GetNextHob (Type, HobList);
-}
-
-
-/**
-  This function searches the first instance of a HOB from the starting HOB pointer. 
-  Such HOB should satisfy two conditions: 
-  its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid. 
-  If there does not exist such HOB from the starting HOB pointer, it will return NULL. 
-  Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
-  to extract the data section and its size info respectively.
-  In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
-  unconditionally: it returns HobStart back if HobStart itself meets the requirement;
-  caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
-  If Guid is NULL, then ASSERT().
-  If HobStart is NULL, then ASSERT().
-
-  @param  Guid          The GUID to match with in the HOB list.
-  @param  HobStart      A pointer to a Guid.
-
-  @return The next instance of the matched GUID HOB from the starting HOB.
-
-**/
-VOID *
-EFIAPI
-GetNextGuidHob (
-  IN CONST EFI_GUID         *Guid,
-  IN CONST VOID             *HobStart
-  ){
-  EFI_PEI_HOB_POINTERS  GuidHob;
-
-  GuidHob.Raw = (UINT8 *) HobStart;
-  while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {
-    if (CompareGuid (Guid, &GuidHob.Guid->Name)) {
-      break;
-    }
-    GuidHob.Raw = GET_NEXT_HOB (GuidHob);
-  }
-  return GuidHob.Raw;
-}
-
-
-/**
-  This function searches the first instance of a HOB among the whole HOB list. 
-  Such HOB should satisfy two conditions:
-  its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
-  If there does not exist such HOB from the starting HOB pointer, it will return NULL.
-  Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
-  to extract the data section and its size info respectively.
-  If Guid is NULL, then ASSERT().
-
-  @param  Guid          The GUID to match with in the HOB list.
-
-  @return The first instance of the matched GUID HOB among the whole HOB list.
-
-**/
-VOID *
-EFIAPI
-GetFirstGuidHob (
-  IN CONST EFI_GUID         *Guid
-  )
-{
-  VOID      *HobList;
-
-  HobList = GetHobList ();
-  return GetNextGuidHob (Guid, HobList);
-}
-
-
-/**
-  Get the Boot Mode from the HOB list.
-
-  This function returns the system boot mode information from the 
-  PHIT HOB in HOB list.
-
-  @param  VOID
-
-  @return The Boot Mode.
-
-**/
-EFI_BOOT_MODE
-EFIAPI
-GetBootMode (
-  VOID
-  )
-{
-  EFI_PEI_HOB_POINTERS  Hob;
-
-  Hob.Raw = GetHobList ();
-  return Hob.HandoffInformationTable->BootMode;
-}
-
-
-/**
-  Get the Boot Mode from the HOB list.
-
-  This function returns the system boot mode information from the 
-  PHIT HOB in HOB list.
-
-  @param  VOID
-
-  @return The Boot Mode.
-
-**/
-EFI_STATUS
-EFIAPI
-SetBootMode (
-  IN  EFI_BOOT_MODE   BootMode
-  )
-{
-  EFI_PEI_HOB_POINTERS  Hob;
-
-  Hob.Raw = GetHobList ();
-  Hob.HandoffInformationTable->BootMode = BootMode;
-  return BootMode;
-}
-
-/**
-  Builds a HOB for a loaded PE32 module.
-
-  This function builds a HOB for a loaded PE32 module.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If ModuleName is NULL, then ASSERT().
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  ModuleName              The GUID File Name of the module.
-  @param  MemoryAllocationModule  The 64 bit physical address of the module.
-  @param  ModuleLength            The length of the module in bytes.
-  @param  EntryPoint              The 64 bit physical address of the module entry point.
-
-**/
-VOID
-EFIAPI
-BuildModuleHob (
-  IN CONST EFI_GUID         *ModuleName,
-  IN EFI_PHYSICAL_ADDRESS   MemoryAllocationModule,
-  IN UINT64                 ModuleLength,
-  IN EFI_PHYSICAL_ADDRESS   EntryPoint
-  )
-{
-  EFI_HOB_MEMORY_ALLOCATION_MODULE  *Hob;
-
-  ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&
-          ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0));
-
-  Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));
-
-  CopyGuid (&(Hob->MemoryAllocationHeader.Name), &gEfiHobMemoryAllocModuleGuid);
-  Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;
-  Hob->MemoryAllocationHeader.MemoryLength      = ModuleLength;
-  Hob->MemoryAllocationHeader.MemoryType        = EfiBootServicesCode;
-
-  //
-  // Zero the reserved space to match HOB spec
-  //
-  ZeroMem (Hob->MemoryAllocationHeader.Reserved, sizeof (Hob->MemoryAllocationHeader.Reserved));
-  
-  CopyGuid (&Hob->ModuleName, ModuleName);
-  Hob->EntryPoint = EntryPoint;
-}
-
-/**
-  Builds a GUID HOB with a certain data length.
-
-  This function builds a customized HOB tagged with a GUID for identification 
-  and returns the start address of GUID HOB data so that caller can fill the customized data. 
-  The HOB Header and Name field is already stripped.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If Guid is NULL, then ASSERT().
-  If there is no additional space for HOB creation, then ASSERT().
-  If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
-
-  @param  Guid          The GUID to tag the customized HOB.
-  @param  DataLength    The size of the data payload for the GUID HOB.
-
-  @return The start address of GUID HOB data.
-
-**/
-VOID *
-EFIAPI
-BuildGuidHob (
-  IN CONST EFI_GUID              *Guid,
-  IN UINTN                       DataLength
-  )
-{
-  EFI_HOB_GUID_TYPE *Hob;
-
-  //
-  // Make sure that data length is not too long.
-  //
-  ASSERT (DataLength <= (0xffff - sizeof (EFI_HOB_GUID_TYPE)));
-
-  Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength));
-  CopyGuid (&Hob->Name, Guid);
-  return Hob + 1;
-}
-
-
-/**
-  Copies a data buffer to a newly-built HOB.
-
-  This function builds a customized HOB tagged with a GUID for identification,
-  copies the input data to the HOB data field and returns the start address of the GUID HOB data.
-  The HOB Header and Name field is already stripped.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If Guid is NULL, then ASSERT().
-  If Data is NULL and DataLength > 0, then ASSERT().
-  If there is no additional space for HOB creation, then ASSERT().
-  If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
-
-  @param  Guid          The GUID to tag the customized HOB.
-  @param  Data          The data to be copied into the data field of the GUID HOB.
-  @param  DataLength    The size of the data payload for the GUID HOB.
-
-  @return The start address of GUID HOB data.
-
-**/
-VOID *
-EFIAPI
-BuildGuidDataHob (
-  IN CONST EFI_GUID              *Guid,
-  IN VOID                        *Data,
-  IN UINTN                       DataLength
-  )
-{
-  VOID  *HobData;
-
-  ASSERT (Data != NULL || DataLength == 0);
-
-  HobData = BuildGuidHob (Guid, DataLength);
-
-  return CopyMem (HobData, Data, DataLength);
-}
-
-
-/**
-  Builds a Firmware Volume HOB.
-
-  This function builds a Firmware Volume HOB.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  BaseAddress   The base address of the Firmware Volume.
-  @param  Length        The size of the Firmware Volume in bytes.
-
-**/
-VOID
-EFIAPI
-BuildFvHob (
-  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
-  IN UINT64                      Length
-  )
-{
-  EFI_HOB_FIRMWARE_VOLUME  *Hob;
-
-  Hob = CreateHob (EFI_HOB_TYPE_FV, sizeof (EFI_HOB_FIRMWARE_VOLUME));
-
-  Hob->BaseAddress = BaseAddress;
-  Hob->Length      = Length;
-}
-
-
-/**
-  Builds a EFI_HOB_TYPE_FV2 HOB.
-
-  This function builds a EFI_HOB_TYPE_FV2 HOB.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  BaseAddress   The base address of the Firmware Volume.
-  @param  Length        The size of the Firmware Volume in bytes.
-  @param  FvName       The name of the Firmware Volume.
-  @param  FileName      The name of the file.
-  
-**/
-VOID
-EFIAPI
-BuildFv2Hob (
-  IN          EFI_PHYSICAL_ADDRESS        BaseAddress,
-  IN          UINT64                      Length,
-  IN CONST    EFI_GUID                    *FvName,
-  IN CONST    EFI_GUID                    *FileName
-  )
-{
-  EFI_HOB_FIRMWARE_VOLUME2  *Hob;
-
-  Hob = CreateHob (EFI_HOB_TYPE_FV2, sizeof (EFI_HOB_FIRMWARE_VOLUME2));
-
-  Hob->BaseAddress = BaseAddress;
-  Hob->Length      = Length;
-  CopyGuid (&Hob->FvName, FvName);
-  CopyGuid (&Hob->FileName, FileName);
-}
-
-
-
-/**
-  Builds a Capsule Volume HOB.
-
-  This function builds a Capsule Volume HOB.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  BaseAddress   The base address of the Capsule Volume.
-  @param  Length        The size of the Capsule Volume in bytes.
-
-**/
-VOID
-EFIAPI
-BuildCvHob (
-  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
-  IN UINT64                      Length
-  )
-{
-  ASSERT (FALSE);
-}
-
-
-/**
-  Builds a HOB for the CPU.
-
-  This function builds a HOB for the CPU.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  SizeOfMemorySpace   The maximum physical memory addressability of the processor.
-  @param  SizeOfIoSpace       The maximum physical I/O addressability of the processor.
-
-**/
-VOID
-EFIAPI
-BuildCpuHob (
-  IN UINT8                       SizeOfMemorySpace,
-  IN UINT8                       SizeOfIoSpace
-  )
-{
-  EFI_HOB_CPU  *Hob;
-
-  Hob = CreateHob (EFI_HOB_TYPE_CPU, sizeof (EFI_HOB_CPU));
-
-  Hob->SizeOfMemorySpace = SizeOfMemorySpace;
-  Hob->SizeOfIoSpace     = SizeOfIoSpace;
-
-  //
-  // Zero the reserved space to match HOB spec
-  //
-  ZeroMem (Hob->Reserved, sizeof (Hob->Reserved)); 
-}
-
-
-/**
-  Builds a HOB for the Stack.
-
-  This function builds a HOB for the stack.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  BaseAddress   The 64 bit physical address of the Stack.
-  @param  Length        The length of the stack in bytes.
-
-**/
-VOID
-EFIAPI
-BuildStackHob (
-  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
-  IN UINT64                      Length
-  )
-{
-  EFI_HOB_MEMORY_ALLOCATION_STACK  *Hob;
-
-  ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
-          ((Length & (EFI_PAGE_SIZE - 1)) == 0));
-
-  Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));
-
-  CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);
-  Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
-  Hob->AllocDescriptor.MemoryLength      = Length;
-  Hob->AllocDescriptor.MemoryType        = EfiBootServicesData;
-
-  //
-  // Zero the reserved space to match HOB spec
-  //
-  ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));
-}
-
-
-/**
-  Update the Stack Hob if the stack has been moved
-
-  @param  BaseAddress   The 64 bit physical address of the Stack.
-  @param  Length        The length of the stack in bytes.
-
-**/
-VOID
-UpdateStackHob (
-  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
-  IN UINT64                      Length
-  )
-{
-  EFI_PEI_HOB_POINTERS           Hob;
-
-  Hob.Raw = GetHobList ();
-  while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {
-    if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &(Hob.MemoryAllocationStack->AllocDescriptor.Name))) {
-      //
-      // Build a new memory allocation HOB with old stack info with EfiConventionalMemory type
-      // to be reclaimed by DXE core.
-      //
-      BuildMemoryAllocationHob (
-        Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress,
-        Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength,
-        EfiConventionalMemory
-        );
-      //
-      // Update the BSP Stack Hob to reflect the new stack info.
-      //
-      Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress = BaseAddress;
-      Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength = Length;
-      break;
-    }
-    Hob.Raw = GET_NEXT_HOB (Hob);
-  }
-}
-
-
-
-/**
-  Builds a HOB for the memory allocation.
-
-  This function builds a HOB for the memory allocation.
-  It can only be invoked during PEI phase;
-  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  BaseAddress   The 64 bit physical address of the memory.
-  @param  Length        The length of the memory allocation in bytes.
-  @param  MemoryType    Type of memory allocated by this HOB.
-
-**/
-VOID
-EFIAPI
-BuildMemoryAllocationHob (
-  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
-  IN UINT64                      Length,
-  IN EFI_MEMORY_TYPE             MemoryType
-  )
-{
-  EFI_HOB_MEMORY_ALLOCATION  *Hob;
-
-  ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
-          ((Length & (EFI_PAGE_SIZE - 1)) == 0));
-  
-  Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION));
-  
-  ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));
-  Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
-  Hob->AllocDescriptor.MemoryLength      = Length;
-  Hob->AllocDescriptor.MemoryType        = MemoryType;
-  //
-  // Zero the reserved space to match HOB spec
-  //
-  ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));
-}
-
-
-
-VOID
-EFIAPI
-BuildExtractSectionHob (
-  IN  EFI_GUID                                  *Guid,
-  IN  EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER   SectionGetInfo,
-  IN  EXTRACT_GUIDED_SECTION_DECODE_HANDLER     SectionExtraction
-  )
-{
-  EXTRACT_SECTION_DATA Data;
-  
-  Data.SectionGetInfo    = SectionGetInfo;
-  Data.SectionExtraction = SectionExtraction;
-  BuildGuidDataHob (Guid, &Data, sizeof (Data));
-}
-
-PE_COFF_LOADER_PROTOCOL gPeCoffProtocol = {
-  PeCoffLoaderGetImageInfo,
-  PeCoffLoaderLoadImage,
-  PeCoffLoaderRelocateImage,
-  PeCoffLoaderImageReadFromMemory,
-  PeCoffLoaderRelocateImageForRuntime,
-  PeCoffLoaderUnloadImage
-};
-
-
-
-VOID
-EFIAPI
-BuildPeCoffLoaderHob (
-  VOID
-  )
-{
-  VOID  *Ptr;      
-  
-  Ptr = &gPeCoffProtocol;
-  BuildGuidDataHob (&gPeCoffLoaderProtocolGuid, &Ptr, sizeof (VOID *));  
-}
-
-// May want to put this into a library so you only need the PCD setings if you are using the feature?
-VOID
-BuildMemoryTypeInformationHob (
-  VOID
-  )
-{
-  EFI_MEMORY_TYPE_INFORMATION   Info[10];
-
-  Info[0].Type          = EfiACPIReclaimMemory;
-  Info[0].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory);
-  Info[1].Type          = EfiACPIMemoryNVS;
-  Info[1].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS);
-  Info[2].Type          = EfiReservedMemoryType;
-  Info[2].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiReservedMemoryType);
-  Info[3].Type          = EfiRuntimeServicesData;
-  Info[3].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesData);
-  Info[4].Type          = EfiRuntimeServicesCode;
-  Info[4].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode);
-  Info[5].Type          = EfiBootServicesCode;
-  Info[5].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiBootServicesCode);
-  Info[6].Type          = EfiBootServicesData;
-  Info[6].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiBootServicesData);
-  Info[7].Type          = EfiLoaderCode;
-  Info[7].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderCode);
-  Info[8].Type          = EfiLoaderData;
-  Info[8].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderData);
-
-  // Terminator for the list
-  Info[9].Type          = EfiMaxMemoryType;
-  Info[9].NumberOfPages = 0;
-
-
-  BuildGuidDataHob (&gEfiMemoryTypeInformationGuid, &Info, sizeof (Info));
-}
-
+/** @file\r
+\r
+  Copyright (c) 2010, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiPei.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/PrePiHobListPointerLib.h>\r
+\r
+#include <Protocol/PeCoffLoader.h>\r
+#include <Guid/ExtractSection.h>\r
+#include <Guid/MemoryTypeInformation.h>\r
+#include <Guid/MemoryAllocationHob.h>\r
+\r
+VOID\r
+BuildMemoryTypeInformationHob (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Returns the pointer to the HOB list.\r
+\r
+  This function returns the pointer to first HOB in the list.\r
+\r
+  @return The pointer to the HOB list.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+GetHobList (\r
+  VOID\r
+  )\r
+{\r
+  return PrePeiGetHobList ();\r
+}\r
+\r
+\r
+\r
+/**\r
+  Updates the pointer to the HOB list.\r
+\r
+  @param  HobList       Hob list pointer to store\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SetHobList (\r
+  IN  VOID      *HobList\r
+  )\r
+{\r
+  return PrePeiSetHobList (HobList);\r
+}\r
+\r
+/**\r
+\r
+\r
+**/\r
+EFI_HOB_HANDOFF_INFO_TABLE*\r
+HobConstructor (\r
+  IN VOID   *EfiMemoryBegin,\r
+  IN UINTN  EfiMemoryLength,\r
+  IN VOID   *EfiFreeMemoryBottom,\r
+  IN VOID   *EfiFreeMemoryTop\r
+  )\r
+{\r
+  EFI_HOB_HANDOFF_INFO_TABLE  *Hob;\r
+  EFI_HOB_GENERIC_HEADER      *HobEnd;\r
+\r
+  Hob    = EfiFreeMemoryBottom;\r
+  HobEnd = (EFI_HOB_GENERIC_HEADER *)(Hob+1);\r
+\r
+  Hob->Header.HobType     = EFI_HOB_TYPE_HANDOFF;\r
+  Hob->Header.HobLength   = sizeof(EFI_HOB_HANDOFF_INFO_TABLE);\r
+  Hob->Header.Reserved    = 0;\r
+\r
+  HobEnd->HobType     = EFI_HOB_TYPE_END_OF_HOB_LIST;\r
+  HobEnd->HobLength   = sizeof(EFI_HOB_GENERIC_HEADER);\r
+  HobEnd->Reserved    = 0;\r
+\r
+  Hob->Version             = EFI_HOB_HANDOFF_TABLE_VERSION;\r
+  Hob->BootMode            = BOOT_WITH_FULL_CONFIGURATION;\r
+\r
+  Hob->EfiMemoryTop        = (UINTN)EfiMemoryBegin + EfiMemoryLength;\r
+  Hob->EfiMemoryBottom     = (UINTN)EfiMemoryBegin;\r
+  Hob->EfiFreeMemoryTop    = (UINTN)EfiFreeMemoryTop;\r
+  Hob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS)(UINTN)(HobEnd+1);\r
+  Hob->EfiEndOfHobList     = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd;\r
+\r
+  return Hob;\r
+}\r
+\r
+VOID *\r
+CreateHob (\r
+  IN  UINT16    HobType,\r
+  IN  UINT16    HobLength\r
+  )\r
+{\r
+  EFI_HOB_HANDOFF_INFO_TABLE  *HandOffHob;\r
+  EFI_HOB_GENERIC_HEADER      *HobEnd;\r
+  EFI_PHYSICAL_ADDRESS        FreeMemory;\r
+  VOID                        *Hob;\r
+\r
+  HandOffHob = GetHobList ();\r
+\r
+  HobLength = (UINT16)((HobLength + 0x7) & (~0x7));\r
+\r
+  FreeMemory = HandOffHob->EfiFreeMemoryTop - HandOffHob->EfiFreeMemoryBottom;\r
+\r
+  if (FreeMemory < HobLength) {\r
+      return NULL;\r
+  }\r
+\r
+  Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList;\r
+  ((EFI_HOB_GENERIC_HEADER*) Hob)->HobType = HobType;\r
+  ((EFI_HOB_GENERIC_HEADER*) Hob)->HobLength = HobLength;\r
+  ((EFI_HOB_GENERIC_HEADER*) Hob)->Reserved = 0;\r
+\r
+  HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN)Hob + HobLength);\r
+  HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
+\r
+  HobEnd->HobType   = EFI_HOB_TYPE_END_OF_HOB_LIST;\r
+  HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);\r
+  HobEnd->Reserved  = 0;\r
+  HobEnd++;\r
+  HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
+\r
+  return Hob;\r
+}\r
+\r
+/**\r
+  Builds a HOB that describes a chunk of system memory.\r
+\r
+  This function builds a HOB that describes a chunk of system memory.\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  ResourceType        The type of resource described by this HOB.\r
+  @param  ResourceAttribute   The resource attributes of the memory described by this HOB.\r
+  @param  PhysicalStart       The 64 bit physical address of memory described by this HOB.\r
+  @param  NumberOfBytes       The length of the memory described by this HOB in bytes.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+BuildResourceDescriptorHob (\r
+  IN EFI_RESOURCE_TYPE            ResourceType,\r
+  IN EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute,\r
+  IN EFI_PHYSICAL_ADDRESS         PhysicalStart,\r
+  IN UINT64                       NumberOfBytes\r
+  )\r
+{\r
+  EFI_HOB_RESOURCE_DESCRIPTOR  *Hob;\r
+\r
+  Hob = CreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));\r
+  ASSERT(Hob != NULL);\r
+\r
+  Hob->ResourceType      = ResourceType;\r
+  Hob->ResourceAttribute = ResourceAttribute;\r
+  Hob->PhysicalStart     = PhysicalStart;\r
+  Hob->ResourceLength    = NumberOfBytes;\r
+}\r
+\r
+/**\r
+\r
+\r
+**/\r
+VOID\r
+CreateHobList (\r
+  IN VOID   *MemoryBegin,\r
+  IN UINTN  MemoryLength,\r
+  IN VOID   *HobBase,\r
+  IN VOID   *StackBase\r
+  )\r
+{\r
+  EFI_HOB_HANDOFF_INFO_TABLE  *Hob;\r
+  EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;\r
+\r
+  Hob = HobConstructor (MemoryBegin,MemoryLength,HobBase,StackBase);\r
+  SetHobList (Hob);\r
+\r
+  BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r
+  \r
+  Attributes =(\r
+    EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
+    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
+    EFI_RESOURCE_ATTRIBUTE_TESTED |\r
+    EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r
+    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r
+    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r
+    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE\r
+  );\r
+\r
+  BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, Attributes, (UINTN)MemoryBegin, MemoryLength);\r
+\r
+  BuildStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)StackBase, ((UINTN)MemoryBegin + MemoryLength) - (UINTN)StackBase);\r
+\r
+  if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {\r
+    // Optional feature that helps prevent EFI memory map fragmentation. \r
+    BuildMemoryTypeInformationHob ();\r
+  }\r
+}  \r
+  \r
+\r
+VOID\r
+EFIAPI\r
+BuildFvHobs (  \r
+  IN EFI_PHYSICAL_ADDRESS         PhysicalStart,\r
+  IN UINT64                       NumberOfBytes,\r
+  IN EFI_RESOURCE_ATTRIBUTE_TYPE  *ResourceAttribute\r
+  ) \r
+{\r
+\r
+  EFI_RESOURCE_ATTRIBUTE_TYPE Resource;\r
+  \r
+  BuildFvHob (PhysicalStart, NumberOfBytes);\r
+  \r
+  if (ResourceAttribute == NULL) {\r
+    Resource = (EFI_RESOURCE_ATTRIBUTE_PRESENT    |\r
+                EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
+                EFI_RESOURCE_ATTRIBUTE_TESTED |\r
+                EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE);\r
+  } else {\r
+    Resource = *ResourceAttribute;\r
+  }\r
+  \r
+  BuildResourceDescriptorHob (EFI_RESOURCE_FIRMWARE_DEVICE, Resource, PhysicalStart, NumberOfBytes);\r
+}\r
+\r
+/**\r
+  Returns the next instance of a HOB type from the starting HOB.\r
+\r
+  This function searches the first instance of a HOB type from the starting HOB pointer. \r
+  If there does not exist such HOB type from the starting HOB pointer, it will return NULL.\r
+  In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
+  unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
+  caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
+  If HobStart is NULL, then ASSERT().\r
+\r
+  @param  Type          The HOB type to return.\r
+  @param  HobStart      The starting HOB pointer to search from.\r
+\r
+  @return The next instance of a HOB type from the starting HOB.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+GetNextHob (\r
+  IN UINT16                 Type,\r
+  IN CONST VOID             *HobStart\r
+  )\r
+{\r
+  EFI_PEI_HOB_POINTERS  Hob;\r
+\r
+  ASSERT (HobStart != NULL);\r
+   \r
+  Hob.Raw = (UINT8 *) HobStart;\r
+  //\r
+  // Parse the HOB list until end of list or matching type is found.\r
+  //\r
+  while (!END_OF_HOB_LIST (Hob)) {\r
+    if (Hob.Header->HobType == Type) {\r
+      return Hob.Raw;\r
+    }\r
+    Hob.Raw = GET_NEXT_HOB (Hob);\r
+  }\r
+  return NULL;\r
+}\r
+  \r
+  \r
+\r
+/**\r
+  Returns the first instance of a HOB type among the whole HOB list.\r
+\r
+  This function searches the first instance of a HOB type among the whole HOB list. \r
+  If there does not exist such HOB type in the HOB list, it will return NULL. \r
+\r
+  @param  Type          The HOB type to return.\r
+\r
+  @return The next instance of a HOB type from the starting HOB.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+GetFirstHob (\r
+  IN UINT16                 Type\r
+  )\r
+{\r
+  VOID      *HobList;\r
+\r
+  HobList = GetHobList ();\r
+  return GetNextHob (Type, HobList);\r
+}\r
+\r
+\r
+/**\r
+  This function searches the first instance of a HOB from the starting HOB pointer. \r
+  Such HOB should satisfy two conditions: \r
+  its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid. \r
+  If there does not exist such HOB from the starting HOB pointer, it will return NULL. \r
+  Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
+  to extract the data section and its size info respectively.\r
+  In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
+  unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
+  caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
+  If Guid is NULL, then ASSERT().\r
+  If HobStart is NULL, then ASSERT().\r
+\r
+  @param  Guid          The GUID to match with in the HOB list.\r
+  @param  HobStart      A pointer to a Guid.\r
+\r
+  @return The next instance of the matched GUID HOB from the starting HOB.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+GetNextGuidHob (\r
+  IN CONST EFI_GUID         *Guid,\r
+  IN CONST VOID             *HobStart\r
+  ){\r
+  EFI_PEI_HOB_POINTERS  GuidHob;\r
+\r
+  GuidHob.Raw = (UINT8 *) HobStart;\r
+  while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {\r
+    if (CompareGuid (Guid, &GuidHob.Guid->Name)) {\r
+      break;\r
+    }\r
+    GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r
+  }\r
+  return GuidHob.Raw;\r
+}\r
+\r
+\r
+/**\r
+  This function searches the first instance of a HOB among the whole HOB list. \r
+  Such HOB should satisfy two conditions:\r
+  its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.\r
+  If there does not exist such HOB from the starting HOB pointer, it will return NULL.\r
+  Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
+  to extract the data section and its size info respectively.\r
+  If Guid is NULL, then ASSERT().\r
+\r
+  @param  Guid          The GUID to match with in the HOB list.\r
+\r
+  @return The first instance of the matched GUID HOB among the whole HOB list.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+GetFirstGuidHob (\r
+  IN CONST EFI_GUID         *Guid\r
+  )\r
+{\r
+  VOID      *HobList;\r
+\r
+  HobList = GetHobList ();\r
+  return GetNextGuidHob (Guid, HobList);\r
+}\r
+\r
+\r
+/**\r
+  Get the Boot Mode from the HOB list.\r
+\r
+  This function returns the system boot mode information from the \r
+  PHIT HOB in HOB list.\r
+\r
+  @param  VOID\r
+\r
+  @return The Boot Mode.\r
+\r
+**/\r
+EFI_BOOT_MODE\r
+EFIAPI\r
+GetBootMode (\r
+  VOID\r
+  )\r
+{\r
+  EFI_PEI_HOB_POINTERS  Hob;\r
+\r
+  Hob.Raw = GetHobList ();\r
+  return Hob.HandoffInformationTable->BootMode;\r
+}\r
+\r
+\r
+/**\r
+  Get the Boot Mode from the HOB list.\r
+\r
+  This function returns the system boot mode information from the \r
+  PHIT HOB in HOB list.\r
+\r
+  @param  VOID\r
+\r
+  @return The Boot Mode.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SetBootMode (\r
+  IN  EFI_BOOT_MODE   BootMode\r
+  )\r
+{\r
+  EFI_PEI_HOB_POINTERS  Hob;\r
+\r
+  Hob.Raw = GetHobList ();\r
+  Hob.HandoffInformationTable->BootMode = BootMode;\r
+  return BootMode;\r
+}\r
+\r
+/**\r
+  Builds a HOB for a loaded PE32 module.\r
+\r
+  This function builds a HOB for a loaded PE32 module.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If ModuleName is NULL, then ASSERT().\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  ModuleName              The GUID File Name of the module.\r
+  @param  MemoryAllocationModule  The 64 bit physical address of the module.\r
+  @param  ModuleLength            The length of the module in bytes.\r
+  @param  EntryPoint              The 64 bit physical address of the module entry point.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+BuildModuleHob (\r
+  IN CONST EFI_GUID         *ModuleName,\r
+  IN EFI_PHYSICAL_ADDRESS   MemoryAllocationModule,\r
+  IN UINT64                 ModuleLength,\r
+  IN EFI_PHYSICAL_ADDRESS   EntryPoint\r
+  )\r
+{\r
+  EFI_HOB_MEMORY_ALLOCATION_MODULE  *Hob;\r
+\r
+  ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&\r
+          ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0));\r
+\r
+  Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));\r
+\r
+  CopyGuid (&(Hob->MemoryAllocationHeader.Name), &gEfiHobMemoryAllocModuleGuid);\r
+  Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;\r
+  Hob->MemoryAllocationHeader.MemoryLength      = ModuleLength;\r
+  Hob->MemoryAllocationHeader.MemoryType        = EfiBootServicesCode;\r
+\r
+  //\r
+  // Zero the reserved space to match HOB spec\r
+  //\r
+  ZeroMem (Hob->MemoryAllocationHeader.Reserved, sizeof (Hob->MemoryAllocationHeader.Reserved));\r
+  \r
+  CopyGuid (&Hob->ModuleName, ModuleName);\r
+  Hob->EntryPoint = EntryPoint;\r
+}\r
+\r
+/**\r
+  Builds a GUID HOB with a certain data length.\r
+\r
+  This function builds a customized HOB tagged with a GUID for identification \r
+  and returns the start address of GUID HOB data so that caller can fill the customized data. \r
+  The HOB Header and Name field is already stripped.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If Guid is NULL, then ASSERT().\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+  If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
+\r
+  @param  Guid          The GUID to tag the customized HOB.\r
+  @param  DataLength    The size of the data payload for the GUID HOB.\r
+\r
+  @return The start address of GUID HOB data.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+BuildGuidHob (\r
+  IN CONST EFI_GUID              *Guid,\r
+  IN UINTN                       DataLength\r
+  )\r
+{\r
+  EFI_HOB_GUID_TYPE *Hob;\r
+\r
+  //\r
+  // Make sure that data length is not too long.\r
+  //\r
+  ASSERT (DataLength <= (0xffff - sizeof (EFI_HOB_GUID_TYPE)));\r
+\r
+  Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength));\r
+  CopyGuid (&Hob->Name, Guid);\r
+  return Hob + 1;\r
+}\r
+\r
+\r
+/**\r
+  Copies a data buffer to a newly-built HOB.\r
+\r
+  This function builds a customized HOB tagged with a GUID for identification,\r
+  copies the input data to the HOB data field and returns the start address of the GUID HOB data.\r
+  The HOB Header and Name field is already stripped.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If Guid is NULL, then ASSERT().\r
+  If Data is NULL and DataLength > 0, then ASSERT().\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+  If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
+\r
+  @param  Guid          The GUID to tag the customized HOB.\r
+  @param  Data          The data to be copied into the data field of the GUID HOB.\r
+  @param  DataLength    The size of the data payload for the GUID HOB.\r
+\r
+  @return The start address of GUID HOB data.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+BuildGuidDataHob (\r
+  IN CONST EFI_GUID              *Guid,\r
+  IN VOID                        *Data,\r
+  IN UINTN                       DataLength\r
+  )\r
+{\r
+  VOID  *HobData;\r
+\r
+  ASSERT (Data != NULL || DataLength == 0);\r
+\r
+  HobData = BuildGuidHob (Guid, DataLength);\r
+\r
+  return CopyMem (HobData, Data, DataLength);\r
+}\r
+\r
+\r
+/**\r
+  Builds a Firmware Volume HOB.\r
+\r
+  This function builds a Firmware Volume HOB.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  BaseAddress   The base address of the Firmware Volume.\r
+  @param  Length        The size of the Firmware Volume in bytes.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+BuildFvHob (\r
+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,\r
+  IN UINT64                      Length\r
+  )\r
+{\r
+  EFI_HOB_FIRMWARE_VOLUME  *Hob;\r
+\r
+  Hob = CreateHob (EFI_HOB_TYPE_FV, sizeof (EFI_HOB_FIRMWARE_VOLUME));\r
+\r
+  Hob->BaseAddress = BaseAddress;\r
+  Hob->Length      = Length;\r
+}\r
+\r
+\r
+/**\r
+  Builds a EFI_HOB_TYPE_FV2 HOB.\r
+\r
+  This function builds a EFI_HOB_TYPE_FV2 HOB.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  BaseAddress   The base address of the Firmware Volume.\r
+  @param  Length        The size of the Firmware Volume in bytes.\r
+  @param  FvName       The name of the Firmware Volume.\r
+  @param  FileName      The name of the file.\r
+  \r
+**/\r
+VOID\r
+EFIAPI\r
+BuildFv2Hob (\r
+  IN          EFI_PHYSICAL_ADDRESS        BaseAddress,\r
+  IN          UINT64                      Length,\r
+  IN CONST    EFI_GUID                    *FvName,\r
+  IN CONST    EFI_GUID                    *FileName\r
+  )\r
+{\r
+  EFI_HOB_FIRMWARE_VOLUME2  *Hob;\r
+\r
+  Hob = CreateHob (EFI_HOB_TYPE_FV2, sizeof (EFI_HOB_FIRMWARE_VOLUME2));\r
+\r
+  Hob->BaseAddress = BaseAddress;\r
+  Hob->Length      = Length;\r
+  CopyGuid (&Hob->FvName, FvName);\r
+  CopyGuid (&Hob->FileName, FileName);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Builds a Capsule Volume HOB.\r
+\r
+  This function builds a Capsule Volume HOB.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  BaseAddress   The base address of the Capsule Volume.\r
+  @param  Length        The size of the Capsule Volume in bytes.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+BuildCvHob (\r
+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,\r
+  IN UINT64                      Length\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+}\r
+\r
+\r
+/**\r
+  Builds a HOB for the CPU.\r
+\r
+  This function builds a HOB for the CPU.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  SizeOfMemorySpace   The maximum physical memory addressability of the processor.\r
+  @param  SizeOfIoSpace       The maximum physical I/O addressability of the processor.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+BuildCpuHob (\r
+  IN UINT8                       SizeOfMemorySpace,\r
+  IN UINT8                       SizeOfIoSpace\r
+  )\r
+{\r
+  EFI_HOB_CPU  *Hob;\r
+\r
+  Hob = CreateHob (EFI_HOB_TYPE_CPU, sizeof (EFI_HOB_CPU));\r
+\r
+  Hob->SizeOfMemorySpace = SizeOfMemorySpace;\r
+  Hob->SizeOfIoSpace     = SizeOfIoSpace;\r
+\r
+  //\r
+  // Zero the reserved space to match HOB spec\r
+  //\r
+  ZeroMem (Hob->Reserved, sizeof (Hob->Reserved)); \r
+}\r
+\r
+\r
+/**\r
+  Builds a HOB for the Stack.\r
+\r
+  This function builds a HOB for the stack.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  BaseAddress   The 64 bit physical address of the Stack.\r
+  @param  Length        The length of the stack in bytes.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+BuildStackHob (\r
+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,\r
+  IN UINT64                      Length\r
+  )\r
+{\r
+  EFI_HOB_MEMORY_ALLOCATION_STACK  *Hob;\r
+\r
+  ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
+          ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
+\r
+  Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));\r
+\r
+  CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);\r
+  Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
+  Hob->AllocDescriptor.MemoryLength      = Length;\r
+  Hob->AllocDescriptor.MemoryType        = EfiBootServicesData;\r
+\r
+  //\r
+  // Zero the reserved space to match HOB spec\r
+  //\r
+  ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r
+}\r
+\r
+\r
+/**\r
+  Update the Stack Hob if the stack has been moved\r
+\r
+  @param  BaseAddress   The 64 bit physical address of the Stack.\r
+  @param  Length        The length of the stack in bytes.\r
+\r
+**/\r
+VOID\r
+UpdateStackHob (\r
+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,\r
+  IN UINT64                      Length\r
+  )\r
+{\r
+  EFI_PEI_HOB_POINTERS           Hob;\r
+\r
+  Hob.Raw = GetHobList ();\r
+  while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {\r
+    if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &(Hob.MemoryAllocationStack->AllocDescriptor.Name))) {\r
+      //\r
+      // Build a new memory allocation HOB with old stack info with EfiConventionalMemory type\r
+      // to be reclaimed by DXE core.\r
+      //\r
+      BuildMemoryAllocationHob (\r
+        Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress,\r
+        Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength,\r
+        EfiConventionalMemory\r
+        );\r
+      //\r
+      // Update the BSP Stack Hob to reflect the new stack info.\r
+      //\r
+      Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
+      Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength = Length;\r
+      break;\r
+    }\r
+    Hob.Raw = GET_NEXT_HOB (Hob);\r
+  }\r
+}\r
+\r
+\r
+\r
+/**\r
+  Builds a HOB for the memory allocation.\r
+\r
+  This function builds a HOB for the memory allocation.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  BaseAddress   The 64 bit physical address of the memory.\r
+  @param  Length        The length of the memory allocation in bytes.\r
+  @param  MemoryType    Type of memory allocated by this HOB.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+BuildMemoryAllocationHob (\r
+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,\r
+  IN UINT64                      Length,\r
+  IN EFI_MEMORY_TYPE             MemoryType\r
+  )\r
+{\r
+  EFI_HOB_MEMORY_ALLOCATION  *Hob;\r
+\r
+  ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
+          ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
+  \r
+  Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION));\r
+  \r
+  ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));\r
+  Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
+  Hob->AllocDescriptor.MemoryLength      = Length;\r
+  Hob->AllocDescriptor.MemoryType        = MemoryType;\r
+  //\r
+  // Zero the reserved space to match HOB spec\r
+  //\r
+  ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r
+}\r
+\r
+\r
+\r
+VOID\r
+EFIAPI\r
+BuildExtractSectionHob (\r
+  IN  EFI_GUID                                  *Guid,\r
+  IN  EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER   SectionGetInfo,\r
+  IN  EXTRACT_GUIDED_SECTION_DECODE_HANDLER     SectionExtraction\r
+  )\r
+{\r
+  EXTRACT_SECTION_DATA Data;\r
+  \r
+  Data.SectionGetInfo    = SectionGetInfo;\r
+  Data.SectionExtraction = SectionExtraction;\r
+  BuildGuidDataHob (Guid, &Data, sizeof (Data));\r
+}\r
+\r
+PE_COFF_LOADER_PROTOCOL gPeCoffProtocol = {\r
+  PeCoffLoaderGetImageInfo,\r
+  PeCoffLoaderLoadImage,\r
+  PeCoffLoaderRelocateImage,\r
+  PeCoffLoaderImageReadFromMemory,\r
+  PeCoffLoaderRelocateImageForRuntime,\r
+  PeCoffLoaderUnloadImage\r
+};\r
+\r
+\r
+\r
+VOID\r
+EFIAPI\r
+BuildPeCoffLoaderHob (\r
+  VOID\r
+  )\r
+{\r
+  VOID  *Ptr;      \r
+  \r
+  Ptr = &gPeCoffProtocol;\r
+  BuildGuidDataHob (&gPeCoffLoaderProtocolGuid, &Ptr, sizeof (VOID *));  \r
+}\r
+\r
+// May want to put this into a library so you only need the PCD setings if you are using the feature?\r
+VOID\r
+BuildMemoryTypeInformationHob (\r
+  VOID\r
+  )\r
+{\r
+  EFI_MEMORY_TYPE_INFORMATION   Info[10];\r
+\r
+  Info[0].Type          = EfiACPIReclaimMemory;\r
+  Info[0].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory);\r
+  Info[1].Type          = EfiACPIMemoryNVS;\r
+  Info[1].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS);\r
+  Info[2].Type          = EfiReservedMemoryType;\r
+  Info[2].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiReservedMemoryType);\r
+  Info[3].Type          = EfiRuntimeServicesData;\r
+  Info[3].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesData);\r
+  Info[4].Type          = EfiRuntimeServicesCode;\r
+  Info[4].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode);\r
+  Info[5].Type          = EfiBootServicesCode;\r
+  Info[5].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiBootServicesCode);\r
+  Info[6].Type          = EfiBootServicesData;\r
+  Info[6].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiBootServicesData);\r
+  Info[7].Type          = EfiLoaderCode;\r
+  Info[7].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderCode);\r
+  Info[8].Type          = EfiLoaderData;\r
+  Info[8].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderData);\r
+\r
+  // Terminator for the list\r
+  Info[9].Type          = EfiMaxMemoryType;\r
+  Info[9].NumberOfPages = 0;\r
+\r
+\r
+  BuildGuidDataHob (&gEfiMemoryTypeInformationGuid, &Info, sizeof (Info));\r
+}\r
+\r
index 9f9e9c7d44208f0bbe2a8d52b2566dc3eb27fe0b..bf4f80f4e426799101775359935989288265ba55 100644 (file)
 #include <Library/DebugLib.h>\r
 #include <Library/PcdLib.h>\r
 \r
 #include <Library/DebugLib.h>\r
 #include <Library/PcdLib.h>\r
 \r
-//
-// Have to use build system to set the original value in case we are running
-// from FLASH and globals don't work. So if you do a GetHobList() and gHobList
-// and gHobList is NULL the PCD default values are used.
-//
+//\r
+// Have to use build system to set the original value in case we are running\r
+// from FLASH and globals don't work. So if you do a GetHobList() and gHobList\r
+// and gHobList is NULL the PCD default values are used.\r
+//\r
 VOID *gHobList = NULL;\r
 \r
 \r
 VOID *gHobList = NULL;\r
 \r
 \r
index 1ba976780b147a9cc4cd049795c47541f05da9b7..fea8f436871d5ed8bc95aa9d80cbd94882e90902 100644 (file)
@@ -36,4 +36,4 @@
   \r
 [FixedPcd.common]\r
   gEmbeddedTokenSpaceGuid.PcdPrePiHobBase\r
   \r
 [FixedPcd.common]\r
   gEmbeddedTokenSpaceGuid.PcdPrePiHobBase\r
-  
\ No newline at end of file
+  \r
\ No newline at end of file
index 75d28a725732d0a0e3bc95b38f6bf064cb6c80ff..9e4cdd002ec6143df77120186e95aa732d8ee225 100644 (file)
-/** @file
-  Implementation of the 6 PEI Ffs (FV) APIs in library form.
-  
-  This code only knows about a FV if it has a EFI_HOB_TYPE_FV entry in the HOB list
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <PrePi.h>
-#include <Library/ExtractGuidedSectionLib.h>
-
-
-#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \
-  (ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1))
-
-
-/**
-  Returns the highest bit set of the State field
-  
-  @param ErasePolarity   Erase Polarity  as defined by EFI_FVB2_ERASE_POLARITY
-                         in the Attributes field.
-  @param FfsHeader       Pointer to FFS File Header
-                      
-
-  @retval the highest bit in the State field
-
-**/
-STATIC
-EFI_FFS_FILE_STATE
-GetFileState(
-  IN UINT8                ErasePolarity,
-  IN EFI_FFS_FILE_HEADER  *FfsHeader
-  )
-{
-  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;
-} 
-
-
-/**
-  Calculates the checksum of the header of a file.
-  The header is a zero byte checksum, so zero means header is good
-  
-  @param FfsHeader       Pointer to FFS File Header
-                      
-  @retval Checksum of the header
-
-**/
-STATIC
-UINT8
-CalculateHeaderChecksum (
-  IN EFI_FFS_FILE_HEADER  *FileHeader
-  )
-{
-  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;
-}
-
-
-/**
-  Given a FileHandle return the VolumeHandle
-  
-  @param FileHandle   File handle to look up
-  @param VolumeHandle Match for FileHandle
-                      
-  @retval TRUE  VolumeHandle is valid
-
-**/
-STATIC
-BOOLEAN
-EFIAPI
-FileHandleToVolume (
-  IN   EFI_PEI_FILE_HANDLE     FileHandle,
-  OUT  EFI_PEI_FV_HANDLE       *VolumeHandle
-  )
-{
-  EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader;
-  EFI_PEI_HOB_POINTERS        Hob;
-
-  Hob.Raw = GetHobList ();
-  if (Hob.Raw == NULL) {
-    return FALSE;
-  }
-  
-  do {
-    Hob.Raw = GetNextHob (EFI_HOB_TYPE_FV, Hob.Raw);
-    if (Hob.Raw != NULL) {
-      FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)(Hob.FirmwareVolume->BaseAddress);
-      if (((UINT64) (UINTN) FileHandle > (UINT64) (UINTN) FwVolHeader ) &&   \
-          ((UINT64) (UINTN) FileHandle <= ((UINT64) (UINTN) FwVolHeader + FwVolHeader->FvLength - 1))) {
-        *VolumeHandle = (EFI_PEI_FV_HANDLE)FwVolHeader;
-        return TRUE;
-      }
-
-      Hob.Raw = GetNextHob (EFI_HOB_TYPE_FV, GET_NEXT_HOB (Hob));
-    }
-  } while (Hob.Raw != NULL);
-    
-  return FALSE;
-}
-
-
-
-/**
-  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.
-  
-  @param FileHandle   File handle to look up
-  @param VolumeHandle Match for FileHandle
-                      
-
-**/
-EFI_STATUS
-FindFileEx (
-  IN  CONST EFI_PEI_FV_HANDLE        FvHandle,
-  IN  CONST EFI_GUID                 *FileName,   OPTIONAL
-  IN        EFI_FV_FILETYPE          SearchType,
-  IN OUT    EFI_PEI_FILE_HANDLE      *FileHandle
-  )
-{
-  EFI_FIRMWARE_VOLUME_HEADER           *FwVolHeader;
-  EFI_FFS_FILE_HEADER                   **FileHeader;
-  EFI_FFS_FILE_HEADER                   *FfsFileHeader;
-  EFI_FIRMWARE_VOLUME_EXT_HEADER        *FwVolExHeaderInfo;
-  UINT32                                FileLength;
-  UINT32                                FileOccupiedSize;
-  UINT32                                FileOffset;
-  UINT64                                FvLength;
-  UINT8                                 ErasePolarity;
-  UINT8                                 FileState;
-
-  FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)FvHandle;
-  FileHeader  = (EFI_FFS_FILE_HEADER **)FileHandle;
-
-  FvLength = FwVolHeader->FvLength;
-  if (FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) {
-    ErasePolarity = 1;
-  } else {
-    ErasePolarity = 0;
-  }
-
-  //
-  // If FileHeader is not specified (NULL) or FileName is not NULL,
-  // start with the first file in the firmware volume.  Otherwise,
-  // start from the FileHeader.
-  //
-  if ((*FileHeader == NULL) || (FileName != NULL)) {
-    FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FwVolHeader + FwVolHeader->HeaderLength);
-    if (FwVolHeader->ExtHeaderOffset != 0) {
-      FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER *)(((UINT8 *)FwVolHeader) + FwVolHeader->ExtHeaderOffset);
-      FfsFileHeader = (EFI_FFS_FILE_HEADER *)(((UINT8 *)FwVolExHeaderInfo) + FwVolExHeaderInfo->ExtHeaderSize);
-    }
-  } 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);
-  ASSERT (FileOffset <= 0xFFFFFFFF);
-
-  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) {
-        ASSERT (FALSE);
-        *FileHeader = NULL;
-        return EFI_NOT_FOUND;
-      }
-
-      FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;
-      FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8);
-
-      if (FileName != NULL) {
-        if (CompareGuid (&FfsFileHeader->Name, (EFI_GUID*)FileName)) {
-          *FileHeader = FfsFileHeader;
-          return EFI_SUCCESS;
-        }
-      } else if (((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) && 
-                 (FfsFileHeader->Type != EFI_FV_FILETYPE_FFS_PAD)) { 
-        *FileHeader = FfsFileHeader;
-        return EFI_SUCCESS;
-      }
-
-      FileOffset += FileOccupiedSize; 
-      FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);
-      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:
-      *FileHeader = NULL;
-      return EFI_NOT_FOUND;
-    } 
-  }
-
-  
-  *FileHeader = NULL;
-  return EFI_NOT_FOUND;  
-}
-
-
-/**
-  Go through the file to search SectionType section,
-  when meeting an encapsuled section. 
-  
-  @param  SectionType  - Filter to find only section of this type.
-  @param  Section      - From where to search.
-  @param  SectionSize  - The file size to search.
-  @param  OutputBuffer - Pointer to the section to search.
-                      
-  @retval EFI_SUCCESS
-**/
-EFI_STATUS
-FfsProcessSection (
-  IN EFI_SECTION_TYPE           SectionType,
-  IN EFI_COMMON_SECTION_HEADER  *Section,
-  IN UINTN                      SectionSize,
-  OUT VOID                      **OutputBuffer
-  )
-{
-  EFI_STATUS                              Status;
-  UINT32                                  SectionLength;
-  UINT32                                  ParsedLength;
-  EFI_COMPRESSION_SECTION                 *CompressionSection;
-  UINTN                                   DstBufferSize;
-  VOID                                    *ScratchBuffer;
-  UINT32                                  ScratchBufferSize;
-  VOID                                    *DstBuffer;
-  UINT16                                  SectionAttribute;
-  UINT32                                  AuthenticationStatus;
-
-
-  *OutputBuffer = NULL;
-  ParsedLength  = 0;
-  Status        = EFI_NOT_FOUND;
-  while (ParsedLength < SectionSize) {
-    if (Section->Type == SectionType) {
-      *OutputBuffer = (VOID *)(Section + 1);
-
-      return EFI_SUCCESS;
-    } else if ((Section->Type == EFI_SECTION_COMPRESSION) || (Section->Type == EFI_SECTION_GUID_DEFINED)) {
-    
-      if (Section->Type == EFI_SECTION_COMPRESSION) {
-        CompressionSection  = (EFI_COMPRESSION_SECTION *) Section;
-        SectionLength       = *(UINT32 *)Section->Size & 0x00FFFFFF;
-        
-        if (CompressionSection->CompressionType != EFI_STANDARD_COMPRESSION) {
-          return EFI_UNSUPPORTED;
-        }
-
-        Status = UefiDecompressGetInfo (
-                   (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),
-                   (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION),
-                   (UINT32 *) &DstBufferSize,
-                   &ScratchBufferSize
-                   );
-      } else if (Section->Type == EFI_SECTION_GUID_DEFINED) {
-        Status = ExtractGuidedSectionGetInfo (
-                   Section,
-                   (UINT32 *) &DstBufferSize,
-                   &ScratchBufferSize,
-                   &SectionAttribute
-                   );
-      }
-      
-      if (EFI_ERROR (Status)) {
-        //
-        // GetInfo failed
-        //
-        DEBUG ((EFI_D_ERROR, "Decompress GetInfo Failed - %r\n", Status));
-        return EFI_NOT_FOUND;
-      }
-      //
-      // Allocate scratch buffer
-      //
-      ScratchBuffer = (VOID *)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));
-      if (ScratchBuffer == NULL) {
-        return EFI_OUT_OF_RESOURCES;
-      }
-      //
-      // Allocate destination buffer, extra one page for adjustment 
-      //
-      DstBuffer = (VOID *)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize) + 1);
-      if (DstBuffer == NULL) {
-        return EFI_OUT_OF_RESOURCES;
-      }
-      //
-      // DstBuffer still is one section. Adjust DstBuffer offset, skip EFI section header
-      // to make section data at page alignment.
-      //
-      DstBuffer = (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER);
-      //
-      // Call decompress function
-      //
-      if (Section->Type == EFI_SECTION_COMPRESSION) {
-        Status = UefiDecompress (
-                    (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),
-                    DstBuffer,
-                    ScratchBuffer
-                    );
-      } else if (Section->Type == EFI_SECTION_GUID_DEFINED) {
-        Status = ExtractGuidedSectionDecode (
-                    Section,
-                    &DstBuffer,
-                    ScratchBuffer,
-                    &AuthenticationStatus
-                    );
-      }
-      
-      if (EFI_ERROR (Status)) {
-        //
-        // Decompress failed
-        //
-        DEBUG ((EFI_D_ERROR, "Decompress Failed - %r\n", Status));
-        return EFI_NOT_FOUND;
-      } else {
-        return FfsProcessSection (
-                SectionType, 
-                DstBuffer, 
-                DstBufferSize, 
-                OutputBuffer 
-                );
-       }        
-    }
-
-    //
-    // 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);
-    ASSERT (SectionLength != 0);
-    ParsedLength += SectionLength;
-    Section = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + SectionLength);
-  }
-  
-  return EFI_NOT_FOUND;
-}
-
-
-
-/**
-  This service enables discovery sections of a given type within a valid FFS file.
-
-  @param  SearchType            The value of the section type to find.
-  @param  FfsFileHeader         A pointer to the file header that contains the set of sections to
-                                be searched.
-  @param  SectionData           A pointer to the discovered section, if successful.
-
-  @retval EFI_SUCCESS           The section was found.
-  @retval EFI_NOT_FOUND         The section was not found.
-
-**/
-EFI_STATUS
-EFIAPI
-FfsFindSectionData (
-  IN EFI_SECTION_TYPE           SectionType,
-  IN EFI_PEI_FILE_HANDLE        FileHandle,
-  OUT VOID                      **SectionData
-  )
-{
-  EFI_FFS_FILE_HEADER                     *FfsFileHeader;
-  UINT32                                  FileSize;
-  EFI_COMMON_SECTION_HEADER               *Section;
-
-  FfsFileHeader = (EFI_FFS_FILE_HEADER *)(FileHandle);
-
-  //
-  // 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);
-
-  return FfsProcessSection (
-          SectionType, 
-          Section, 
-          FileSize, 
-          SectionData
-          );
-}
-
-
-
-
-
-
-/**
-  This service enables discovery of additional firmware files.
-
-  @param  SearchType            A filter to find files only of this type.
-  @param  FwVolHeader           Pointer to the firmware volume header of the volume to search.
-                                This parameter must point to a valid FFS volume.
-  @param  FileHeader            Pointer to the current file from which to begin searching.
-
-  @retval EFI_SUCCESS           The file was found.
-  @retval EFI_NOT_FOUND         The file was not found.
-  @retval EFI_NOT_FOUND         The header checksum was not zero.
-
-**/
-EFI_STATUS
-EFIAPI
-FfsFindNextFile (
-  IN UINT8                       SearchType,
-  IN EFI_PEI_FV_HANDLE           VolumeHandle,
-  IN OUT EFI_PEI_FILE_HANDLE     *FileHandle
-  )
-{
-  return FindFileEx (VolumeHandle, NULL, SearchType, FileHandle);
-}
-
-
-/**
-  This service enables discovery of additional firmware volumes.
-
-  @param  Instance              This instance of the firmware volume to find.  The value 0 is the
-                                Boot Firmware Volume (BFV).
-  @param  FwVolHeader           Pointer to the firmware volume header of the volume to return.
-
-  @retval EFI_SUCCESS           The volume was found.
-  @retval EFI_NOT_FOUND         The volume was not found.
-
-**/
-EFI_STATUS
-EFIAPI
-FfsFindNextVolume (
-  IN UINTN                          Instance,
-  IN OUT EFI_PEI_FV_HANDLE          *VolumeHandle
-  )
-{
-  EFI_PEI_HOB_POINTERS        Hob;
-  
-
-  Hob.Raw = GetHobList ();
-  if (Hob.Raw == NULL) {
-    return EFI_NOT_FOUND;
-  }
-  
-  do {
-    Hob.Raw = GetNextHob (EFI_HOB_TYPE_FV, Hob.Raw);
-    if (Hob.Raw != NULL) {
-      if (Instance-- == 0) {
-        *VolumeHandle = (EFI_PEI_FV_HANDLE)(UINTN)(Hob.FirmwareVolume->BaseAddress);
-        return EFI_SUCCESS;
-      }
-
-      Hob.Raw = GetNextHob (EFI_HOB_TYPE_FV, GET_NEXT_HOB (Hob));
-    }
-  } while (Hob.Raw != NULL);
-    
-  return EFI_NOT_FOUND;
-
-}
-
-
-/**
-  Find a file in the volume by name
-  
-  @param FileName       A pointer to the name of the file to
-                        find within the firmware volume.
-
-  @param VolumeHandle   The firmware volume to search FileHandle
-                        Upon exit, points to the found file's
-                        handle or NULL if it could not be found.
-
-  @retval EFI_SUCCESS             File was found.
-
-  @retval EFI_NOT_FOUND           File was not found.
-
-  @retval EFI_INVALID_PARAMETER   VolumeHandle or FileHandle or
-                                  FileName was NULL.
-
-**/
-EFI_STATUS
-EFIAPI 
-FfsFindFileByName (
-  IN  CONST EFI_GUID        *FileName,
-  IN  EFI_PEI_FV_HANDLE     VolumeHandle,
-  OUT EFI_PEI_FILE_HANDLE   *FileHandle
-  )
-{
-  EFI_STATUS  Status;
-  if ((VolumeHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) {
-    return EFI_INVALID_PARAMETER;
-  }
-  Status = FindFileEx (VolumeHandle, FileName, 0, FileHandle);
-  if (Status == EFI_NOT_FOUND) {
-    *FileHandle = NULL;
-  }
-  return Status;
-}
-
-
-
-
-/**
-  Get information about the file by name.
-
-  @param FileHandle   Handle of the file.
-
-  @param FileInfo     Upon exit, points to the file's
-                      information.
-
-  @retval EFI_SUCCESS             File information returned.
-  
-  @retval EFI_INVALID_PARAMETER   If FileHandle does not
-                                  represent a valid file.
-  
-  @retval EFI_INVALID_PARAMETER   If FileInfo is NULL.
-  
-**/
-EFI_STATUS
-EFIAPI 
-FfsGetFileInfo (
-  IN EFI_PEI_FILE_HANDLE  FileHandle,
-  OUT EFI_FV_FILE_INFO    *FileInfo
-  )
-{
-  UINT8                       FileState;
-  UINT8                       ErasePolarity;
-  EFI_FFS_FILE_HEADER         *FileHeader;
-  EFI_PEI_FV_HANDLE           VolumeHandle;
-
-  if ((FileHandle == NULL) || (FileInfo == NULL)) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  VolumeHandle = 0;
-  //
-  // Retrieve the FirmwareVolume which the file resides in.
-  //
-  if (!FileHandleToVolume(FileHandle, &VolumeHandle)) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  if (((EFI_FIRMWARE_VOLUME_HEADER*)VolumeHandle)->Attributes & EFI_FVB2_ERASE_POLARITY) {
-    ErasePolarity = 1;
-  } else {
-    ErasePolarity = 0;
-  }
-
-  //
-  // Get FileState which is the highest bit of the State 
-  //
-  FileState = GetFileState (ErasePolarity, (EFI_FFS_FILE_HEADER*)FileHandle);
-
-  switch (FileState) {
-    case EFI_FILE_DATA_VALID:
-    case EFI_FILE_MARKED_FOR_UPDATE:
-      break;  
-    default:
-      return EFI_INVALID_PARAMETER;
-    }
-
-  FileHeader = (EFI_FFS_FILE_HEADER *)FileHandle;
-  CopyMem (&FileInfo->FileName, &FileHeader->Name, sizeof(EFI_GUID));
-  FileInfo->FileType = FileHeader->Type;
-  FileInfo->FileAttributes = FileHeader->Attributes;
-  FileInfo->BufferSize = ((*(UINT32 *)FileHeader->Size) & 0x00FFFFFF) -  sizeof (EFI_FFS_FILE_HEADER);
-  FileInfo->Buffer = (FileHeader + 1);
-  return EFI_SUCCESS;
-}
-
-
-/**
-  Get Information about the volume by name
-
-  @param VolumeHandle   Handle of the volume.
-
-  @param VolumeInfo     Upon exit, points to the volume's
-                        information.
-
-  @retval EFI_SUCCESS             File information returned.
-  
-  @retval EFI_INVALID_PARAMETER   If FileHandle does not
-                                  represent a valid file.
-  
-  @retval EFI_INVALID_PARAMETER   If FileInfo is NULL.
-
-**/
-EFI_STATUS
-EFIAPI 
-FfsGetVolumeInfo (
-  IN EFI_PEI_FV_HANDLE  VolumeHandle,
-  OUT EFI_FV_INFO       *VolumeInfo
-  )
-{
-  EFI_FIRMWARE_VOLUME_HEADER             FwVolHeader;
-  EFI_FIRMWARE_VOLUME_EXT_HEADER         *FwVolExHeaderInfo;
-
-  if (VolumeInfo == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-  
-  //
-  // VolumeHandle may not align at 8 byte, 
-  // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte. 
-  // So, Copy FvHeader into the local FvHeader structure.
-  //
-  CopyMem (&FwVolHeader, VolumeHandle, sizeof (EFI_FIRMWARE_VOLUME_HEADER));
-  //
-  // Check Fv Image Signature
-  //
-  if (FwVolHeader.Signature != EFI_FVH_SIGNATURE) {
-    return EFI_INVALID_PARAMETER;
-  }
-  VolumeInfo->FvAttributes = FwVolHeader.Attributes;
-  VolumeInfo->FvStart = (VOID *) VolumeHandle;
-  VolumeInfo->FvSize = FwVolHeader.FvLength;
-  CopyMem (&VolumeInfo->FvFormat, &FwVolHeader.FileSystemGuid, sizeof(EFI_GUID));
-
-  if (FwVolHeader.ExtHeaderOffset != 0) {
-    FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER*)(((UINT8 *)VolumeHandle) + FwVolHeader.ExtHeaderOffset);
-    CopyMem (&VolumeInfo->FvName, &FwVolExHeaderInfo->FvName, sizeof(EFI_GUID));
-  }
-  return EFI_SUCCESS;
-}
-
-
-
-/**
-  Search through every FV until you find a file of type FileType
-
-       @param FileType             File handle of a Fv type file.
-  @param Volumehandle   On succes Volume Handle of the match
-  @param FileHandle     On success File Handle of the match
-  
-  @retval EFI_NOT_FOUND                                FV image can't be found.
-  @retval EFI_SUCCESS                                          Successfully found FileType
-
-**/
-EFI_STATUS
-EFIAPI
-FfsAnyFvFindFirstFile (
-  IN  EFI_FV_FILETYPE       FileType,
-  OUT EFI_PEI_FV_HANDLE     *VolumeHandle,
-  OUT EFI_PEI_FILE_HANDLE   *FileHandle
-  )
-{
-  EFI_STATUS        Status;
-  UINTN             Instance;
-
-  //
-  // Search every FV for the DXE Core
-  //
-  Instance    = 0;
-  *FileHandle = NULL;
-
-  while (1)
-  {
-    Status = FfsFindNextVolume (Instance++, VolumeHandle);
-    if (EFI_ERROR (Status))
-    {
-      break;
-    }
-
-    Status = FfsFindNextFile (FileType, *VolumeHandle, FileHandle);
-    if (!EFI_ERROR (Status))
-    {
-      break;
-    }
-  }
-  
-  return Status;
-}
-
-
-
-/**
-  Get Fv image from the FV type file, then add FV & FV2 Hob.
-
-       @param FileHandle               File handle of a Fv type file.
-
-
-  @retval EFI_NOT_FOUND                                FV image can't be found.
-  @retval EFI_SUCCESS                                          Successfully to process it.
-
-**/
-EFI_STATUS
-EFIAPI
-FfsProcessFvFile (
-  IN  EFI_PEI_FILE_HANDLE   FvFileHandle
-  )
-{
-  EFI_STATUS            Status;
-  EFI_PEI_FV_HANDLE     FvImageHandle;
-  EFI_FV_INFO           FvImageInfo;
-  UINT32                FvAlignment;
-  VOID                  *FvBuffer;
-  EFI_PEI_HOB_POINTERS  HobFv2;
-
-  FvBuffer             = NULL;
-
-
-  //
-  // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
-  // been extracted.
-  //
-  HobFv2.Raw = GetHobList ();
-  while ((HobFv2.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobFv2.Raw)) != NULL) {
-    if (CompareGuid (&(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name), &HobFv2.FirmwareVolume2->FileName)) {
-      //
-      // this FILE has been dispatched, it will not be dispatched again.
-      //
-      return EFI_SUCCESS;
-    }
-    HobFv2.Raw = GET_NEXT_HOB (HobFv2);
-  }
-
-  //
-  // Find FvImage in FvFile
-  //
-  Status = FfsFindSectionData (EFI_SECTION_FIRMWARE_VOLUME_IMAGE, FvFileHandle, (VOID **)&FvImageHandle);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-  
-  //
-  // Collect FvImage Info.
-  //
-  ZeroMem (&FvImageInfo, sizeof (FvImageInfo));
-  Status = FfsGetVolumeInfo (FvImageHandle, &FvImageInfo);
-  ASSERT_EFI_ERROR (Status);
-  
-  //
-  // FvAlignment must be more than 8 bytes required by FvHeader structure.
-  //
-  FvAlignment = 1 << ((FvImageInfo.FvAttributes & EFI_FVB2_ALIGNMENT) >> 16);
-  if (FvAlignment < 8) {
-    FvAlignment = 8;
-  }
-  
-  //
-  // Check FvImage
-  //
-  if ((UINTN) FvImageInfo.FvStart % FvAlignment != 0) {
-    FvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvImageInfo.FvSize), FvAlignment);
-    if (FvBuffer == NULL) {
-      return EFI_OUT_OF_RESOURCES;
-    }
-    CopyMem (FvBuffer, FvImageInfo.FvStart, (UINTN) FvImageInfo.FvSize);
-    //
-    // Update FvImageInfo after reload FvImage to new aligned memory
-    //
-    FfsGetVolumeInfo ((EFI_PEI_FV_HANDLE) FvBuffer, &FvImageInfo);
-  }
-
-
-  //
-  // Inform HOB consumer phase, i.e. DXE core, the existance of this FV
-  //
-  BuildFvHob ((EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart, FvImageInfo.FvSize);
-  
-  //
-  // Makes the encapsulated volume show up in DXE phase to skip processing of
-  // encapsulated file again.
-  //
-  BuildFv2Hob (
-    (EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart,
-    FvImageInfo.FvSize,
-    &FvImageInfo.FvName,
-    &(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name)
-    );
-
-  return EFI_SUCCESS;
-}
-
-
+/** @file\r
+  Implementation of the 6 PEI Ffs (FV) APIs in library form.\r
+  \r
+  This code only knows about a FV if it has a EFI_HOB_TYPE_FV entry in the HOB list\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PrePi.h>\r
+#include <Library/ExtractGuidedSectionLib.h>\r
+\r
+\r
+#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \\r
+  (ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1))\r
+\r
+\r
+/**\r
+  Returns the highest bit set of the State field\r
+  \r
+  @param ErasePolarity   Erase Polarity  as defined by EFI_FVB2_ERASE_POLARITY\r
+                         in the Attributes field.\r
+  @param FfsHeader       Pointer to FFS File Header\r
+                      \r
+\r
+  @retval the highest bit in the State field\r
+\r
+**/\r
+STATIC\r
+EFI_FFS_FILE_STATE\r
+GetFileState(\r
+  IN UINT8                ErasePolarity,\r
+  IN EFI_FFS_FILE_HEADER  *FfsHeader\r
+  )\r
+{\r
+  EFI_FFS_FILE_STATE  FileState;\r
+  EFI_FFS_FILE_STATE  HighestBit;\r
+\r
+  FileState = FfsHeader->State;\r
+\r
+  if (ErasePolarity != 0) {\r
+    FileState = (EFI_FFS_FILE_STATE)~FileState;\r
+  }\r
+\r
+  HighestBit = 0x80;\r
+  while (HighestBit != 0 && (HighestBit & FileState) == 0) {\r
+    HighestBit >>= 1;\r
+  }\r
+\r
+  return HighestBit;\r
+} \r
+\r
+\r
+/**\r
+  Calculates the checksum of the header of a file.\r
+  The header is a zero byte checksum, so zero means header is good\r
+  \r
+  @param FfsHeader       Pointer to FFS File Header\r
+                      \r
+  @retval Checksum of the header\r
+\r
+**/\r
+STATIC\r
+UINT8\r
+CalculateHeaderChecksum (\r
+  IN EFI_FFS_FILE_HEADER  *FileHeader\r
+  )\r
+{\r
+  UINT8   *Ptr;\r
+  UINTN   Index;\r
+  UINT8   Sum;\r
+  \r
+  Sum = 0;\r
+  Ptr = (UINT8 *)FileHeader;\r
+\r
+  for (Index = 0; Index < sizeof(EFI_FFS_FILE_HEADER) - 3; Index += 4) {\r
+    Sum = (UINT8)(Sum + Ptr[Index]);\r
+    Sum = (UINT8)(Sum + Ptr[Index+1]);\r
+    Sum = (UINT8)(Sum + Ptr[Index+2]);\r
+    Sum = (UINT8)(Sum + Ptr[Index+3]);\r
+  }\r
+\r
+  for (; Index < sizeof(EFI_FFS_FILE_HEADER); Index++) {\r
+    Sum = (UINT8)(Sum + Ptr[Index]);\r
+  }\r
+  \r
+  //\r
+  // State field (since this indicates the different state of file). \r
+  //\r
+  Sum = (UINT8)(Sum - FileHeader->State);\r
+  //\r
+  // Checksum field of the file is not part of the header checksum.\r
+  //\r
+  Sum = (UINT8)(Sum - FileHeader->IntegrityCheck.Checksum.File);\r
+\r
+  return Sum;\r
+}\r
+\r
+\r
+/**\r
+  Given a FileHandle return the VolumeHandle\r
+  \r
+  @param FileHandle   File handle to look up\r
+  @param VolumeHandle Match for FileHandle\r
+                      \r
+  @retval TRUE  VolumeHandle is valid\r
+\r
+**/\r
+STATIC\r
+BOOLEAN\r
+EFIAPI\r
+FileHandleToVolume (\r
+  IN   EFI_PEI_FILE_HANDLE     FileHandle,\r
+  OUT  EFI_PEI_FV_HANDLE       *VolumeHandle\r
+  )\r
+{\r
+  EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader;\r
+  EFI_PEI_HOB_POINTERS        Hob;\r
+\r
+  Hob.Raw = GetHobList ();\r
+  if (Hob.Raw == NULL) {\r
+    return FALSE;\r
+  }\r
+  \r
+  do {\r
+    Hob.Raw = GetNextHob (EFI_HOB_TYPE_FV, Hob.Raw);\r
+    if (Hob.Raw != NULL) {\r
+      FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)(Hob.FirmwareVolume->BaseAddress);\r
+      if (((UINT64) (UINTN) FileHandle > (UINT64) (UINTN) FwVolHeader ) &&   \\r
+          ((UINT64) (UINTN) FileHandle <= ((UINT64) (UINTN) FwVolHeader + FwVolHeader->FvLength - 1))) {\r
+        *VolumeHandle = (EFI_PEI_FV_HANDLE)FwVolHeader;\r
+        return TRUE;\r
+      }\r
+\r
+      Hob.Raw = GetNextHob (EFI_HOB_TYPE_FV, GET_NEXT_HOB (Hob));\r
+    }\r
+  } while (Hob.Raw != NULL);\r
+    \r
+  return FALSE;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Given the input file pointer, search for the next matching file in the\r
+  FFS volume as defined by SearchType. The search starts from FileHeader inside\r
+  the Firmware Volume defined by FwVolHeader.\r
+  \r
+  @param FileHandle   File handle to look up\r
+  @param VolumeHandle Match for FileHandle\r
+                      \r
+\r
+**/\r
+EFI_STATUS\r
+FindFileEx (\r
+  IN  CONST EFI_PEI_FV_HANDLE        FvHandle,\r
+  IN  CONST EFI_GUID                 *FileName,   OPTIONAL\r
+  IN        EFI_FV_FILETYPE          SearchType,\r
+  IN OUT    EFI_PEI_FILE_HANDLE      *FileHandle\r
+  )\r
+{\r
+  EFI_FIRMWARE_VOLUME_HEADER           *FwVolHeader;\r
+  EFI_FFS_FILE_HEADER                   **FileHeader;\r
+  EFI_FFS_FILE_HEADER                   *FfsFileHeader;\r
+  EFI_FIRMWARE_VOLUME_EXT_HEADER        *FwVolExHeaderInfo;\r
+  UINT32                                FileLength;\r
+  UINT32                                FileOccupiedSize;\r
+  UINT32                                FileOffset;\r
+  UINT64                                FvLength;\r
+  UINT8                                 ErasePolarity;\r
+  UINT8                                 FileState;\r
+\r
+  FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)FvHandle;\r
+  FileHeader  = (EFI_FFS_FILE_HEADER **)FileHandle;\r
+\r
+  FvLength = FwVolHeader->FvLength;\r
+  if (FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) {\r
+    ErasePolarity = 1;\r
+  } else {\r
+    ErasePolarity = 0;\r
+  }\r
+\r
+  //\r
+  // If FileHeader is not specified (NULL) or FileName is not NULL,\r
+  // start with the first file in the firmware volume.  Otherwise,\r
+  // start from the FileHeader.\r
+  //\r
+  if ((*FileHeader == NULL) || (FileName != NULL)) {\r
+    FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FwVolHeader + FwVolHeader->HeaderLength);\r
+    if (FwVolHeader->ExtHeaderOffset != 0) {\r
+      FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER *)(((UINT8 *)FwVolHeader) + FwVolHeader->ExtHeaderOffset);\r
+      FfsFileHeader = (EFI_FFS_FILE_HEADER *)(((UINT8 *)FwVolExHeaderInfo) + FwVolExHeaderInfo->ExtHeaderSize);\r
+    }\r
+  } else {\r
+    //\r
+    // Length is 24 bits wide so mask upper 8 bits\r
+    // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.\r
+    //\r
+    FileLength = *(UINT32 *)(*FileHeader)->Size & 0x00FFFFFF;\r
+    FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);\r
+    FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)*FileHeader + FileOccupiedSize);\r
+  }\r
+  \r
+  FileOffset = (UINT32) ((UINT8 *)FfsFileHeader - (UINT8 *)FwVolHeader);\r
+  ASSERT (FileOffset <= 0xFFFFFFFF);\r
+\r
+  while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) {\r
+    //\r
+    // Get FileState which is the highest bit of the State \r
+    //\r
+    FileState = GetFileState (ErasePolarity, FfsFileHeader);\r
+\r
+    switch (FileState) {\r
+\r
+    case EFI_FILE_HEADER_INVALID:\r
+      FileOffset += sizeof(EFI_FFS_FILE_HEADER);\r
+      FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + sizeof(EFI_FFS_FILE_HEADER));\r
+      break;\r
+        \r
+    case EFI_FILE_DATA_VALID:\r
+    case EFI_FILE_MARKED_FOR_UPDATE:\r
+      if (CalculateHeaderChecksum (FfsFileHeader) != 0) {\r
+        ASSERT (FALSE);\r
+        *FileHeader = NULL;\r
+        return EFI_NOT_FOUND;\r
+      }\r
+\r
+      FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r
+      FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8);\r
+\r
+      if (FileName != NULL) {\r
+        if (CompareGuid (&FfsFileHeader->Name, (EFI_GUID*)FileName)) {\r
+          *FileHeader = FfsFileHeader;\r
+          return EFI_SUCCESS;\r
+        }\r
+      } else if (((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) && \r
+                 (FfsFileHeader->Type != EFI_FV_FILETYPE_FFS_PAD)) { \r
+        *FileHeader = FfsFileHeader;\r
+        return EFI_SUCCESS;\r
+      }\r
+\r
+      FileOffset += FileOccupiedSize; \r
+      FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);\r
+      break;\r
+    \r
+    case EFI_FILE_DELETED:\r
+      FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r
+      FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8);\r
+      FileOffset += FileOccupiedSize;\r
+      FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);\r
+      break;\r
+\r
+    default:\r
+      *FileHeader = NULL;\r
+      return EFI_NOT_FOUND;\r
+    } \r
+  }\r
+\r
+  \r
+  *FileHeader = NULL;\r
+  return EFI_NOT_FOUND;  \r
+}\r
+\r
+\r
+/**\r
+  Go through the file to search SectionType section,\r
+  when meeting an encapsuled section. \r
+  \r
+  @param  SectionType  - Filter to find only section of this type.\r
+  @param  Section      - From where to search.\r
+  @param  SectionSize  - The file size to search.\r
+  @param  OutputBuffer - Pointer to the section to search.\r
+                      \r
+  @retval EFI_SUCCESS\r
+**/\r
+EFI_STATUS\r
+FfsProcessSection (\r
+  IN EFI_SECTION_TYPE           SectionType,\r
+  IN EFI_COMMON_SECTION_HEADER  *Section,\r
+  IN UINTN                      SectionSize,\r
+  OUT VOID                      **OutputBuffer\r
+  )\r
+{\r
+  EFI_STATUS                              Status;\r
+  UINT32                                  SectionLength;\r
+  UINT32                                  ParsedLength;\r
+  EFI_COMPRESSION_SECTION                 *CompressionSection;\r
+  UINTN                                   DstBufferSize;\r
+  VOID                                    *ScratchBuffer;\r
+  UINT32                                  ScratchBufferSize;\r
+  VOID                                    *DstBuffer;\r
+  UINT16                                  SectionAttribute;\r
+  UINT32                                  AuthenticationStatus;\r
+\r
+\r
+  *OutputBuffer = NULL;\r
+  ParsedLength  = 0;\r
+  Status        = EFI_NOT_FOUND;\r
+  while (ParsedLength < SectionSize) {\r
+    if (Section->Type == SectionType) {\r
+      *OutputBuffer = (VOID *)(Section + 1);\r
+\r
+      return EFI_SUCCESS;\r
+    } else if ((Section->Type == EFI_SECTION_COMPRESSION) || (Section->Type == EFI_SECTION_GUID_DEFINED)) {\r
+    \r
+      if (Section->Type == EFI_SECTION_COMPRESSION) {\r
+        CompressionSection  = (EFI_COMPRESSION_SECTION *) Section;\r
+        SectionLength       = *(UINT32 *)Section->Size & 0x00FFFFFF;\r
+        \r
+        if (CompressionSection->CompressionType != EFI_STANDARD_COMPRESSION) {\r
+          return EFI_UNSUPPORTED;\r
+        }\r
+\r
+        Status = UefiDecompressGetInfo (\r
+                   (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
+                   (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION),\r
+                   (UINT32 *) &DstBufferSize,\r
+                   &ScratchBufferSize\r
+                   );\r
+      } else if (Section->Type == EFI_SECTION_GUID_DEFINED) {\r
+        Status = ExtractGuidedSectionGetInfo (\r
+                   Section,\r
+                   (UINT32 *) &DstBufferSize,\r
+                   &ScratchBufferSize,\r
+                   &SectionAttribute\r
+                   );\r
+      }\r
+      \r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // GetInfo failed\r
+        //\r
+        DEBUG ((EFI_D_ERROR, "Decompress GetInfo Failed - %r\n", Status));\r
+        return EFI_NOT_FOUND;\r
+      }\r
+      //\r
+      // Allocate scratch buffer\r
+      //\r
+      ScratchBuffer = (VOID *)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r
+      if (ScratchBuffer == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      //\r
+      // Allocate destination buffer, extra one page for adjustment \r
+      //\r
+      DstBuffer = (VOID *)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize) + 1);\r
+      if (DstBuffer == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      //\r
+      // DstBuffer still is one section. Adjust DstBuffer offset, skip EFI section header\r
+      // to make section data at page alignment.\r
+      //\r
+      DstBuffer = (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER);\r
+      //\r
+      // Call decompress function\r
+      //\r
+      if (Section->Type == EFI_SECTION_COMPRESSION) {\r
+        Status = UefiDecompress (\r
+                    (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
+                    DstBuffer,\r
+                    ScratchBuffer\r
+                    );\r
+      } else if (Section->Type == EFI_SECTION_GUID_DEFINED) {\r
+        Status = ExtractGuidedSectionDecode (\r
+                    Section,\r
+                    &DstBuffer,\r
+                    ScratchBuffer,\r
+                    &AuthenticationStatus\r
+                    );\r
+      }\r
+      \r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // Decompress failed\r
+        //\r
+        DEBUG ((EFI_D_ERROR, "Decompress Failed - %r\n", Status));\r
+        return EFI_NOT_FOUND;\r
+      } else {\r
+        return FfsProcessSection (\r
+                SectionType, \r
+                DstBuffer, \r
+                DstBufferSize, \r
+                OutputBuffer \r
+                );\r
+       }        \r
+    }\r
+\r
+    //\r
+    // Size is 24 bits wide so mask upper 8 bits. \r
+    // SectionLength is adjusted it is 4 byte aligned.\r
+    // Go to the next section\r
+    //\r
+    SectionLength = *(UINT32 *)Section->Size & 0x00FFFFFF;\r
+    SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);\r
+    ASSERT (SectionLength != 0);\r
+    ParsedLength += SectionLength;\r
+    Section = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + SectionLength);\r
+  }\r
+  \r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+\r
+\r
+/**\r
+  This service enables discovery sections of a given type within a valid FFS file.\r
+\r
+  @param  SearchType            The value of the section type to find.\r
+  @param  FfsFileHeader         A pointer to the file header that contains the set of sections to\r
+                                be searched.\r
+  @param  SectionData           A pointer to the discovered section, if successful.\r
+\r
+  @retval EFI_SUCCESS           The section was found.\r
+  @retval EFI_NOT_FOUND         The section was not found.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FfsFindSectionData (\r
+  IN EFI_SECTION_TYPE           SectionType,\r
+  IN EFI_PEI_FILE_HANDLE        FileHandle,\r
+  OUT VOID                      **SectionData\r
+  )\r
+{\r
+  EFI_FFS_FILE_HEADER                     *FfsFileHeader;\r
+  UINT32                                  FileSize;\r
+  EFI_COMMON_SECTION_HEADER               *Section;\r
+\r
+  FfsFileHeader = (EFI_FFS_FILE_HEADER *)(FileHandle);\r
+\r
+  //\r
+  // Size is 24 bits wide so mask upper 8 bits. \r
+  // Does not include FfsFileHeader header size\r
+  // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned.\r
+  //\r
+  Section = (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1);\r
+  FileSize = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r
+  FileSize -= sizeof (EFI_FFS_FILE_HEADER);\r
+\r
+  return FfsProcessSection (\r
+          SectionType, \r
+          Section, \r
+          FileSize, \r
+          SectionData\r
+          );\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+/**\r
+  This service enables discovery of additional firmware files.\r
+\r
+  @param  SearchType            A filter to find files only of this type.\r
+  @param  FwVolHeader           Pointer to the firmware volume header of the volume to search.\r
+                                This parameter must point to a valid FFS volume.\r
+  @param  FileHeader            Pointer to the current file from which to begin searching.\r
+\r
+  @retval EFI_SUCCESS           The file was found.\r
+  @retval EFI_NOT_FOUND         The file was not found.\r
+  @retval EFI_NOT_FOUND         The header checksum was not zero.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FfsFindNextFile (\r
+  IN UINT8                       SearchType,\r
+  IN EFI_PEI_FV_HANDLE           VolumeHandle,\r
+  IN OUT EFI_PEI_FILE_HANDLE     *FileHandle\r
+  )\r
+{\r
+  return FindFileEx (VolumeHandle, NULL, SearchType, FileHandle);\r
+}\r
+\r
+\r
+/**\r
+  This service enables discovery of additional firmware volumes.\r
+\r
+  @param  Instance              This instance of the firmware volume to find.  The value 0 is the\r
+                                Boot Firmware Volume (BFV).\r
+  @param  FwVolHeader           Pointer to the firmware volume header of the volume to return.\r
+\r
+  @retval EFI_SUCCESS           The volume was found.\r
+  @retval EFI_NOT_FOUND         The volume was not found.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FfsFindNextVolume (\r
+  IN UINTN                          Instance,\r
+  IN OUT EFI_PEI_FV_HANDLE          *VolumeHandle\r
+  )\r
+{\r
+  EFI_PEI_HOB_POINTERS        Hob;\r
+  \r
+\r
+  Hob.Raw = GetHobList ();\r
+  if (Hob.Raw == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  \r
+  do {\r
+    Hob.Raw = GetNextHob (EFI_HOB_TYPE_FV, Hob.Raw);\r
+    if (Hob.Raw != NULL) {\r
+      if (Instance-- == 0) {\r
+        *VolumeHandle = (EFI_PEI_FV_HANDLE)(UINTN)(Hob.FirmwareVolume->BaseAddress);\r
+        return EFI_SUCCESS;\r
+      }\r
+\r
+      Hob.Raw = GetNextHob (EFI_HOB_TYPE_FV, GET_NEXT_HOB (Hob));\r
+    }\r
+  } while (Hob.Raw != NULL);\r
+    \r
+  return EFI_NOT_FOUND;\r
+\r
+}\r
+\r
+\r
+/**\r
+  Find a file in the volume by name\r
+  \r
+  @param FileName       A pointer to the name of the file to\r
+                        find within the firmware volume.\r
+\r
+  @param VolumeHandle   The firmware volume to search FileHandle\r
+                        Upon exit, points to the found file's\r
+                        handle or NULL if it could not be found.\r
+\r
+  @retval EFI_SUCCESS             File was found.\r
+\r
+  @retval EFI_NOT_FOUND           File was not found.\r
+\r
+  @retval EFI_INVALID_PARAMETER   VolumeHandle or FileHandle or\r
+                                  FileName was NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI \r
+FfsFindFileByName (\r
+  IN  CONST EFI_GUID        *FileName,\r
+  IN  EFI_PEI_FV_HANDLE     VolumeHandle,\r
+  OUT EFI_PEI_FILE_HANDLE   *FileHandle\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  if ((VolumeHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  Status = FindFileEx (VolumeHandle, FileName, 0, FileHandle);\r
+  if (Status == EFI_NOT_FOUND) {\r
+    *FileHandle = NULL;\r
+  }\r
+  return Status;\r
+}\r
+\r
+\r
+\r
+\r
+/**\r
+  Get information about the file by name.\r
+\r
+  @param FileHandle   Handle of the file.\r
+\r
+  @param FileInfo     Upon exit, points to the file's\r
+                      information.\r
+\r
+  @retval EFI_SUCCESS             File information returned.\r
+  \r
+  @retval EFI_INVALID_PARAMETER   If FileHandle does not\r
+                                  represent a valid file.\r
+  \r
+  @retval EFI_INVALID_PARAMETER   If FileInfo is NULL.\r
+  \r
+**/\r
+EFI_STATUS\r
+EFIAPI \r
+FfsGetFileInfo (\r
+  IN EFI_PEI_FILE_HANDLE  FileHandle,\r
+  OUT EFI_FV_FILE_INFO    *FileInfo\r
+  )\r
+{\r
+  UINT8                       FileState;\r
+  UINT8                       ErasePolarity;\r
+  EFI_FFS_FILE_HEADER         *FileHeader;\r
+  EFI_PEI_FV_HANDLE           VolumeHandle;\r
+\r
+  if ((FileHandle == NULL) || (FileInfo == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  VolumeHandle = 0;\r
+  //\r
+  // Retrieve the FirmwareVolume which the file resides in.\r
+  //\r
+  if (!FileHandleToVolume(FileHandle, &VolumeHandle)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (((EFI_FIRMWARE_VOLUME_HEADER*)VolumeHandle)->Attributes & EFI_FVB2_ERASE_POLARITY) {\r
+    ErasePolarity = 1;\r
+  } else {\r
+    ErasePolarity = 0;\r
+  }\r
+\r
+  //\r
+  // Get FileState which is the highest bit of the State \r
+  //\r
+  FileState = GetFileState (ErasePolarity, (EFI_FFS_FILE_HEADER*)FileHandle);\r
+\r
+  switch (FileState) {\r
+    case EFI_FILE_DATA_VALID:\r
+    case EFI_FILE_MARKED_FOR_UPDATE:\r
+      break;  \r
+    default:\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+  FileHeader = (EFI_FFS_FILE_HEADER *)FileHandle;\r
+  CopyMem (&FileInfo->FileName, &FileHeader->Name, sizeof(EFI_GUID));\r
+  FileInfo->FileType = FileHeader->Type;\r
+  FileInfo->FileAttributes = FileHeader->Attributes;\r
+  FileInfo->BufferSize = ((*(UINT32 *)FileHeader->Size) & 0x00FFFFFF) -  sizeof (EFI_FFS_FILE_HEADER);\r
+  FileInfo->Buffer = (FileHeader + 1);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Get Information about the volume by name\r
+\r
+  @param VolumeHandle   Handle of the volume.\r
+\r
+  @param VolumeInfo     Upon exit, points to the volume's\r
+                        information.\r
+\r
+  @retval EFI_SUCCESS             File information returned.\r
+  \r
+  @retval EFI_INVALID_PARAMETER   If FileHandle does not\r
+                                  represent a valid file.\r
+  \r
+  @retval EFI_INVALID_PARAMETER   If FileInfo is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI \r
+FfsGetVolumeInfo (\r
+  IN EFI_PEI_FV_HANDLE  VolumeHandle,\r
+  OUT EFI_FV_INFO       *VolumeInfo\r
+  )\r
+{\r
+  EFI_FIRMWARE_VOLUME_HEADER             FwVolHeader;\r
+  EFI_FIRMWARE_VOLUME_EXT_HEADER         *FwVolExHeaderInfo;\r
+\r
+  if (VolumeInfo == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  //\r
+  // VolumeHandle may not align at 8 byte, \r
+  // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte. \r
+  // So, Copy FvHeader into the local FvHeader structure.\r
+  //\r
+  CopyMem (&FwVolHeader, VolumeHandle, sizeof (EFI_FIRMWARE_VOLUME_HEADER));\r
+  //\r
+  // Check Fv Image Signature\r
+  //\r
+  if (FwVolHeader.Signature != EFI_FVH_SIGNATURE) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  VolumeInfo->FvAttributes = FwVolHeader.Attributes;\r
+  VolumeInfo->FvStart = (VOID *) VolumeHandle;\r
+  VolumeInfo->FvSize = FwVolHeader.FvLength;\r
+  CopyMem (&VolumeInfo->FvFormat, &FwVolHeader.FileSystemGuid, sizeof(EFI_GUID));\r
+\r
+  if (FwVolHeader.ExtHeaderOffset != 0) {\r
+    FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER*)(((UINT8 *)VolumeHandle) + FwVolHeader.ExtHeaderOffset);\r
+    CopyMem (&VolumeInfo->FvName, &FwVolExHeaderInfo->FvName, sizeof(EFI_GUID));\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Search through every FV until you find a file of type FileType\r
+\r
+       @param FileType             File handle of a Fv type file.\r
+  @param Volumehandle   On succes Volume Handle of the match\r
+  @param FileHandle     On success File Handle of the match\r
+  \r
+  @retval EFI_NOT_FOUND                                FV image can't be found.\r
+  @retval EFI_SUCCESS                                          Successfully found FileType\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FfsAnyFvFindFirstFile (\r
+  IN  EFI_FV_FILETYPE       FileType,\r
+  OUT EFI_PEI_FV_HANDLE     *VolumeHandle,\r
+  OUT EFI_PEI_FILE_HANDLE   *FileHandle\r
+  )\r
+{\r
+  EFI_STATUS        Status;\r
+  UINTN             Instance;\r
+\r
+  //\r
+  // Search every FV for the DXE Core\r
+  //\r
+  Instance    = 0;\r
+  *FileHandle = NULL;\r
+\r
+  while (1)\r
+  {\r
+    Status = FfsFindNextVolume (Instance++, VolumeHandle);\r
+    if (EFI_ERROR (Status))\r
+    {\r
+      break;\r
+    }\r
+\r
+    Status = FfsFindNextFile (FileType, *VolumeHandle, FileHandle);\r
+    if (!EFI_ERROR (Status))\r
+    {\r
+      break;\r
+    }\r
+  }\r
+  \r
+  return Status;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Get Fv image from the FV type file, then add FV & FV2 Hob.\r
+\r
+       @param FileHandle               File handle of a Fv type file.\r
+\r
+\r
+  @retval EFI_NOT_FOUND                                FV image can't be found.\r
+  @retval EFI_SUCCESS                                          Successfully to process it.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FfsProcessFvFile (\r
+  IN  EFI_PEI_FILE_HANDLE   FvFileHandle\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_PEI_FV_HANDLE     FvImageHandle;\r
+  EFI_FV_INFO           FvImageInfo;\r
+  UINT32                FvAlignment;\r
+  VOID                  *FvBuffer;\r
+  EFI_PEI_HOB_POINTERS  HobFv2;\r
+\r
+  FvBuffer             = NULL;\r
+\r
+\r
+  //\r
+  // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r
+  // been extracted.\r
+  //\r
+  HobFv2.Raw = GetHobList ();\r
+  while ((HobFv2.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobFv2.Raw)) != NULL) {\r
+    if (CompareGuid (&(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name), &HobFv2.FirmwareVolume2->FileName)) {\r
+      //\r
+      // this FILE has been dispatched, it will not be dispatched again.\r
+      //\r
+      return EFI_SUCCESS;\r
+    }\r
+    HobFv2.Raw = GET_NEXT_HOB (HobFv2);\r
+  }\r
+\r
+  //\r
+  // Find FvImage in FvFile\r
+  //\r
+  Status = FfsFindSectionData (EFI_SECTION_FIRMWARE_VOLUME_IMAGE, FvFileHandle, (VOID **)&FvImageHandle);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  \r
+  //\r
+  // Collect FvImage Info.\r
+  //\r
+  ZeroMem (&FvImageInfo, sizeof (FvImageInfo));\r
+  Status = FfsGetVolumeInfo (FvImageHandle, &FvImageInfo);\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  //\r
+  // FvAlignment must be more than 8 bytes required by FvHeader structure.\r
+  //\r
+  FvAlignment = 1 << ((FvImageInfo.FvAttributes & EFI_FVB2_ALIGNMENT) >> 16);\r
+  if (FvAlignment < 8) {\r
+    FvAlignment = 8;\r
+  }\r
+  \r
+  //\r
+  // Check FvImage\r
+  //\r
+  if ((UINTN) FvImageInfo.FvStart % FvAlignment != 0) {\r
+    FvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvImageInfo.FvSize), FvAlignment);\r
+    if (FvBuffer == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    CopyMem (FvBuffer, FvImageInfo.FvStart, (UINTN) FvImageInfo.FvSize);\r
+    //\r
+    // Update FvImageInfo after reload FvImage to new aligned memory\r
+    //\r
+    FfsGetVolumeInfo ((EFI_PEI_FV_HANDLE) FvBuffer, &FvImageInfo);\r
+  }\r
+\r
+\r
+  //\r
+  // Inform HOB consumer phase, i.e. DXE core, the existance of this FV\r
+  //\r
+  BuildFvHob ((EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart, FvImageInfo.FvSize);\r
+  \r
+  //\r
+  // Makes the encapsulated volume show up in DXE phase to skip processing of\r
+  // encapsulated file again.\r
+  //\r
+  BuildFv2Hob (\r
+    (EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart,\r
+    FvImageInfo.FvSize,\r
+    &FvImageInfo.FvName,\r
+    &(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name)\r
+    );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
index 77fe32898bab6e3eb2191566b83c11e17aa07ab7..d637277d2a3d423616e20fbd53e2ef8af991fae5 100644 (file)
@@ -1,46 +1,46 @@
-/** @file
-  Library that helps implement monolithic PEI (i.e. PEI part of SEC)
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef _PI_PEI_H_
-#define _PI_PEI_H_
-
-#include <PiPei.h>
-
-#include <Library/BaseLib.h>
-#include <Library/PrePiLib.h>
-#include <Library/PcdLib.h>
-#include <Library/DebugLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/UefiDecompressLib.h>
-#include <Library/PeCoffLib.h>
-#include <Library/CacheMaintenanceLib.h>
-#include <Library/TimerLib.h>
-#include <Library/PerformanceLib.h>
-
-#include <Guid/MemoryAllocationHob.h>
-
-
-#define GET_HOB_TYPE(Hob)     ((Hob).Header->HobType)
-#define GET_HOB_LENGTH(Hob)   ((Hob).Header->HobLength)
-#define GET_NEXT_HOB(Hob)     ((Hob).Raw + GET_HOB_LENGTH (Hob))
-#define END_OF_HOB_LIST(Hob)  (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_END_OF_HOB_LIST)
-
-//
-// Get the data and data size field of GUID 
-//
-#define GET_GUID_HOB_DATA(GuidHob)      ((VOID *) (((UINT8 *) &((GuidHob)->Name)) + sizeof (EFI_GUID)))
-#define GET_GUID_HOB_DATA_SIZE(GuidHob) (((GuidHob)->Header).HobLength - sizeof (EFI_HOB_GUID_TYPE))
-
-#endif
+/** @file\r
+  Library that helps implement monolithic PEI (i.e. PEI part of SEC)\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _PI_PEI_H_\r
+#define _PI_PEI_H_\r
+\r
+#include <PiPei.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/PrePiLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiDecompressLib.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/CacheMaintenanceLib.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/PerformanceLib.h>\r
+\r
+#include <Guid/MemoryAllocationHob.h>\r
+\r
+\r
+#define GET_HOB_TYPE(Hob)     ((Hob).Header->HobType)\r
+#define GET_HOB_LENGTH(Hob)   ((Hob).Header->HobLength)\r
+#define GET_NEXT_HOB(Hob)     ((Hob).Raw + GET_HOB_LENGTH (Hob))\r
+#define END_OF_HOB_LIST(Hob)  (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_END_OF_HOB_LIST)\r
+\r
+//\r
+// Get the data and data size field of GUID \r
+//\r
+#define GET_GUID_HOB_DATA(GuidHob)      ((VOID *) (((UINT8 *) &((GuidHob)->Name)) + sizeof (EFI_GUID)))\r
+#define GET_GUID_HOB_DATA_SIZE(GuidHob) (((GuidHob)->Header).HobLength - sizeof (EFI_HOB_GUID_TYPE))\r
+\r
+#endif\r
index e46cafec3bbeb1ce5bc6774987dc5b8c755605be..4cc974f1a9b3cc152b86c71ad8e48fb5b777bbf8 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <PrePi.h>
-
-//
-// Hack to work in NT32
-//
-EFI_STATUS
-
-EFIAPI
-
-SecWinNtPeiLoadFile (
-  IN  VOID                    *Pe32Data,
-  IN  EFI_PHYSICAL_ADDRESS    *ImageAddress,
-  IN  UINT64                  *ImageSize,
-  IN  EFI_PHYSICAL_ADDRESS    *EntryPoint
-  );
-
-
-EFI_STATUS
-EFIAPI
-LoadPeCoffImage (
-  IN  VOID                                      *PeCoffImage,
-  OUT EFI_PHYSICAL_ADDRESS                      *ImageAddress,
-  OUT UINT64                                    *ImageSize,
-  OUT EFI_PHYSICAL_ADDRESS                      *EntryPoint
-  )
-{
-  RETURN_STATUS                 Status;
-  PE_COFF_LOADER_IMAGE_CONTEXT  ImageContext;
-  VOID                           *Buffer;
-
-  ZeroMem (&ImageContext, sizeof (ImageContext));
-    
-  ImageContext.Handle    = PeCoffImage;
-  ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
-
-  Status = PeCoffLoaderGetImageInfo (&ImageContext);
-  ASSERT_EFI_ERROR (Status);
-  
-
-  //
-  // Allocate Memory for the image
-  //
-  Buffer = AllocatePages (EFI_SIZE_TO_PAGES((UINT32)ImageContext.ImageSize));
-  ASSERT (Buffer != 0);
-
-
-  ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer;
-
-  //
-  // Load the image to our new buffer
-  //
-  Status = PeCoffLoaderLoadImage (&ImageContext);
-  ASSERT_EFI_ERROR (Status);
-
-  //
-  // Relocate the image in our new buffer
-  //
-  Status = PeCoffLoaderRelocateImage (&ImageContext);
-  ASSERT_EFI_ERROR (Status);
-
-
-  *ImageAddress = ImageContext.ImageAddress;
-  *ImageSize    = ImageContext.ImageSize;
-  *EntryPoint   = ImageContext.EntryPoint;
-
-  //
-  // Flush not needed for all architectures. We could have a processor specific
-  // function in this library that does the no-op if needed.
-  //
-  InvalidateInstructionCacheRange ((VOID *)(UINTN)*ImageAddress, (UINTN)*ImageSize);
-
-  return Status;
-}
-
-
-
-typedef 
-VOID
-(EFIAPI *DXE_CORE_ENTRY_POINT) (
-  IN  VOID *HobStart
-  );
-
-EFI_STATUS
-EFIAPI
-LoadDxeCoreFromFfsFile (
-  IN EFI_PEI_FILE_HANDLE  FileHandle,
-  IN UINTN                StackSize
-  )
-{
-  EFI_STATUS              Status;
-  VOID                    *PeCoffImage;
-  EFI_PHYSICAL_ADDRESS    ImageAddress;
-  UINT64                  ImageSize;
-  EFI_PHYSICAL_ADDRESS    EntryPoint;
-  VOID                    *BaseOfStack;
-  VOID                    *TopOfStack;
-  VOID                    *Hob;
-  EFI_FV_FILE_INFO        FvFileInfo;
-
-  Status = FfsFindSectionData (EFI_SECTION_PE32, FileHandle, &PeCoffImage);
-  if (EFI_ERROR  (Status)) {
-    return Status;
-  }
-
-  
-  Status = LoadPeCoffImage (PeCoffImage, &ImageAddress, &ImageSize, &EntryPoint);
-// For NT32 Debug  Status = SecWinNtPeiLoadFile (PeCoffImage, &ImageAddress, &ImageSize, &EntryPoint);
-  ASSERT_EFI_ERROR (Status);
-
-  //
-  // Extract the DxeCore GUID file name.
-  //
-  Status = FfsGetFileInfo (FileHandle, &FvFileInfo);
-  ASSERT_EFI_ERROR (Status);
-
-  BuildModuleHob (&FvFileInfo.FileName, (EFI_PHYSICAL_ADDRESS)(UINTN)ImageAddress, EFI_SIZE_TO_PAGES ((UINT32) ImageSize) * EFI_PAGE_SIZE, EntryPoint);
-  
-  DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading DxeCore at 0x%10p EntryPoint=0x%10p\n", (VOID *)(UINTN)ImageAddress, (VOID *)(UINTN)EntryPoint));
-
-  Hob = GetHobList ();
-  if (StackSize == 0) {
-    // User the current stack
-  
-    ((DXE_CORE_ENTRY_POINT)(UINTN)EntryPoint) (Hob);
-  } else {
-    
-    //
-    // Allocate 128KB for the Stack
-    //
-    BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (StackSize));
-    ASSERT (BaseOfStack != NULL);
-  
-    //
-    // Compute the top of the stack we were allocated. Pre-allocate a UINTN
-    // for safety.
-    //
-    TopOfStack = (VOID *) ((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (StackSize) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);
-    TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
-
-    //
-    // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.
-    //    
-    UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN) BaseOfStack, StackSize);
-
-    SwitchStack (
-      (SWITCH_STACK_ENTRY_POINT)(UINTN)EntryPoint,
-      Hob,
-      NULL,
-      TopOfStack
-      );
-
-  }
-  
-  // Should never get here as DXE Core does not return
-  DEBUG ((EFI_D_ERROR, "DxeCore returned\n"));
-  ASSERT (FALSE);
-  
-  return EFI_DEVICE_ERROR;
-}
-
-
-
-EFI_STATUS
-EFIAPI
-LoadDxeCoreFromFv (
-  IN UINTN  *FvInstance,   OPTIONAL
-  IN UINTN  StackSize
-  )
-{
-  EFI_STATUS          Status;
-  EFI_PEI_FV_HANDLE   VolumeHandle;
-  EFI_PEI_FILE_HANDLE FileHandle = NULL;
-
-  if (FvInstance != NULL) {
-    //
-    // Caller passed in a specific FV to try, so only try that one
-    //
-    Status = FfsFindNextVolume (*FvInstance, &VolumeHandle);
-    if (!EFI_ERROR (Status)) {
-      Status = FfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE, VolumeHandle, &FileHandle);
-    }
-  } else {
-    Status = FfsAnyFvFindFirstFile (EFI_FV_FILETYPE_DXE_CORE, &VolumeHandle, &FileHandle);
-  }
-
-  if (!EFI_ERROR (Status)) {
-    return LoadDxeCoreFromFfsFile (FileHandle, StackSize);
-  } 
-  
-  return Status;  
-}
-
-
-EFI_STATUS
-EFIAPI
-DecompressFirstFv (
-  VOID
-  )
-{
-  EFI_STATUS          Status;
-  EFI_PEI_FV_HANDLE   VolumeHandle;
-  EFI_PEI_FILE_HANDLE FileHandle;
-
-  Status = FfsAnyFvFindFirstFile (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, &VolumeHandle, &FileHandle);
-  if (!EFI_ERROR (Status)) {
-    Status = FfsProcessFvFile (FileHandle);
-  }
-  
-  return Status;
-}
-
-
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PrePi.h>\r
+\r
+//\r
+// Hack to work in NT32\r
+//\r
+EFI_STATUS\r
+\r
+EFIAPI\r
+\r
+SecWinNtPeiLoadFile (\r
+  IN  VOID                    *Pe32Data,\r
+  IN  EFI_PHYSICAL_ADDRESS    *ImageAddress,\r
+  IN  UINT64                  *ImageSize,\r
+  IN  EFI_PHYSICAL_ADDRESS    *EntryPoint\r
+  );\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+LoadPeCoffImage (\r
+  IN  VOID                                      *PeCoffImage,\r
+  OUT EFI_PHYSICAL_ADDRESS                      *ImageAddress,\r
+  OUT UINT64                                    *ImageSize,\r
+  OUT EFI_PHYSICAL_ADDRESS                      *EntryPoint\r
+  )\r
+{\r
+  RETURN_STATUS                 Status;\r
+  PE_COFF_LOADER_IMAGE_CONTEXT  ImageContext;\r
+  VOID                           *Buffer;\r
+\r
+  ZeroMem (&ImageContext, sizeof (ImageContext));\r
+    \r
+  ImageContext.Handle    = PeCoffImage;\r
+  ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;\r
+\r
+  Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+\r
+  //\r
+  // Allocate Memory for the image\r
+  //\r
+  Buffer = AllocatePages (EFI_SIZE_TO_PAGES((UINT32)ImageContext.ImageSize));\r
+  ASSERT (Buffer != 0);\r
+\r
+\r
+  ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer;\r
+\r
+  //\r
+  // Load the image to our new buffer\r
+  //\r
+  Status = PeCoffLoaderLoadImage (&ImageContext);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Relocate the image in our new buffer\r
+  //\r
+  Status = PeCoffLoaderRelocateImage (&ImageContext);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  *ImageAddress = ImageContext.ImageAddress;\r
+  *ImageSize    = ImageContext.ImageSize;\r
+  *EntryPoint   = ImageContext.EntryPoint;\r
+\r
+  //\r
+  // Flush not needed for all architectures. We could have a processor specific\r
+  // function in this library that does the no-op if needed.\r
+  //\r
+  InvalidateInstructionCacheRange ((VOID *)(UINTN)*ImageAddress, (UINTN)*ImageSize);\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+\r
+typedef \r
+VOID\r
+(EFIAPI *DXE_CORE_ENTRY_POINT) (\r
+  IN  VOID *HobStart\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+LoadDxeCoreFromFfsFile (\r
+  IN EFI_PEI_FILE_HANDLE  FileHandle,\r
+  IN UINTN                StackSize\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  VOID                    *PeCoffImage;\r
+  EFI_PHYSICAL_ADDRESS    ImageAddress;\r
+  UINT64                  ImageSize;\r
+  EFI_PHYSICAL_ADDRESS    EntryPoint;\r
+  VOID                    *BaseOfStack;\r
+  VOID                    *TopOfStack;\r
+  VOID                    *Hob;\r
+  EFI_FV_FILE_INFO        FvFileInfo;\r
+\r
+  Status = FfsFindSectionData (EFI_SECTION_PE32, FileHandle, &PeCoffImage);\r
+  if (EFI_ERROR  (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  \r
+  Status = LoadPeCoffImage (PeCoffImage, &ImageAddress, &ImageSize, &EntryPoint);\r
+// For NT32 Debug  Status = SecWinNtPeiLoadFile (PeCoffImage, &ImageAddress, &ImageSize, &EntryPoint);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Extract the DxeCore GUID file name.\r
+  //\r
+  Status = FfsGetFileInfo (FileHandle, &FvFileInfo);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  BuildModuleHob (&FvFileInfo.FileName, (EFI_PHYSICAL_ADDRESS)(UINTN)ImageAddress, EFI_SIZE_TO_PAGES ((UINT32) ImageSize) * EFI_PAGE_SIZE, EntryPoint);\r
+  \r
+  DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading DxeCore at 0x%10p EntryPoint=0x%10p\n", (VOID *)(UINTN)ImageAddress, (VOID *)(UINTN)EntryPoint));\r
+\r
+  Hob = GetHobList ();\r
+  if (StackSize == 0) {\r
+    // User the current stack\r
+  \r
+    ((DXE_CORE_ENTRY_POINT)(UINTN)EntryPoint) (Hob);\r
+  } else {\r
+    \r
+    //\r
+    // Allocate 128KB for the Stack\r
+    //\r
+    BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (StackSize));\r
+    ASSERT (BaseOfStack != NULL);\r
+  \r
+    //\r
+    // Compute the top of the stack we were allocated. Pre-allocate a UINTN\r
+    // for safety.\r
+    //\r
+    TopOfStack = (VOID *) ((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (StackSize) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);\r
+    TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
+\r
+    //\r
+    // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.\r
+    //    \r
+    UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN) BaseOfStack, StackSize);\r
+\r
+    SwitchStack (\r
+      (SWITCH_STACK_ENTRY_POINT)(UINTN)EntryPoint,\r
+      Hob,\r
+      NULL,\r
+      TopOfStack\r
+      );\r
+\r
+  }\r
+  \r
+  // Should never get here as DXE Core does not return\r
+  DEBUG ((EFI_D_ERROR, "DxeCore returned\n"));\r
+  ASSERT (FALSE);\r
+  \r
+  return EFI_DEVICE_ERROR;\r
+}\r
+\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+LoadDxeCoreFromFv (\r
+  IN UINTN  *FvInstance,   OPTIONAL\r
+  IN UINTN  StackSize\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  EFI_PEI_FV_HANDLE   VolumeHandle;\r
+  EFI_PEI_FILE_HANDLE FileHandle = NULL;\r
+\r
+  if (FvInstance != NULL) {\r
+    //\r
+    // Caller passed in a specific FV to try, so only try that one\r
+    //\r
+    Status = FfsFindNextVolume (*FvInstance, &VolumeHandle);\r
+    if (!EFI_ERROR (Status)) {\r
+      Status = FfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE, VolumeHandle, &FileHandle);\r
+    }\r
+  } else {\r
+    Status = FfsAnyFvFindFirstFile (EFI_FV_FILETYPE_DXE_CORE, &VolumeHandle, &FileHandle);\r
+  }\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    return LoadDxeCoreFromFfsFile (FileHandle, StackSize);\r
+  } \r
+  \r
+  return Status;  \r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+DecompressFirstFv (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  EFI_PEI_FV_HANDLE   VolumeHandle;\r
+  EFI_PEI_FILE_HANDLE FileHandle;\r
+\r
+  Status = FfsAnyFvFindFirstFile (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, &VolumeHandle, &FileHandle);\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = FfsProcessFvFile (FileHandle);\r
+  }\r
+  \r
+  return Status;\r
+}\r
+\r
+\r
index f898808deb71f686a6f663320b50b79a586b0f8f..8d60d5ab5d411d22152adab2fbf9560d885c0291 100644 (file)
-/** @file
-  Library that helps implement monolithic PEI
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <PrePi.h>
-#include <Library/ReportStatusCodeLib.h>
-#include <Library/SerialPortLib.h>
-#include <Library/PrintLib.h>
-
-#include <Protocol/StatusCode.h>
-#include <Guid/StatusCodeDataTypeId.h>
-#include <Guid/StatusCodeDataTypeDebug.h>
-#include <FrameworkPei.h>
-
-#define EFI_STATUS_CODE_DATA_MAX_SIZE 200
-
-EFI_STATUS
-EFIAPI
-SerialReportStatusCode (
-  IN EFI_STATUS_CODE_TYPE             CodeType,
-  IN EFI_STATUS_CODE_VALUE            Value,
-  IN UINT32                           Instance,
-  IN CONST EFI_GUID                   *CallerId,
-  IN CONST EFI_STATUS_CODE_DATA       *Data OPTIONAL
-  );
-
-
-EFI_STATUS_CODE_PROTOCOL gStatusCode = { 
-  (EFI_REPORT_STATUS_CODE)SerialReportStatusCode 
-};
-
-/**
-  Extracts ASSERT() information from a status code structure.
-
-  Converts the status code specified by CodeType, Value, and Data to the ASSERT()
-  arguments specified by Filename, Description, and LineNumber.  If CodeType is
-  an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and
-  Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract
-  Filename, Description, and LineNumber from the optional data area of the
-  status code buffer specified by Data.  The optional data area of Data contains
-  a Null-terminated ASCII string for the FileName, followed by a Null-terminated
-  ASCII string for the Description, followed by a 32-bit LineNumber.  If the
-  ASSERT() information could be extracted from Data, then return TRUE.
-  Otherwise, FALSE is returned.
-
-  If Data is NULL, then ASSERT().
-  If Filename is NULL, then ASSERT().
-  If Description is NULL, then ASSERT().
-  If LineNumber is NULL, then ASSERT().
-
-  @param  CodeType     The type of status code being converted.
-  @param  Value        The status code value being converted.
-  @param  Data         Pointer to status code data buffer.
-  @param  Filename     Pointer to the source file name that generated the ASSERT().
-  @param  Description  Pointer to the description of the ASSERT().
-  @param  LineNumber   Pointer to source line number that generated the ASSERT().
-
-  @retval  TRUE   The status code specified by CodeType, Value, and Data was
-                  converted ASSERT() arguments specified by Filename, Description,
-                  and LineNumber.
-  @retval  FALSE  The status code specified by CodeType, Value, and Data could
-                  not be converted to ASSERT() arguments.
-
-**/
-BOOLEAN
-EFIAPI
-ReportStatusCodeExtractAssertInfo (
-  IN EFI_STATUS_CODE_TYPE        CodeType,
-  IN EFI_STATUS_CODE_VALUE       Value,
-  IN CONST EFI_STATUS_CODE_DATA  *Data,
-  OUT CHAR8                      **Filename,
-  OUT CHAR8                      **Description,
-  OUT UINT32                     *LineNumber
-  )
-{
-  EFI_DEBUG_ASSERT_DATA  *AssertData;
-
-  ASSERT (Data        != NULL);
-  ASSERT (Filename    != NULL);
-  ASSERT (Description != NULL);
-  ASSERT (LineNumber  != NULL);
-
-  if (((CodeType & EFI_STATUS_CODE_TYPE_MASK)      == EFI_ERROR_CODE) &&
-      ((CodeType & EFI_STATUS_CODE_SEVERITY_MASK)  == EFI_ERROR_UNRECOVERED) &&
-      ((Value    & EFI_STATUS_CODE_OPERATION_MASK) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE)) {
-    AssertData   = (EFI_DEBUG_ASSERT_DATA *)(Data + 1);
-    *Filename    = (CHAR8 *)(AssertData + 1);
-    *Description = *Filename + AsciiStrLen (*Filename) + 1;
-    *LineNumber  = AssertData->LineNumber;
-    return TRUE;
-  }
-  return FALSE;
-}
-
-
-/**
-  Extracts DEBUG() information from a status code structure.
-
-  Converts the status code specified by Data to the DEBUG() arguments specified
-  by ErrorLevel, Marker, and Format.  If type GUID in Data is
-  EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and
-  Format from the optional data area of the status code buffer specified by Data.
-  The optional data area of Data contains a 32-bit ErrorLevel followed by Marker
-  which is 12 UINTN parameters, followed by a Null-terminated ASCII string for
-  the Format.  If the DEBUG() information could be extracted from Data, then
-  return TRUE.  Otherwise, FALSE is returned.
-
-  If Data is NULL, then ASSERT().
-  If ErrorLevel is NULL, then ASSERT().
-  If Marker is NULL, then ASSERT().
-  If Format is NULL, then ASSERT().
-
-  @param  Data        Pointer to status code data buffer.
-  @param  ErrorLevel  Pointer to error level mask for a debug message.
-  @param  Marker      Pointer to the variable argument list associated with Format.
-  @param  Format      Pointer to a Null-terminated ASCII format string of a
-                      debug message.
-
-  @retval  TRUE   The status code specified by Data was converted DEBUG() arguments
-                  specified by ErrorLevel, Marker, and Format.
-  @retval  FALSE  The status code specified by Data could not be converted to
-                  DEBUG() arguments.
-
-**/
-BOOLEAN
-EFIAPI
-ReportStatusCodeExtractDebugInfo (
-  IN CONST EFI_STATUS_CODE_DATA  *Data,
-  OUT UINT32                     *ErrorLevel,
-  OUT BASE_LIST                  *Marker,
-  OUT CHAR8                      **Format
-  )
-{
-  EFI_DEBUG_INFO  *DebugInfo;
-
-  ASSERT (Data          != NULL);
-  ASSERT (ErrorLevel    != NULL);
-  ASSERT (Marker     != NULL);
-  ASSERT (Format     != NULL);
-
-  //
-  // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE
-  //
-  if (!CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeDebugGuid)) {
-    return FALSE;
-  }
-
-  //
-  // Retrieve the debug information from the status code record
-  //
-  DebugInfo = (EFI_DEBUG_INFO *)(Data + 1);
-
-  *ErrorLevel = DebugInfo->ErrorLevel;
-
-  //
-  // The first 12 * UINTN bytes of the string are really an
-  // argument stack to support varargs on the Format string.
-  //
-  *Marker = (BASE_LIST) (DebugInfo + 1);
-  *Format = (CHAR8 *)(((UINT64 *)*Marker) + 12);
-
-  return TRUE;
-}
-
-
-
-
-EFI_STATUS
-EFIAPI
-SerialReportStatusCode (
-  IN EFI_STATUS_CODE_TYPE             CodeType,
-  IN EFI_STATUS_CODE_VALUE            Value,
-  IN UINT32                           Instance,
-  IN CONST EFI_GUID                   *CallerId,
-  IN CONST 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;
-  BASE_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.
-    //
-    SerialPortWrite ((UINT8 *)Buffer, CharCount);
-    return EFI_SUCCESS;
-
-  } else if (Data != NULL &&
-    ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
-    
-    //
-    // Print DEBUG() information into output buffer.
-    //
-    CharCount = AsciiBSPrint (
-                  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    = (BASE_LIST) (DebugInfo + 1);
-    Format    = (CHAR8 *) (((UINT64 *) (DebugInfo + 1)) + 12);
-
-    CharCount = AsciiBSPrint (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
-                  );
-
-  }
-
-  SerialPortWrite ((UINT8 *)Buffer, CharCount);
-  return EFI_SUCCESS;
-
-}
-
-
-VOID
-EFIAPI
-AddDxeCoreReportStatusCodeCallback (
-  VOID
-  )
-{
-  BuildGuidDataHob (&gEfiStatusCodeRuntimeProtocolGuid, &gStatusCode, sizeof(VOID *));
-}
-
+/** @file\r
+  Library that helps implement monolithic PEI\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PrePi.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
+#include <Library/SerialPortLib.h>\r
+#include <Library/PrintLib.h>\r
+\r
+#include <Protocol/StatusCode.h>\r
+#include <Guid/StatusCodeDataTypeId.h>\r
+#include <Guid/StatusCodeDataTypeDebug.h>\r
+#include <FrameworkPei.h>\r
+\r
+#define EFI_STATUS_CODE_DATA_MAX_SIZE 200\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SerialReportStatusCode (\r
+  IN EFI_STATUS_CODE_TYPE             CodeType,\r
+  IN EFI_STATUS_CODE_VALUE            Value,\r
+  IN UINT32                           Instance,\r
+  IN CONST EFI_GUID                   *CallerId,\r
+  IN CONST EFI_STATUS_CODE_DATA       *Data OPTIONAL\r
+  );\r
+\r
+\r
+EFI_STATUS_CODE_PROTOCOL gStatusCode = { \r
+  (EFI_REPORT_STATUS_CODE)SerialReportStatusCode \r
+};\r
+\r
+/**\r
+  Extracts ASSERT() information from a status code structure.\r
+\r
+  Converts the status code specified by CodeType, Value, and Data to the ASSERT()\r
+  arguments specified by Filename, Description, and LineNumber.  If CodeType is\r
+  an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and\r
+  Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract\r
+  Filename, Description, and LineNumber from the optional data area of the\r
+  status code buffer specified by Data.  The optional data area of Data contains\r
+  a Null-terminated ASCII string for the FileName, followed by a Null-terminated\r
+  ASCII string for the Description, followed by a 32-bit LineNumber.  If the\r
+  ASSERT() information could be extracted from Data, then return TRUE.\r
+  Otherwise, FALSE is returned.\r
+\r
+  If Data is NULL, then ASSERT().\r
+  If Filename is NULL, then ASSERT().\r
+  If Description is NULL, then ASSERT().\r
+  If LineNumber is NULL, then ASSERT().\r
+\r
+  @param  CodeType     The type of status code being converted.\r
+  @param  Value        The status code value being converted.\r
+  @param  Data         Pointer to status code data buffer.\r
+  @param  Filename     Pointer to the source file name that generated the ASSERT().\r
+  @param  Description  Pointer to the description of the ASSERT().\r
+  @param  LineNumber   Pointer to source line number that generated the ASSERT().\r
+\r
+  @retval  TRUE   The status code specified by CodeType, Value, and Data was\r
+                  converted ASSERT() arguments specified by Filename, Description,\r
+                  and LineNumber.\r
+  @retval  FALSE  The status code specified by CodeType, Value, and Data could\r
+                  not be converted to ASSERT() arguments.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+ReportStatusCodeExtractAssertInfo (\r
+  IN EFI_STATUS_CODE_TYPE        CodeType,\r
+  IN EFI_STATUS_CODE_VALUE       Value,\r
+  IN CONST EFI_STATUS_CODE_DATA  *Data,\r
+  OUT CHAR8                      **Filename,\r
+  OUT CHAR8                      **Description,\r
+  OUT UINT32                     *LineNumber\r
+  )\r
+{\r
+  EFI_DEBUG_ASSERT_DATA  *AssertData;\r
+\r
+  ASSERT (Data        != NULL);\r
+  ASSERT (Filename    != NULL);\r
+  ASSERT (Description != NULL);\r
+  ASSERT (LineNumber  != NULL);\r
+\r
+  if (((CodeType & EFI_STATUS_CODE_TYPE_MASK)      == EFI_ERROR_CODE) &&\r
+      ((CodeType & EFI_STATUS_CODE_SEVERITY_MASK)  == EFI_ERROR_UNRECOVERED) &&\r
+      ((Value    & EFI_STATUS_CODE_OPERATION_MASK) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE)) {\r
+    AssertData   = (EFI_DEBUG_ASSERT_DATA *)(Data + 1);\r
+    *Filename    = (CHAR8 *)(AssertData + 1);\r
+    *Description = *Filename + AsciiStrLen (*Filename) + 1;\r
+    *LineNumber  = AssertData->LineNumber;\r
+    return TRUE;\r
+  }\r
+  return FALSE;\r
+}\r
+\r
+\r
+/**\r
+  Extracts DEBUG() information from a status code structure.\r
+\r
+  Converts the status code specified by Data to the DEBUG() arguments specified\r
+  by ErrorLevel, Marker, and Format.  If type GUID in Data is\r
+  EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and\r
+  Format from the optional data area of the status code buffer specified by Data.\r
+  The optional data area of Data contains a 32-bit ErrorLevel followed by Marker\r
+  which is 12 UINTN parameters, followed by a Null-terminated ASCII string for\r
+  the Format.  If the DEBUG() information could be extracted from Data, then\r
+  return TRUE.  Otherwise, FALSE is returned.\r
+\r
+  If Data is NULL, then ASSERT().\r
+  If ErrorLevel is NULL, then ASSERT().\r
+  If Marker is NULL, then ASSERT().\r
+  If Format is NULL, then ASSERT().\r
+\r
+  @param  Data        Pointer to status code data buffer.\r
+  @param  ErrorLevel  Pointer to error level mask for a debug message.\r
+  @param  Marker      Pointer to the variable argument list associated with Format.\r
+  @param  Format      Pointer to a Null-terminated ASCII format string of a\r
+                      debug message.\r
+\r
+  @retval  TRUE   The status code specified by Data was converted DEBUG() arguments\r
+                  specified by ErrorLevel, Marker, and Format.\r
+  @retval  FALSE  The status code specified by Data could not be converted to\r
+                  DEBUG() arguments.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+ReportStatusCodeExtractDebugInfo (\r
+  IN CONST EFI_STATUS_CODE_DATA  *Data,\r
+  OUT UINT32                     *ErrorLevel,\r
+  OUT BASE_LIST                  *Marker,\r
+  OUT CHAR8                      **Format\r
+  )\r
+{\r
+  EFI_DEBUG_INFO  *DebugInfo;\r
+\r
+  ASSERT (Data          != NULL);\r
+  ASSERT (ErrorLevel    != NULL);\r
+  ASSERT (Marker     != NULL);\r
+  ASSERT (Format     != NULL);\r
+\r
+  //\r
+  // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE\r
+  //\r
+  if (!CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeDebugGuid)) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Retrieve the debug information from the status code record\r
+  //\r
+  DebugInfo = (EFI_DEBUG_INFO *)(Data + 1);\r
+\r
+  *ErrorLevel = DebugInfo->ErrorLevel;\r
+\r
+  //\r
+  // The first 12 * UINTN bytes of the string are really an\r
+  // argument stack to support varargs on the Format string.\r
+  //\r
+  *Marker = (BASE_LIST) (DebugInfo + 1);\r
+  *Format = (CHAR8 *)(((UINT64 *)*Marker) + 12);\r
+\r
+  return TRUE;\r
+}\r
+\r
+\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SerialReportStatusCode (\r
+  IN EFI_STATUS_CODE_TYPE             CodeType,\r
+  IN EFI_STATUS_CODE_VALUE            Value,\r
+  IN UINT32                           Instance,\r
+  IN CONST EFI_GUID                   *CallerId,\r
+  IN CONST EFI_STATUS_CODE_DATA       *Data OPTIONAL\r
+  )\r
+{\r
+  CHAR8           *Filename;\r
+  CHAR8           *Description;\r
+  CHAR8           *Format;\r
+  CHAR8           Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];\r
+  UINT32          ErrorLevel;\r
+  UINT32          LineNumber;\r
+  UINTN           CharCount;\r
+  BASE_LIST       Marker;\r
+  EFI_DEBUG_INFO  *DebugInfo;\r
+\r
+  Buffer[0] = '\0';\r
+\r
+\r
+  if (Data != NULL &&\r
+    ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {\r
+\r
+    //\r
+    // Print ASSERT() information into output buffer.\r
+    //\r
+    CharCount = AsciiSPrint (\r
+                  Buffer,\r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE,\r
+                  "\n\rASSERT!: %a (%d): %a\n\r",\r
+                  Filename,\r
+                  LineNumber,\r
+                  Description\r
+                  );\r
+\r
+\r
+    //\r
+    // Callout to standard output.\r
+    //\r
+    SerialPortWrite ((UINT8 *)Buffer, CharCount);\r
+    return EFI_SUCCESS;\r
+\r
+  } else if (Data != NULL &&\r
+    ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {\r
+    \r
+    //\r
+    // Print DEBUG() information into output buffer.\r
+    //\r
+    CharCount = AsciiBSPrint (\r
+                  Buffer,\r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE,\r
+                  Format,\r
+                  Marker\r
+                  );\r
+\r
+  } else if (Data != NULL &&\r
+             CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&\r
+             (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {\r
+\r
+    //\r
+    // Print specific data into output buffer.\r
+    //\r
+    DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);\r
+    Marker    = (BASE_LIST) (DebugInfo + 1);\r
+    Format    = (CHAR8 *) (((UINT64 *) (DebugInfo + 1)) + 12);\r
+\r
+    CharCount = AsciiBSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);\r
+\r
+  } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {\r
+    //\r
+    // Print ERROR information into output buffer.\r
+    //\r
+\r
+    CharCount = AsciiSPrint (\r
+                  Buffer,\r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE,\r
+                  "ERROR: C%x:V%x I%x",\r
+                  CodeType,\r
+                  Value,\r
+                  Instance\r
+                  );\r
+\r
+    //\r
+    // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.\r
+    //\r
+    if (CallerId != NULL) {\r
+      CharCount += AsciiSPrint (\r
+                     &Buffer[CharCount - 1],\r
+                     (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
+                     " %g",\r
+                     CallerId\r
+                     );\r
+    }\r
+\r
+    if (Data != NULL) {\r
+      CharCount += AsciiSPrint (\r
+                     &Buffer[CharCount - 1],\r
+                     (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
+                     " %x",\r
+                     Data\r
+                     );\r
+\r
+    }\r
+\r
+\r
+    CharCount += AsciiSPrint (\r
+                   &Buffer[CharCount - 1],\r
+                   (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
+                   "\n\r"\r
+                   );\r
+\r
+  } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {\r
+    CharCount = AsciiSPrint (\r
+                  Buffer,\r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE,\r
+                  "PROGRESS CODE: V%x I%x\n\r",\r
+                  Value,\r
+                  Instance\r
+                  );\r
+  } else {\r
+    CharCount = AsciiSPrint (\r
+                  Buffer,\r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE,\r
+                  "Undefined: C%x:V%x I%x\n\r",\r
+                  CodeType,\r
+                  Value,\r
+                  Instance\r
+                  );\r
+\r
+  }\r
+\r
+  SerialPortWrite ((UINT8 *)Buffer, CharCount);\r
+  return EFI_SUCCESS;\r
+\r
+}\r
+\r
+\r
+VOID\r
+EFIAPI\r
+AddDxeCoreReportStatusCodeCallback (\r
+  VOID\r
+  )\r
+{\r
+  BuildGuidDataHob (&gEfiStatusCodeRuntimeProtocolGuid, &gStatusCode, sizeof(VOID *));\r
+}\r
+\r
index b88d9abf5c7b82dbf984387395ffb981bc3df76a..ce0d13257c225567c4cc5424afd632fe13686bdc 100644 (file)
@@ -34,4 +34,4 @@
 [LibraryClasses]\r
   IoLib\r
   DebugLib\r
 [LibraryClasses]\r
   IoLib\r
   DebugLib\r
-  
\ No newline at end of file
+  \r
\ No newline at end of file
index 446c56b39d807e75813c67c1276beee885e99b1a..375cb4942155e6ac588d07d81d3cfe1280be50a4 100644 (file)
@@ -32,4 +32,4 @@
 \r
 [LibraryClasses]\r
   IoLib\r
 \r
 [LibraryClasses]\r
   IoLib\r
-  DebugLib
\ No newline at end of file
+  DebugLib\r
\ No newline at end of file
index a7dad5e3292f81e14da1bb6989a912b3bb21a19e..81f4ac761b36fe017801da84915b33661b3dbcb9 100644 (file)
@@ -1,65 +1,65 @@
-#/** @file
-#  
-#    Component description file for DxeIpl module
-#  
-#   The responsibility of this module is to load the DXE Core from a Firmware Volume. This implementation i used to load a 32-bit DXE Core.
-#  
-#  Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
-#  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                      = TemplateSec
-  FILE_GUID                      = 1D6F730F-5A55-4078-869B-E0A18324BDC8
-  MODULE_TYPE                    = SEC
-  VERSION_STRING                 = 1.0
-
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-#  VALID_ARCHITECTURES           = IA32 X64 ARM
-#
-
-[Sources.common]
-  TemplateSec.c
-
-[Sources.Ia32]
-#  Ia32/ResetVector.asm | MSFT
-#  Ia32/ResetVector.S   | GCC
-
-[Sources.X64]
-#  X64/ResetVector.asm | MSFT
-#  X64/ResetVector.S   | GCC
-
-[Sources.ARM]
-#  Arm/ResetVector.asm | RVCT
-#  Arm/ResetVector.S   | GCC
-
-[Packages]
-  MdePkg/MdePkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  
-
-[LibraryClasses]
-  BaseLib
-  DebugLib
-  BaseMemoryLib
-  UefiDecompressLib
-  PeCoffLib
-  CacheMaintenanceLib
-  PrePiLib
-  
-[Pcd]
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedFdBaseAddress
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedFdSize
-
+#/** @file\r
+#  \r
+#    Component description file for DxeIpl module\r
+#  \r
+#   The responsibility of this module is to load the DXE Core from a Firmware Volume. This implementation i used to load a 32-bit DXE Core.\r
+#  \r
+#  Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = TemplateSec\r
+  FILE_GUID                      = 1D6F730F-5A55-4078-869B-E0A18324BDC8\r
+  MODULE_TYPE                    = SEC\r
+  VERSION_STRING                 = 1.0\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 ARM\r
+#\r
+\r
+[Sources.common]\r
+  TemplateSec.c\r
+\r
+[Sources.Ia32]\r
+#  Ia32/ResetVector.asm | MSFT\r
+#  Ia32/ResetVector.S   | GCC\r
+\r
+[Sources.X64]\r
+#  X64/ResetVector.asm | MSFT\r
+#  X64/ResetVector.S   | GCC\r
+\r
+[Sources.ARM]\r
+#  Arm/ResetVector.asm | RVCT\r
+#  Arm/ResetVector.S   | GCC\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  \r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  BaseMemoryLib\r
+  UefiDecompressLib\r
+  PeCoffLib\r
+  CacheMaintenanceLib\r
+  PrePiLib\r
+  \r
+[Pcd]\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedFdBaseAddress\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedFdSize\r
+\r
index 4a21fb4952dc449ad0edeedfc834d7604e13c03e..9deceea9c17b68206d55461afe364a3b75dc571b 100644 (file)
@@ -47,4 +47,4 @@
   gEfiDriverDiagnostics2ProtocolGuid\r
   \r
 [Depex]\r
   gEfiDriverDiagnostics2ProtocolGuid\r
   \r
 [Depex]\r
-  TRUE
\ No newline at end of file
+  TRUE\r
\ No newline at end of file
index 0056acd6b94683e71f25e59c9aa2f00bc4f4efcf..c63e0a3395b2c6813245ab4023744452118d3a4e 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 "Flash.h"
-
-NAND_PART_INFO_TABLE gNandPartInfoTable[1] = {
-  { 0x2C, 0xBA, 17, 11 }
-};
-
-NAND_FLASH_INFO *gNandFlashInfo = NULL;
-UINT8           *gEccCode;
-UINTN           gNum512BytesChunks = 0;
-
-//
-
-// Device path for SemiHosting. It contains our autogened Caller ID GUID.
-
-//
-
-typedef struct {
-
-  VENDOR_DEVICE_PATH        Guid;
-
-  EFI_DEVICE_PATH_PROTOCOL  End;
-
-} FLASH_DEVICE_PATH;
-
-
-
-FLASH_DEVICE_PATH gDevicePath = {
-
-  {
-
-    { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, sizeof (VENDOR_DEVICE_PATH), 0 },
-
-    EFI_CALLER_ID_GUID
-
-  },
-
-  { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, sizeof (EFI_DEVICE_PATH_PROTOCOL), 0}
-
-};
-
-
-
-//Actual page address = Column address + Page address + Block address.
-UINTN
-GetActualPageAddressInBytes (
-  UINTN BlockIndex,
-  UINTN PageIndex
-)
-{
-  //BlockAddressStart = Start of the Block address in actual NAND
-  //PageAddressStart = Start of the Page address in actual NAND
-  return ((BlockIndex << gNandFlashInfo->BlockAddressStart) + (PageIndex << gNandFlashInfo->PageAddressStart));
-}
-
-VOID
-NandSendCommand (
-  UINT8 Command
-)
-{
-  MmioWrite16(GPMC_NAND_COMMAND_0, Command);
-}
-
-VOID
-NandSendAddress (
-  UINT8 Address
-)
-{
-  MmioWrite16(GPMC_NAND_ADDRESS_0, Address);
-}
-
-UINT16
-NandReadStatus (
-  VOID
-  )
-{
-  //Send READ STATUS command
-  NandSendCommand(READ_STATUS_CMD);
-
-  //Read status.
-  return MmioRead16(GPMC_NAND_DATA_0);
-}
-
-VOID
-NandSendAddressCycles (
-  UINTN Address
-)
-{
-  //Column address
-  NandSendAddress(Address & 0xff);
-  Address >>= 8;
-
-  //Column address
-  NandSendAddress(Address & 0x07);
-  Address >>= 3;
-
-  //Page and Block address
-  NandSendAddress(Address & 0xff);
-  Address >>= 8;
-
-  //Block address
-  NandSendAddress(Address & 0xff);
-  Address >>= 8;
-
-  //Block address
-  NandSendAddress(Address & 0x01);
-}
-
-VOID
-GpmcInit (
-  VOID
-  )
-{
-  //Enable Smart-idle mode.
-  MmioWrite32 (GPMC_SYSCONFIG, SMARTIDLEMODE);
-
-  //Set IRQSTATUS and IRQENABLE to the reset value
-  MmioWrite32 (GPMC_IRQSTATUS, 0x0);
-  MmioWrite32 (GPMC_IRQENABLE, 0x0);
-
-  //Disable GPMC timeout control.
-  MmioWrite32 (GPMC_TIMEOUT_CONTROL, TIMEOUTDISABLE);
-
-  //Set WRITEPROTECT bit to enable write access.
-  MmioWrite32 (GPMC_CONFIG, WRITEPROTECT_HIGH);
-
-  //NOTE: Following GPMC_CONFIGi_0 register settings are taken from u-boot memory dump.
-  MmioWrite32 (GPMC_CONFIG1_0, DEVICETYPE_NAND | DEVICESIZE_X16);
-  MmioWrite32 (GPMC_CONFIG2_0, CSRDOFFTIME | CSWROFFTIME);
-  MmioWrite32 (GPMC_CONFIG3_0, ADVRDOFFTIME | ADVWROFFTIME);
-  MmioWrite32 (GPMC_CONFIG4_0, OEONTIME | OEOFFTIME | WEONTIME | WEOFFTIME);
-  MmioWrite32 (GPMC_CONFIG5_0, RDCYCLETIME | WRCYCLETIME | RDACCESSTIME | PAGEBURSTACCESSTIME);
-  MmioWrite32 (GPMC_CONFIG6_0, WRACCESSTIME | WRDATAONADMUXBUS | CYCLE2CYCLEDELAY | CYCLE2CYCLESAMECSEN);
-  MmioWrite32 (GPMC_CONFIG7_0, MASKADDRESS_128MB | CSVALID | BASEADDRESS);
-}
-
-EFI_STATUS
-NandDetectPart (
-  VOID
-)
-{
-  UINT8      NandInfo = 0;
-  UINT8      PartInfo[5];
-  UINTN      Index;
-  BOOLEAN    Found = FALSE;
-
-  //Send READ ID command
-  NandSendCommand(READ_ID_CMD);
-
-  //Send one address cycle.
-  NandSendAddress(0);
-
-  //Read 5-bytes to idenfity code programmed into the NAND flash devices.
-  //BYTE 0 = Manufacture ID
-  //Byte 1 = Device ID
-  //Byte 2, 3, 4 = Nand part specific information (Page size, Block size etc)
-  for (Index = 0; Index < sizeof(PartInfo); Index++) {
-    PartInfo[Index] = MmioRead16(GPMC_NAND_DATA_0);
-  }
-
-  //Check if the ManufactureId and DeviceId are part of the currently supported nand parts.
-  for (Index = 0; Index < sizeof(gNandPartInfoTable)/sizeof(NAND_PART_INFO_TABLE); Index++) {
-    if (gNandPartInfoTable[Index].ManufactureId == PartInfo[0] && gNandPartInfoTable[Index].DeviceId == PartInfo[1]) {
-      gNandFlashInfo->BlockAddressStart = gNandPartInfoTable[Index].BlockAddressStart;
-      gNandFlashInfo->PageAddressStart = gNandPartInfoTable[Index].PageAddressStart;
-      Found = TRUE;
-      break;
-    }
-  }
-
-  if (Found == FALSE) {
-    DEBUG ((EFI_D_ERROR, "Nand part is not currently supported. Manufacture id: %x, Device id: %x\n", PartInfo[0], PartInfo[1]));
-    return EFI_NOT_FOUND;
-  }
-
-  //Populate NAND_FLASH_INFO based on the result of READ ID command.
-  gNandFlashInfo->ManufactureId = PartInfo[0];
-  gNandFlashInfo->DeviceId = PartInfo[1];
-  NandInfo = PartInfo[3];
-
-  if (PAGE_SIZE(NandInfo) == PAGE_SIZE_2K_VAL) {
-    gNandFlashInfo->PageSize = PAGE_SIZE_2K;
-  } else {
-    DEBUG ((EFI_D_ERROR, "Unknown Page size.\n"));
-    return EFI_DEVICE_ERROR;
-  }
-
-  if (SPARE_AREA_SIZE(NandInfo) == SPARE_AREA_SIZE_64B_VAL) {
-    gNandFlashInfo->SparePageSize = SPARE_AREA_SIZE_64B;
-  } else {
-    DEBUG ((EFI_D_ERROR, "Unknown Spare area size.\n"));
-    return EFI_DEVICE_ERROR;
-  }
-
-  if (BLOCK_SIZE(NandInfo) == BLOCK_SIZE_128K_VAL) {
-    gNandFlashInfo->BlockSize = BLOCK_SIZE_128K;
-  } else {
-    DEBUG ((EFI_D_ERROR, "Unknown Block size.\n"));
-    return EFI_DEVICE_ERROR;
-  }
-
-  if (ORGANIZATION(NandInfo) == ORGANIZATION_X8) {
-    gNandFlashInfo->Organization = 0;
-  } else if (ORGANIZATION(NandInfo) == ORGANIZATION_X16) {
-    gNandFlashInfo->Organization = 1;
-  }
-
-  //Calculate total number of blocks.
-  gNandFlashInfo->NumPagesPerBlock = DivU64x32(gNandFlashInfo->BlockSize, gNandFlashInfo->PageSize);
-
-  return EFI_SUCCESS;
-}
-
-VOID
-NandConfigureEcc (
-  VOID
-  )
-{
-  //Define ECC size 0 and size 1 to 512 bytes
-  MmioWrite32 (GPMC_ECC_SIZE_CONFIG, (ECCSIZE0_512BYTES | ECCSIZE1_512BYTES));
-}
-
-VOID 
-NandEnableEcc (
-  VOID
-  )
-{
-  //Clear all the ECC result registers and select ECC result register 1
-  MmioWrite32 (GPMC_ECC_CONTROL, (ECCCLEAR | ECCPOINTER_REG1));
-
-  //Enable ECC engine on CS0
-  MmioWrite32 (GPMC_ECC_CONFIG, (ECCENABLE | ECCCS_0 | ECC16B));
-}
-
-VOID
-NandDisableEcc (
-  VOID
-  )
-{
-  //Turn off ECC engine.
-  MmioWrite32 (GPMC_ECC_CONFIG, ECCDISABLE);
-}
-
-VOID
-NandCalculateEcc (
-  VOID
-  )
-{
-  UINTN Index;
-  UINTN EccResultRegister;
-  UINTN EccResult;
-
-  //Capture 32-bit ECC result for each 512-bytes chunk.
-  //In our case PageSize is 2K so read ECC1-ECC4 result registers and
-  //generate total of 12-bytes of ECC code for the particular page.
-
-  EccResultRegister = GPMC_ECC1_RESULT;
-
-  for (Index = 0; Index < gNum512BytesChunks; Index++) {
-
-    EccResult = MmioRead32 (EccResultRegister);
-
-    //Calculate ECC code from 32-bit ECC result value.
-    //NOTE: Following calculation is not part of TRM. We got this information 
-    //from Beagleboard mailing list.
-    gEccCode[Index * 3] = EccResult & 0xFF;
-    gEccCode[(Index * 3) + 1] = (EccResult >> 16) & 0xFF;
-    gEccCode[(Index * 3) + 2] = (((EccResult >> 20) & 0xF0) | ((EccResult >> 8) & 0x0F));
-
-    //Point to next ECC result register.
-    EccResultRegister += 4;
-  }
-}
-
-EFI_STATUS
-NandReadPage (
-  IN  UINTN                         BlockIndex,
-  IN  UINTN                         PageIndex,
-  OUT VOID                          *Buffer,
-  OUT UINT8                         *SpareBuffer
-)
-{
-  UINTN      Address;
-  UINTN      Index;
-  UINTN      NumMainAreaWords = (gNandFlashInfo->PageSize/2);
-  UINTN      NumSpareAreaWords = (gNandFlashInfo->SparePageSize/2);
-  UINT16     *MainAreaWordBuffer = Buffer;
-  UINT16     *SpareAreaWordBuffer = (UINT16 *)SpareBuffer;
-  UINTN      Timeout = MAX_RETRY_COUNT;
-
-  //Generate device address in bytes to access specific block and page index
-  Address = GetActualPageAddressInBytes(BlockIndex, PageIndex);
-
-  //Send READ command
-  NandSendCommand(PAGE_READ_CMD);
-
-  //Send 5 Address cycles to access specific device address
-  NandSendAddressCycles(Address);
-
-  //Send READ CONFIRM command
-  NandSendCommand(PAGE_READ_CONFIRM_CMD);
-
-  //Poll till device is busy.
-  while (Timeout) {
-    if ((NandReadStatus() & NAND_READY) == NAND_READY) {
-      break;
-    }
-    Timeout--;
-  }
-
-  if (Timeout == 0) {
-    DEBUG ((EFI_D_ERROR, "Read page timed out.\n"));
-    return EFI_TIMEOUT;
-  }
-
-  //Reissue READ command
-  NandSendCommand(PAGE_READ_CMD);
-
-  //Enable ECC engine.
-  NandEnableEcc();
-
-  //Read data into the buffer.
-  for (Index = 0; Index < NumMainAreaWords; Index++) {
-    *MainAreaWordBuffer++ = MmioRead16(GPMC_NAND_DATA_0);
-  }
-
-  //Read spare area into the buffer.
-  for (Index = 0; Index < NumSpareAreaWords; Index++) {
-    *SpareAreaWordBuffer++ = MmioRead16(GPMC_NAND_DATA_0);
-  }
-
-  //Calculate ECC.
-  NandCalculateEcc();
-
-  //Turn off ECC engine.
-  NandDisableEcc();
-
-  //Perform ECC correction.
-  //Need to implement..
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-NandWritePage (
-  IN  UINTN                         BlockIndex,
-  IN  UINTN                         PageIndex,
-  OUT VOID                          *Buffer,
-  IN  UINT8                         *SpareBuffer
-)
-{
-  UINTN      Address;
-  UINT16     *MainAreaWordBuffer = Buffer;
-  UINT16     *SpareAreaWordBuffer = (UINT16 *)SpareBuffer;
-  UINTN      Index;
-  UINTN      NandStatus;
-  UINTN      Timeout = MAX_RETRY_COUNT;
-
-  //Generate device address in bytes to access specific block and page index
-  Address = GetActualPageAddressInBytes(BlockIndex, PageIndex);
-
-  //Send SERIAL DATA INPUT command
-  NandSendCommand(PROGRAM_PAGE_CMD);
-
-  //Send 5 Address cycles to access specific device address
-  NandSendAddressCycles(Address);
-
-  //Enable ECC engine.
-  NandEnableEcc();
-
-  //Data input from Buffer
-  for (Index = 0; Index < (gNandFlashInfo->PageSize/2); Index++) {
-    MmioWrite16(GPMC_NAND_DATA_0, *MainAreaWordBuffer++);
-
-    //After each write access, device has to wait to accept data.
-    //Currently we may not be programming proper timing parameters to 
-    //the GPMC_CONFIGi_0 registers and we would need to figure that out.
-    //Without following delay, page programming fails.
-    gBS->Stall(1);
-  }
-
-  //Calculate ECC.
-  NandCalculateEcc();
-
-  //Turn off ECC engine.
-  NandDisableEcc();
-
-  //Prepare Spare area buffer with ECC codes.
-  SetMem(SpareBuffer, gNandFlashInfo->SparePageSize, 0xFF);
-  CopyMem(&SpareBuffer[ECC_POSITION], gEccCode, gNum512BytesChunks * 3);
-
-  //Program spare area with calculated ECC.
-  for (Index = 0; Index < (gNandFlashInfo->SparePageSize/2); Index++) {
-    MmioWrite16(GPMC_NAND_DATA_0, *SpareAreaWordBuffer++);
-  }
-
-  //Send PROGRAM command
-  NandSendCommand(PROGRAM_PAGE_CONFIRM_CMD);
-
-  //Poll till device is busy.
-  NandStatus = 0;
-  while (Timeout) {
-    NandStatus = NandReadStatus();
-    if ((NandStatus & NAND_READY) == NAND_READY) {
-      break;
-    }
-    Timeout--;
-  }
-
-  if (Timeout == 0) {
-    DEBUG ((EFI_D_ERROR, "Program page timed out.\n"));
-    return EFI_TIMEOUT;
-  }
-
-  //Bit0 indicates Pass/Fail status
-  if (NandStatus & NAND_FAILURE) {
-    return EFI_DEVICE_ERROR;
-  }
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-NandEraseBlock (
-  IN UINTN BlockIndex
-)
-{
-  UINTN      Address;
-  UINTN      NandStatus;
-  UINTN      Timeout = MAX_RETRY_COUNT;
-
-  //Generate device address in bytes to access specific block and page index
-  Address = GetActualPageAddressInBytes(BlockIndex, 0);
-
-  //Send ERASE SETUP command
-  NandSendCommand(BLOCK_ERASE_CMD);
-
-  //Send 3 address cycles to device to access Page address and Block address
-  Address >>= 11; //Ignore column addresses
-
-  NandSendAddress(Address & 0xff);
-  Address >>= 8;
-
-  NandSendAddress(Address & 0xff);
-  Address >>= 8;
-
-  NandSendAddress(Address & 0xff);
-
-  //Send ERASE CONFIRM command
-  NandSendCommand(BLOCK_ERASE_CONFIRM_CMD);
-
-  //Poll till device is busy.
-  NandStatus = 0;
-  while (Timeout) {
-    NandStatus = NandReadStatus();
-    if ((NandStatus & NAND_READY) == NAND_READY) {
-      break;
-    }
-    Timeout--;
-    gBS->Stall(1);
-  }
-
-  if (Timeout == 0) {
-    DEBUG ((EFI_D_ERROR, "Erase block timed out for Block: %d.\n", BlockIndex));
-    return EFI_TIMEOUT;
-  }
-
-  //Bit0 indicates Pass/Fail status
-  if (NandStatus & NAND_FAILURE) {
-    return EFI_DEVICE_ERROR;
-  }
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-NandReadBlock (
-  IN UINTN                          StartBlockIndex,
-  IN UINTN                          EndBlockIndex,
-  OUT VOID                          *Buffer,
-  OUT VOID                          *SpareBuffer
-)
-{
-  UINTN      BlockIndex;
-  UINTN      PageIndex;
-  EFI_STATUS Status = EFI_SUCCESS;
-
-  for (BlockIndex = StartBlockIndex; BlockIndex <= EndBlockIndex; BlockIndex++) {
-    //For each block read number of pages
-    for (PageIndex = 0; PageIndex < gNandFlashInfo->NumPagesPerBlock; PageIndex++) {
-      Status = NandReadPage(BlockIndex, PageIndex, Buffer, SpareBuffer);
-      if (EFI_ERROR(Status)) {
-        return Status;
-      }
-      Buffer = ((UINT8 *)Buffer + gNandFlashInfo->PageSize);
-    }
-  }
-
-  return Status;
-}
-
-EFI_STATUS
-NandWriteBlock (
-  IN UINTN                          StartBlockIndex,
-  IN UINTN                          EndBlockIndex,
-  OUT VOID                          *Buffer,
-  OUT VOID                          *SpareBuffer
-  )
-{
-  UINTN      BlockIndex;
-  UINTN      PageIndex;
-  EFI_STATUS Status = EFI_SUCCESS;
-
-  for (BlockIndex = StartBlockIndex; BlockIndex <= EndBlockIndex; BlockIndex++) {
-    //Page programming.
-    for (PageIndex = 0; PageIndex < gNandFlashInfo->NumPagesPerBlock; PageIndex++) {
-      Status = NandWritePage(BlockIndex, PageIndex, Buffer, SpareBuffer);
-      if (EFI_ERROR(Status)) {
-        return Status;
-      }
-      Buffer = ((UINT8 *)Buffer + gNandFlashInfo->PageSize);
-    }
-  }
-
-  return Status;
-}
-
-EFI_STATUS
-EFIAPI
-NandFlashReset (
-  IN EFI_BLOCK_IO_PROTOCOL          *This,
-  IN BOOLEAN                        ExtendedVerification
-  )
-{
-  UINTN BusyStall = 50;                            // microSeconds
-  UINTN ResetBusyTimeout = (1000000 / BusyStall);  // 1 Second
-
-  //Send RESET command to device.
-  NandSendCommand(RESET_CMD);
-  
-  //Wait for 1ms before we check status register.
-  gBS->Stall(1000);
-
-  //Check BIT#5 & BIT#6 in Status register to make sure RESET is done.
-  while ((NandReadStatus() & NAND_RESET_STATUS) != NAND_RESET_STATUS) {
-
-    //In case of extended verification, wait for extended amount of time
-    //to make sure device is reset.
-    if (ExtendedVerification) {
-      if (ResetBusyTimeout == 0) {
-        return EFI_DEVICE_ERROR;
-      }
-
-      gBS->Stall(BusyStall);
-      ResetBusyTimeout--;
-    }
-  }
-  
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-NandFlashReadBlocks (
-  IN EFI_BLOCK_IO_PROTOCOL          *This,
-  IN UINT32                         MediaId,
-  IN EFI_LBA                        Lba,
-  IN UINTN                          BufferSize,
-  OUT VOID                          *Buffer
-  )
-{
-  UINTN      NumBlocks;
-  UINTN      EndBlockIndex;
-  EFI_STATUS Status;
-  UINT8      *SpareBuffer = NULL;
-
-  if (Buffer == NULL) {
-    Status = EFI_INVALID_PARAMETER;
-    goto exit;
-  }
-  
-  if (Lba > LAST_BLOCK) {
-    Status = EFI_INVALID_PARAMETER;
-    goto exit;
-  }
-  
-  if ((BufferSize % gNandFlashInfo->BlockSize) != 0) {
-    Status = EFI_BAD_BUFFER_SIZE;
-    goto exit;
-  }
-
-  NumBlocks = DivU64x32(BufferSize, gNandFlashInfo->BlockSize);
-  EndBlockIndex = ((UINTN)Lba + NumBlocks) - 1;
-
-  SpareBuffer = (UINT8 *)AllocatePool(gNandFlashInfo->SparePageSize);
-  if (SpareBuffer == NULL) {
-    Status = EFI_OUT_OF_RESOURCES;
-    goto exit;
-  }
-
-  //Read block
-  Status = NandReadBlock((UINTN)Lba, EndBlockIndex, Buffer, SpareBuffer);
-  if (EFI_ERROR(Status)) {
-    DEBUG((EFI_D_ERROR, "Read block fails: %x\n", Status));
-    goto exit;
-  }
-
-exit:
-  if (SpareBuffer != NULL) {
-    FreePool (SpareBuffer);
-  }
-
-  return Status;
-}
-
-EFI_STATUS
-EFIAPI
-NandFlashWriteBlocks (
-  IN EFI_BLOCK_IO_PROTOCOL          *This,
-  IN UINT32                         MediaId,
-  IN EFI_LBA                        Lba,
-  IN UINTN                          BufferSize,
-  IN VOID                           *Buffer
-  )
-{
-  UINTN      BlockIndex;
-  UINTN      NumBlocks;
-  UINTN      EndBlockIndex;
-  EFI_STATUS Status;
-  UINT8      *SpareBuffer = NULL;
-
-  if (Buffer == NULL) {
-    Status = EFI_INVALID_PARAMETER;
-    goto exit;
-  }
-  
-  if (Lba > LAST_BLOCK) {
-    Status = EFI_INVALID_PARAMETER;
-    goto exit;
-  }
-  
-  if ((BufferSize % gNandFlashInfo->BlockSize) != 0) {
-    Status = EFI_BAD_BUFFER_SIZE;
-    goto exit;
-  }
-
-  NumBlocks = DivU64x32(BufferSize, gNandFlashInfo->BlockSize);
-  EndBlockIndex = ((UINTN)Lba + NumBlocks) - 1;
-
-  SpareBuffer = (UINT8 *)AllocatePool(gNandFlashInfo->SparePageSize);
-  if (SpareBuffer == NULL) {
-    Status = EFI_OUT_OF_RESOURCES;
-    goto exit;
-  }
-
-  // Erase block
-  for (BlockIndex = (UINTN)Lba; BlockIndex <= EndBlockIndex; BlockIndex++) {
-    Status = NandEraseBlock(BlockIndex);
-    if (EFI_ERROR(Status)) {
-      DEBUG((EFI_D_ERROR, "Erase block failed. Status: %x\n", Status));
-      goto exit;
-    }
-  }
-  
-  // Program data
-  Status = NandWriteBlock((UINTN)Lba, EndBlockIndex, Buffer, SpareBuffer);
-  if (EFI_ERROR(Status)) {
-    DEBUG((EFI_D_ERROR, "Block write fails: %x\n", Status));
-    goto exit;
-  }
-
-exit:
-  if (SpareBuffer != NULL) {
-    FreePool (SpareBuffer);
-  }
-
-  return Status;
-}
-
-EFI_STATUS
-EFIAPI
-NandFlashFlushBlocks (
-  IN EFI_BLOCK_IO_PROTOCOL  *This
-  )
-{
-  return EFI_SUCCESS;
-}
-
-
-
-EFI_BLOCK_IO_MEDIA gNandFlashMedia = {
-  SIGNATURE_32('n','a','n','d'),            // MediaId
-  FALSE,                                    // RemovableMedia
-  TRUE,                                     // MediaPresent
-  FALSE,                                    // LogicalPartition
-  FALSE,                                    // ReadOnly
-  FALSE,                                    // WriteCaching
-  0,                                        // BlockSize
-  2,                                        // IoAlign
-  0,                                        // Pad
-  0                                         // LastBlock
-};
-
-EFI_BLOCK_IO_PROTOCOL BlockIo = 
-{
-  EFI_BLOCK_IO_INTERFACE_REVISION,  // Revision
-  &gNandFlashMedia,                  // *Media
-  NandFlashReset,                   // Reset
-  NandFlashReadBlocks,              // ReadBlocks
-  NandFlashWriteBlocks,             // WriteBlocks
-  NandFlashFlushBlocks              // FlushBlocks
-};
-
-EFI_STATUS
-NandFlashInitialize (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
-  )
-{
-  EFI_STATUS  Status;
-  
-  gNandFlashInfo = (NAND_FLASH_INFO *)AllocateZeroPool (sizeof(NAND_FLASH_INFO));
-
-  //Initialize GPMC module.
-  GpmcInit();
-
-  //Reset NAND part
-  NandFlashReset(&BlockIo, FALSE);
-
-  //Detect NAND part and populate gNandFlashInfo structure
-  Status = NandDetectPart ();
-  if (EFI_ERROR(Status)) {
-    DEBUG((EFI_D_ERROR, "Nand part id detection failure: Status: %x\n", Status));
-    return Status;
-  }
-
-  //Count total number of 512Bytes chunk based on the page size.
-  if (gNandFlashInfo->PageSize == PAGE_SIZE_512B) {
-    gNum512BytesChunks = 1;
-  } else if (gNandFlashInfo->PageSize == PAGE_SIZE_2K) {
-    gNum512BytesChunks = 4;
-  } else if (gNandFlashInfo->PageSize == PAGE_SIZE_4K) {
-    gNum512BytesChunks = 8;
-  }
-
-  gEccCode = (UINT8 *)AllocatePool(gNum512BytesChunks * 3);
-  if (gEccCode == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  //Configure ECC
-  NandConfigureEcc ();
-
-  //Patch EFI_BLOCK_IO_MEDIA structure.
-  gNandFlashMedia.BlockSize = gNandFlashInfo->BlockSize;
-  gNandFlashMedia.LastBlock = LAST_BLOCK;
-
-  //Publish BlockIO.
-  Status = gBS->InstallMultipleProtocolInterfaces (
-                  &ImageHandle, 
-                  &gEfiBlockIoProtocolGuid, &BlockIo,
-                  &gEfiDevicePathProtocolGuid, &gDevicePath, 
-                  NULL
-                  );
-  return Status;
-}
-
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "Flash.h"\r
+\r
+NAND_PART_INFO_TABLE gNandPartInfoTable[1] = {\r
+  { 0x2C, 0xBA, 17, 11 }\r
+};\r
+\r
+NAND_FLASH_INFO *gNandFlashInfo = NULL;\r
+UINT8           *gEccCode;\r
+UINTN           gNum512BytesChunks = 0;\r
+\r
+//\r
+\r
+// Device path for SemiHosting. It contains our autogened Caller ID GUID.\r
+\r
+//\r
+\r
+typedef struct {\r
+\r
+  VENDOR_DEVICE_PATH        Guid;\r
+\r
+  EFI_DEVICE_PATH_PROTOCOL  End;\r
+\r
+} FLASH_DEVICE_PATH;\r
+\r
+\r
+\r
+FLASH_DEVICE_PATH gDevicePath = {\r
+\r
+  {\r
+\r
+    { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, sizeof (VENDOR_DEVICE_PATH), 0 },\r
+\r
+    EFI_CALLER_ID_GUID\r
+\r
+  },\r
+\r
+  { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, sizeof (EFI_DEVICE_PATH_PROTOCOL), 0}\r
+\r
+};\r
+\r
+\r
+\r
+//Actual page address = Column address + Page address + Block address.\r
+UINTN\r
+GetActualPageAddressInBytes (\r
+  UINTN BlockIndex,\r
+  UINTN PageIndex\r
+)\r
+{\r
+  //BlockAddressStart = Start of the Block address in actual NAND\r
+  //PageAddressStart = Start of the Page address in actual NAND\r
+  return ((BlockIndex << gNandFlashInfo->BlockAddressStart) + (PageIndex << gNandFlashInfo->PageAddressStart));\r
+}\r
+\r
+VOID\r
+NandSendCommand (\r
+  UINT8 Command\r
+)\r
+{\r
+  MmioWrite16(GPMC_NAND_COMMAND_0, Command);\r
+}\r
+\r
+VOID\r
+NandSendAddress (\r
+  UINT8 Address\r
+)\r
+{\r
+  MmioWrite16(GPMC_NAND_ADDRESS_0, Address);\r
+}\r
+\r
+UINT16\r
+NandReadStatus (\r
+  VOID\r
+  )\r
+{\r
+  //Send READ STATUS command\r
+  NandSendCommand(READ_STATUS_CMD);\r
+\r
+  //Read status.\r
+  return MmioRead16(GPMC_NAND_DATA_0);\r
+}\r
+\r
+VOID\r
+NandSendAddressCycles (\r
+  UINTN Address\r
+)\r
+{\r
+  //Column address\r
+  NandSendAddress(Address & 0xff);\r
+  Address >>= 8;\r
+\r
+  //Column address\r
+  NandSendAddress(Address & 0x07);\r
+  Address >>= 3;\r
+\r
+  //Page and Block address\r
+  NandSendAddress(Address & 0xff);\r
+  Address >>= 8;\r
+\r
+  //Block address\r
+  NandSendAddress(Address & 0xff);\r
+  Address >>= 8;\r
+\r
+  //Block address\r
+  NandSendAddress(Address & 0x01);\r
+}\r
+\r
+VOID\r
+GpmcInit (\r
+  VOID\r
+  )\r
+{\r
+  //Enable Smart-idle mode.\r
+  MmioWrite32 (GPMC_SYSCONFIG, SMARTIDLEMODE);\r
+\r
+  //Set IRQSTATUS and IRQENABLE to the reset value\r
+  MmioWrite32 (GPMC_IRQSTATUS, 0x0);\r
+  MmioWrite32 (GPMC_IRQENABLE, 0x0);\r
+\r
+  //Disable GPMC timeout control.\r
+  MmioWrite32 (GPMC_TIMEOUT_CONTROL, TIMEOUTDISABLE);\r
+\r
+  //Set WRITEPROTECT bit to enable write access.\r
+  MmioWrite32 (GPMC_CONFIG, WRITEPROTECT_HIGH);\r
+\r
+  //NOTE: Following GPMC_CONFIGi_0 register settings are taken from u-boot memory dump.\r
+  MmioWrite32 (GPMC_CONFIG1_0, DEVICETYPE_NAND | DEVICESIZE_X16);\r
+  MmioWrite32 (GPMC_CONFIG2_0, CSRDOFFTIME | CSWROFFTIME);\r
+  MmioWrite32 (GPMC_CONFIG3_0, ADVRDOFFTIME | ADVWROFFTIME);\r
+  MmioWrite32 (GPMC_CONFIG4_0, OEONTIME | OEOFFTIME | WEONTIME | WEOFFTIME);\r
+  MmioWrite32 (GPMC_CONFIG5_0, RDCYCLETIME | WRCYCLETIME | RDACCESSTIME | PAGEBURSTACCESSTIME);\r
+  MmioWrite32 (GPMC_CONFIG6_0, WRACCESSTIME | WRDATAONADMUXBUS | CYCLE2CYCLEDELAY | CYCLE2CYCLESAMECSEN);\r
+  MmioWrite32 (GPMC_CONFIG7_0, MASKADDRESS_128MB | CSVALID | BASEADDRESS);\r
+}\r
+\r
+EFI_STATUS\r
+NandDetectPart (\r
+  VOID\r
+)\r
+{\r
+  UINT8      NandInfo = 0;\r
+  UINT8      PartInfo[5];\r
+  UINTN      Index;\r
+  BOOLEAN    Found = FALSE;\r
+\r
+  //Send READ ID command\r
+  NandSendCommand(READ_ID_CMD);\r
+\r
+  //Send one address cycle.\r
+  NandSendAddress(0);\r
+\r
+  //Read 5-bytes to idenfity code programmed into the NAND flash devices.\r
+  //BYTE 0 = Manufacture ID\r
+  //Byte 1 = Device ID\r
+  //Byte 2, 3, 4 = Nand part specific information (Page size, Block size etc)\r
+  for (Index = 0; Index < sizeof(PartInfo); Index++) {\r
+    PartInfo[Index] = MmioRead16(GPMC_NAND_DATA_0);\r
+  }\r
+\r
+  //Check if the ManufactureId and DeviceId are part of the currently supported nand parts.\r
+  for (Index = 0; Index < sizeof(gNandPartInfoTable)/sizeof(NAND_PART_INFO_TABLE); Index++) {\r
+    if (gNandPartInfoTable[Index].ManufactureId == PartInfo[0] && gNandPartInfoTable[Index].DeviceId == PartInfo[1]) {\r
+      gNandFlashInfo->BlockAddressStart = gNandPartInfoTable[Index].BlockAddressStart;\r
+      gNandFlashInfo->PageAddressStart = gNandPartInfoTable[Index].PageAddressStart;\r
+      Found = TRUE;\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (Found == FALSE) {\r
+    DEBUG ((EFI_D_ERROR, "Nand part is not currently supported. Manufacture id: %x, Device id: %x\n", PartInfo[0], PartInfo[1]));\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  //Populate NAND_FLASH_INFO based on the result of READ ID command.\r
+  gNandFlashInfo->ManufactureId = PartInfo[0];\r
+  gNandFlashInfo->DeviceId = PartInfo[1];\r
+  NandInfo = PartInfo[3];\r
+\r
+  if (PAGE_SIZE(NandInfo) == PAGE_SIZE_2K_VAL) {\r
+    gNandFlashInfo->PageSize = PAGE_SIZE_2K;\r
+  } else {\r
+    DEBUG ((EFI_D_ERROR, "Unknown Page size.\n"));\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (SPARE_AREA_SIZE(NandInfo) == SPARE_AREA_SIZE_64B_VAL) {\r
+    gNandFlashInfo->SparePageSize = SPARE_AREA_SIZE_64B;\r
+  } else {\r
+    DEBUG ((EFI_D_ERROR, "Unknown Spare area size.\n"));\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (BLOCK_SIZE(NandInfo) == BLOCK_SIZE_128K_VAL) {\r
+    gNandFlashInfo->BlockSize = BLOCK_SIZE_128K;\r
+  } else {\r
+    DEBUG ((EFI_D_ERROR, "Unknown Block size.\n"));\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (ORGANIZATION(NandInfo) == ORGANIZATION_X8) {\r
+    gNandFlashInfo->Organization = 0;\r
+  } else if (ORGANIZATION(NandInfo) == ORGANIZATION_X16) {\r
+    gNandFlashInfo->Organization = 1;\r
+  }\r
+\r
+  //Calculate total number of blocks.\r
+  gNandFlashInfo->NumPagesPerBlock = DivU64x32(gNandFlashInfo->BlockSize, gNandFlashInfo->PageSize);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+VOID\r
+NandConfigureEcc (\r
+  VOID\r
+  )\r
+{\r
+  //Define ECC size 0 and size 1 to 512 bytes\r
+  MmioWrite32 (GPMC_ECC_SIZE_CONFIG, (ECCSIZE0_512BYTES | ECCSIZE1_512BYTES));\r
+}\r
+\r
+VOID \r
+NandEnableEcc (\r
+  VOID\r
+  )\r
+{\r
+  //Clear all the ECC result registers and select ECC result register 1\r
+  MmioWrite32 (GPMC_ECC_CONTROL, (ECCCLEAR | ECCPOINTER_REG1));\r
+\r
+  //Enable ECC engine on CS0\r
+  MmioWrite32 (GPMC_ECC_CONFIG, (ECCENABLE | ECCCS_0 | ECC16B));\r
+}\r
+\r
+VOID\r
+NandDisableEcc (\r
+  VOID\r
+  )\r
+{\r
+  //Turn off ECC engine.\r
+  MmioWrite32 (GPMC_ECC_CONFIG, ECCDISABLE);\r
+}\r
+\r
+VOID\r
+NandCalculateEcc (\r
+  VOID\r
+  )\r
+{\r
+  UINTN Index;\r
+  UINTN EccResultRegister;\r
+  UINTN EccResult;\r
+\r
+  //Capture 32-bit ECC result for each 512-bytes chunk.\r
+  //In our case PageSize is 2K so read ECC1-ECC4 result registers and\r
+  //generate total of 12-bytes of ECC code for the particular page.\r
+\r
+  EccResultRegister = GPMC_ECC1_RESULT;\r
+\r
+  for (Index = 0; Index < gNum512BytesChunks; Index++) {\r
+\r
+    EccResult = MmioRead32 (EccResultRegister);\r
+\r
+    //Calculate ECC code from 32-bit ECC result value.\r
+    //NOTE: Following calculation is not part of TRM. We got this information \r
+    //from Beagleboard mailing list.\r
+    gEccCode[Index * 3] = EccResult & 0xFF;\r
+    gEccCode[(Index * 3) + 1] = (EccResult >> 16) & 0xFF;\r
+    gEccCode[(Index * 3) + 2] = (((EccResult >> 20) & 0xF0) | ((EccResult >> 8) & 0x0F));\r
+\r
+    //Point to next ECC result register.\r
+    EccResultRegister += 4;\r
+  }\r
+}\r
+\r
+EFI_STATUS\r
+NandReadPage (\r
+  IN  UINTN                         BlockIndex,\r
+  IN  UINTN                         PageIndex,\r
+  OUT VOID                          *Buffer,\r
+  OUT UINT8                         *SpareBuffer\r
+)\r
+{\r
+  UINTN      Address;\r
+  UINTN      Index;\r
+  UINTN      NumMainAreaWords = (gNandFlashInfo->PageSize/2);\r
+  UINTN      NumSpareAreaWords = (gNandFlashInfo->SparePageSize/2);\r
+  UINT16     *MainAreaWordBuffer = Buffer;\r
+  UINT16     *SpareAreaWordBuffer = (UINT16 *)SpareBuffer;\r
+  UINTN      Timeout = MAX_RETRY_COUNT;\r
+\r
+  //Generate device address in bytes to access specific block and page index\r
+  Address = GetActualPageAddressInBytes(BlockIndex, PageIndex);\r
+\r
+  //Send READ command\r
+  NandSendCommand(PAGE_READ_CMD);\r
+\r
+  //Send 5 Address cycles to access specific device address\r
+  NandSendAddressCycles(Address);\r
+\r
+  //Send READ CONFIRM command\r
+  NandSendCommand(PAGE_READ_CONFIRM_CMD);\r
+\r
+  //Poll till device is busy.\r
+  while (Timeout) {\r
+    if ((NandReadStatus() & NAND_READY) == NAND_READY) {\r
+      break;\r
+    }\r
+    Timeout--;\r
+  }\r
+\r
+  if (Timeout == 0) {\r
+    DEBUG ((EFI_D_ERROR, "Read page timed out.\n"));\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  //Reissue READ command\r
+  NandSendCommand(PAGE_READ_CMD);\r
+\r
+  //Enable ECC engine.\r
+  NandEnableEcc();\r
+\r
+  //Read data into the buffer.\r
+  for (Index = 0; Index < NumMainAreaWords; Index++) {\r
+    *MainAreaWordBuffer++ = MmioRead16(GPMC_NAND_DATA_0);\r
+  }\r
+\r
+  //Read spare area into the buffer.\r
+  for (Index = 0; Index < NumSpareAreaWords; Index++) {\r
+    *SpareAreaWordBuffer++ = MmioRead16(GPMC_NAND_DATA_0);\r
+  }\r
+\r
+  //Calculate ECC.\r
+  NandCalculateEcc();\r
+\r
+  //Turn off ECC engine.\r
+  NandDisableEcc();\r
+\r
+  //Perform ECC correction.\r
+  //Need to implement..\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+NandWritePage (\r
+  IN  UINTN                         BlockIndex,\r
+  IN  UINTN                         PageIndex,\r
+  OUT VOID                          *Buffer,\r
+  IN  UINT8                         *SpareBuffer\r
+)\r
+{\r
+  UINTN      Address;\r
+  UINT16     *MainAreaWordBuffer = Buffer;\r
+  UINT16     *SpareAreaWordBuffer = (UINT16 *)SpareBuffer;\r
+  UINTN      Index;\r
+  UINTN      NandStatus;\r
+  UINTN      Timeout = MAX_RETRY_COUNT;\r
+\r
+  //Generate device address in bytes to access specific block and page index\r
+  Address = GetActualPageAddressInBytes(BlockIndex, PageIndex);\r
+\r
+  //Send SERIAL DATA INPUT command\r
+  NandSendCommand(PROGRAM_PAGE_CMD);\r
+\r
+  //Send 5 Address cycles to access specific device address\r
+  NandSendAddressCycles(Address);\r
+\r
+  //Enable ECC engine.\r
+  NandEnableEcc();\r
+\r
+  //Data input from Buffer\r
+  for (Index = 0; Index < (gNandFlashInfo->PageSize/2); Index++) {\r
+    MmioWrite16(GPMC_NAND_DATA_0, *MainAreaWordBuffer++);\r
+\r
+    //After each write access, device has to wait to accept data.\r
+    //Currently we may not be programming proper timing parameters to \r
+    //the GPMC_CONFIGi_0 registers and we would need to figure that out.\r
+    //Without following delay, page programming fails.\r
+    gBS->Stall(1);\r
+  }\r
+\r
+  //Calculate ECC.\r
+  NandCalculateEcc();\r
+\r
+  //Turn off ECC engine.\r
+  NandDisableEcc();\r
+\r
+  //Prepare Spare area buffer with ECC codes.\r
+  SetMem(SpareBuffer, gNandFlashInfo->SparePageSize, 0xFF);\r
+  CopyMem(&SpareBuffer[ECC_POSITION], gEccCode, gNum512BytesChunks * 3);\r
+\r
+  //Program spare area with calculated ECC.\r
+  for (Index = 0; Index < (gNandFlashInfo->SparePageSize/2); Index++) {\r
+    MmioWrite16(GPMC_NAND_DATA_0, *SpareAreaWordBuffer++);\r
+  }\r
+\r
+  //Send PROGRAM command\r
+  NandSendCommand(PROGRAM_PAGE_CONFIRM_CMD);\r
+\r
+  //Poll till device is busy.\r
+  NandStatus = 0;\r
+  while (Timeout) {\r
+    NandStatus = NandReadStatus();\r
+    if ((NandStatus & NAND_READY) == NAND_READY) {\r
+      break;\r
+    }\r
+    Timeout--;\r
+  }\r
+\r
+  if (Timeout == 0) {\r
+    DEBUG ((EFI_D_ERROR, "Program page timed out.\n"));\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  //Bit0 indicates Pass/Fail status\r
+  if (NandStatus & NAND_FAILURE) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+NandEraseBlock (\r
+  IN UINTN BlockIndex\r
+)\r
+{\r
+  UINTN      Address;\r
+  UINTN      NandStatus;\r
+  UINTN      Timeout = MAX_RETRY_COUNT;\r
+\r
+  //Generate device address in bytes to access specific block and page index\r
+  Address = GetActualPageAddressInBytes(BlockIndex, 0);\r
+\r
+  //Send ERASE SETUP command\r
+  NandSendCommand(BLOCK_ERASE_CMD);\r
+\r
+  //Send 3 address cycles to device to access Page address and Block address\r
+  Address >>= 11; //Ignore column addresses\r
+\r
+  NandSendAddress(Address & 0xff);\r
+  Address >>= 8;\r
+\r
+  NandSendAddress(Address & 0xff);\r
+  Address >>= 8;\r
+\r
+  NandSendAddress(Address & 0xff);\r
+\r
+  //Send ERASE CONFIRM command\r
+  NandSendCommand(BLOCK_ERASE_CONFIRM_CMD);\r
+\r
+  //Poll till device is busy.\r
+  NandStatus = 0;\r
+  while (Timeout) {\r
+    NandStatus = NandReadStatus();\r
+    if ((NandStatus & NAND_READY) == NAND_READY) {\r
+      break;\r
+    }\r
+    Timeout--;\r
+    gBS->Stall(1);\r
+  }\r
+\r
+  if (Timeout == 0) {\r
+    DEBUG ((EFI_D_ERROR, "Erase block timed out for Block: %d.\n", BlockIndex));\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  //Bit0 indicates Pass/Fail status\r
+  if (NandStatus & NAND_FAILURE) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+NandReadBlock (\r
+  IN UINTN                          StartBlockIndex,\r
+  IN UINTN                          EndBlockIndex,\r
+  OUT VOID                          *Buffer,\r
+  OUT VOID                          *SpareBuffer\r
+)\r
+{\r
+  UINTN      BlockIndex;\r
+  UINTN      PageIndex;\r
+  EFI_STATUS Status = EFI_SUCCESS;\r
+\r
+  for (BlockIndex = StartBlockIndex; BlockIndex <= EndBlockIndex; BlockIndex++) {\r
+    //For each block read number of pages\r
+    for (PageIndex = 0; PageIndex < gNandFlashInfo->NumPagesPerBlock; PageIndex++) {\r
+      Status = NandReadPage(BlockIndex, PageIndex, Buffer, SpareBuffer);\r
+      if (EFI_ERROR(Status)) {\r
+        return Status;\r
+      }\r
+      Buffer = ((UINT8 *)Buffer + gNandFlashInfo->PageSize);\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+NandWriteBlock (\r
+  IN UINTN                          StartBlockIndex,\r
+  IN UINTN                          EndBlockIndex,\r
+  OUT VOID                          *Buffer,\r
+  OUT VOID                          *SpareBuffer\r
+  )\r
+{\r
+  UINTN      BlockIndex;\r
+  UINTN      PageIndex;\r
+  EFI_STATUS Status = EFI_SUCCESS;\r
+\r
+  for (BlockIndex = StartBlockIndex; BlockIndex <= EndBlockIndex; BlockIndex++) {\r
+    //Page programming.\r
+    for (PageIndex = 0; PageIndex < gNandFlashInfo->NumPagesPerBlock; PageIndex++) {\r
+      Status = NandWritePage(BlockIndex, PageIndex, Buffer, SpareBuffer);\r
+      if (EFI_ERROR(Status)) {\r
+        return Status;\r
+      }\r
+      Buffer = ((UINT8 *)Buffer + gNandFlashInfo->PageSize);\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+NandFlashReset (\r
+  IN EFI_BLOCK_IO_PROTOCOL          *This,\r
+  IN BOOLEAN                        ExtendedVerification\r
+  )\r
+{\r
+  UINTN BusyStall = 50;                            // microSeconds\r
+  UINTN ResetBusyTimeout = (1000000 / BusyStall);  // 1 Second\r
+\r
+  //Send RESET command to device.\r
+  NandSendCommand(RESET_CMD);\r
+  \r
+  //Wait for 1ms before we check status register.\r
+  gBS->Stall(1000);\r
+\r
+  //Check BIT#5 & BIT#6 in Status register to make sure RESET is done.\r
+  while ((NandReadStatus() & NAND_RESET_STATUS) != NAND_RESET_STATUS) {\r
+\r
+    //In case of extended verification, wait for extended amount of time\r
+    //to make sure device is reset.\r
+    if (ExtendedVerification) {\r
+      if (ResetBusyTimeout == 0) {\r
+        return EFI_DEVICE_ERROR;\r
+      }\r
+\r
+      gBS->Stall(BusyStall);\r
+      ResetBusyTimeout--;\r
+    }\r
+  }\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+NandFlashReadBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL          *This,\r
+  IN UINT32                         MediaId,\r
+  IN EFI_LBA                        Lba,\r
+  IN UINTN                          BufferSize,\r
+  OUT VOID                          *Buffer\r
+  )\r
+{\r
+  UINTN      NumBlocks;\r
+  UINTN      EndBlockIndex;\r
+  EFI_STATUS Status;\r
+  UINT8      *SpareBuffer = NULL;\r
+\r
+  if (Buffer == NULL) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto exit;\r
+  }\r
+  \r
+  if (Lba > LAST_BLOCK) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto exit;\r
+  }\r
+  \r
+  if ((BufferSize % gNandFlashInfo->BlockSize) != 0) {\r
+    Status = EFI_BAD_BUFFER_SIZE;\r
+    goto exit;\r
+  }\r
+\r
+  NumBlocks = DivU64x32(BufferSize, gNandFlashInfo->BlockSize);\r
+  EndBlockIndex = ((UINTN)Lba + NumBlocks) - 1;\r
+\r
+  SpareBuffer = (UINT8 *)AllocatePool(gNandFlashInfo->SparePageSize);\r
+  if (SpareBuffer == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto exit;\r
+  }\r
+\r
+  //Read block\r
+  Status = NandReadBlock((UINTN)Lba, EndBlockIndex, Buffer, SpareBuffer);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG((EFI_D_ERROR, "Read block fails: %x\n", Status));\r
+    goto exit;\r
+  }\r
+\r
+exit:\r
+  if (SpareBuffer != NULL) {\r
+    FreePool (SpareBuffer);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+NandFlashWriteBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL          *This,\r
+  IN UINT32                         MediaId,\r
+  IN EFI_LBA                        Lba,\r
+  IN UINTN                          BufferSize,\r
+  IN VOID                           *Buffer\r
+  )\r
+{\r
+  UINTN      BlockIndex;\r
+  UINTN      NumBlocks;\r
+  UINTN      EndBlockIndex;\r
+  EFI_STATUS Status;\r
+  UINT8      *SpareBuffer = NULL;\r
+\r
+  if (Buffer == NULL) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto exit;\r
+  }\r
+  \r
+  if (Lba > LAST_BLOCK) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto exit;\r
+  }\r
+  \r
+  if ((BufferSize % gNandFlashInfo->BlockSize) != 0) {\r
+    Status = EFI_BAD_BUFFER_SIZE;\r
+    goto exit;\r
+  }\r
+\r
+  NumBlocks = DivU64x32(BufferSize, gNandFlashInfo->BlockSize);\r
+  EndBlockIndex = ((UINTN)Lba + NumBlocks) - 1;\r
+\r
+  SpareBuffer = (UINT8 *)AllocatePool(gNandFlashInfo->SparePageSize);\r
+  if (SpareBuffer == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto exit;\r
+  }\r
+\r
+  // Erase block\r
+  for (BlockIndex = (UINTN)Lba; BlockIndex <= EndBlockIndex; BlockIndex++) {\r
+    Status = NandEraseBlock(BlockIndex);\r
+    if (EFI_ERROR(Status)) {\r
+      DEBUG((EFI_D_ERROR, "Erase block failed. Status: %x\n", Status));\r
+      goto exit;\r
+    }\r
+  }\r
+  \r
+  // Program data\r
+  Status = NandWriteBlock((UINTN)Lba, EndBlockIndex, Buffer, SpareBuffer);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG((EFI_D_ERROR, "Block write fails: %x\n", Status));\r
+    goto exit;\r
+  }\r
+\r
+exit:\r
+  if (SpareBuffer != NULL) {\r
+    FreePool (SpareBuffer);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+NandFlashFlushBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+\r
+EFI_BLOCK_IO_MEDIA gNandFlashMedia = {\r
+  SIGNATURE_32('n','a','n','d'),            // MediaId\r
+  FALSE,                                    // RemovableMedia\r
+  TRUE,                                     // MediaPresent\r
+  FALSE,                                    // LogicalPartition\r
+  FALSE,                                    // ReadOnly\r
+  FALSE,                                    // WriteCaching\r
+  0,                                        // BlockSize\r
+  2,                                        // IoAlign\r
+  0,                                        // Pad\r
+  0                                         // LastBlock\r
+};\r
+\r
+EFI_BLOCK_IO_PROTOCOL BlockIo = \r
+{\r
+  EFI_BLOCK_IO_INTERFACE_REVISION,  // Revision\r
+  &gNandFlashMedia,                  // *Media\r
+  NandFlashReset,                   // Reset\r
+  NandFlashReadBlocks,              // ReadBlocks\r
+  NandFlashWriteBlocks,             // WriteBlocks\r
+  NandFlashFlushBlocks              // FlushBlocks\r
+};\r
+\r
+EFI_STATUS\r
+NandFlashInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  \r
+  gNandFlashInfo = (NAND_FLASH_INFO *)AllocateZeroPool (sizeof(NAND_FLASH_INFO));\r
+\r
+  //Initialize GPMC module.\r
+  GpmcInit();\r
+\r
+  //Reset NAND part\r
+  NandFlashReset(&BlockIo, FALSE);\r
+\r
+  //Detect NAND part and populate gNandFlashInfo structure\r
+  Status = NandDetectPart ();\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG((EFI_D_ERROR, "Nand part id detection failure: Status: %x\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  //Count total number of 512Bytes chunk based on the page size.\r
+  if (gNandFlashInfo->PageSize == PAGE_SIZE_512B) {\r
+    gNum512BytesChunks = 1;\r
+  } else if (gNandFlashInfo->PageSize == PAGE_SIZE_2K) {\r
+    gNum512BytesChunks = 4;\r
+  } else if (gNandFlashInfo->PageSize == PAGE_SIZE_4K) {\r
+    gNum512BytesChunks = 8;\r
+  }\r
+\r
+  gEccCode = (UINT8 *)AllocatePool(gNum512BytesChunks * 3);\r
+  if (gEccCode == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //Configure ECC\r
+  NandConfigureEcc ();\r
+\r
+  //Patch EFI_BLOCK_IO_MEDIA structure.\r
+  gNandFlashMedia.BlockSize = gNandFlashInfo->BlockSize;\r
+  gNandFlashMedia.LastBlock = LAST_BLOCK;\r
+\r
+  //Publish BlockIO.\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &ImageHandle, \r
+                  &gEfiBlockIoProtocolGuid, &BlockIo,\r
+                  &gEfiDevicePathProtocolGuid, &gDevicePath, \r
+                  NULL\r
+                  );\r
+  return Status;\r
+}\r
+\r
index 9bfdba5d03f2070614c45ef1681bd670ab6e01eb..46ec4db9e18328412ae1a1afa0ae20968144e122 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef FLASH_H
-#define FLASH_H
-
-#include <Uefi.h>
-
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/DebugLib.h>
-#include <Library/IoLib.h>
-#include <Library/PcdLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/IoLib.h>
-
-#include <Protocol/BlockIo.h>
-#include <Protocol/Cpu.h>
-#include <Omap3530/Omap3530.h>
-
-#define PAGE_SIZE(x)             ((x) & 0x01)
-#define PAGE_SIZE_2K_VAL         (0x01UL)
-
-#define SPARE_AREA_SIZE(x)       (((x) >> 2) & 0x01)
-#define SPARE_AREA_SIZE_64B_VAL  (0x1UL)
-
-#define BLOCK_SIZE(x)            (((x) >> 4) & 0x01)
-#define BLOCK_SIZE_128K_VAL      (0x01UL)
-
-#define ORGANIZATION(x)          (((x) >> 6) & 0x01)
-#define ORGANIZATION_X8          (0x0UL)
-#define ORGANIZATION_X16         (0x1UL)
-
-#define PAGE_SIZE_512B           (512)
-#define PAGE_SIZE_2K             (2048)
-#define PAGE_SIZE_4K             (4096)
-#define SPARE_AREA_SIZE_16B      (16)
-#define SPARE_AREA_SIZE_64B      (64)
-
-#define BLOCK_SIZE_16K           (16*1024)
-#define BLOCK_SIZE_128K          (128*1024)
-
-#define BLOCK_COUNT              (2048)
-#define LAST_BLOCK               (BLOCK_COUNT - 1)
-
-#define ECC_POSITION             2
-
-//List of commands.
-#define RESET_CMD                0xFF
-#define READ_ID_CMD              0x90
-
-#define READ_STATUS_CMD          0x70
-
-#define PAGE_READ_CMD            0x00
-#define PAGE_READ_CONFIRM_CMD    0x30
-
-#define BLOCK_ERASE_CMD          0x60
-#define BLOCK_ERASE_CONFIRM_CMD  0xD0
-
-#define PROGRAM_PAGE_CMD         0x80
-#define PROGRAM_PAGE_CONFIRM_CMD 0x10
-
-//Nand status register bit definition
-#define NAND_SUCCESS             (0x0UL << 0)
-#define NAND_FAILURE             BIT0
-
-#define NAND_BUSY                (0x0UL << 6)
-#define NAND_READY               BIT6
-
-#define NAND_RESET_STATUS        (0x60UL << 0)
-
-#define MAX_RETRY_COUNT          1500
-
-
-typedef struct {
-  UINT8 ManufactureId;
-  UINT8 DeviceId;
-  UINT8 BlockAddressStart; //Start of the Block address in actual NAND
-  UINT8 PageAddressStart;  //Start of the Page address in actual NAND
-} NAND_PART_INFO_TABLE;
-
-typedef struct {
-  UINT8     ManufactureId;
-  UINT8     DeviceId;
-  UINT8     Organization;      //x8 or x16
-  UINT32    PageSize;
-  UINT32    SparePageSize;
-  UINT32    BlockSize;
-  UINT32    NumPagesPerBlock;
-  UINT8     BlockAddressStart; //Start of the Block address in actual NAND
-  UINT8     PageAddressStart;  //Start of the Page address in actual NAND
-} NAND_FLASH_INFO;
-
-#endif //FLASH_H
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef FLASH_H\r
+#define FLASH_H\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/IoLib.h>\r
+\r
+#include <Protocol/BlockIo.h>\r
+#include <Protocol/Cpu.h>\r
+#include <Omap3530/Omap3530.h>\r
+\r
+#define PAGE_SIZE(x)             ((x) & 0x01)\r
+#define PAGE_SIZE_2K_VAL         (0x01UL)\r
+\r
+#define SPARE_AREA_SIZE(x)       (((x) >> 2) & 0x01)\r
+#define SPARE_AREA_SIZE_64B_VAL  (0x1UL)\r
+\r
+#define BLOCK_SIZE(x)            (((x) >> 4) & 0x01)\r
+#define BLOCK_SIZE_128K_VAL      (0x01UL)\r
+\r
+#define ORGANIZATION(x)          (((x) >> 6) & 0x01)\r
+#define ORGANIZATION_X8          (0x0UL)\r
+#define ORGANIZATION_X16         (0x1UL)\r
+\r
+#define PAGE_SIZE_512B           (512)\r
+#define PAGE_SIZE_2K             (2048)\r
+#define PAGE_SIZE_4K             (4096)\r
+#define SPARE_AREA_SIZE_16B      (16)\r
+#define SPARE_AREA_SIZE_64B      (64)\r
+\r
+#define BLOCK_SIZE_16K           (16*1024)\r
+#define BLOCK_SIZE_128K          (128*1024)\r
+\r
+#define BLOCK_COUNT              (2048)\r
+#define LAST_BLOCK               (BLOCK_COUNT - 1)\r
+\r
+#define ECC_POSITION             2\r
+\r
+//List of commands.\r
+#define RESET_CMD                0xFF\r
+#define READ_ID_CMD              0x90\r
+\r
+#define READ_STATUS_CMD          0x70\r
+\r
+#define PAGE_READ_CMD            0x00\r
+#define PAGE_READ_CONFIRM_CMD    0x30\r
+\r
+#define BLOCK_ERASE_CMD          0x60\r
+#define BLOCK_ERASE_CONFIRM_CMD  0xD0\r
+\r
+#define PROGRAM_PAGE_CMD         0x80\r
+#define PROGRAM_PAGE_CONFIRM_CMD 0x10\r
+\r
+//Nand status register bit definition\r
+#define NAND_SUCCESS             (0x0UL << 0)\r
+#define NAND_FAILURE             BIT0\r
+\r
+#define NAND_BUSY                (0x0UL << 6)\r
+#define NAND_READY               BIT6\r
+\r
+#define NAND_RESET_STATUS        (0x60UL << 0)\r
+\r
+#define MAX_RETRY_COUNT          1500\r
+\r
+\r
+typedef struct {\r
+  UINT8 ManufactureId;\r
+  UINT8 DeviceId;\r
+  UINT8 BlockAddressStart; //Start of the Block address in actual NAND\r
+  UINT8 PageAddressStart;  //Start of the Page address in actual NAND\r
+} NAND_PART_INFO_TABLE;\r
+\r
+typedef struct {\r
+  UINT8     ManufactureId;\r
+  UINT8     DeviceId;\r
+  UINT8     Organization;      //x8 or x16\r
+  UINT32    PageSize;\r
+  UINT32    SparePageSize;\r
+  UINT32    BlockSize;\r
+  UINT32    NumPagesPerBlock;\r
+  UINT8     BlockAddressStart; //Start of the Block address in actual NAND\r
+  UINT8     PageAddressStart;  //Start of the Page address in actual NAND\r
+} NAND_FLASH_INFO;\r
+\r
+#endif //FLASH_H\r
index 1dfd5bcffb6647b01f6ba79d30246e676645e767..4f12a274855c6ff98a0d6f478b01ed6d9aded89e 100644 (file)
@@ -1,48 +1,48 @@
-#/** @file
-#  
-#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-#  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                      = NandFlash
-  FILE_GUID                      = 4d00ef14-c4e0-426b-81b7-30a00a14aad6
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-
-  ENTRY_POINT                    = NandFlashInitialize
-
-
-[Sources.common]
-  Flash.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  Omap35xxPkg/Omap35xxPkg.dec
-
-[LibraryClasses]
-  PcdLib
-  UefiLib
-  UefiDriverEntryPoint
-  MemoryAllocationLib
-  IoLib
-
-[Guids]
-  
-[Protocols]
-  gEfiBlockIoProtocolGuid
-  gEfiCpuArchProtocolGuid
-
-[Pcd]
-  gOmap35xxTokenSpaceGuid.PcdOmap35xxGpmcOffset
-
-[depex]
-  TRUE
\ No newline at end of file
+#/** @file\r
+#  \r
+#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = NandFlash\r
+  FILE_GUID                      = 4d00ef14-c4e0-426b-81b7-30a00a14aad6\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = NandFlashInitialize\r
+\r
+\r
+[Sources.common]\r
+  Flash.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  Omap35xxPkg/Omap35xxPkg.dec\r
+\r
+[LibraryClasses]\r
+  PcdLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  MemoryAllocationLib\r
+  IoLib\r
+\r
+[Guids]\r
+  \r
+[Protocols]\r
+  gEfiBlockIoProtocolGuid\r
+  gEfiCpuArchProtocolGuid\r
+\r
+[Pcd]\r
+  gOmap35xxTokenSpaceGuid.PcdOmap35xxGpmcOffset\r
+\r
+[depex]\r
+  TRUE\r
\ No newline at end of file
index 33786aeeee86d4cf4a4ae84f28d7e5a12523a2be..c64e6be7bb098bd319194d45aca93a4080cb3396 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <Uefi.h>
-
-#include <Library/IoLib.h>
-#include <Library/OmapLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-
-#include <Protocol/EmbeddedGpio.h>
-
-#include <Omap3530/Omap3530.h>
-
-EFI_STATUS
-Get (
-  IN  EMBEDDED_GPIO     *This,
-  IN  EMBEDDED_GPIO_PIN Gpio,
-  OUT UINTN               *Value
-  )
-{
-  UINTN  Port;
-  UINTN  Pin;
-  UINT32 DataInRegister;
-
-  if (Value == NULL)
-  {
-    return EFI_UNSUPPORTED;
-  }
-
-  Port    = GPIO_PORT(Gpio);
-  Pin     = GPIO_PIN(Gpio);
-
-  DataInRegister = GpioBase(Port) + GPIO_DATAIN;
-
-  if (MmioRead32 (DataInRegister) & GPIO_DATAIN_MASK(Pin)) {
-    *Value = 1;
-  } else {
-    *Value = 0;
-  }
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-Set (
-  IN  EMBEDDED_GPIO       *This,
-  IN  EMBEDDED_GPIO_PIN   Gpio,
-  IN  EMBEDDED_GPIO_MODE  Mode
-  )
-{
-  UINTN  Port;
-  UINTN  Pin;
-  UINT32 OutputEnableRegister;
-  UINT32 SetDataOutRegister;
-  UINT32 ClearDataOutRegister;
-
-  Port    = GPIO_PORT(Gpio);
-  Pin     = GPIO_PIN(Gpio);
-
-  OutputEnableRegister = GpioBase(Port) + GPIO_OE;
-  SetDataOutRegister   = GpioBase(Port) + GPIO_SETDATAOUT;
-  ClearDataOutRegister = GpioBase(Port) + GPIO_CLEARDATAOUT;
-
-  switch (Mode)
-  {
-    case GPIO_MODE_INPUT:
-      MmioAndThenOr32(OutputEnableRegister, ~GPIO_OE_MASK(Pin), GPIO_OE_INPUT(Pin));
-      break;
-
-    case GPIO_MODE_OUTPUT_0:
-      MmioWrite32 (ClearDataOutRegister, GPIO_CLEARDATAOUT_BIT(Pin));
-      MmioAndThenOr32(OutputEnableRegister, ~GPIO_OE_MASK(Pin), GPIO_OE_OUTPUT(Pin));
-      break;
-
-    case GPIO_MODE_OUTPUT_1:
-      MmioWrite32 (SetDataOutRegister, GPIO_SETDATAOUT_BIT(Pin));
-      MmioAndThenOr32(OutputEnableRegister, ~GPIO_OE_MASK(Pin), GPIO_OE_OUTPUT(Pin));
-      break;
-
-    default:
-      return EFI_UNSUPPORTED;
-  }
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-GetMode (
-  IN  EMBEDDED_GPIO       *This,
-  IN  EMBEDDED_GPIO_PIN   Gpio,
-  OUT EMBEDDED_GPIO_MODE  *Mode
-  )
-{
-  return EFI_UNSUPPORTED;
-}
-
-EFI_STATUS
-SetPull (
-  IN  EMBEDDED_GPIO       *This,
-  IN  EMBEDDED_GPIO_PIN   Gpio,
-  IN  EMBEDDED_GPIO_PULL  Direction
-  )
-{
-  return EFI_UNSUPPORTED;
-}
-
-EMBEDDED_GPIO Gpio = {
-  Get,
-  Set,
-  GetMode,
-  SetPull
-};
-
-EFI_STATUS
-GpioInitialize (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
-  )
-{
-  EFI_STATUS  Status;
-  
-  Status = gBS->InstallMultipleProtocolInterfaces(&ImageHandle, &gEmbeddedGpioProtocolGuid, &Gpio, NULL);
-  return Status;
-}
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Library/IoLib.h>\r
+#include <Library/OmapLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#include <Protocol/EmbeddedGpio.h>\r
+\r
+#include <Omap3530/Omap3530.h>\r
+\r
+EFI_STATUS\r
+Get (\r
+  IN  EMBEDDED_GPIO     *This,\r
+  IN  EMBEDDED_GPIO_PIN Gpio,\r
+  OUT UINTN               *Value\r
+  )\r
+{\r
+  UINTN  Port;\r
+  UINTN  Pin;\r
+  UINT32 DataInRegister;\r
+\r
+  if (Value == NULL)\r
+  {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Port    = GPIO_PORT(Gpio);\r
+  Pin     = GPIO_PIN(Gpio);\r
+\r
+  DataInRegister = GpioBase(Port) + GPIO_DATAIN;\r
+\r
+  if (MmioRead32 (DataInRegister) & GPIO_DATAIN_MASK(Pin)) {\r
+    *Value = 1;\r
+  } else {\r
+    *Value = 0;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+Set (\r
+  IN  EMBEDDED_GPIO       *This,\r
+  IN  EMBEDDED_GPIO_PIN   Gpio,\r
+  IN  EMBEDDED_GPIO_MODE  Mode\r
+  )\r
+{\r
+  UINTN  Port;\r
+  UINTN  Pin;\r
+  UINT32 OutputEnableRegister;\r
+  UINT32 SetDataOutRegister;\r
+  UINT32 ClearDataOutRegister;\r
+\r
+  Port    = GPIO_PORT(Gpio);\r
+  Pin     = GPIO_PIN(Gpio);\r
+\r
+  OutputEnableRegister = GpioBase(Port) + GPIO_OE;\r
+  SetDataOutRegister   = GpioBase(Port) + GPIO_SETDATAOUT;\r
+  ClearDataOutRegister = GpioBase(Port) + GPIO_CLEARDATAOUT;\r
+\r
+  switch (Mode)\r
+  {\r
+    case GPIO_MODE_INPUT:\r
+      MmioAndThenOr32(OutputEnableRegister, ~GPIO_OE_MASK(Pin), GPIO_OE_INPUT(Pin));\r
+      break;\r
+\r
+    case GPIO_MODE_OUTPUT_0:\r
+      MmioWrite32 (ClearDataOutRegister, GPIO_CLEARDATAOUT_BIT(Pin));\r
+      MmioAndThenOr32(OutputEnableRegister, ~GPIO_OE_MASK(Pin), GPIO_OE_OUTPUT(Pin));\r
+      break;\r
+\r
+    case GPIO_MODE_OUTPUT_1:\r
+      MmioWrite32 (SetDataOutRegister, GPIO_SETDATAOUT_BIT(Pin));\r
+      MmioAndThenOr32(OutputEnableRegister, ~GPIO_OE_MASK(Pin), GPIO_OE_OUTPUT(Pin));\r
+      break;\r
+\r
+    default:\r
+      return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+GetMode (\r
+  IN  EMBEDDED_GPIO       *This,\r
+  IN  EMBEDDED_GPIO_PIN   Gpio,\r
+  OUT EMBEDDED_GPIO_MODE  *Mode\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+SetPull (\r
+  IN  EMBEDDED_GPIO       *This,\r
+  IN  EMBEDDED_GPIO_PIN   Gpio,\r
+  IN  EMBEDDED_GPIO_PULL  Direction\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EMBEDDED_GPIO Gpio = {\r
+  Get,\r
+  Set,\r
+  GetMode,\r
+  SetPull\r
+};\r
+\r
+EFI_STATUS\r
+GpioInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  \r
+  Status = gBS->InstallMultipleProtocolInterfaces(&ImageHandle, &gEmbeddedGpioProtocolGuid, &Gpio, NULL);\r
+  return Status;\r
+}\r
index c20346a4c0151840cfd4fa54caa1273c4225e70f..2069d2d734e20ee3dc75e77f2b4618eb52eae752 100644 (file)
@@ -1,45 +1,45 @@
-#/** @file
-#  
-#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-#  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                      = Gpio
-  FILE_GUID                      = E7D9CAE1-6930-46E3-BDF9-0027446E7DF2
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-
-  ENTRY_POINT                    = GpioInitialize
-
-
-[Sources.common]
-  Gpio.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  Omap35xxPkg/Omap35xxPkg.dec
-
-[LibraryClasses]
-  IoLib
-  UefiDriverEntryPoint
-  OmapLib
-
-[Guids]
-  
-[Protocols]
-  gEmbeddedGpioProtocolGuid
-
-[Pcd]
-
-[depex]
-  TRUE
\ No newline at end of file
+#/** @file\r
+#  \r
+#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = Gpio\r
+  FILE_GUID                      = E7D9CAE1-6930-46E3-BDF9-0027446E7DF2\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = GpioInitialize\r
+\r
+\r
+[Sources.common]\r
+  Gpio.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  Omap35xxPkg/Omap35xxPkg.dec\r
+\r
+[LibraryClasses]\r
+  IoLib\r
+  UefiDriverEntryPoint\r
+  OmapLib\r
+\r
+[Guids]\r
+  \r
+[Protocols]\r
+  gEmbeddedGpioProtocolGuid\r
+\r
+[Pcd]\r
+\r
+[depex]\r
+  TRUE\r
\ No newline at end of file
index 0dc4468c917c94a7537a6d110b26f56eb9683b5d..f13b73379632e1fd1d9e65e0fd7918f7aa6fd1a0 100755 (executable)
@@ -1,25 +1,25 @@
-/** @file
-
-  Abstractions for simple OMAP DMA. 
-  OMAP_DMA4 structure elements are described in the OMAP35xx TRM. 
-
-  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __OMAP_DMA_LIB_H__
-#define __OMAP_DMA_LIB_H__
-
-
-// Example from DMA chapter of the OMAP35xx spec
+/** @file\r
+\r
+  Abstractions for simple OMAP DMA. \r
+  OMAP_DMA4 structure elements are described in the OMAP35xx TRM. \r
+\r
+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __OMAP_DMA_LIB_H__\r
+#define __OMAP_DMA_LIB_H__\r
+\r
+\r
+// Example from DMA chapter of the OMAP35xx spec\r
 typedef struct {\r
   UINT8     DataType;                      // DMA4_CSDPi[1:0]\r
   UINT8     ReadPortAccessType;            // DMA4_CSDPi[8:7]\r
 typedef struct {\r
   UINT8     DataType;                      // DMA4_CSDPi[1:0]\r
   UINT8     ReadPortAccessType;            // DMA4_CSDPi[8:7]\r
@@ -42,10 +42,10 @@ typedef struct {
   UINT8     ReadPriority;                  // DMA4_CCRi[6]\r
   UINT8     WritePriority;                 // DMA4_CCRi[23]\r
   UINT8     ReadRequestNumber;             // DMA4_CCRi[4:0]\r
   UINT8     ReadPriority;                  // DMA4_CCRi[6]\r
   UINT8     WritePriority;                 // DMA4_CCRi[23]\r
   UINT8     ReadRequestNumber;             // DMA4_CCRi[4:0]\r
-  UINT8     WriteRequestNumber;            // DMA4_CCRi[20:19]
-} OMAP_DMA4;
-
-
+  UINT8     WriteRequestNumber;            // DMA4_CCRi[20:19]\r
+} OMAP_DMA4;\r
+\r
+\r
 /**                                                                 \r
   Configure OMAP DMA Channel\r
             \r
 /**                                                                 \r
   Configure OMAP DMA Channel\r
             \r
@@ -56,14 +56,14 @@ typedef struct {
   @retval EFI_INVALID_PARAMETER Channel is not valid\r
   @retval EFI_DEVICE_ERROR      The system hardware could not map the requested information.\r
                                    \r
   @retval EFI_INVALID_PARAMETER Channel is not valid\r
   @retval EFI_DEVICE_ERROR      The system hardware could not map the requested information.\r
                                    \r
-**/
-EFI_STATUS
-EFIAPI
-EnableDmaChannel (
-  IN  UINTN       Channel,
-  IN  OMAP_DMA4   *Dma4
-  );
-
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EnableDmaChannel (\r
+  IN  UINTN       Channel,\r
+  IN  OMAP_DMA4   *Dma4\r
+  );\r
+\r
 /**                                                                 \r
   Turn of DMA channel configured by EnableDma().\r
             \r
 /**                                                                 \r
   Turn of DMA channel configured by EnableDma().\r
             \r
@@ -75,16 +75,16 @@ EnableDmaChannel (
   @retval EFI_INVALID_PARAMETER Channel is not valid\r
   @retval EFI_DEVICE_ERROR      The system hardware could not map the requested information.\r
                                    \r
   @retval EFI_INVALID_PARAMETER Channel is not valid\r
   @retval EFI_DEVICE_ERROR      The system hardware could not map the requested information.\r
                                    \r
-**/
-EFI_STATUS
-EFIAPI
-DisableDmaChannel (
-  IN  UINTN       Channel,
-  IN  UINT32      SuccessMask,
-  IN  UINT32      ErrorMask
-  );
-
-
-
-#endif 
-
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DisableDmaChannel (\r
+  IN  UINTN       Channel,\r
+  IN  UINT32      SuccessMask,\r
+  IN  UINT32      ErrorMask\r
+  );\r
+\r
+\r
+\r
+#endif \r
+\r
index 4192275157dcc1b7cf9766cd2edb5d84d6702701..80e5e0d2cbe98bdaa598ee58e96107cca2b9e046 100644 (file)
@@ -1,44 +1,44 @@
-/** @file
-
-  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __OMAPLIB_H__
-#define __OMAPLIB_H__
-
-UINT32 
-EFIAPI
-GpioBase (
-  IN  UINTN Port
-  );
-
-UINT32 
-EFIAPI
-TimerBase (
-  IN  UINTN Timer
-  );
-
-UINTN
-EFIAPI
-InterruptVectorForTimer (
-  IN  UINTN TImer
-  );
-
-UINT32
-EFIAPI
-UartBase (
-  IN  UINTN Uart
-  );
-
-
-#endif // __OMAPLIB_H__
-
+/** @file\r
+\r
+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __OMAPLIB_H__\r
+#define __OMAPLIB_H__\r
+\r
+UINT32 \r
+EFIAPI\r
+GpioBase (\r
+  IN  UINTN Port\r
+  );\r
+\r
+UINT32 \r
+EFIAPI\r
+TimerBase (\r
+  IN  UINTN Timer\r
+  );\r
+\r
+UINTN\r
+EFIAPI\r
+InterruptVectorForTimer (\r
+  IN  UINTN TImer\r
+  );\r
+\r
+UINT32\r
+EFIAPI\r
+UartBase (\r
+  IN  UINTN Uart\r
+  );\r
+\r
+\r
+#endif // __OMAPLIB_H__\r
+\r
index 1cf99eb036b4730f1663e16d951ad2c2f59d3324..4d3781576493362c92c700827cd1840621faa48d 100644 (file)
@@ -1,40 +1,40 @@
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __OMAP3530_H__
-#define __OMAP3530_H__
-
-#include "Omap3530Gpio.h"
-#include "Omap3530Interrupt.h"
-#include "Omap3530Prcm.h"
-#include "Omap3530Timer.h"
-#include "Omap3530Uart.h"
-#include "Omap3530Usb.h"
-#include "Omap3530MMCHS.h"
-#include "Omap3530I2c.h"
-#include "Omap3530PadConfiguration.h"
-#include "Omap3530Gpmc.h"
-#include "Omap3530Dma.h"
-
-
-//CONTROL_PBIAS_LITE
-#define CONTROL_PBIAS_LITE    0x48002520
-#define PBIASLITEVMODE0       BIT0
-#define PBIASLITEPWRDNZ0      BIT1
-#define PBIASSPEEDCTRL0       BIT2
-#define PBIASLITEVMODE1       BIT8
-#define PBIASLITEWRDNZ1       BIT9
-
-#endif // __OMAP3530_H__
-
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __OMAP3530_H__\r
+#define __OMAP3530_H__\r
+\r
+#include "Omap3530Gpio.h"\r
+#include "Omap3530Interrupt.h"\r
+#include "Omap3530Prcm.h"\r
+#include "Omap3530Timer.h"\r
+#include "Omap3530Uart.h"\r
+#include "Omap3530Usb.h"\r
+#include "Omap3530MMCHS.h"\r
+#include "Omap3530I2c.h"\r
+#include "Omap3530PadConfiguration.h"\r
+#include "Omap3530Gpmc.h"\r
+#include "Omap3530Dma.h"\r
+\r
+\r
+//CONTROL_PBIAS_LITE\r
+#define CONTROL_PBIAS_LITE    0x48002520\r
+#define PBIASLITEVMODE0       BIT0\r
+#define PBIASLITEPWRDNZ0      BIT1\r
+#define PBIASSPEEDCTRL0       BIT2\r
+#define PBIASLITEVMODE1       BIT8\r
+#define PBIASLITEWRDNZ1       BIT9\r
+\r
+#endif // __OMAP3530_H__\r
+\r
index 242c325331e30ff3a6d9fde214bfb8c780057eeb..5db9a0797265828123b904197ff760fb5e4eb07f 100755 (executable)
-/** @file
-
-  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __OMAP3530DMA_H__
-#define __OMAP3530DMA_H__
-
-
-#define DMA4_MAX_CHANNEL 31
-
-#define DMA4_IRQENABLE_L(_i)  (0x48056018 + (0x4*(_i)))
-
-#define DMA4_CCR(_i)  (0x48056080 + (0x60*(_i)))
-#define DMA4_CICR(_i) (0x48056088 + (0x60*(_i)))
-#define DMA4_CSR(_i)  (0x4805608c + (0x60*(_i)))
-#define DMA4_CSDP(_i) (0x48056090 + (0x60*(_i)))
-#define DMA4_CEN(_i)  (0x48056094 + (0x60*(_i)))
-#define DMA4_CFN(_i)  (0x48056098 + (0x60*(_i)))
-#define DMA4_CSSA(_i) (0x4805609c + (0x60*(_i)))
-#define DMA4_CDSA(_i) (0x480560a0 + (0x60*(_i)))
-#define DMA4_CSEI(_i) (0x480560a4 + (0x60*(_i)))
-#define DMA4_CSFI(_i) (0x480560a8 + (0x60*(_i)))
-#define DMA4_CDEI(_i) (0x480560ac + (0x60*(_i)))
-#define DMA4_CDFI(_i) (0x480560b0 + (0x60*(_i)))
-
-#define DMA4_GCR      (0x48056078)
-
-// Channel Source Destination parameters
-#define DMA4_CSDP_DATA_TYPE8    0
-#define DMA4_CSDP_DATA_TYPE16   1
-#define DMA4_CSDP_DATA_TYPE32   2
-
-#define DMA4_CSDP_SRC_PACKED      BIT6
-#define DMA4_CSDP_SRC_NONPACKED   0
-
-#define DMA4_CSDP_SRC_BURST_EN    (0x0 << 7)
-#define DMA4_CSDP_SRC_BURST_EN16  (0x1 << 7)
-#define DMA4_CSDP_SRC_BURST_EN32  (0x2 << 7)
-#define DMA4_CSDP_SRC_BURST_EN64  (0x3 << 7)
-
-#define DMA4_CSDP_DST_PACKED      BIT13
-#define DMA4_CSDP_DST_NONPACKED   0
-
-#define DMA4_CSDP_BURST_EN        (0x0 << 14)
-#define DMA4_CSDP_BURST_EN16      (0x1 << 14)
-#define DMA4_CSDP_BURST_EN32      (0x2 << 14)
-#define DMA4_CSDP_BURST_EN64      (0x3 << 14)
-
-#define DMA4_CSDP_WRITE_MODE_NONE_POSTED      (0x0 << 16)  
-#define DMA4_CSDP_WRITE_MODE_POSTED           (0x1 << 16)
-#define DMA4_CSDP_WRITE_MODE_LAST_NON_POSTED  (0x2 << 16)  
-
-#define DMA4_CSDP_DST_ENDIAN_LOCK_LOCK    BIT18
-#define DMA4_CSDP_DST_ENDIAN_LOCK_ADAPT   0
-
-#define DMA4_CSDP_DST_ENDIAN_BIG          BIT19
-#define DMA4_CSDP_DST_ENDIAN_LITTLE       0
-
-#define DMA4_CSDP_SRC_ENDIAN_LOCK_LOCK    BIT20
-#define DMA4_CSDP_SRC_ENDIAN_LOCK_ADAPT   0
-
-#define DMA4_CSDP_SRC_ENDIAN_BIG          BIT21
-#define DMA4_CSDP_SRC_ENDIAN_LITTLE       0
-
-// Channel Control 
-#define DMA4_CCR_SYNCHRO_CONTROL_MASK     0x1f
-
-#define DMA4_CCR_FS_ELEMENT     (0    | 0)
-#define DMA4_CCR_FS_BLOCK       (0    | BIT18)
-#define DMA4_CCR_FS_FRAME       (BIT5 | 0)
-#define DMA4_CCR_FS_PACKET      (BIT5 | BIT18)
-
-#define DMA4_CCR_READ_PRIORITY_HIGH   BIT6
-#define DMA4_CCR_READ_PRIORITY_LOW    0
-
-#define DMA4_CCR_ENABLE               BIT7
-#define DMA4_CCR_DISABLE              0
-
-#define DMA4_CCR_SUSPEND_SENSITIVE_IGNORE BIT8
-#define DMA4_CCR_SUSPEND_SENSITIVE        0
-
-#define DMA4_CCR_RD_ACTIVE                BIT9
-#define DMA4_CCR_WR_ACTIVE                BIT10
-
-#define DMA4_CCR_SRC_AMODE                (0     | 0)
-#define DMA4_CCR_SRC_AMODE_POST_INC       (0     | BIT12)
-#define DMA4_CCR_SRC_AMODE_SINGLE_INDEX   (BIT13 | 0)
-#define DMA4_CCR_SRC_AMODE_DOUBLE_INDEX   (BIT13 | BIT12)
-
-#define DMA4_CCR_DST_AMODE                (0     | 0)
-#define DMA4_CCR_DST_AMODE_POST_INC       (0     | BIT14)
-#define DMA4_CCR_DST_AMODE_SINGLE_INDEX   (BIT15 | 0)
-#define DMA4_CCR_DST_AMODE_DOUBLE_INDEX   (BIT15 | BIT14)
-
-#define DMA4_CCR_CONST_FILL_ENABLE        BIT16
-#define DMA4_CCR_TRANSPARENT_COPY_ENABLE  BIT17
-  
-#define DMA4_CCR_SEL_SRC_DEST_SYNC_SOURCE BIT24
-
-#define DMA4_CSR_DROP                     BIT1
-#define DMA4_CSR_HALF                     BIT2
-#define DMA4_CSR_FRAME                    BIT3
-#define DMA4_CSR_LAST                     BIT4
-#define DMA4_CSR_BLOCK                    BIT5
-#define DMA4_CSR_SYNC                     BIT6
-#define DMA4_CSR_PKT                      BIT7
-#define DMA4_CSR_TRANS_ERR                BIT8
-#define DMA4_CSR_SECURE_ERR               BIT9
-#define DMA4_CSR_SUPERVISOR_ERR           BIT10
-#define DMA4_CSR_MISALIGNED_ADRS_ERR      BIT11
-#define DMA4_CSR_DRAIN_END                BIT12
-#define DMA4_CSR_RESET                    0x1FE
-#define DMA4_CSR_ERR                      (DMA4_CSR_TRANS_ERR | DMA4_CSR_SECURE_ERR | DMA4_CSR_SUPERVISOR_ERR | DMA4_CSR_MISALIGNED_ADRS_ERR)
-
-// same mapping as CSR except for SYNC. Enable all since we are polling
-#define DMA4_CICR_ENABLE_ALL              0x1FBE
-
-
-#endif 
-
+/** @file\r
+\r
+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __OMAP3530DMA_H__\r
+#define __OMAP3530DMA_H__\r
+\r
+\r
+#define DMA4_MAX_CHANNEL 31\r
+\r
+#define DMA4_IRQENABLE_L(_i)  (0x48056018 + (0x4*(_i)))\r
+\r
+#define DMA4_CCR(_i)  (0x48056080 + (0x60*(_i)))\r
+#define DMA4_CICR(_i) (0x48056088 + (0x60*(_i)))\r
+#define DMA4_CSR(_i)  (0x4805608c + (0x60*(_i)))\r
+#define DMA4_CSDP(_i) (0x48056090 + (0x60*(_i)))\r
+#define DMA4_CEN(_i)  (0x48056094 + (0x60*(_i)))\r
+#define DMA4_CFN(_i)  (0x48056098 + (0x60*(_i)))\r
+#define DMA4_CSSA(_i) (0x4805609c + (0x60*(_i)))\r
+#define DMA4_CDSA(_i) (0x480560a0 + (0x60*(_i)))\r
+#define DMA4_CSEI(_i) (0x480560a4 + (0x60*(_i)))\r
+#define DMA4_CSFI(_i) (0x480560a8 + (0x60*(_i)))\r
+#define DMA4_CDEI(_i) (0x480560ac + (0x60*(_i)))\r
+#define DMA4_CDFI(_i) (0x480560b0 + (0x60*(_i)))\r
+\r
+#define DMA4_GCR      (0x48056078)\r
+\r
+// Channel Source Destination parameters\r
+#define DMA4_CSDP_DATA_TYPE8    0\r
+#define DMA4_CSDP_DATA_TYPE16   1\r
+#define DMA4_CSDP_DATA_TYPE32   2\r
+\r
+#define DMA4_CSDP_SRC_PACKED      BIT6\r
+#define DMA4_CSDP_SRC_NONPACKED   0\r
+\r
+#define DMA4_CSDP_SRC_BURST_EN    (0x0 << 7)\r
+#define DMA4_CSDP_SRC_BURST_EN16  (0x1 << 7)\r
+#define DMA4_CSDP_SRC_BURST_EN32  (0x2 << 7)\r
+#define DMA4_CSDP_SRC_BURST_EN64  (0x3 << 7)\r
+\r
+#define DMA4_CSDP_DST_PACKED      BIT13\r
+#define DMA4_CSDP_DST_NONPACKED   0\r
+\r
+#define DMA4_CSDP_BURST_EN        (0x0 << 14)\r
+#define DMA4_CSDP_BURST_EN16      (0x1 << 14)\r
+#define DMA4_CSDP_BURST_EN32      (0x2 << 14)\r
+#define DMA4_CSDP_BURST_EN64      (0x3 << 14)\r
+\r
+#define DMA4_CSDP_WRITE_MODE_NONE_POSTED      (0x0 << 16)  \r
+#define DMA4_CSDP_WRITE_MODE_POSTED           (0x1 << 16)\r
+#define DMA4_CSDP_WRITE_MODE_LAST_NON_POSTED  (0x2 << 16)  \r
+\r
+#define DMA4_CSDP_DST_ENDIAN_LOCK_LOCK    BIT18\r
+#define DMA4_CSDP_DST_ENDIAN_LOCK_ADAPT   0\r
+\r
+#define DMA4_CSDP_DST_ENDIAN_BIG          BIT19\r
+#define DMA4_CSDP_DST_ENDIAN_LITTLE       0\r
+\r
+#define DMA4_CSDP_SRC_ENDIAN_LOCK_LOCK    BIT20\r
+#define DMA4_CSDP_SRC_ENDIAN_LOCK_ADAPT   0\r
+\r
+#define DMA4_CSDP_SRC_ENDIAN_BIG          BIT21\r
+#define DMA4_CSDP_SRC_ENDIAN_LITTLE       0\r
+\r
+// Channel Control \r
+#define DMA4_CCR_SYNCHRO_CONTROL_MASK     0x1f\r
+\r
+#define DMA4_CCR_FS_ELEMENT     (0    | 0)\r
+#define DMA4_CCR_FS_BLOCK       (0    | BIT18)\r
+#define DMA4_CCR_FS_FRAME       (BIT5 | 0)\r
+#define DMA4_CCR_FS_PACKET      (BIT5 | BIT18)\r
+\r
+#define DMA4_CCR_READ_PRIORITY_HIGH   BIT6\r
+#define DMA4_CCR_READ_PRIORITY_LOW    0\r
+\r
+#define DMA4_CCR_ENABLE               BIT7\r
+#define DMA4_CCR_DISABLE              0\r
+\r
+#define DMA4_CCR_SUSPEND_SENSITIVE_IGNORE BIT8\r
+#define DMA4_CCR_SUSPEND_SENSITIVE        0\r
+\r
+#define DMA4_CCR_RD_ACTIVE                BIT9\r
+#define DMA4_CCR_WR_ACTIVE                BIT10\r
+\r
+#define DMA4_CCR_SRC_AMODE                (0     | 0)\r
+#define DMA4_CCR_SRC_AMODE_POST_INC       (0     | BIT12)\r
+#define DMA4_CCR_SRC_AMODE_SINGLE_INDEX   (BIT13 | 0)\r
+#define DMA4_CCR_SRC_AMODE_DOUBLE_INDEX   (BIT13 | BIT12)\r
+\r
+#define DMA4_CCR_DST_AMODE                (0     | 0)\r
+#define DMA4_CCR_DST_AMODE_POST_INC       (0     | BIT14)\r
+#define DMA4_CCR_DST_AMODE_SINGLE_INDEX   (BIT15 | 0)\r
+#define DMA4_CCR_DST_AMODE_DOUBLE_INDEX   (BIT15 | BIT14)\r
+\r
+#define DMA4_CCR_CONST_FILL_ENABLE        BIT16\r
+#define DMA4_CCR_TRANSPARENT_COPY_ENABLE  BIT17\r
+  \r
+#define DMA4_CCR_SEL_SRC_DEST_SYNC_SOURCE BIT24\r
+\r
+#define DMA4_CSR_DROP                     BIT1\r
+#define DMA4_CSR_HALF                     BIT2\r
+#define DMA4_CSR_FRAME                    BIT3\r
+#define DMA4_CSR_LAST                     BIT4\r
+#define DMA4_CSR_BLOCK                    BIT5\r
+#define DMA4_CSR_SYNC                     BIT6\r
+#define DMA4_CSR_PKT                      BIT7\r
+#define DMA4_CSR_TRANS_ERR                BIT8\r
+#define DMA4_CSR_SECURE_ERR               BIT9\r
+#define DMA4_CSR_SUPERVISOR_ERR           BIT10\r
+#define DMA4_CSR_MISALIGNED_ADRS_ERR      BIT11\r
+#define DMA4_CSR_DRAIN_END                BIT12\r
+#define DMA4_CSR_RESET                    0x1FE\r
+#define DMA4_CSR_ERR                      (DMA4_CSR_TRANS_ERR | DMA4_CSR_SECURE_ERR | DMA4_CSR_SUPERVISOR_ERR | DMA4_CSR_MISALIGNED_ADRS_ERR)\r
+\r
+// same mapping as CSR except for SYNC. Enable all since we are polling\r
+#define DMA4_CICR_ENABLE_ALL              0x1FBE\r
+\r
+\r
+#endif \r
+\r
index 94822d453c62ded97fb4a948f141ca4c1764fdac..e45a0f23b5eafb0603151f0a5dac7c47060d9890 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __OMAP3530GPIO_H__
-#define __OMAP3530GPIO_H__
-
-#define GPIO1_BASE (0x48310000)
-#define GPIO2_BASE (0x49050000)
-#define GPIO3_BASE (0x49052000)
-#define GPIO4_BASE (0x49054000)
-#define GPIO5_BASE (0x49056000)
-#define GPIO6_BASE (0x49058000)
-
-#define GPIO_SYSCONFIG        (0x0010)
-#define GPIO_SYSSTATUS        (0x0014)
-#define GPIO_IRQSTATUS1       (0x0018)
-#define GPIO_IRQENABLE1       (0x001C)
-#define GPIO_WAKEUPENABLE     (0x0020)
-#define GPIO_IRQSTATUS2       (0x0028)
-#define GPIO_IRQENABLE2       (0x002C)
-#define GPIO_CTRL             (0x0030)
-#define GPIO_OE               (0x0034)
-#define GPIO_DATAIN           (0x0038)
-#define GPIO_DATAOUT          (0x003C)
-#define GPIO_LEVELDETECT0     (0x0040)
-#define GPIO_LEVELDETECT1     (0x0044)
-#define GPIO_RISINGDETECT     (0x0048)
-#define GPIO_FALLINGDETECT    (0x004C)
-#define GPIO_DEBOUNCENABLE    (0x0050)
-#define GPIO_DEBOUNCINGTIME   (0x0054)
-#define GPIO_CLEARIRQENABLE1  (0x0060)
-#define GPIO_SETIRQENABLE1    (0x0064)
-#define GPIO_CLEARIRQENABLE2  (0x0070)
-#define GPIO_SETIRQENABLE2    (0x0074)
-#define GPIO_CLEARWKUENA      (0x0080)
-#define GPIO_SETWKUENA        (0x0084)
-#define GPIO_CLEARDATAOUT     (0x0090)
-#define GPIO_SETDATAOUT       (0x0094)
-
-#define GPIO_SYSCONFIG_IDLEMODE_MASK      (3UL << 3)
-#define GPIO_SYSCONFIG_IDLEMODE_FORCE     (0UL << 3)
-#define GPIO_SYSCONFIG_IDLEMODE_NONE      BIT3
-#define GPIO_SYSCONFIG_IDLEMODE_SMART     (2UL << 3)
-#define GPIO_SYSCONFIG_ENAWAKEUP_MASK     BIT2
-#define GPIO_SYSCONFIG_ENAWAKEUP_DISABLE  (0UL << 2)
-#define GPIO_SYSCONFIG_ENAWAKEUP_ENABLE   BIT2
-#define GPIO_SYSCONFIG_SOFTRESET_MASK     BIT1
-#define GPIO_SYSCONFIG_SOFTRESET_NORMAL   (0UL << 1)
-#define GPIO_SYSCONFIG_SOFTRESET_RESET    BIT1
-#define GPIO_SYSCONFIG_AUTOIDLE_MASK      BIT0
-#define GPIO_SYSCONFIG_AUTOIDLE_FREE_RUN  (0UL << 0)
-#define GPIO_SYSCONFIG_AUTOIDLE_ON        BIT0
-
-#define GPIO_SYSSTATUS_RESETDONE_MASK     BIT0
-#define GPIO_SYSSTATUS_RESETDONE_ONGOING  (0UL << 0)
-#define GPIO_SYSSTATUS_RESETDONE_COMPLETE BIT0
-
-#define GPIO_IRQSTATUS_MASK(x)            (1UL << (x))
-#define GPIO_IRQSTATUS_NOT_TRIGGERED(x)   (0UL << (x))
-#define GPIO_IRQSTATUS_TRIGGERED(x)       (1UL << (x))
-#define GPIO_IRQSTATUS_CLEAR(x)           (1UL << (x))
-
-#define GPIO_IRQENABLE_MASK(x)            (1UL << (x))
-#define GPIO_IRQENABLE_DISABLE(x)         (0UL << (x))
-#define GPIO_IRQENABLE_ENABLE(x)          (1UL << (x))
-
-#define GPIO_WAKEUPENABLE_MASK(x)         (1UL << (x))
-#define GPIO_WAKEUPENABLE_DISABLE(x)      (0UL << (x))
-#define GPIO_WAKEUPENABLE_ENABLE(x)       (1UL << (x))
-
-#define GPIO_CTRL_GATINGRATIO_MASK        (3UL << 1)
-#define GPIO_CTRL_GATINGRATIO_DIV_1       (0UL << 1)
-#define GPIO_CTRL_GATINGRATIO_DIV_2       BIT1
-#define GPIO_CTRL_GATINGRATIO_DIV_4       (2UL << 1)
-#define GPIO_CTRL_GATINGRATIO_DIV_8       (3UL << 1)
-#define GPIO_CTRL_DISABLEMODULE_MASK      BIT0
-#define GPIO_CTRL_DISABLEMODULE_ENABLE    (0UL << 0)
-#define GPIO_CTRL_DISABLEMODULE_DISABLE   BIT0
-
-#define GPIO_OE_MASK(x)                   (1UL << (x))
-#define GPIO_OE_OUTPUT(x)                 (0UL << (x))
-#define GPIO_OE_INPUT(x)                  (1UL << (x))
-
-#define GPIO_DATAIN_MASK(x)               (1UL << (x))
-
-#define GPIO_DATAOUT_MASK(x)              (1UL << (x))
-
-#define GPIO_LEVELDETECT_MASK(x)          (1UL << (x))
-#define GPIO_LEVELDETECT_DISABLE(x)       (0UL << (x))
-#define GPIO_LEVELDETECT_ENABLE(x)        (1UL << (x))
-
-#define GPIO_RISINGDETECT_MASK(x)         (1UL << (x))
-#define GPIO_RISINGDETECT_DISABLE(x)      (0UL << (x))
-#define GPIO_RISINGDETECT_ENABLE(x)       (1UL << (x))
-
-#define GPIO_FALLINGDETECT_MASK(x)        (1UL << (x))
-#define GPIO_FALLINGDETECT_DISABLE(x)     (0UL << (x))
-#define GPIO_FALLINGDETECT_ENABLE(x)      (1UL << (x))
-
-#define GPIO_DEBOUNCENABLE_MASK(x)        (1UL << (x))
-#define GPIO_DEBOUNCENABLE_DISABLE(x)     (0UL << (x))
-#define GPIO_DEBOUNCENABLE_ENABLE(x)      (1UL << (x))
-
-#define GPIO_DEBOUNCINGTIME_MASK          (0xFF)
-#define GPIO_DEBOUNCINGTIME_US(x)         ((((x) / 31) - 1) & GPIO_DEBOUNCINGTIME_MASK)
-
-#define GPIO_CLEARIRQENABLE_BIT(x)        (1UL << (x))
-
-#define GPIO_SETIRQENABLE_BIT(x)          (1UL << (x))
-
-#define GPIO_CLEARWKUENA_BIT(x)           (1UL << (x))
-
-#define GPIO_SETWKUENA_BIT(x)             (1UL << (x))
-
-#define GPIO_CLEARDATAOUT_BIT(x)          (1UL << (x))
-
-#define GPIO_SETDATAOUT_BIT(x)            (1UL << (x))
-
-#endif // __OMAP3530GPIO_H__
-
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __OMAP3530GPIO_H__\r
+#define __OMAP3530GPIO_H__\r
+\r
+#define GPIO1_BASE (0x48310000)\r
+#define GPIO2_BASE (0x49050000)\r
+#define GPIO3_BASE (0x49052000)\r
+#define GPIO4_BASE (0x49054000)\r
+#define GPIO5_BASE (0x49056000)\r
+#define GPIO6_BASE (0x49058000)\r
+\r
+#define GPIO_SYSCONFIG        (0x0010)\r
+#define GPIO_SYSSTATUS        (0x0014)\r
+#define GPIO_IRQSTATUS1       (0x0018)\r
+#define GPIO_IRQENABLE1       (0x001C)\r
+#define GPIO_WAKEUPENABLE     (0x0020)\r
+#define GPIO_IRQSTATUS2       (0x0028)\r
+#define GPIO_IRQENABLE2       (0x002C)\r
+#define GPIO_CTRL             (0x0030)\r
+#define GPIO_OE               (0x0034)\r
+#define GPIO_DATAIN           (0x0038)\r
+#define GPIO_DATAOUT          (0x003C)\r
+#define GPIO_LEVELDETECT0     (0x0040)\r
+#define GPIO_LEVELDETECT1     (0x0044)\r
+#define GPIO_RISINGDETECT     (0x0048)\r
+#define GPIO_FALLINGDETECT    (0x004C)\r
+#define GPIO_DEBOUNCENABLE    (0x0050)\r
+#define GPIO_DEBOUNCINGTIME   (0x0054)\r
+#define GPIO_CLEARIRQENABLE1  (0x0060)\r
+#define GPIO_SETIRQENABLE1    (0x0064)\r
+#define GPIO_CLEARIRQENABLE2  (0x0070)\r
+#define GPIO_SETIRQENABLE2    (0x0074)\r
+#define GPIO_CLEARWKUENA      (0x0080)\r
+#define GPIO_SETWKUENA        (0x0084)\r
+#define GPIO_CLEARDATAOUT     (0x0090)\r
+#define GPIO_SETDATAOUT       (0x0094)\r
+\r
+#define GPIO_SYSCONFIG_IDLEMODE_MASK      (3UL << 3)\r
+#define GPIO_SYSCONFIG_IDLEMODE_FORCE     (0UL << 3)\r
+#define GPIO_SYSCONFIG_IDLEMODE_NONE      BIT3\r
+#define GPIO_SYSCONFIG_IDLEMODE_SMART     (2UL << 3)\r
+#define GPIO_SYSCONFIG_ENAWAKEUP_MASK     BIT2\r
+#define GPIO_SYSCONFIG_ENAWAKEUP_DISABLE  (0UL << 2)\r
+#define GPIO_SYSCONFIG_ENAWAKEUP_ENABLE   BIT2\r
+#define GPIO_SYSCONFIG_SOFTRESET_MASK     BIT1\r
+#define GPIO_SYSCONFIG_SOFTRESET_NORMAL   (0UL << 1)\r
+#define GPIO_SYSCONFIG_SOFTRESET_RESET    BIT1\r
+#define GPIO_SYSCONFIG_AUTOIDLE_MASK      BIT0\r
+#define GPIO_SYSCONFIG_AUTOIDLE_FREE_RUN  (0UL << 0)\r
+#define GPIO_SYSCONFIG_AUTOIDLE_ON        BIT0\r
+\r
+#define GPIO_SYSSTATUS_RESETDONE_MASK     BIT0\r
+#define GPIO_SYSSTATUS_RESETDONE_ONGOING  (0UL << 0)\r
+#define GPIO_SYSSTATUS_RESETDONE_COMPLETE BIT0\r
+\r
+#define GPIO_IRQSTATUS_MASK(x)            (1UL << (x))\r
+#define GPIO_IRQSTATUS_NOT_TRIGGERED(x)   (0UL << (x))\r
+#define GPIO_IRQSTATUS_TRIGGERED(x)       (1UL << (x))\r
+#define GPIO_IRQSTATUS_CLEAR(x)           (1UL << (x))\r
+\r
+#define GPIO_IRQENABLE_MASK(x)            (1UL << (x))\r
+#define GPIO_IRQENABLE_DISABLE(x)         (0UL << (x))\r
+#define GPIO_IRQENABLE_ENABLE(x)          (1UL << (x))\r
+\r
+#define GPIO_WAKEUPENABLE_MASK(x)         (1UL << (x))\r
+#define GPIO_WAKEUPENABLE_DISABLE(x)      (0UL << (x))\r
+#define GPIO_WAKEUPENABLE_ENABLE(x)       (1UL << (x))\r
+\r
+#define GPIO_CTRL_GATINGRATIO_MASK        (3UL << 1)\r
+#define GPIO_CTRL_GATINGRATIO_DIV_1       (0UL << 1)\r
+#define GPIO_CTRL_GATINGRATIO_DIV_2       BIT1\r
+#define GPIO_CTRL_GATINGRATIO_DIV_4       (2UL << 1)\r
+#define GPIO_CTRL_GATINGRATIO_DIV_8       (3UL << 1)\r
+#define GPIO_CTRL_DISABLEMODULE_MASK      BIT0\r
+#define GPIO_CTRL_DISABLEMODULE_ENABLE    (0UL << 0)\r
+#define GPIO_CTRL_DISABLEMODULE_DISABLE   BIT0\r
+\r
+#define GPIO_OE_MASK(x)                   (1UL << (x))\r
+#define GPIO_OE_OUTPUT(x)                 (0UL << (x))\r
+#define GPIO_OE_INPUT(x)                  (1UL << (x))\r
+\r
+#define GPIO_DATAIN_MASK(x)               (1UL << (x))\r
+\r
+#define GPIO_DATAOUT_MASK(x)              (1UL << (x))\r
+\r
+#define GPIO_LEVELDETECT_MASK(x)          (1UL << (x))\r
+#define GPIO_LEVELDETECT_DISABLE(x)       (0UL << (x))\r
+#define GPIO_LEVELDETECT_ENABLE(x)        (1UL << (x))\r
+\r
+#define GPIO_RISINGDETECT_MASK(x)         (1UL << (x))\r
+#define GPIO_RISINGDETECT_DISABLE(x)      (0UL << (x))\r
+#define GPIO_RISINGDETECT_ENABLE(x)       (1UL << (x))\r
+\r
+#define GPIO_FALLINGDETECT_MASK(x)        (1UL << (x))\r
+#define GPIO_FALLINGDETECT_DISABLE(x)     (0UL << (x))\r
+#define GPIO_FALLINGDETECT_ENABLE(x)      (1UL << (x))\r
+\r
+#define GPIO_DEBOUNCENABLE_MASK(x)        (1UL << (x))\r
+#define GPIO_DEBOUNCENABLE_DISABLE(x)     (0UL << (x))\r
+#define GPIO_DEBOUNCENABLE_ENABLE(x)      (1UL << (x))\r
+\r
+#define GPIO_DEBOUNCINGTIME_MASK          (0xFF)\r
+#define GPIO_DEBOUNCINGTIME_US(x)         ((((x) / 31) - 1) & GPIO_DEBOUNCINGTIME_MASK)\r
+\r
+#define GPIO_CLEARIRQENABLE_BIT(x)        (1UL << (x))\r
+\r
+#define GPIO_SETIRQENABLE_BIT(x)          (1UL << (x))\r
+\r
+#define GPIO_CLEARWKUENA_BIT(x)           (1UL << (x))\r
+\r
+#define GPIO_SETWKUENA_BIT(x)             (1UL << (x))\r
+\r
+#define GPIO_CLEARDATAOUT_BIT(x)          (1UL << (x))\r
+\r
+#define GPIO_SETDATAOUT_BIT(x)            (1UL << (x))\r
+\r
+#endif // __OMAP3530GPIO_H__\r
+\r
index 6cdd5f5114d993c2dfbf247af89bf2352cd89799..6943d303ec637d5e8f7f89089202f603d0ff440b 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __OMAP3530GPMC_H__
-#define __OMAP3530GPMC_H__
-
-#define GPMC_BASE             (0x6E000000)
-
-//GPMC NAND definitions.
-#define GPMC_SYSCONFIG        (GPMC_BASE + 0x10)
-#define SMARTIDLEMODE         (0x2UL << 3)
-
-#define GPMC_SYSSTATUS        (GPMC_BASE + 0x14)
-#define GPMC_IRQSTATUS        (GPMC_BASE + 0x18)
-#define GPMC_IRQENABLE        (GPMC_BASE + 0x1C)
-
-#define GPMC_TIMEOUT_CONTROL  (GPMC_BASE + 0x40)
-#define TIMEOUTENABLE         BIT0
-#define TIMEOUTDISABLE        (0x0UL << 0)
-
-#define GPMC_ERR_ADDRESS      (GPMC_BASE + 0x44)
-#define GPMC_ERR_TYPE         (GPMC_BASE + 0x48)
-
-#define GPMC_CONFIG           (GPMC_BASE + 0x50)
-#define WRITEPROTECT_HIGH     BIT4
-#define WRITEPROTECT_LOW      (0x0UL << 4)
-
-#define GPMC_STATUS           (GPMC_BASE + 0x54)
-
-#define GPMC_CONFIG1_0        (GPMC_BASE + 0x60)
-#define DEVICETYPE_NOR        (0x0UL << 10)
-#define DEVICETYPE_NAND       (0x2UL << 10)
-#define DEVICESIZE_X8         (0x0UL << 12)
-#define DEVICESIZE_X16        BIT12
-
-#define GPMC_CONFIG2_0        (GPMC_BASE + 0x64)
-#define CSONTIME              (0x0UL << 0)
-#define CSRDOFFTIME           (0x14UL << 8)
-#define CSWROFFTIME           (0x14UL << 16)
-
-#define GPMC_CONFIG3_0        (GPMC_BASE + 0x68)
-#define ADVRDOFFTIME          (0x14UL << 8)
-#define ADVWROFFTIME          (0x14UL << 16)
-
-#define GPMC_CONFIG4_0        (GPMC_BASE + 0x6C)
-#define OEONTIME              BIT0
-#define OEOFFTIME             (0xFUL << 8)
-#define WEONTIME              BIT16
-#define WEOFFTIME             (0xFUL << 24)
-
-#define GPMC_CONFIG5_0        (GPMC_BASE + 0x70)
-#define RDCYCLETIME           (0x14UL << 0)
-#define WRCYCLETIME           (0x14UL << 8)
-#define RDACCESSTIME          (0xCUL << 16)
-#define PAGEBURSTACCESSTIME   BIT24
-
-#define GPMC_CONFIG6_0        (GPMC_BASE + 0x74)
-#define CYCLE2CYCLESAMECSEN   BIT7
-#define CYCLE2CYCLEDELAY      (0xAUL << 8)
-#define WRDATAONADMUXBUS      (0xFUL << 16)
-#define WRACCESSTIME          BIT24
-
-#define GPMC_CONFIG7_0        (GPMC_BASE + 0x78)
-#define BASEADDRESS           (0x30UL << 0)
-#define CSVALID               BIT6
-#define MASKADDRESS_128MB     (0x8UL << 8)
-
-#define GPMC_NAND_COMMAND_0   (GPMC_BASE + 0x7C)
-#define GPMC_NAND_ADDRESS_0   (GPMC_BASE + 0x80)
-#define GPMC_NAND_DATA_0      (GPMC_BASE + 0x84)
-
-#define GPMC_ECC_CONFIG       (GPMC_BASE + 0x1F4)
-#define ECCENABLE             BIT0
-#define ECCDISABLE            (0x0UL << 0)
-#define ECCCS_0               (0x0UL << 1)
-#define ECC16B                BIT7
-
-#define GPMC_ECC_CONTROL      (GPMC_BASE + 0x1F8)
-#define ECCPOINTER_REG1       BIT0
-#define ECCCLEAR              BIT8
-
-#define GPMC_ECC_SIZE_CONFIG  (GPMC_BASE + 0x1FC)
-#define ECCSIZE0_512BYTES     (0xFFUL << 12)
-#define ECCSIZE1_512BYTES     (0xFFUL << 22)
-
-#define GPMC_ECC1_RESULT      (GPMC_BASE + 0x200)
-#define GPMC_ECC2_RESULT      (GPMC_BASE + 0x204)
-#define GPMC_ECC3_RESULT      (GPMC_BASE + 0x208)
-#define GPMC_ECC4_RESULT      (GPMC_BASE + 0x20C)
-#define GPMC_ECC5_RESULT      (GPMC_BASE + 0x210)
-#define GPMC_ECC6_RESULT      (GPMC_BASE + 0x214)
-#define GPMC_ECC7_RESULT      (GPMC_BASE + 0x218)
-#define GPMC_ECC8_RESULT      (GPMC_BASE + 0x21C)
-#define GPMC_ECC9_RESULT      (GPMC_BASE + 0x220)
-
-#endif //__OMAP3530GPMC_H__
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __OMAP3530GPMC_H__\r
+#define __OMAP3530GPMC_H__\r
+\r
+#define GPMC_BASE             (0x6E000000)\r
+\r
+//GPMC NAND definitions.\r
+#define GPMC_SYSCONFIG        (GPMC_BASE + 0x10)\r
+#define SMARTIDLEMODE         (0x2UL << 3)\r
+\r
+#define GPMC_SYSSTATUS        (GPMC_BASE + 0x14)\r
+#define GPMC_IRQSTATUS        (GPMC_BASE + 0x18)\r
+#define GPMC_IRQENABLE        (GPMC_BASE + 0x1C)\r
+\r
+#define GPMC_TIMEOUT_CONTROL  (GPMC_BASE + 0x40)\r
+#define TIMEOUTENABLE         BIT0\r
+#define TIMEOUTDISABLE        (0x0UL << 0)\r
+\r
+#define GPMC_ERR_ADDRESS      (GPMC_BASE + 0x44)\r
+#define GPMC_ERR_TYPE         (GPMC_BASE + 0x48)\r
+\r
+#define GPMC_CONFIG           (GPMC_BASE + 0x50)\r
+#define WRITEPROTECT_HIGH     BIT4\r
+#define WRITEPROTECT_LOW      (0x0UL << 4)\r
+\r
+#define GPMC_STATUS           (GPMC_BASE + 0x54)\r
+\r
+#define GPMC_CONFIG1_0        (GPMC_BASE + 0x60)\r
+#define DEVICETYPE_NOR        (0x0UL << 10)\r
+#define DEVICETYPE_NAND       (0x2UL << 10)\r
+#define DEVICESIZE_X8         (0x0UL << 12)\r
+#define DEVICESIZE_X16        BIT12\r
+\r
+#define GPMC_CONFIG2_0        (GPMC_BASE + 0x64)\r
+#define CSONTIME              (0x0UL << 0)\r
+#define CSRDOFFTIME           (0x14UL << 8)\r
+#define CSWROFFTIME           (0x14UL << 16)\r
+\r
+#define GPMC_CONFIG3_0        (GPMC_BASE + 0x68)\r
+#define ADVRDOFFTIME          (0x14UL << 8)\r
+#define ADVWROFFTIME          (0x14UL << 16)\r
+\r
+#define GPMC_CONFIG4_0        (GPMC_BASE + 0x6C)\r
+#define OEONTIME              BIT0\r
+#define OEOFFTIME             (0xFUL << 8)\r
+#define WEONTIME              BIT16\r
+#define WEOFFTIME             (0xFUL << 24)\r
+\r
+#define GPMC_CONFIG5_0        (GPMC_BASE + 0x70)\r
+#define RDCYCLETIME           (0x14UL << 0)\r
+#define WRCYCLETIME           (0x14UL << 8)\r
+#define RDACCESSTIME          (0xCUL << 16)\r
+#define PAGEBURSTACCESSTIME   BIT24\r
+\r
+#define GPMC_CONFIG6_0        (GPMC_BASE + 0x74)\r
+#define CYCLE2CYCLESAMECSEN   BIT7\r
+#define CYCLE2CYCLEDELAY      (0xAUL << 8)\r
+#define WRDATAONADMUXBUS      (0xFUL << 16)\r
+#define WRACCESSTIME          BIT24\r
+\r
+#define GPMC_CONFIG7_0        (GPMC_BASE + 0x78)\r
+#define BASEADDRESS           (0x30UL << 0)\r
+#define CSVALID               BIT6\r
+#define MASKADDRESS_128MB     (0x8UL << 8)\r
+\r
+#define GPMC_NAND_COMMAND_0   (GPMC_BASE + 0x7C)\r
+#define GPMC_NAND_ADDRESS_0   (GPMC_BASE + 0x80)\r
+#define GPMC_NAND_DATA_0      (GPMC_BASE + 0x84)\r
+\r
+#define GPMC_ECC_CONFIG       (GPMC_BASE + 0x1F4)\r
+#define ECCENABLE             BIT0\r
+#define ECCDISABLE            (0x0UL << 0)\r
+#define ECCCS_0               (0x0UL << 1)\r
+#define ECC16B                BIT7\r
+\r
+#define GPMC_ECC_CONTROL      (GPMC_BASE + 0x1F8)\r
+#define ECCPOINTER_REG1       BIT0\r
+#define ECCCLEAR              BIT8\r
+\r
+#define GPMC_ECC_SIZE_CONFIG  (GPMC_BASE + 0x1FC)\r
+#define ECCSIZE0_512BYTES     (0xFFUL << 12)\r
+#define ECCSIZE1_512BYTES     (0xFFUL << 22)\r
+\r
+#define GPMC_ECC1_RESULT      (GPMC_BASE + 0x200)\r
+#define GPMC_ECC2_RESULT      (GPMC_BASE + 0x204)\r
+#define GPMC_ECC3_RESULT      (GPMC_BASE + 0x208)\r
+#define GPMC_ECC4_RESULT      (GPMC_BASE + 0x20C)\r
+#define GPMC_ECC5_RESULT      (GPMC_BASE + 0x210)\r
+#define GPMC_ECC6_RESULT      (GPMC_BASE + 0x214)\r
+#define GPMC_ECC7_RESULT      (GPMC_BASE + 0x218)\r
+#define GPMC_ECC8_RESULT      (GPMC_BASE + 0x21C)\r
+#define GPMC_ECC9_RESULT      (GPMC_BASE + 0x220)\r
+\r
+#endif //__OMAP3530GPMC_H__\r
index 61e1bf5c080fbfc2dde6972870362cf74d02a98a..31d4d5ea6403b90d5ba669bc4ae93d350591c7cf 100644 (file)
@@ -1,62 +1,62 @@
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __OMAP3530I2C_H__
-#define __OMAP3530I2C_H__
-
-//I2C register definitions.
-#define I2C1BASE        0x48070000
-
-#define I2C_IE          (I2C1BASE + 0x4)
-#define XRDY_IE         BIT4
-#define RRDY_IE         BIT3
-#define ARDY_IE         BIT2
-#define NACK_IE         BIT1
-
-#define I2C_STAT        (I2C1BASE + 0x8)
-#define BB              BIT12
-#define XRDY            BIT4
-#define RRDY            BIT3
-#define ARDY            BIT2
-#define NACK            BIT1
-
-#define I2C_WE          (I2C1BASE + 0xC)
-#define I2C_SYSS        (I2C1BASE + 0x10)
-#define I2C_BUF         (I2C1BASE + 0x14)
-#define I2C_CNT         (I2C1BASE + 0x18)
-#define I2C_DATA        (I2C1BASE + 0x1C)
-#define I2C_SYSC        (I2C1BASE + 0x20)
-
-#define I2C_CON         (I2C1BASE + 0x24)
-#define STT             BIT0
-#define STP             BIT1
-#define XSA             BIT8
-#define TRX             BIT9
-#define MST             BIT10
-#define I2C_EN          BIT15
-
-#define I2C_OA0         (I2C1BASE + 0x28)
-#define I2C_SA          (I2C1BASE + 0x2C)
-#define I2C_PSC         (I2C1BASE + 0x30)
-#define I2C_SCLL        (I2C1BASE + 0x34)
-#define I2C_SCLH        (I2C1BASE + 0x38)
-#define I2C_SYSTEST     (I2C1BASE + 0x3C)
-#define I2C_BUFSTAT     (I2C1BASE + 0x40)
-#define I2C_OA1         (I2C1BASE + 0x44)
-#define I2C_OA2         (I2C1BASE + 0x48)
-#define I2C_OA3         (I2C1BASE + 0x4C)
-#define I2C_ACTOA       (I2C1BASE + 0x50)
-#define I2C_SBLOCK      (I2C1BASE + 0x54)
-
-#endif //__OMAP3530I2C_H__
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __OMAP3530I2C_H__\r
+#define __OMAP3530I2C_H__\r
+\r
+//I2C register definitions.\r
+#define I2C1BASE        0x48070000\r
+\r
+#define I2C_IE          (I2C1BASE + 0x4)\r
+#define XRDY_IE         BIT4\r
+#define RRDY_IE         BIT3\r
+#define ARDY_IE         BIT2\r
+#define NACK_IE         BIT1\r
+\r
+#define I2C_STAT        (I2C1BASE + 0x8)\r
+#define BB              BIT12\r
+#define XRDY            BIT4\r
+#define RRDY            BIT3\r
+#define ARDY            BIT2\r
+#define NACK            BIT1\r
+\r
+#define I2C_WE          (I2C1BASE + 0xC)\r
+#define I2C_SYSS        (I2C1BASE + 0x10)\r
+#define I2C_BUF         (I2C1BASE + 0x14)\r
+#define I2C_CNT         (I2C1BASE + 0x18)\r
+#define I2C_DATA        (I2C1BASE + 0x1C)\r
+#define I2C_SYSC        (I2C1BASE + 0x20)\r
+\r
+#define I2C_CON         (I2C1BASE + 0x24)\r
+#define STT             BIT0\r
+#define STP             BIT1\r
+#define XSA             BIT8\r
+#define TRX             BIT9\r
+#define MST             BIT10\r
+#define I2C_EN          BIT15\r
+\r
+#define I2C_OA0         (I2C1BASE + 0x28)\r
+#define I2C_SA          (I2C1BASE + 0x2C)\r
+#define I2C_PSC         (I2C1BASE + 0x30)\r
+#define I2C_SCLL        (I2C1BASE + 0x34)\r
+#define I2C_SCLH        (I2C1BASE + 0x38)\r
+#define I2C_SYSTEST     (I2C1BASE + 0x3C)\r
+#define I2C_BUFSTAT     (I2C1BASE + 0x40)\r
+#define I2C_OA1         (I2C1BASE + 0x44)\r
+#define I2C_OA2         (I2C1BASE + 0x48)\r
+#define I2C_OA3         (I2C1BASE + 0x4C)\r
+#define I2C_ACTOA       (I2C1BASE + 0x50)\r
+#define I2C_SBLOCK      (I2C1BASE + 0x54)\r
+\r
+#endif //__OMAP3530I2C_H__\r
index 9d1036d0dc1cc7a915c04c91c435c684035d9f0a..774d8730153da9dfb4ee82333cd84c83795b421d 100644 (file)
@@ -1,48 +1,48 @@
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __OMAP3530INTERRUPT_H__
-#define __OMAP3530INTERRUPT_H__
-
-#define INTERRUPT_BASE (0x48200000)
-
-#define INT_NROF_VECTORS      (96)
-#define MAX_VECTOR            (INT_NROF_VECTORS - 1)
-#define INTCPS_SYSCONFIG      (INTERRUPT_BASE + 0x0010)
-#define INTCPS_SYSSTATUS      (INTERRUPT_BASE + 0x0014)
-#define INTCPS_SIR_IRQ        (INTERRUPT_BASE + 0x0040)
-#define INTCPS_SIR_IFQ        (INTERRUPT_BASE + 0x0044)
-#define INTCPS_CONTROL        (INTERRUPT_BASE + 0x0048)
-#define INTCPS_PROTECTION     (INTERRUPT_BASE + 0x004C)
-#define INTCPS_IDLE           (INTERRUPT_BASE + 0x0050)
-#define INTCPS_IRQ_PRIORITY   (INTERRUPT_BASE + 0x0060)
-#define INTCPS_FIQ_PRIORITY   (INTERRUPT_BASE + 0x0064)
-#define INTCPS_THRESHOLD      (INTERRUPT_BASE + 0x0068)
-#define INTCPS_ITR(n)         (INTERRUPT_BASE + 0x0080 + (0x20 * (n)))
-#define INTCPS_MIR(n)         (INTERRUPT_BASE + 0x0084 + (0x20 * (n)))
-#define INTCPS_MIR_CLEAR(n)   (INTERRUPT_BASE + 0x0088 + (0x20 * (n)))
-#define INTCPS_MIR_SET(n)     (INTERRUPT_BASE + 0x008C + (0x20 * (n)))
-#define INTCPS_ISR_SET(n)     (INTERRUPT_BASE + 0x0090 + (0x20 * (n)))
-#define INTCPS_ISR_CLEAR(n)   (INTERRUPT_BASE + 0x0094 + (0x20 * (n)))
-#define INTCPS_PENDING_IRQ(n) (INTERRUPT_BASE + 0x0098 + (0x20 * (n)))
-#define INTCPS_PENDING_FIQ(n) (INTERRUPT_BASE + 0x009C + (0x20 * (n)))
-#define INTCPS_ILR(m)         (INTERRUPT_BASE + 0x0100 + (0x04 * (m)))
-
-#define INTCPS_ILR_FIQ            BIT0
-#define INTCPS_SIR_IRQ_MASK       (0x7F)
-#define INTCPS_CONTROL_NEWIRQAGR  BIT0
-#define INTCPS_CONTROL_NEWFIQAGR  BIT1
-
-#endif // __OMAP3530INTERRUPT_H__
-
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __OMAP3530INTERRUPT_H__\r
+#define __OMAP3530INTERRUPT_H__\r
+\r
+#define INTERRUPT_BASE (0x48200000)\r
+\r
+#define INT_NROF_VECTORS      (96)\r
+#define MAX_VECTOR            (INT_NROF_VECTORS - 1)\r
+#define INTCPS_SYSCONFIG      (INTERRUPT_BASE + 0x0010)\r
+#define INTCPS_SYSSTATUS      (INTERRUPT_BASE + 0x0014)\r
+#define INTCPS_SIR_IRQ        (INTERRUPT_BASE + 0x0040)\r
+#define INTCPS_SIR_IFQ        (INTERRUPT_BASE + 0x0044)\r
+#define INTCPS_CONTROL        (INTERRUPT_BASE + 0x0048)\r
+#define INTCPS_PROTECTION     (INTERRUPT_BASE + 0x004C)\r
+#define INTCPS_IDLE           (INTERRUPT_BASE + 0x0050)\r
+#define INTCPS_IRQ_PRIORITY   (INTERRUPT_BASE + 0x0060)\r
+#define INTCPS_FIQ_PRIORITY   (INTERRUPT_BASE + 0x0064)\r
+#define INTCPS_THRESHOLD      (INTERRUPT_BASE + 0x0068)\r
+#define INTCPS_ITR(n)         (INTERRUPT_BASE + 0x0080 + (0x20 * (n)))\r
+#define INTCPS_MIR(n)         (INTERRUPT_BASE + 0x0084 + (0x20 * (n)))\r
+#define INTCPS_MIR_CLEAR(n)   (INTERRUPT_BASE + 0x0088 + (0x20 * (n)))\r
+#define INTCPS_MIR_SET(n)     (INTERRUPT_BASE + 0x008C + (0x20 * (n)))\r
+#define INTCPS_ISR_SET(n)     (INTERRUPT_BASE + 0x0090 + (0x20 * (n)))\r
+#define INTCPS_ISR_CLEAR(n)   (INTERRUPT_BASE + 0x0094 + (0x20 * (n)))\r
+#define INTCPS_PENDING_IRQ(n) (INTERRUPT_BASE + 0x0098 + (0x20 * (n)))\r
+#define INTCPS_PENDING_FIQ(n) (INTERRUPT_BASE + 0x009C + (0x20 * (n)))\r
+#define INTCPS_ILR(m)         (INTERRUPT_BASE + 0x0100 + (0x04 * (m)))\r
+\r
+#define INTCPS_ILR_FIQ            BIT0\r
+#define INTCPS_SIR_IRQ_MASK       (0x7F)\r
+#define INTCPS_CONTROL_NEWIRQAGR  BIT0\r
+#define INTCPS_CONTROL_NEWFIQAGR  BIT1\r
+\r
+#endif // __OMAP3530INTERRUPT_H__\r
+\r
index 1b3e734d6a24b5b662b51c48e0d598a2d1622147..5bebe6c5094e70c68160cbaae46e718b344c3856 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __OMAP3530SDIO_H__
-#define __OMAP3530SDIO_H__
-
-//MMC/SD/SDIO1 register definitions.
-#define MMCHS1BASE        0x4809C000
-#define MMC_REFERENCE_CLK (96000000)
-
-#define MMCHS_SYSCONFIG   (MMCHS1BASE + 0x10)
-#define SOFTRESET         BIT1
-#define ENAWAKEUP         BIT2
-
-#define MMCHS_SYSSTATUS   (MMCHS1BASE + 0x14)
-#define RESETDONE_MASK    BIT0
-#define RESETDONE         BIT0
-
-#define MMCHS_CSRE        (MMCHS1BASE + 0x24)
-#define MMCHS_SYSTEST     (MMCHS1BASE + 0x28)
-
-#define MMCHS_CON         (MMCHS1BASE + 0x2C)
-#define OD                BIT0
-#define NOINIT            (0x0UL << 1)
-#define INIT              BIT1
-#define HR                BIT2
-#define STR               BIT3
-#define MODE              BIT4
-#define DW8_1_4_BIT       (0x0UL << 5)
-#define DW8_8_BIT         BIT5
-#define MIT               BIT6
-#define CDP               BIT7
-#define WPP               BIT8
-#define CTPL              BIT11
-#define CEATA_OFF         (0x0UL << 12)
-#define CEATA_ON          BIT12
-
-#define MMCHS_PWCNT       (MMCHS1BASE + 0x30)
-
-#define MMCHS_BLK         (MMCHS1BASE + 0x104)
-#define BLEN_512BYTES     (0x200UL << 0)
-
-#define MMCHS_ARG         (MMCHS1BASE + 0x108)
-
-#define MMCHS_CMD         (MMCHS1BASE + 0x10C)
-#define DE_ENABLE         BIT0
-#define BCE_ENABLE        BIT1
-#define ACEN_ENABLE       BIT2
-#define DDIR_READ         BIT4
-#define DDIR_WRITE        (0x0UL << 4)
-#define MSBS_SGLEBLK      (0x0UL << 5)
-#define MSBS_MULTBLK      BIT5
-#define RSP_TYPE_MASK     (0x3UL << 16)
-#define RSP_TYPE_136BITS  BIT16
-#define RSP_TYPE_48BITS   (0x2UL << 16)
-#define CCCE_ENABLE       BIT19
-#define CICE_ENABLE       BIT20
-#define DP_ENABLE         BIT21 
-#define INDX(CMD_INDX)    ((CMD_INDX & 0x3F) << 24)
-
-#define MMCHS_RSP10       (MMCHS1BASE + 0x110)
-#define MMCHS_RSP32       (MMCHS1BASE + 0x114)
-#define MMCHS_RSP54       (MMCHS1BASE + 0x118)
-#define MMCHS_RSP76       (MMCHS1BASE + 0x11C)
-#define MMCHS_DATA        (MMCHS1BASE + 0x120)
-
-#define MMCHS_PSTATE      (MMCHS1BASE + 0x124)
-#define CMDI_MASK         BIT0
-#define CMDI_ALLOWED      (0x0UL << 0)
-#define CMDI_NOT_ALLOWED  BIT0
-#define DATI_MASK         BIT1
-#define DATI_ALLOWED      (0x0UL << 1)
-#define DATI_NOT_ALLOWED  BIT1
-
-#define MMCHS_HCTL        (MMCHS1BASE + 0x128)
-#define DTW_1_BIT         (0x0UL << 1)
-#define DTW_4_BIT         BIT1
-#define SDBP_MASK         BIT8
-#define SDBP_OFF          (0x0UL << 8)
-#define SDBP_ON           BIT8
-#define SDVS_1_8_V        (0x5UL << 9)
-#define SDVS_3_0_V        (0x6UL << 9)
-#define IWE               BIT24
-
-#define MMCHS_SYSCTL      (MMCHS1BASE + 0x12C)
-#define ICE               BIT0
-#define ICS_MASK          BIT1
-#define ICS               BIT1
-#define CEN               BIT2
-#define CLKD_MASK         (0x3FFUL << 6)
-#define CLKD_80KHZ        (0x258UL) //(96*1000/80)/2
-#define CLKD_400KHZ       (0xF0UL)
-#define DTO_MASK          (0xFUL << 16)
-#define DTO_VAL           (0xEUL << 16)
-#define SRA               BIT24
-#define SRC_MASK          BIT25
-#define SRC               BIT25
-#define SRD               BIT26
-
-#define MMCHS_STAT        (MMCHS1BASE + 0x130)
-#define CC                BIT0
-#define TC                BIT1
-#define BWR               BIT4
-#define BRR               BIT5
-#define ERRI              BIT15
-#define CTO               BIT16
-#define DTO               BIT20
-#define DCRC              BIT21
-#define DEB               BIT22
-
-#define MMCHS_IE          (MMCHS1BASE + 0x134)
-#define CC_EN             BIT0
-#define TC_EN             BIT1
-#define BWR_EN            BIT4
-#define BRR_EN            BIT5
-#define CTO_EN            BIT16
-#define CCRC_EN           BIT17
-#define CEB_EN            BIT18
-#define CIE_EN            BIT19
-#define DTO_EN            BIT20
-#define DCRC_EN           BIT21
-#define DEB_EN            BIT22
-#define CERR_EN           BIT28
-#define BADA_EN           BIT29
-
-#define MMCHS_ISE         (MMCHS1BASE + 0x138)
-#define CC_SIGEN          BIT0
-#define TC_SIGEN          BIT1
-#define BWR_SIGEN         BIT4
-#define BRR_SIGEN         BIT5
-#define CTO_SIGEN         BIT16
-#define CCRC_SIGEN        BIT17
-#define CEB_SIGEN         BIT18
-#define CIE_SIGEN         BIT19
-#define DTO_SIGEN         BIT20
-#define DCRC_SIGEN        BIT21
-#define DEB_SIGEN         BIT22
-#define CERR_SIGEN        BIT28
-#define BADA_SIGEN        BIT29
-
-#define MMCHS_AC12        (MMCHS1BASE + 0x13C)
-
-#define MMCHS_CAPA        (MMCHS1BASE + 0x140)
-#define VS30              BIT25
-#define VS18              BIT26
-
-#define MMCHS_CUR_CAPA    (MMCHS1BASE + 0x148)
-#define MMCHS_REV         (MMCHS1BASE + 0x1FC)
-
-#define CMD0              INDX(0)
-#define CMD0_INT_EN       (CC_EN | CEB_EN)
-
-#define CMD1              (INDX(1) | RSP_TYPE_48BITS)
-#define CMD1_INT_EN       (CC_EN | CEB_EN | CTO_EN)
-
-#define CMD2              (INDX(2) | CCCE_ENABLE | RSP_TYPE_136BITS)
-#define CMD2_INT_EN       (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)
-
-#define CMD3              (INDX(3) | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS)
-#define CMD3_INT_EN       (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)
-
-#define CMD5              (INDX(5) | RSP_TYPE_48BITS)
-#define CMD5_INT_EN       (CC_EN | CEB_EN | CTO_EN)
-
-#define CMD7              (INDX(7) | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS)
-#define CMD7_INT_EN       (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)
-
-#define CMD8              (INDX(8) | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS)
-#define CMD8_INT_EN       (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)
-//Reserved(0)[12:31], Supply voltage(1)[11:8], check pattern(0xCE)[7:0] = 0x1CE
-#define CMD8_ARG          (0x0UL << 12 | BIT8 | 0xCEUL << 0)
-
-#define CMD9              (INDX(9) | CCCE_ENABLE | RSP_TYPE_136BITS)
-#define CMD9_INT_EN       (CCRC_EN | CC_EN | CEB_EN | CTO_EN)
-
-#define CMD16             (INDX(16) | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS)
-#define CMD16_INT_EN      (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)
-
-#define CMD17             (INDX(17) | DP_ENABLE | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS | DDIR_READ)
-#define CMD17_INT_EN      (CERR_EN | CIE_EN | CCRC_EN | CC_EN | TC_EN | BRR_EN | CTO_EN | DTO_EN | DCRC_EN | DEB_EN | CEB_EN)
-
-#define CMD18             (INDX(18) | DP_ENABLE | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS | MSBS_MULTBLK | DDIR_READ | BCE_ENABLE | DE_ENABLE)
-#define CMD18_INT_EN      (CERR_EN | CIE_EN | CCRC_EN | CC_EN | TC_EN | BRR_EN | CTO_EN | DTO_EN | DCRC_EN | DEB_EN | CEB_EN)
-
-#define CMD23             (INDX(23) | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS)
-#define CMD23_INT_EN      (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)
-
-#define CMD24             (INDX(24) | DP_ENABLE | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS | DDIR_WRITE)
-#define CMD24_INT_EN      (CERR_EN | CIE_EN | CCRC_EN | CC_EN | TC_EN | BWR_EN | CTO_EN | DTO_EN | DCRC_EN | DEB_EN | CEB_EN)
-
-#define CMD25             (INDX(25) | DP_ENABLE | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS | MSBS_MULTBLK | DDIR_READ | BCE_ENABLE | DE_ENABLE)
-#define CMD25_INT_EN      (CERR_EN | CIE_EN | CCRC_EN | CC_EN | TC_EN | BRR_EN | CTO_EN | DTO_EN | DCRC_EN | DEB_EN | CEB_EN)
-
-#define CMD55             (INDX(55) | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS)
-#define CMD55_INT_EN      (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)
-
-#define ACMD41            (INDX(41) | RSP_TYPE_48BITS)
-#define ACMD41_INT_EN     (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)
-
-#define ACMD6             (INDX(6) | RSP_TYPE_48BITS)
-#define ACMD6_INT_EN      (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)
-
-#endif //__OMAP3530SDIO_H__
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __OMAP3530SDIO_H__\r
+#define __OMAP3530SDIO_H__\r
+\r
+//MMC/SD/SDIO1 register definitions.\r
+#define MMCHS1BASE        0x4809C000\r
+#define MMC_REFERENCE_CLK (96000000)\r
+\r
+#define MMCHS_SYSCONFIG   (MMCHS1BASE + 0x10)\r
+#define SOFTRESET         BIT1\r
+#define ENAWAKEUP         BIT2\r
+\r
+#define MMCHS_SYSSTATUS   (MMCHS1BASE + 0x14)\r
+#define RESETDONE_MASK    BIT0\r
+#define RESETDONE         BIT0\r
+\r
+#define MMCHS_CSRE        (MMCHS1BASE + 0x24)\r
+#define MMCHS_SYSTEST     (MMCHS1BASE + 0x28)\r
+\r
+#define MMCHS_CON         (MMCHS1BASE + 0x2C)\r
+#define OD                BIT0\r
+#define NOINIT            (0x0UL << 1)\r
+#define INIT              BIT1\r
+#define HR                BIT2\r
+#define STR               BIT3\r
+#define MODE              BIT4\r
+#define DW8_1_4_BIT       (0x0UL << 5)\r
+#define DW8_8_BIT         BIT5\r
+#define MIT               BIT6\r
+#define CDP               BIT7\r
+#define WPP               BIT8\r
+#define CTPL              BIT11\r
+#define CEATA_OFF         (0x0UL << 12)\r
+#define CEATA_ON          BIT12\r
+\r
+#define MMCHS_PWCNT       (MMCHS1BASE + 0x30)\r
+\r
+#define MMCHS_BLK         (MMCHS1BASE + 0x104)\r
+#define BLEN_512BYTES     (0x200UL << 0)\r
+\r
+#define MMCHS_ARG         (MMCHS1BASE + 0x108)\r
+\r
+#define MMCHS_CMD         (MMCHS1BASE + 0x10C)\r
+#define DE_ENABLE         BIT0\r
+#define BCE_ENABLE        BIT1\r
+#define ACEN_ENABLE       BIT2\r
+#define DDIR_READ         BIT4\r
+#define DDIR_WRITE        (0x0UL << 4)\r
+#define MSBS_SGLEBLK      (0x0UL << 5)\r
+#define MSBS_MULTBLK      BIT5\r
+#define RSP_TYPE_MASK     (0x3UL << 16)\r
+#define RSP_TYPE_136BITS  BIT16\r
+#define RSP_TYPE_48BITS   (0x2UL << 16)\r
+#define CCCE_ENABLE       BIT19\r
+#define CICE_ENABLE       BIT20\r
+#define DP_ENABLE         BIT21 \r
+#define INDX(CMD_INDX)    ((CMD_INDX & 0x3F) << 24)\r
+\r
+#define MMCHS_RSP10       (MMCHS1BASE + 0x110)\r
+#define MMCHS_RSP32       (MMCHS1BASE + 0x114)\r
+#define MMCHS_RSP54       (MMCHS1BASE + 0x118)\r
+#define MMCHS_RSP76       (MMCHS1BASE + 0x11C)\r
+#define MMCHS_DATA        (MMCHS1BASE + 0x120)\r
+\r
+#define MMCHS_PSTATE      (MMCHS1BASE + 0x124)\r
+#define CMDI_MASK         BIT0\r
+#define CMDI_ALLOWED      (0x0UL << 0)\r
+#define CMDI_NOT_ALLOWED  BIT0\r
+#define DATI_MASK         BIT1\r
+#define DATI_ALLOWED      (0x0UL << 1)\r
+#define DATI_NOT_ALLOWED  BIT1\r
+\r
+#define MMCHS_HCTL        (MMCHS1BASE + 0x128)\r
+#define DTW_1_BIT         (0x0UL << 1)\r
+#define DTW_4_BIT         BIT1\r
+#define SDBP_MASK         BIT8\r
+#define SDBP_OFF          (0x0UL << 8)\r
+#define SDBP_ON           BIT8\r
+#define SDVS_1_8_V        (0x5UL << 9)\r
+#define SDVS_3_0_V        (0x6UL << 9)\r
+#define IWE               BIT24\r
+\r
+#define MMCHS_SYSCTL      (MMCHS1BASE + 0x12C)\r
+#define ICE               BIT0\r
+#define ICS_MASK          BIT1\r
+#define ICS               BIT1\r
+#define CEN               BIT2\r
+#define CLKD_MASK         (0x3FFUL << 6)\r
+#define CLKD_80KHZ        (0x258UL) //(96*1000/80)/2\r
+#define CLKD_400KHZ       (0xF0UL)\r
+#define DTO_MASK          (0xFUL << 16)\r
+#define DTO_VAL           (0xEUL << 16)\r
+#define SRA               BIT24\r
+#define SRC_MASK          BIT25\r
+#define SRC               BIT25\r
+#define SRD               BIT26\r
+\r
+#define MMCHS_STAT        (MMCHS1BASE + 0x130)\r
+#define CC                BIT0\r
+#define TC                BIT1\r
+#define BWR               BIT4\r
+#define BRR               BIT5\r
+#define ERRI              BIT15\r
+#define CTO               BIT16\r
+#define DTO               BIT20\r
+#define DCRC              BIT21\r
+#define DEB               BIT22\r
+\r
+#define MMCHS_IE          (MMCHS1BASE + 0x134)\r
+#define CC_EN             BIT0\r
+#define TC_EN             BIT1\r
+#define BWR_EN            BIT4\r
+#define BRR_EN            BIT5\r
+#define CTO_EN            BIT16\r
+#define CCRC_EN           BIT17\r
+#define CEB_EN            BIT18\r
+#define CIE_EN            BIT19\r
+#define DTO_EN            BIT20\r
+#define DCRC_EN           BIT21\r
+#define DEB_EN            BIT22\r
+#define CERR_EN           BIT28\r
+#define BADA_EN           BIT29\r
+\r
+#define MMCHS_ISE         (MMCHS1BASE + 0x138)\r
+#define CC_SIGEN          BIT0\r
+#define TC_SIGEN          BIT1\r
+#define BWR_SIGEN         BIT4\r
+#define BRR_SIGEN         BIT5\r
+#define CTO_SIGEN         BIT16\r
+#define CCRC_SIGEN        BIT17\r
+#define CEB_SIGEN         BIT18\r
+#define CIE_SIGEN         BIT19\r
+#define DTO_SIGEN         BIT20\r
+#define DCRC_SIGEN        BIT21\r
+#define DEB_SIGEN         BIT22\r
+#define CERR_SIGEN        BIT28\r
+#define BADA_SIGEN        BIT29\r
+\r
+#define MMCHS_AC12        (MMCHS1BASE + 0x13C)\r
+\r
+#define MMCHS_CAPA        (MMCHS1BASE + 0x140)\r
+#define VS30              BIT25\r
+#define VS18              BIT26\r
+\r
+#define MMCHS_CUR_CAPA    (MMCHS1BASE + 0x148)\r
+#define MMCHS_REV         (MMCHS1BASE + 0x1FC)\r
+\r
+#define CMD0              INDX(0)\r
+#define CMD0_INT_EN       (CC_EN | CEB_EN)\r
+\r
+#define CMD1              (INDX(1) | RSP_TYPE_48BITS)\r
+#define CMD1_INT_EN       (CC_EN | CEB_EN | CTO_EN)\r
+\r
+#define CMD2              (INDX(2) | CCCE_ENABLE | RSP_TYPE_136BITS)\r
+#define CMD2_INT_EN       (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)\r
+\r
+#define CMD3              (INDX(3) | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS)\r
+#define CMD3_INT_EN       (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)\r
+\r
+#define CMD5              (INDX(5) | RSP_TYPE_48BITS)\r
+#define CMD5_INT_EN       (CC_EN | CEB_EN | CTO_EN)\r
+\r
+#define CMD7              (INDX(7) | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS)\r
+#define CMD7_INT_EN       (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)\r
+\r
+#define CMD8              (INDX(8) | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS)\r
+#define CMD8_INT_EN       (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)\r
+//Reserved(0)[12:31], Supply voltage(1)[11:8], check pattern(0xCE)[7:0] = 0x1CE\r
+#define CMD8_ARG          (0x0UL << 12 | BIT8 | 0xCEUL << 0)\r
+\r
+#define CMD9              (INDX(9) | CCCE_ENABLE | RSP_TYPE_136BITS)\r
+#define CMD9_INT_EN       (CCRC_EN | CC_EN | CEB_EN | CTO_EN)\r
+\r
+#define CMD16             (INDX(16) | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS)\r
+#define CMD16_INT_EN      (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)\r
+\r
+#define CMD17             (INDX(17) | DP_ENABLE | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS | DDIR_READ)\r
+#define CMD17_INT_EN      (CERR_EN | CIE_EN | CCRC_EN | CC_EN | TC_EN | BRR_EN | CTO_EN | DTO_EN | DCRC_EN | DEB_EN | CEB_EN)\r
+\r
+#define CMD18             (INDX(18) | DP_ENABLE | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS | MSBS_MULTBLK | DDIR_READ | BCE_ENABLE | DE_ENABLE)\r
+#define CMD18_INT_EN      (CERR_EN | CIE_EN | CCRC_EN | CC_EN | TC_EN | BRR_EN | CTO_EN | DTO_EN | DCRC_EN | DEB_EN | CEB_EN)\r
+\r
+#define CMD23             (INDX(23) | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS)\r
+#define CMD23_INT_EN      (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)\r
+\r
+#define CMD24             (INDX(24) | DP_ENABLE | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS | DDIR_WRITE)\r
+#define CMD24_INT_EN      (CERR_EN | CIE_EN | CCRC_EN | CC_EN | TC_EN | BWR_EN | CTO_EN | DTO_EN | DCRC_EN | DEB_EN | CEB_EN)\r
+\r
+#define CMD25             (INDX(25) | DP_ENABLE | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS | MSBS_MULTBLK | DDIR_READ | BCE_ENABLE | DE_ENABLE)\r
+#define CMD25_INT_EN      (CERR_EN | CIE_EN | CCRC_EN | CC_EN | TC_EN | BRR_EN | CTO_EN | DTO_EN | DCRC_EN | DEB_EN | CEB_EN)\r
+\r
+#define CMD55             (INDX(55) | CICE_ENABLE | CCCE_ENABLE | RSP_TYPE_48BITS)\r
+#define CMD55_INT_EN      (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)\r
+\r
+#define ACMD41            (INDX(41) | RSP_TYPE_48BITS)\r
+#define ACMD41_INT_EN     (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)\r
+\r
+#define ACMD6             (INDX(6) | RSP_TYPE_48BITS)\r
+#define ACMD6_INT_EN      (CERR_EN | CIE_EN | CCRC_EN | CC_EN | CEB_EN | CTO_EN)\r
+\r
+#endif //__OMAP3530SDIO_H__\r
index d23156cf0836630e827d558888d4976e801cec7e..1588e1d4d91fc15ae820ba9b6d194bb02d1eaf9f 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __OMAP3530_PAD_CONFIGURATION_H__
-#define __OMAP3530_PAD_CONFIGURATION_H__
-
-#define SYSTEM_CONTROL_MODULE_BASE  0x48002000
-
-//Pin definition
-#define SDRC_D0             (SYSTEM_CONTROL_MODULE_BASE + 0x030)
-#define SDRC_D1             (SYSTEM_CONTROL_MODULE_BASE + 0x032)
-#define SDRC_D2             (SYSTEM_CONTROL_MODULE_BASE + 0x034)
-#define SDRC_D3             (SYSTEM_CONTROL_MODULE_BASE + 0x036)
-#define SDRC_D4             (SYSTEM_CONTROL_MODULE_BASE + 0x038)
-#define SDRC_D5             (SYSTEM_CONTROL_MODULE_BASE + 0x03A)
-#define SDRC_D6             (SYSTEM_CONTROL_MODULE_BASE + 0x03C)
-#define SDRC_D7             (SYSTEM_CONTROL_MODULE_BASE + 0x03E)
-#define SDRC_D8             (SYSTEM_CONTROL_MODULE_BASE + 0x040)
-#define SDRC_D9             (SYSTEM_CONTROL_MODULE_BASE + 0x042)
-#define SDRC_D10            (SYSTEM_CONTROL_MODULE_BASE + 0x044)
-#define SDRC_D11            (SYSTEM_CONTROL_MODULE_BASE + 0x046)
-#define SDRC_D12            (SYSTEM_CONTROL_MODULE_BASE + 0x048)
-#define SDRC_D13            (SYSTEM_CONTROL_MODULE_BASE + 0x04A)
-#define SDRC_D14            (SYSTEM_CONTROL_MODULE_BASE + 0x04C)
-#define SDRC_D15            (SYSTEM_CONTROL_MODULE_BASE + 0x04E)
-#define SDRC_D16            (SYSTEM_CONTROL_MODULE_BASE + 0x050)
-#define SDRC_D17            (SYSTEM_CONTROL_MODULE_BASE + 0x052)
-#define SDRC_D18            (SYSTEM_CONTROL_MODULE_BASE + 0x054)
-#define SDRC_D19            (SYSTEM_CONTROL_MODULE_BASE + 0x056)
-#define SDRC_D20            (SYSTEM_CONTROL_MODULE_BASE + 0x058)
-#define SDRC_D21            (SYSTEM_CONTROL_MODULE_BASE + 0x05A)
-#define SDRC_D22            (SYSTEM_CONTROL_MODULE_BASE + 0x05C)
-#define SDRC_D23            (SYSTEM_CONTROL_MODULE_BASE + 0x05E)
-#define SDRC_D24            (SYSTEM_CONTROL_MODULE_BASE + 0x060)
-#define SDRC_D25            (SYSTEM_CONTROL_MODULE_BASE + 0x062)
-#define SDRC_D26            (SYSTEM_CONTROL_MODULE_BASE + 0x064)
-#define SDRC_D27            (SYSTEM_CONTROL_MODULE_BASE + 0x066)
-#define SDRC_D28            (SYSTEM_CONTROL_MODULE_BASE + 0x068)
-#define SDRC_D29            (SYSTEM_CONTROL_MODULE_BASE + 0x06A)
-#define SDRC_D30            (SYSTEM_CONTROL_MODULE_BASE + 0x06C)
-#define SDRC_D31            (SYSTEM_CONTROL_MODULE_BASE + 0x06E)
-#define SDRC_CLK            (SYSTEM_CONTROL_MODULE_BASE + 0x070)
-#define SDRC_DQS0           (SYSTEM_CONTROL_MODULE_BASE + 0x072)
-#define SDRC_CKE0           (SYSTEM_CONTROL_MODULE_BASE + 0x262)
-#define SDRC_CKE1           (SYSTEM_CONTROL_MODULE_BASE + 0x264)
-#define SDRC_DQS1           (SYSTEM_CONTROL_MODULE_BASE + 0x074)
-#define SDRC_DQS2           (SYSTEM_CONTROL_MODULE_BASE + 0x076)
-#define SDRC_DQS3           (SYSTEM_CONTROL_MODULE_BASE + 0x078)
-#define GPMC_A1             (SYSTEM_CONTROL_MODULE_BASE + 0x07A)
-#define GPMC_A2             (SYSTEM_CONTROL_MODULE_BASE + 0x07C)
-#define GPMC_A3             (SYSTEM_CONTROL_MODULE_BASE + 0x07E)
-#define GPMC_A4             (SYSTEM_CONTROL_MODULE_BASE + 0x080)
-#define GPMC_A5             (SYSTEM_CONTROL_MODULE_BASE + 0x082)
-#define GPMC_A6             (SYSTEM_CONTROL_MODULE_BASE + 0x084)
-#define GPMC_A7             (SYSTEM_CONTROL_MODULE_BASE + 0x086)
-#define GPMC_A8             (SYSTEM_CONTROL_MODULE_BASE + 0x088)
-#define GPMC_A9             (SYSTEM_CONTROL_MODULE_BASE + 0x08A)
-#define GPMC_A10            (SYSTEM_CONTROL_MODULE_BASE + 0x08C)
-#define GPMC_D0             (SYSTEM_CONTROL_MODULE_BASE + 0x08E)
-#define GPMC_D1             (SYSTEM_CONTROL_MODULE_BASE + 0x090)
-#define GPMC_D2             (SYSTEM_CONTROL_MODULE_BASE + 0x092)
-#define GPMC_D3             (SYSTEM_CONTROL_MODULE_BASE + 0x094)
-#define GPMC_D4             (SYSTEM_CONTROL_MODULE_BASE + 0x096)
-#define GPMC_D5             (SYSTEM_CONTROL_MODULE_BASE + 0x098)
-#define GPMC_D6             (SYSTEM_CONTROL_MODULE_BASE + 0x09A)
-#define GPMC_D7             (SYSTEM_CONTROL_MODULE_BASE + 0x09C)
-#define GPMC_D8             (SYSTEM_CONTROL_MODULE_BASE + 0x09E)
-#define GPMC_D9             (SYSTEM_CONTROL_MODULE_BASE + 0x0A0)
-#define GPMC_D10            (SYSTEM_CONTROL_MODULE_BASE + 0x0A2)
-#define GPMC_D11            (SYSTEM_CONTROL_MODULE_BASE + 0x0A4)
-#define GPMC_D12            (SYSTEM_CONTROL_MODULE_BASE + 0x0A6)
-#define GPMC_D13            (SYSTEM_CONTROL_MODULE_BASE + 0x0A8)
-#define GPMC_D14            (SYSTEM_CONTROL_MODULE_BASE + 0x0AA)
-#define GPMC_D15            (SYSTEM_CONTROL_MODULE_BASE + 0x0AC)
-#define GPMC_NCS0           (SYSTEM_CONTROL_MODULE_BASE + 0x0AE)
-#define GPMC_NCS1           (SYSTEM_CONTROL_MODULE_BASE + 0x0B0)
-#define GPMC_NCS2           (SYSTEM_CONTROL_MODULE_BASE + 0x0B2)
-#define GPMC_NCS3           (SYSTEM_CONTROL_MODULE_BASE + 0x0B4)
-#define GPMC_NCS4           (SYSTEM_CONTROL_MODULE_BASE + 0x0B6)
-#define GPMC_NCS5           (SYSTEM_CONTROL_MODULE_BASE + 0x0B8)
-#define GPMC_NCS6           (SYSTEM_CONTROL_MODULE_BASE + 0x0BA)
-#define GPMC_NCS7           (SYSTEM_CONTROL_MODULE_BASE + 0x0BC)
-#define GPMC_CLK            (SYSTEM_CONTROL_MODULE_BASE + 0x0BE)
-#define GPMC_NADV_ALE       (SYSTEM_CONTROL_MODULE_BASE + 0x0C0)
-#define GPMC_NOE            (SYSTEM_CONTROL_MODULE_BASE + 0x0C2)
-#define GPMC_NWE            (SYSTEM_CONTROL_MODULE_BASE + 0x0C4)
-#define GPMC_NBE0_CLE       (SYSTEM_CONTROL_MODULE_BASE + 0x0C6)
-#define GPMC_NBE1           (SYSTEM_CONTROL_MODULE_BASE + 0x0C8)
-#define GPMC_NWP            (SYSTEM_CONTROL_MODULE_BASE + 0x0CA)
-#define GPMC_WAIT0          (SYSTEM_CONTROL_MODULE_BASE + 0x0CC)
-#define GPMC_WAIT1          (SYSTEM_CONTROL_MODULE_BASE + 0x0CE)
-#define GPMC_WAIT2          (SYSTEM_CONTROL_MODULE_BASE + 0x0D0)
-#define GPMC_WAIT3          (SYSTEM_CONTROL_MODULE_BASE + 0x0D2)
-#define DSS_PCLK            (SYSTEM_CONTROL_MODULE_BASE + 0x0D4)
-#define DSS_HSYNC           (SYSTEM_CONTROL_MODULE_BASE + 0x0D6)
-#define DSS_PSYNC           (SYSTEM_CONTROL_MODULE_BASE + 0x0D8)
-#define DSS_ACBIAS          (SYSTEM_CONTROL_MODULE_BASE + 0x0DA)
-#define DSS_DATA0           (SYSTEM_CONTROL_MODULE_BASE + 0x0DC)
-#define DSS_DATA1           (SYSTEM_CONTROL_MODULE_BASE + 0x0DE)
-#define DSS_DATA2           (SYSTEM_CONTROL_MODULE_BASE + 0x0E0)
-#define DSS_DATA3           (SYSTEM_CONTROL_MODULE_BASE + 0x0E2)
-#define DSS_DATA4           (SYSTEM_CONTROL_MODULE_BASE + 0x0E4)
-#define DSS_DATA5           (SYSTEM_CONTROL_MODULE_BASE + 0x0E6)
-#define DSS_DATA6           (SYSTEM_CONTROL_MODULE_BASE + 0x0E8)
-#define DSS_DATA7           (SYSTEM_CONTROL_MODULE_BASE + 0x0EA)
-#define DSS_DATA8           (SYSTEM_CONTROL_MODULE_BASE + 0x0EC)
-#define DSS_DATA9           (SYSTEM_CONTROL_MODULE_BASE + 0x0EE)
-#define DSS_DATA10          (SYSTEM_CONTROL_MODULE_BASE + 0x0F0)
-#define DSS_DATA11          (SYSTEM_CONTROL_MODULE_BASE + 0x0F2)
-#define DSS_DATA12          (SYSTEM_CONTROL_MODULE_BASE + 0x0F4)
-#define DSS_DATA13          (SYSTEM_CONTROL_MODULE_BASE + 0x0F6)
-#define DSS_DATA14          (SYSTEM_CONTROL_MODULE_BASE + 0x0F8)
-#define DSS_DATA15          (SYSTEM_CONTROL_MODULE_BASE + 0x0FA)
-#define DSS_DATA16          (SYSTEM_CONTROL_MODULE_BASE + 0x0FC)
-#define DSS_DATA17          (SYSTEM_CONTROL_MODULE_BASE + 0x0FE)
-#define DSS_DATA18          (SYSTEM_CONTROL_MODULE_BASE + 0x100)
-#define DSS_DATA19          (SYSTEM_CONTROL_MODULE_BASE + 0x102)
-#define DSS_DATA20          (SYSTEM_CONTROL_MODULE_BASE + 0x104)
-#define DSS_DATA21          (SYSTEM_CONTROL_MODULE_BASE + 0x106)
-#define DSS_DATA22          (SYSTEM_CONTROL_MODULE_BASE + 0x108)
-#define DSS_DATA23          (SYSTEM_CONTROL_MODULE_BASE + 0x10A)
-#define CAM_HS              (SYSTEM_CONTROL_MODULE_BASE + 0x10C)
-#define CAM_VS              (SYSTEM_CONTROL_MODULE_BASE + 0x10E)
-#define CAM_XCLKA           (SYSTEM_CONTROL_MODULE_BASE + 0x110)
-#define CAM_PCLK            (SYSTEM_CONTROL_MODULE_BASE + 0x112)
-#define CAM_FLD             (SYSTEM_CONTROL_MODULE_BASE + 0x114)
-#define CAM_D0              (SYSTEM_CONTROL_MODULE_BASE + 0x116)
-#define CAM_D1              (SYSTEM_CONTROL_MODULE_BASE + 0x118)
-#define CAM_D2              (SYSTEM_CONTROL_MODULE_BASE + 0x11A)
-#define CAM_D3              (SYSTEM_CONTROL_MODULE_BASE + 0x11C)
-#define CAM_D4              (SYSTEM_CONTROL_MODULE_BASE + 0x11E)
-#define CAM_D5              (SYSTEM_CONTROL_MODULE_BASE + 0x120)
-#define CAM_D6              (SYSTEM_CONTROL_MODULE_BASE + 0x122)
-#define CAM_D7              (SYSTEM_CONTROL_MODULE_BASE + 0x124)
-#define CAM_D8              (SYSTEM_CONTROL_MODULE_BASE + 0x126)
-#define CAM_D9              (SYSTEM_CONTROL_MODULE_BASE + 0x128)
-#define CAM_D10             (SYSTEM_CONTROL_MODULE_BASE + 0x12A)
-#define CAM_D11             (SYSTEM_CONTROL_MODULE_BASE + 0x12C)
-#define CAM_XCLKB           (SYSTEM_CONTROL_MODULE_BASE + 0x12E)
-#define CAM_WEN             (SYSTEM_CONTROL_MODULE_BASE + 0x130)
-#define CAM_STROBE          (SYSTEM_CONTROL_MODULE_BASE + 0x132)
-#define CSI2_DX0            (SYSTEM_CONTROL_MODULE_BASE + 0x134)
-#define CSI2_DY0            (SYSTEM_CONTROL_MODULE_BASE + 0x136)
-#define CSI2_DX1            (SYSTEM_CONTROL_MODULE_BASE + 0x138)
-#define CSI2_DY1            (SYSTEM_CONTROL_MODULE_BASE + 0x13A)
-#define MCBSP2_FSX          (SYSTEM_CONTROL_MODULE_BASE + 0x13C)
-#define MCBSP2_CLKX         (SYSTEM_CONTROL_MODULE_BASE + 0x13E)
-#define MCBSP2_DR           (SYSTEM_CONTROL_MODULE_BASE + 0x140)
-#define MCBSP2_DX           (SYSTEM_CONTROL_MODULE_BASE + 0x142)
-#define MMC1_CLK            (SYSTEM_CONTROL_MODULE_BASE + 0x144)
-#define MMC1_CMD            (SYSTEM_CONTROL_MODULE_BASE + 0x146)
-#define MMC1_DAT0           (SYSTEM_CONTROL_MODULE_BASE + 0x148)
-#define MMC1_DAT1           (SYSTEM_CONTROL_MODULE_BASE + 0x14A)
-#define MMC1_DAT2           (SYSTEM_CONTROL_MODULE_BASE + 0x14C)
-#define MMC1_DAT3           (SYSTEM_CONTROL_MODULE_BASE + 0x14E)
-#define MMC1_DAT4           (SYSTEM_CONTROL_MODULE_BASE + 0x150)
-#define MMC1_DAT5           (SYSTEM_CONTROL_MODULE_BASE + 0x152)
-#define MMC1_DAT6           (SYSTEM_CONTROL_MODULE_BASE + 0x154)
-#define MMC1_DAT7           (SYSTEM_CONTROL_MODULE_BASE + 0x156)
-#define MMC2_CLK            (SYSTEM_CONTROL_MODULE_BASE + 0x158)
-#define MMC2_CMD            (SYSTEM_CONTROL_MODULE_BASE + 0x15A)
-#define MMC2_DAT0           (SYSTEM_CONTROL_MODULE_BASE + 0x15C)
-#define MMC2_DAT1           (SYSTEM_CONTROL_MODULE_BASE + 0x15E)
-#define MMC2_DAT2           (SYSTEM_CONTROL_MODULE_BASE + 0x160)
-#define MMC2_DAT3           (SYSTEM_CONTROL_MODULE_BASE + 0x162)
-#define MMC2_DAT4           (SYSTEM_CONTROL_MODULE_BASE + 0x164)
-#define MMC2_DAT5           (SYSTEM_CONTROL_MODULE_BASE + 0x166)
-#define MMC2_DAT6           (SYSTEM_CONTROL_MODULE_BASE + 0x168)
-#define MMC2_DAT7           (SYSTEM_CONTROL_MODULE_BASE + 0x16A)
-#define MCBSP3_DX           (SYSTEM_CONTROL_MODULE_BASE + 0x16C)
-#define MCBSP3_DR           (SYSTEM_CONTROL_MODULE_BASE + 0x16E)
-#define MCBSP3_CLKX         (SYSTEM_CONTROL_MODULE_BASE + 0x170)
-#define MCBSP3_FSX          (SYSTEM_CONTROL_MODULE_BASE + 0x172)
-#define UART2_CTS           (SYSTEM_CONTROL_MODULE_BASE + 0x174)
-#define UART2_RTS           (SYSTEM_CONTROL_MODULE_BASE + 0x176)
-#define UART2_TX            (SYSTEM_CONTROL_MODULE_BASE + 0x178)
-#define UART2_RX            (SYSTEM_CONTROL_MODULE_BASE + 0x17A)
-#define UART1_TX            (SYSTEM_CONTROL_MODULE_BASE + 0x17C)
-#define UART1_RTS           (SYSTEM_CONTROL_MODULE_BASE + 0x17E)
-#define UART1_CTS           (SYSTEM_CONTROL_MODULE_BASE + 0x180)
-#define UART1_RX            (SYSTEM_CONTROL_MODULE_BASE + 0x182)
-#define MCBSP4_CLKX         (SYSTEM_CONTROL_MODULE_BASE + 0x184)
-#define MCBSP4_DR           (SYSTEM_CONTROL_MODULE_BASE + 0x186)
-#define MCBSP4_DX           (SYSTEM_CONTROL_MODULE_BASE + 0x188)
-#define MCBSP4_FSX          (SYSTEM_CONTROL_MODULE_BASE + 0x18A)
-#define MCBSP1_CLKR         (SYSTEM_CONTROL_MODULE_BASE + 0x18C)
-#define MCBSP1_FSR          (SYSTEM_CONTROL_MODULE_BASE + 0x18E)
-#define MCBSP1_DX           (SYSTEM_CONTROL_MODULE_BASE + 0x190)
-#define MCBSP1_DR           (SYSTEM_CONTROL_MODULE_BASE + 0x192)
-#define MCBSP1_CLKS         (SYSTEM_CONTROL_MODULE_BASE + 0x194)
-#define MCBSP1_FSX          (SYSTEM_CONTROL_MODULE_BASE + 0x196)
-#define MCBSP1_CLKX         (SYSTEM_CONTROL_MODULE_BASE + 0x198)
-#define UART3_CTS_RCTX      (SYSTEM_CONTROL_MODULE_BASE + 0x19A)
-#define UART3_RTS_SD        (SYSTEM_CONTROL_MODULE_BASE + 0x19C)
-#define UART3_RX_IRRX       (SYSTEM_CONTROL_MODULE_BASE + 0x19E)
-#define UART3_TX_IRTX       (SYSTEM_CONTROL_MODULE_BASE + 0x1A0)
-#define HSUSB0_CLK          (SYSTEM_CONTROL_MODULE_BASE + 0x1A2)
-#define HSUSB0_STP          (SYSTEM_CONTROL_MODULE_BASE + 0x1A4)
-#define HSUSB0_DIR          (SYSTEM_CONTROL_MODULE_BASE + 0x1A6)
-#define HSUSB0_NXT          (SYSTEM_CONTROL_MODULE_BASE + 0x1A8)
-#define HSUSB0_DATA0        (SYSTEM_CONTROL_MODULE_BASE + 0x1AA)
-#define HSUSB0_DATA1        (SYSTEM_CONTROL_MODULE_BASE + 0x1AC)
-#define HSUSB0_DATA2        (SYSTEM_CONTROL_MODULE_BASE + 0x1AE)
-#define HSUSB0_DATA3        (SYSTEM_CONTROL_MODULE_BASE + 0x1B0)
-#define HSUSB0_DATA4        (SYSTEM_CONTROL_MODULE_BASE + 0x1B2)
-#define HSUSB0_DATA5        (SYSTEM_CONTROL_MODULE_BASE + 0x1B4)
-#define HSUSB0_DATA6        (SYSTEM_CONTROL_MODULE_BASE + 0x1B6)
-#define HSUSB0_DATA7        (SYSTEM_CONTROL_MODULE_BASE + 0x1B8)
-#define I2C1_SCL            (SYSTEM_CONTROL_MODULE_BASE + 0x1BA)
-#define I2C1_SDA            (SYSTEM_CONTROL_MODULE_BASE + 0x1BC)
-#define I2C2_SCL            (SYSTEM_CONTROL_MODULE_BASE + 0x1BE)
-#define I2C2_SDA            (SYSTEM_CONTROL_MODULE_BASE + 0x1C0)
-#define I2C3_SCL            (SYSTEM_CONTROL_MODULE_BASE + 0x1C2)
-#define I2C3_SDA            (SYSTEM_CONTROL_MODULE_BASE + 0x1C4)
-#define HDQ_SIO             (SYSTEM_CONTROL_MODULE_BASE + 0x1C6)
-#define MCSPI1_CLK          (SYSTEM_CONTROL_MODULE_BASE + 0x1C8)
-#define MCSPI1_SIMO         (SYSTEM_CONTROL_MODULE_BASE + 0x1CA)
-#define MCSPI1_SOMI         (SYSTEM_CONTROL_MODULE_BASE + 0x1CC)
-#define MCSPI1_CS0          (SYSTEM_CONTROL_MODULE_BASE + 0x1CE)
-#define MCSPI1_CS1          (SYSTEM_CONTROL_MODULE_BASE + 0x1D0)
-#define MCSPI1_CS2          (SYSTEM_CONTROL_MODULE_BASE + 0x1D2)
-#define MCSPI1_CS3          (SYSTEM_CONTROL_MODULE_BASE + 0x1D4)
-#define MCSPI2_CLK          (SYSTEM_CONTROL_MODULE_BASE + 0x1D6)
-#define MCSPI2_SIMO         (SYSTEM_CONTROL_MODULE_BASE + 0x1D8)
-#define MCSPI2_SOMI         (SYSTEM_CONTROL_MODULE_BASE + 0x1DA)
-#define MCSPI2_CS0          (SYSTEM_CONTROL_MODULE_BASE + 0x1DC)
-#define MCSPI2_CS1          (SYSTEM_CONTROL_MODULE_BASE + 0x1DE)
-#define SYS_NIRQ            (SYSTEM_CONTROL_MODULE_BASE + 0x1E0)
-#define SYS_CLKOUT2         (SYSTEM_CONTROL_MODULE_BASE + 0x1E2)
-#define ETK_CLK             (SYSTEM_CONTROL_MODULE_BASE + 0x5D8)
-#define ETK_CTL             (SYSTEM_CONTROL_MODULE_BASE + 0x5DA)
-#define ETK_D0              (SYSTEM_CONTROL_MODULE_BASE + 0x5DC)
-#define ETK_D1              (SYSTEM_CONTROL_MODULE_BASE + 0x5DE)
-#define ETK_D2              (SYSTEM_CONTROL_MODULE_BASE + 0x5E0)
-#define ETK_D3              (SYSTEM_CONTROL_MODULE_BASE + 0x5E2)
-#define ETK_D4              (SYSTEM_CONTROL_MODULE_BASE + 0x5E4)
-#define ETK_D5              (SYSTEM_CONTROL_MODULE_BASE + 0x5E6)
-#define ETK_D6              (SYSTEM_CONTROL_MODULE_BASE + 0x5E8)
-#define ETK_D7              (SYSTEM_CONTROL_MODULE_BASE + 0x5EA)
-#define ETK_D8              (SYSTEM_CONTROL_MODULE_BASE + 0x5EC)
-#define ETK_D9              (SYSTEM_CONTROL_MODULE_BASE + 0x5EE)
-#define ETK_D10             (SYSTEM_CONTROL_MODULE_BASE + 0x5F0)
-#define ETK_D11             (SYSTEM_CONTROL_MODULE_BASE + 0x5F2)
-#define ETK_D12             (SYSTEM_CONTROL_MODULE_BASE + 0x5F4)
-#define ETK_D13             (SYSTEM_CONTROL_MODULE_BASE + 0x5F6)
-#define ETK_D14             (SYSTEM_CONTROL_MODULE_BASE + 0x5F8)
-#define ETK_D15             (SYSTEM_CONTROL_MODULE_BASE + 0x5FA)
-#define SYS_BOOT0           (SYSTEM_CONTROL_MODULE_BASE + 0xA0A)
-#define SYS_BOOT1           (SYSTEM_CONTROL_MODULE_BASE + 0xA0C)
-#define SYS_BOOT3           (SYSTEM_CONTROL_MODULE_BASE + 0xA10)
-#define SYS_BOOT4           (SYSTEM_CONTROL_MODULE_BASE + 0xA12)
-#define SYS_BOOT5           (SYSTEM_CONTROL_MODULE_BASE + 0xA14)
-#define SYS_BOOT6           (SYSTEM_CONTROL_MODULE_BASE + 0xA16)
-
-//Mux modes
-#define MUXMODE0            (0x0UL)
-#define MUXMODE1            (0x1UL)
-#define MUXMODE2            (0x2UL)
-#define MUXMODE3            (0x3UL)
-#define MUXMODE4            (0x4UL)
-#define MUXMODE5            (0x5UL)
-#define MUXMODE6            (0x6UL)
-#define MUXMODE7            (0x7UL)
-
-//Pad configuration register.
-#define PAD_CONFIG_MASK      (0xFFFFUL)
-#define MUXMODE_OFFSET       0
-#define MUXMODE_MASK         (0x7UL << MUXMODE_OFFSET)
-#define PULL_CONFIG_OFFSET   3
-#define PULL_CONFIG_MASK     (0x3UL << PULL_CONFIG_OFFSET)
-#define INPUTENABLE_OFFSET   8
-#define INPUTENABLE_MASK     (0x1UL << INPUTENABLE_OFFSET)
-#define OFFMODE_VALUE_OFFSET 9
-#define OFFMODE_VALUE_MASK   (0x1FUL << OFFMODE_VALUE_OFFSET)
-#define WAKEUP_OFFSET        14
-#define WAKEUP_MASK          (0x2UL << WAKEUP_OFFSET)
-
-#define PULL_DOWN_SELECTED   ((0x0UL << 1) | BIT0)
-#define PULL_UP_SELECTED     (BIT1 | BIT0)
-#define PULL_DISABLED        (0x0UL << 0)
-
-#define OUTPUT               (0x0UL) //Pin is configured in output only mode.
-#define INPUT                (0x1UL) //Pin is configured in bi-directional mode.
-
-typedef struct {
-  UINTN   Pin;
-  UINTN   MuxMode;
-  UINTN   PullConfig;
-  UINTN   InputEnable;
-} PAD_CONFIGURATION;
-
-#endif //__OMAP3530_PAD_CONFIGURATION_H__
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __OMAP3530_PAD_CONFIGURATION_H__\r
+#define __OMAP3530_PAD_CONFIGURATION_H__\r
+\r
+#define SYSTEM_CONTROL_MODULE_BASE  0x48002000\r
+\r
+//Pin definition\r
+#define SDRC_D0             (SYSTEM_CONTROL_MODULE_BASE + 0x030)\r
+#define SDRC_D1             (SYSTEM_CONTROL_MODULE_BASE + 0x032)\r
+#define SDRC_D2             (SYSTEM_CONTROL_MODULE_BASE + 0x034)\r
+#define SDRC_D3             (SYSTEM_CONTROL_MODULE_BASE + 0x036)\r
+#define SDRC_D4             (SYSTEM_CONTROL_MODULE_BASE + 0x038)\r
+#define SDRC_D5             (SYSTEM_CONTROL_MODULE_BASE + 0x03A)\r
+#define SDRC_D6             (SYSTEM_CONTROL_MODULE_BASE + 0x03C)\r
+#define SDRC_D7             (SYSTEM_CONTROL_MODULE_BASE + 0x03E)\r
+#define SDRC_D8             (SYSTEM_CONTROL_MODULE_BASE + 0x040)\r
+#define SDRC_D9             (SYSTEM_CONTROL_MODULE_BASE + 0x042)\r
+#define SDRC_D10            (SYSTEM_CONTROL_MODULE_BASE + 0x044)\r
+#define SDRC_D11            (SYSTEM_CONTROL_MODULE_BASE + 0x046)\r
+#define SDRC_D12            (SYSTEM_CONTROL_MODULE_BASE + 0x048)\r
+#define SDRC_D13            (SYSTEM_CONTROL_MODULE_BASE + 0x04A)\r
+#define SDRC_D14            (SYSTEM_CONTROL_MODULE_BASE + 0x04C)\r
+#define SDRC_D15            (SYSTEM_CONTROL_MODULE_BASE + 0x04E)\r
+#define SDRC_D16            (SYSTEM_CONTROL_MODULE_BASE + 0x050)\r
+#define SDRC_D17            (SYSTEM_CONTROL_MODULE_BASE + 0x052)\r
+#define SDRC_D18            (SYSTEM_CONTROL_MODULE_BASE + 0x054)\r
+#define SDRC_D19            (SYSTEM_CONTROL_MODULE_BASE + 0x056)\r
+#define SDRC_D20            (SYSTEM_CONTROL_MODULE_BASE + 0x058)\r
+#define SDRC_D21            (SYSTEM_CONTROL_MODULE_BASE + 0x05A)\r
+#define SDRC_D22            (SYSTEM_CONTROL_MODULE_BASE + 0x05C)\r
+#define SDRC_D23            (SYSTEM_CONTROL_MODULE_BASE + 0x05E)\r
+#define SDRC_D24            (SYSTEM_CONTROL_MODULE_BASE + 0x060)\r
+#define SDRC_D25            (SYSTEM_CONTROL_MODULE_BASE + 0x062)\r
+#define SDRC_D26            (SYSTEM_CONTROL_MODULE_BASE + 0x064)\r
+#define SDRC_D27            (SYSTEM_CONTROL_MODULE_BASE + 0x066)\r
+#define SDRC_D28            (SYSTEM_CONTROL_MODULE_BASE + 0x068)\r
+#define SDRC_D29            (SYSTEM_CONTROL_MODULE_BASE + 0x06A)\r
+#define SDRC_D30            (SYSTEM_CONTROL_MODULE_BASE + 0x06C)\r
+#define SDRC_D31            (SYSTEM_CONTROL_MODULE_BASE + 0x06E)\r
+#define SDRC_CLK            (SYSTEM_CONTROL_MODULE_BASE + 0x070)\r
+#define SDRC_DQS0           (SYSTEM_CONTROL_MODULE_BASE + 0x072)\r
+#define SDRC_CKE0           (SYSTEM_CONTROL_MODULE_BASE + 0x262)\r
+#define SDRC_CKE1           (SYSTEM_CONTROL_MODULE_BASE + 0x264)\r
+#define SDRC_DQS1           (SYSTEM_CONTROL_MODULE_BASE + 0x074)\r
+#define SDRC_DQS2           (SYSTEM_CONTROL_MODULE_BASE + 0x076)\r
+#define SDRC_DQS3           (SYSTEM_CONTROL_MODULE_BASE + 0x078)\r
+#define GPMC_A1             (SYSTEM_CONTROL_MODULE_BASE + 0x07A)\r
+#define GPMC_A2             (SYSTEM_CONTROL_MODULE_BASE + 0x07C)\r
+#define GPMC_A3             (SYSTEM_CONTROL_MODULE_BASE + 0x07E)\r
+#define GPMC_A4             (SYSTEM_CONTROL_MODULE_BASE + 0x080)\r
+#define GPMC_A5             (SYSTEM_CONTROL_MODULE_BASE + 0x082)\r
+#define GPMC_A6             (SYSTEM_CONTROL_MODULE_BASE + 0x084)\r
+#define GPMC_A7             (SYSTEM_CONTROL_MODULE_BASE + 0x086)\r
+#define GPMC_A8             (SYSTEM_CONTROL_MODULE_BASE + 0x088)\r
+#define GPMC_A9             (SYSTEM_CONTROL_MODULE_BASE + 0x08A)\r
+#define GPMC_A10            (SYSTEM_CONTROL_MODULE_BASE + 0x08C)\r
+#define GPMC_D0             (SYSTEM_CONTROL_MODULE_BASE + 0x08E)\r
+#define GPMC_D1             (SYSTEM_CONTROL_MODULE_BASE + 0x090)\r
+#define GPMC_D2             (SYSTEM_CONTROL_MODULE_BASE + 0x092)\r
+#define GPMC_D3             (SYSTEM_CONTROL_MODULE_BASE + 0x094)\r
+#define GPMC_D4             (SYSTEM_CONTROL_MODULE_BASE + 0x096)\r
+#define GPMC_D5             (SYSTEM_CONTROL_MODULE_BASE + 0x098)\r
+#define GPMC_D6             (SYSTEM_CONTROL_MODULE_BASE + 0x09A)\r
+#define GPMC_D7             (SYSTEM_CONTROL_MODULE_BASE + 0x09C)\r
+#define GPMC_D8             (SYSTEM_CONTROL_MODULE_BASE + 0x09E)\r
+#define GPMC_D9             (SYSTEM_CONTROL_MODULE_BASE + 0x0A0)\r
+#define GPMC_D10            (SYSTEM_CONTROL_MODULE_BASE + 0x0A2)\r
+#define GPMC_D11            (SYSTEM_CONTROL_MODULE_BASE + 0x0A4)\r
+#define GPMC_D12            (SYSTEM_CONTROL_MODULE_BASE + 0x0A6)\r
+#define GPMC_D13            (SYSTEM_CONTROL_MODULE_BASE + 0x0A8)\r
+#define GPMC_D14            (SYSTEM_CONTROL_MODULE_BASE + 0x0AA)\r
+#define GPMC_D15            (SYSTEM_CONTROL_MODULE_BASE + 0x0AC)\r
+#define GPMC_NCS0           (SYSTEM_CONTROL_MODULE_BASE + 0x0AE)\r
+#define GPMC_NCS1           (SYSTEM_CONTROL_MODULE_BASE + 0x0B0)\r
+#define GPMC_NCS2           (SYSTEM_CONTROL_MODULE_BASE + 0x0B2)\r
+#define GPMC_NCS3           (SYSTEM_CONTROL_MODULE_BASE + 0x0B4)\r
+#define GPMC_NCS4           (SYSTEM_CONTROL_MODULE_BASE + 0x0B6)\r
+#define GPMC_NCS5           (SYSTEM_CONTROL_MODULE_BASE + 0x0B8)\r
+#define GPMC_NCS6           (SYSTEM_CONTROL_MODULE_BASE + 0x0BA)\r
+#define GPMC_NCS7           (SYSTEM_CONTROL_MODULE_BASE + 0x0BC)\r
+#define GPMC_CLK            (SYSTEM_CONTROL_MODULE_BASE + 0x0BE)\r
+#define GPMC_NADV_ALE       (SYSTEM_CONTROL_MODULE_BASE + 0x0C0)\r
+#define GPMC_NOE            (SYSTEM_CONTROL_MODULE_BASE + 0x0C2)\r
+#define GPMC_NWE            (SYSTEM_CONTROL_MODULE_BASE + 0x0C4)\r
+#define GPMC_NBE0_CLE       (SYSTEM_CONTROL_MODULE_BASE + 0x0C6)\r
+#define GPMC_NBE1           (SYSTEM_CONTROL_MODULE_BASE + 0x0C8)\r
+#define GPMC_NWP            (SYSTEM_CONTROL_MODULE_BASE + 0x0CA)\r
+#define GPMC_WAIT0          (SYSTEM_CONTROL_MODULE_BASE + 0x0CC)\r
+#define GPMC_WAIT1          (SYSTEM_CONTROL_MODULE_BASE + 0x0CE)\r
+#define GPMC_WAIT2          (SYSTEM_CONTROL_MODULE_BASE + 0x0D0)\r
+#define GPMC_WAIT3          (SYSTEM_CONTROL_MODULE_BASE + 0x0D2)\r
+#define DSS_PCLK            (SYSTEM_CONTROL_MODULE_BASE + 0x0D4)\r
+#define DSS_HSYNC           (SYSTEM_CONTROL_MODULE_BASE + 0x0D6)\r
+#define DSS_PSYNC           (SYSTEM_CONTROL_MODULE_BASE + 0x0D8)\r
+#define DSS_ACBIAS          (SYSTEM_CONTROL_MODULE_BASE + 0x0DA)\r
+#define DSS_DATA0           (SYSTEM_CONTROL_MODULE_BASE + 0x0DC)\r
+#define DSS_DATA1           (SYSTEM_CONTROL_MODULE_BASE + 0x0DE)\r
+#define DSS_DATA2           (SYSTEM_CONTROL_MODULE_BASE + 0x0E0)\r
+#define DSS_DATA3           (SYSTEM_CONTROL_MODULE_BASE + 0x0E2)\r
+#define DSS_DATA4           (SYSTEM_CONTROL_MODULE_BASE + 0x0E4)\r
+#define DSS_DATA5           (SYSTEM_CONTROL_MODULE_BASE + 0x0E6)\r
+#define DSS_DATA6           (SYSTEM_CONTROL_MODULE_BASE + 0x0E8)\r
+#define DSS_DATA7           (SYSTEM_CONTROL_MODULE_BASE + 0x0EA)\r
+#define DSS_DATA8           (SYSTEM_CONTROL_MODULE_BASE + 0x0EC)\r
+#define DSS_DATA9           (SYSTEM_CONTROL_MODULE_BASE + 0x0EE)\r
+#define DSS_DATA10          (SYSTEM_CONTROL_MODULE_BASE + 0x0F0)\r
+#define DSS_DATA11          (SYSTEM_CONTROL_MODULE_BASE + 0x0F2)\r
+#define DSS_DATA12          (SYSTEM_CONTROL_MODULE_BASE + 0x0F4)\r
+#define DSS_DATA13          (SYSTEM_CONTROL_MODULE_BASE + 0x0F6)\r
+#define DSS_DATA14          (SYSTEM_CONTROL_MODULE_BASE + 0x0F8)\r
+#define DSS_DATA15          (SYSTEM_CONTROL_MODULE_BASE + 0x0FA)\r
+#define DSS_DATA16          (SYSTEM_CONTROL_MODULE_BASE + 0x0FC)\r
+#define DSS_DATA17          (SYSTEM_CONTROL_MODULE_BASE + 0x0FE)\r
+#define DSS_DATA18          (SYSTEM_CONTROL_MODULE_BASE + 0x100)\r
+#define DSS_DATA19          (SYSTEM_CONTROL_MODULE_BASE + 0x102)\r
+#define DSS_DATA20          (SYSTEM_CONTROL_MODULE_BASE + 0x104)\r
+#define DSS_DATA21          (SYSTEM_CONTROL_MODULE_BASE + 0x106)\r
+#define DSS_DATA22          (SYSTEM_CONTROL_MODULE_BASE + 0x108)\r
+#define DSS_DATA23          (SYSTEM_CONTROL_MODULE_BASE + 0x10A)\r
+#define CAM_HS              (SYSTEM_CONTROL_MODULE_BASE + 0x10C)\r
+#define CAM_VS              (SYSTEM_CONTROL_MODULE_BASE + 0x10E)\r
+#define CAM_XCLKA           (SYSTEM_CONTROL_MODULE_BASE + 0x110)\r
+#define CAM_PCLK            (SYSTEM_CONTROL_MODULE_BASE + 0x112)\r
+#define CAM_FLD             (SYSTEM_CONTROL_MODULE_BASE + 0x114)\r
+#define CAM_D0              (SYSTEM_CONTROL_MODULE_BASE + 0x116)\r
+#define CAM_D1              (SYSTEM_CONTROL_MODULE_BASE + 0x118)\r
+#define CAM_D2              (SYSTEM_CONTROL_MODULE_BASE + 0x11A)\r
+#define CAM_D3              (SYSTEM_CONTROL_MODULE_BASE + 0x11C)\r
+#define CAM_D4              (SYSTEM_CONTROL_MODULE_BASE + 0x11E)\r
+#define CAM_D5              (SYSTEM_CONTROL_MODULE_BASE + 0x120)\r
+#define CAM_D6              (SYSTEM_CONTROL_MODULE_BASE + 0x122)\r
+#define CAM_D7              (SYSTEM_CONTROL_MODULE_BASE + 0x124)\r
+#define CAM_D8              (SYSTEM_CONTROL_MODULE_BASE + 0x126)\r
+#define CAM_D9              (SYSTEM_CONTROL_MODULE_BASE + 0x128)\r
+#define CAM_D10             (SYSTEM_CONTROL_MODULE_BASE + 0x12A)\r
+#define CAM_D11             (SYSTEM_CONTROL_MODULE_BASE + 0x12C)\r
+#define CAM_XCLKB           (SYSTEM_CONTROL_MODULE_BASE + 0x12E)\r
+#define CAM_WEN             (SYSTEM_CONTROL_MODULE_BASE + 0x130)\r
+#define CAM_STROBE          (SYSTEM_CONTROL_MODULE_BASE + 0x132)\r
+#define CSI2_DX0            (SYSTEM_CONTROL_MODULE_BASE + 0x134)\r
+#define CSI2_DY0            (SYSTEM_CONTROL_MODULE_BASE + 0x136)\r
+#define CSI2_DX1            (SYSTEM_CONTROL_MODULE_BASE + 0x138)\r
+#define CSI2_DY1            (SYSTEM_CONTROL_MODULE_BASE + 0x13A)\r
+#define MCBSP2_FSX          (SYSTEM_CONTROL_MODULE_BASE + 0x13C)\r
+#define MCBSP2_CLKX         (SYSTEM_CONTROL_MODULE_BASE + 0x13E)\r
+#define MCBSP2_DR           (SYSTEM_CONTROL_MODULE_BASE + 0x140)\r
+#define MCBSP2_DX           (SYSTEM_CONTROL_MODULE_BASE + 0x142)\r
+#define MMC1_CLK            (SYSTEM_CONTROL_MODULE_BASE + 0x144)\r
+#define MMC1_CMD            (SYSTEM_CONTROL_MODULE_BASE + 0x146)\r
+#define MMC1_DAT0           (SYSTEM_CONTROL_MODULE_BASE + 0x148)\r
+#define MMC1_DAT1           (SYSTEM_CONTROL_MODULE_BASE + 0x14A)\r
+#define MMC1_DAT2           (SYSTEM_CONTROL_MODULE_BASE + 0x14C)\r
+#define MMC1_DAT3           (SYSTEM_CONTROL_MODULE_BASE + 0x14E)\r
+#define MMC1_DAT4           (SYSTEM_CONTROL_MODULE_BASE + 0x150)\r
+#define MMC1_DAT5           (SYSTEM_CONTROL_MODULE_BASE + 0x152)\r
+#define MMC1_DAT6           (SYSTEM_CONTROL_MODULE_BASE + 0x154)\r
+#define MMC1_DAT7           (SYSTEM_CONTROL_MODULE_BASE + 0x156)\r
+#define MMC2_CLK            (SYSTEM_CONTROL_MODULE_BASE + 0x158)\r
+#define MMC2_CMD            (SYSTEM_CONTROL_MODULE_BASE + 0x15A)\r
+#define MMC2_DAT0           (SYSTEM_CONTROL_MODULE_BASE + 0x15C)\r
+#define MMC2_DAT1           (SYSTEM_CONTROL_MODULE_BASE + 0x15E)\r
+#define MMC2_DAT2           (SYSTEM_CONTROL_MODULE_BASE + 0x160)\r
+#define MMC2_DAT3           (SYSTEM_CONTROL_MODULE_BASE + 0x162)\r
+#define MMC2_DAT4           (SYSTEM_CONTROL_MODULE_BASE + 0x164)\r
+#define MMC2_DAT5           (SYSTEM_CONTROL_MODULE_BASE + 0x166)\r
+#define MMC2_DAT6           (SYSTEM_CONTROL_MODULE_BASE + 0x168)\r
+#define MMC2_DAT7           (SYSTEM_CONTROL_MODULE_BASE + 0x16A)\r
+#define MCBSP3_DX           (SYSTEM_CONTROL_MODULE_BASE + 0x16C)\r
+#define MCBSP3_DR           (SYSTEM_CONTROL_MODULE_BASE + 0x16E)\r
+#define MCBSP3_CLKX         (SYSTEM_CONTROL_MODULE_BASE + 0x170)\r
+#define MCBSP3_FSX          (SYSTEM_CONTROL_MODULE_BASE + 0x172)\r
+#define UART2_CTS           (SYSTEM_CONTROL_MODULE_BASE + 0x174)\r
+#define UART2_RTS           (SYSTEM_CONTROL_MODULE_BASE + 0x176)\r
+#define UART2_TX            (SYSTEM_CONTROL_MODULE_BASE + 0x178)\r
+#define UART2_RX            (SYSTEM_CONTROL_MODULE_BASE + 0x17A)\r
+#define UART1_TX            (SYSTEM_CONTROL_MODULE_BASE + 0x17C)\r
+#define UART1_RTS           (SYSTEM_CONTROL_MODULE_BASE + 0x17E)\r
+#define UART1_CTS           (SYSTEM_CONTROL_MODULE_BASE + 0x180)\r
+#define UART1_RX            (SYSTEM_CONTROL_MODULE_BASE + 0x182)\r
+#define MCBSP4_CLKX         (SYSTEM_CONTROL_MODULE_BASE + 0x184)\r
+#define MCBSP4_DR           (SYSTEM_CONTROL_MODULE_BASE + 0x186)\r
+#define MCBSP4_DX           (SYSTEM_CONTROL_MODULE_BASE + 0x188)\r
+#define MCBSP4_FSX          (SYSTEM_CONTROL_MODULE_BASE + 0x18A)\r
+#define MCBSP1_CLKR         (SYSTEM_CONTROL_MODULE_BASE + 0x18C)\r
+#define MCBSP1_FSR          (SYSTEM_CONTROL_MODULE_BASE + 0x18E)\r
+#define MCBSP1_DX           (SYSTEM_CONTROL_MODULE_BASE + 0x190)\r
+#define MCBSP1_DR           (SYSTEM_CONTROL_MODULE_BASE + 0x192)\r
+#define MCBSP1_CLKS         (SYSTEM_CONTROL_MODULE_BASE + 0x194)\r
+#define MCBSP1_FSX          (SYSTEM_CONTROL_MODULE_BASE + 0x196)\r
+#define MCBSP1_CLKX         (SYSTEM_CONTROL_MODULE_BASE + 0x198)\r
+#define UART3_CTS_RCTX      (SYSTEM_CONTROL_MODULE_BASE + 0x19A)\r
+#define UART3_RTS_SD        (SYSTEM_CONTROL_MODULE_BASE + 0x19C)\r
+#define UART3_RX_IRRX       (SYSTEM_CONTROL_MODULE_BASE + 0x19E)\r
+#define UART3_TX_IRTX       (SYSTEM_CONTROL_MODULE_BASE + 0x1A0)\r
+#define HSUSB0_CLK          (SYSTEM_CONTROL_MODULE_BASE + 0x1A2)\r
+#define HSUSB0_STP          (SYSTEM_CONTROL_MODULE_BASE + 0x1A4)\r
+#define HSUSB0_DIR          (SYSTEM_CONTROL_MODULE_BASE + 0x1A6)\r
+#define HSUSB0_NXT          (SYSTEM_CONTROL_MODULE_BASE + 0x1A8)\r
+#define HSUSB0_DATA0        (SYSTEM_CONTROL_MODULE_BASE + 0x1AA)\r
+#define HSUSB0_DATA1        (SYSTEM_CONTROL_MODULE_BASE + 0x1AC)\r
+#define HSUSB0_DATA2        (SYSTEM_CONTROL_MODULE_BASE + 0x1AE)\r
+#define HSUSB0_DATA3        (SYSTEM_CONTROL_MODULE_BASE + 0x1B0)\r
+#define HSUSB0_DATA4        (SYSTEM_CONTROL_MODULE_BASE + 0x1B2)\r
+#define HSUSB0_DATA5        (SYSTEM_CONTROL_MODULE_BASE + 0x1B4)\r
+#define HSUSB0_DATA6        (SYSTEM_CONTROL_MODULE_BASE + 0x1B6)\r
+#define HSUSB0_DATA7        (SYSTEM_CONTROL_MODULE_BASE + 0x1B8)\r
+#define I2C1_SCL            (SYSTEM_CONTROL_MODULE_BASE + 0x1BA)\r
+#define I2C1_SDA            (SYSTEM_CONTROL_MODULE_BASE + 0x1BC)\r
+#define I2C2_SCL            (SYSTEM_CONTROL_MODULE_BASE + 0x1BE)\r
+#define I2C2_SDA            (SYSTEM_CONTROL_MODULE_BASE + 0x1C0)\r
+#define I2C3_SCL            (SYSTEM_CONTROL_MODULE_BASE + 0x1C2)\r
+#define I2C3_SDA            (SYSTEM_CONTROL_MODULE_BASE + 0x1C4)\r
+#define HDQ_SIO             (SYSTEM_CONTROL_MODULE_BASE + 0x1C6)\r
+#define MCSPI1_CLK          (SYSTEM_CONTROL_MODULE_BASE + 0x1C8)\r
+#define MCSPI1_SIMO         (SYSTEM_CONTROL_MODULE_BASE + 0x1CA)\r
+#define MCSPI1_SOMI         (SYSTEM_CONTROL_MODULE_BASE + 0x1CC)\r
+#define MCSPI1_CS0          (SYSTEM_CONTROL_MODULE_BASE + 0x1CE)\r
+#define MCSPI1_CS1          (SYSTEM_CONTROL_MODULE_BASE + 0x1D0)\r
+#define MCSPI1_CS2          (SYSTEM_CONTROL_MODULE_BASE + 0x1D2)\r
+#define MCSPI1_CS3          (SYSTEM_CONTROL_MODULE_BASE + 0x1D4)\r
+#define MCSPI2_CLK          (SYSTEM_CONTROL_MODULE_BASE + 0x1D6)\r
+#define MCSPI2_SIMO         (SYSTEM_CONTROL_MODULE_BASE + 0x1D8)\r
+#define MCSPI2_SOMI         (SYSTEM_CONTROL_MODULE_BASE + 0x1DA)\r
+#define MCSPI2_CS0          (SYSTEM_CONTROL_MODULE_BASE + 0x1DC)\r
+#define MCSPI2_CS1          (SYSTEM_CONTROL_MODULE_BASE + 0x1DE)\r
+#define SYS_NIRQ            (SYSTEM_CONTROL_MODULE_BASE + 0x1E0)\r
+#define SYS_CLKOUT2         (SYSTEM_CONTROL_MODULE_BASE + 0x1E2)\r
+#define ETK_CLK             (SYSTEM_CONTROL_MODULE_BASE + 0x5D8)\r
+#define ETK_CTL             (SYSTEM_CONTROL_MODULE_BASE + 0x5DA)\r
+#define ETK_D0              (SYSTEM_CONTROL_MODULE_BASE + 0x5DC)\r
+#define ETK_D1              (SYSTEM_CONTROL_MODULE_BASE + 0x5DE)\r
+#define ETK_D2              (SYSTEM_CONTROL_MODULE_BASE + 0x5E0)\r
+#define ETK_D3              (SYSTEM_CONTROL_MODULE_BASE + 0x5E2)\r
+#define ETK_D4              (SYSTEM_CONTROL_MODULE_BASE + 0x5E4)\r
+#define ETK_D5              (SYSTEM_CONTROL_MODULE_BASE + 0x5E6)\r
+#define ETK_D6              (SYSTEM_CONTROL_MODULE_BASE + 0x5E8)\r
+#define ETK_D7              (SYSTEM_CONTROL_MODULE_BASE + 0x5EA)\r
+#define ETK_D8              (SYSTEM_CONTROL_MODULE_BASE + 0x5EC)\r
+#define ETK_D9              (SYSTEM_CONTROL_MODULE_BASE + 0x5EE)\r
+#define ETK_D10             (SYSTEM_CONTROL_MODULE_BASE + 0x5F0)\r
+#define ETK_D11             (SYSTEM_CONTROL_MODULE_BASE + 0x5F2)\r
+#define ETK_D12             (SYSTEM_CONTROL_MODULE_BASE + 0x5F4)\r
+#define ETK_D13             (SYSTEM_CONTROL_MODULE_BASE + 0x5F6)\r
+#define ETK_D14             (SYSTEM_CONTROL_MODULE_BASE + 0x5F8)\r
+#define ETK_D15             (SYSTEM_CONTROL_MODULE_BASE + 0x5FA)\r
+#define SYS_BOOT0           (SYSTEM_CONTROL_MODULE_BASE + 0xA0A)\r
+#define SYS_BOOT1           (SYSTEM_CONTROL_MODULE_BASE + 0xA0C)\r
+#define SYS_BOOT3           (SYSTEM_CONTROL_MODULE_BASE + 0xA10)\r
+#define SYS_BOOT4           (SYSTEM_CONTROL_MODULE_BASE + 0xA12)\r
+#define SYS_BOOT5           (SYSTEM_CONTROL_MODULE_BASE + 0xA14)\r
+#define SYS_BOOT6           (SYSTEM_CONTROL_MODULE_BASE + 0xA16)\r
+\r
+//Mux modes\r
+#define MUXMODE0            (0x0UL)\r
+#define MUXMODE1            (0x1UL)\r
+#define MUXMODE2            (0x2UL)\r
+#define MUXMODE3            (0x3UL)\r
+#define MUXMODE4            (0x4UL)\r
+#define MUXMODE5            (0x5UL)\r
+#define MUXMODE6            (0x6UL)\r
+#define MUXMODE7            (0x7UL)\r
+\r
+//Pad configuration register.\r
+#define PAD_CONFIG_MASK      (0xFFFFUL)\r
+#define MUXMODE_OFFSET       0\r
+#define MUXMODE_MASK         (0x7UL << MUXMODE_OFFSET)\r
+#define PULL_CONFIG_OFFSET   3\r
+#define PULL_CONFIG_MASK     (0x3UL << PULL_CONFIG_OFFSET)\r
+#define INPUTENABLE_OFFSET   8\r
+#define INPUTENABLE_MASK     (0x1UL << INPUTENABLE_OFFSET)\r
+#define OFFMODE_VALUE_OFFSET 9\r
+#define OFFMODE_VALUE_MASK   (0x1FUL << OFFMODE_VALUE_OFFSET)\r
+#define WAKEUP_OFFSET        14\r
+#define WAKEUP_MASK          (0x2UL << WAKEUP_OFFSET)\r
+\r
+#define PULL_DOWN_SELECTED   ((0x0UL << 1) | BIT0)\r
+#define PULL_UP_SELECTED     (BIT1 | BIT0)\r
+#define PULL_DISABLED        (0x0UL << 0)\r
+\r
+#define OUTPUT               (0x0UL) //Pin is configured in output only mode.\r
+#define INPUT                (0x1UL) //Pin is configured in bi-directional mode.\r
+\r
+typedef struct {\r
+  UINTN   Pin;\r
+  UINTN   MuxMode;\r
+  UINTN   PullConfig;\r
+  UINTN   InputEnable;\r
+} PAD_CONFIGURATION;\r
+\r
+#endif //__OMAP3530_PAD_CONFIGURATION_H__\r
index cd639e306d3ef71ff999989c8c59da3f16db0e91..3a297d0a9865cd0637194c0f5dfff04f5394e7cf 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __OMAP3530PRCM_H__
-#define __OMAP3530PRCM_H__
-
-#define CM_FCLKEN1_CORE   (0x48004A00)
-#define CM_FCLKEN3_CORE   (0x48004A08)
-#define CM_ICLKEN1_CORE   (0x48004A10)
-#define CM_ICLKEN3_CORE   (0x48004A18)
-#define CM_CLKEN2_PLL     (0x48004D04)
-#define CM_CLKSEL4_PLL    (0x48004D4C)
-#define CM_CLKSEL5_PLL    (0x48004D50)
-#define CM_FCLKEN_USBHOST  (0x48005400)
-#define CM_ICLKEN_USBHOST  (0x48005410)
-#define CM_CLKSTST_USBHOST (0x4800544c)
-
-//Wakeup clock defintion
-#define CM_FCLKEN_WKUP    (0x48004C00)
-#define CM_ICLKEN_WKUP    (0x48004C10)
-
-//Peripheral clock definition
-#define CM_FCLKEN_PER     (0x48005000)
-#define CM_ICLKEN_PER     (0x48005010)
-#define CM_CLKSEL_PER     (0x48005040)
-
-//Reset management definition
-#define PRM_RSTCTRL       (0x48307250)
-#define PRM_RSTST         (0x48307258)
-
-//CORE clock
-#define CM_FCLKEN1_CORE_EN_I2C1_MASK    BIT15
-#define CM_FCLKEN1_CORE_EN_I2C1_DISABLE (0UL << 15)
-#define CM_FCLKEN1_CORE_EN_I2C1_ENABLE  BIT15
-
-#define CM_ICLKEN1_CORE_EN_I2C1_MASK    BIT15
-#define CM_ICLKEN1_CORE_EN_I2C1_DISABLE (0UL << 15)
-#define CM_ICLKEN1_CORE_EN_I2C1_ENABLE  BIT15
-
-#define CM_FCLKEN1_CORE_EN_MMC1_MASK    BIT24
-#define CM_FCLKEN1_CORE_EN_MMC1_DISABLE (0UL << 24)
-#define CM_FCLKEN1_CORE_EN_MMC1_ENABLE  BIT24
-
-#define CM_FCLKEN3_CORE_EN_USBTLL_MASK    BIT2
-#define CM_FCLKEN3_CORE_EN_USBTLL_DISABLE (0UL << 2)
-#define CM_FCLKEN3_CORE_EN_USBTLL_ENABLE  BIT2
-
-#define CM_ICLKEN1_CORE_EN_MMC1_MASK    BIT24
-#define CM_ICLKEN1_CORE_EN_MMC1_DISABLE (0UL << 24)
-#define CM_ICLKEN1_CORE_EN_MMC1_ENABLE  BIT24
-
-#define CM_ICLKEN3_CORE_EN_USBTLL_MASK    BIT2
-#define CM_ICLKEN3_CORE_EN_USBTLL_DISABLE (0UL << 2)
-#define CM_ICLKEN3_CORE_EN_USBTLL_ENABLE  BIT2
-
-#define CM_CLKEN_FREQSEL_075_100        (0x03UL << 4)
-#define CM_CLKEN_ENABLE                 (7UL << 0)
-
-#define CM_CLKSEL_PLL_MULT(x)           (((x) & 0x07FF) << 8)
-#define CM_CLKSEL_PLL_DIV(x)            ((((x) - 1) & 0x7F) << 0)
-  
-#define CM_CLKSEL_DIV_120M(x)           (((x) & 0x1F) << 0)
-
-#define CM_FCLKEN_USBHOST_EN_USBHOST2_MASK    BIT1
-#define CM_FCLKEN_USBHOST_EN_USBHOST2_DISABLE (0UL << 1)
-#define CM_FCLKEN_USBHOST_EN_USBHOST2_ENABLE  BIT1
-
-#define CM_FCLKEN_USBHOST_EN_USBHOST1_MASK    BIT0
-#define CM_FCLKEN_USBHOST_EN_USBHOST1_DISABLE (0UL << 0)
-#define CM_FCLKEN_USBHOST_EN_USBHOST1_ENABLE  BIT0
-
-#define CM_ICLKEN_USBHOST_EN_USBHOST_MASK     BIT0
-#define CM_ICLKEN_USBHOST_EN_USBHOST_DISABLE  (0UL << 0)
-#define CM_ICLKEN_USBHOST_EN_USBHOST_ENABLE   BIT0
-
-//Wakeup functional clock
-#define CM_FCLKEN_WKUP_EN_GPIO1_DISABLE       (0UL << 3)
-#define CM_FCLKEN_WKUP_EN_GPIO1_ENABLE        BIT3
-
-#define CM_FCLKEN_WKUP_EN_WDT2_DISABLE        (0UL << 5)
-#define CM_FCLKEN_WKUP_EN_WDT2_ENABLE         BIT5
-
-//Wakeup interface clock
-#define CM_ICLKEN_WKUP_EN_GPIO1_DISABLE       (0UL << 3)
-#define CM_ICLKEN_WKUP_EN_GPIO1_ENABLE        BIT3
-
-#define CM_ICLKEN_WKUP_EN_WDT2_DISABLE        (0UL << 5)
-#define CM_ICLKEN_WKUP_EN_WDT2_ENABLE         BIT5
-
-//Peripheral functional clock
-#define CM_FCLKEN_PER_EN_GPT3_DISABLE         (0UL << 4)
-#define CM_FCLKEN_PER_EN_GPT3_ENABLE          BIT4
-
-#define CM_FCLKEN_PER_EN_GPT4_DISABLE         (0UL << 5)
-#define CM_FCLKEN_PER_EN_GPT4_ENABLE          BIT5
-
-#define CM_FCLKEN_PER_EN_UART3_DISABLE        (0UL << 11)
-#define CM_FCLKEN_PER_EN_UART3_ENABLE         BIT11
-
-#define CM_FCLKEN_PER_EN_GPIO2_DISABLE        (0UL << 13)
-#define CM_FCLKEN_PER_EN_GPIO2_ENABLE         BIT13
-
-#define CM_FCLKEN_PER_EN_GPIO3_DISABLE        (0UL << 14)
-#define CM_FCLKEN_PER_EN_GPIO3_ENABLE         BIT14
-
-#define CM_FCLKEN_PER_EN_GPIO4_DISABLE        (0UL << 15)
-#define CM_FCLKEN_PER_EN_GPIO4_ENABLE         BIT15
-
-#define CM_FCLKEN_PER_EN_GPIO5_DISABLE        (0UL << 16)
-#define CM_FCLKEN_PER_EN_GPIO5_ENABLE         BIT16
-
-#define CM_FCLKEN_PER_EN_GPIO6_DISABLE        (0UL << 17)
-#define CM_FCLKEN_PER_EN_GPIO6_ENABLE         BIT17
-
-//Peripheral interface clock
-#define CM_ICLKEN_PER_EN_GPT3_DISABLE         (0UL << 4)
-#define CM_ICLKEN_PER_EN_GPT3_ENABLE          BIT4
-
-#define CM_ICLKEN_PER_EN_GPT4_DISABLE         (0UL << 5)
-#define CM_ICLKEN_PER_EN_GPT4_ENABLE          BIT5
-
-#define CM_ICLKEN_PER_EN_UART3_DISABLE        (0UL << 11)
-#define CM_ICLKEN_PER_EN_UART3_ENABLE         BIT11
-
-#define CM_ICLKEN_PER_EN_GPIO2_DISABLE        (0UL << 13)
-#define CM_ICLKEN_PER_EN_GPIO2_ENABLE         BIT13
-
-#define CM_ICLKEN_PER_EN_GPIO3_DISABLE        (0UL << 14)
-#define CM_ICLKEN_PER_EN_GPIO3_ENABLE         BIT14
-
-#define CM_ICLKEN_PER_EN_GPIO4_DISABLE        (0UL << 15)
-#define CM_ICLKEN_PER_EN_GPIO4_ENABLE         BIT15
-
-#define CM_ICLKEN_PER_EN_GPIO5_DISABLE        (0UL << 16)
-#define CM_ICLKEN_PER_EN_GPIO5_ENABLE         BIT16
-
-#define CM_ICLKEN_PER_EN_GPIO6_DISABLE        (0UL << 17)
-#define CM_ICLKEN_PER_EN_GPIO6_ENABLE         BIT17
-
-//Timer source clock selection
-#define CM_CLKSEL_PER_CLKSEL_GPT3_32K         (0UL << 1)
-#define CM_CLKSEL_PER_CLKSEL_GPT3_SYS         BIT1
-
-#define CM_CLKSEL_PER_CLKSEL_GPT4_32K         (0UL << 2)
-#define CM_CLKSEL_PER_CLKSEL_GPT4_SYS         BIT2
-
-//Reset management (Global and Cold reset)
-#define RST_GS            BIT1
-#define RST_DPLL3         BIT2
-#define GLOBAL_SW_RST     BIT1
-#define GLOBAL_COLD_RST   (0x0UL << 0)
-
-#endif // __OMAP3530PRCM_H__
-
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __OMAP3530PRCM_H__\r
+#define __OMAP3530PRCM_H__\r
+\r
+#define CM_FCLKEN1_CORE   (0x48004A00)\r
+#define CM_FCLKEN3_CORE   (0x48004A08)\r
+#define CM_ICLKEN1_CORE   (0x48004A10)\r
+#define CM_ICLKEN3_CORE   (0x48004A18)\r
+#define CM_CLKEN2_PLL     (0x48004D04)\r
+#define CM_CLKSEL4_PLL    (0x48004D4C)\r
+#define CM_CLKSEL5_PLL    (0x48004D50)\r
+#define CM_FCLKEN_USBHOST  (0x48005400)\r
+#define CM_ICLKEN_USBHOST  (0x48005410)\r
+#define CM_CLKSTST_USBHOST (0x4800544c)\r
+\r
+//Wakeup clock defintion\r
+#define CM_FCLKEN_WKUP    (0x48004C00)\r
+#define CM_ICLKEN_WKUP    (0x48004C10)\r
+\r
+//Peripheral clock definition\r
+#define CM_FCLKEN_PER     (0x48005000)\r
+#define CM_ICLKEN_PER     (0x48005010)\r
+#define CM_CLKSEL_PER     (0x48005040)\r
+\r
+//Reset management definition\r
+#define PRM_RSTCTRL       (0x48307250)\r
+#define PRM_RSTST         (0x48307258)\r
+\r
+//CORE clock\r
+#define CM_FCLKEN1_CORE_EN_I2C1_MASK    BIT15\r
+#define CM_FCLKEN1_CORE_EN_I2C1_DISABLE (0UL << 15)\r
+#define CM_FCLKEN1_CORE_EN_I2C1_ENABLE  BIT15\r
+\r
+#define CM_ICLKEN1_CORE_EN_I2C1_MASK    BIT15\r
+#define CM_ICLKEN1_CORE_EN_I2C1_DISABLE (0UL << 15)\r
+#define CM_ICLKEN1_CORE_EN_I2C1_ENABLE  BIT15\r
+\r
+#define CM_FCLKEN1_CORE_EN_MMC1_MASK    BIT24\r
+#define CM_FCLKEN1_CORE_EN_MMC1_DISABLE (0UL << 24)\r
+#define CM_FCLKEN1_CORE_EN_MMC1_ENABLE  BIT24\r
+\r
+#define CM_FCLKEN3_CORE_EN_USBTLL_MASK    BIT2\r
+#define CM_FCLKEN3_CORE_EN_USBTLL_DISABLE (0UL << 2)\r
+#define CM_FCLKEN3_CORE_EN_USBTLL_ENABLE  BIT2\r
+\r
+#define CM_ICLKEN1_CORE_EN_MMC1_MASK    BIT24\r
+#define CM_ICLKEN1_CORE_EN_MMC1_DISABLE (0UL << 24)\r
+#define CM_ICLKEN1_CORE_EN_MMC1_ENABLE  BIT24\r
+\r
+#define CM_ICLKEN3_CORE_EN_USBTLL_MASK    BIT2\r
+#define CM_ICLKEN3_CORE_EN_USBTLL_DISABLE (0UL << 2)\r
+#define CM_ICLKEN3_CORE_EN_USBTLL_ENABLE  BIT2\r
+\r
+#define CM_CLKEN_FREQSEL_075_100        (0x03UL << 4)\r
+#define CM_CLKEN_ENABLE                 (7UL << 0)\r
+\r
+#define CM_CLKSEL_PLL_MULT(x)           (((x) & 0x07FF) << 8)\r
+#define CM_CLKSEL_PLL_DIV(x)            ((((x) - 1) & 0x7F) << 0)\r
+  \r
+#define CM_CLKSEL_DIV_120M(x)           (((x) & 0x1F) << 0)\r
+\r
+#define CM_FCLKEN_USBHOST_EN_USBHOST2_MASK    BIT1\r
+#define CM_FCLKEN_USBHOST_EN_USBHOST2_DISABLE (0UL << 1)\r
+#define CM_FCLKEN_USBHOST_EN_USBHOST2_ENABLE  BIT1\r
+\r
+#define CM_FCLKEN_USBHOST_EN_USBHOST1_MASK    BIT0\r
+#define CM_FCLKEN_USBHOST_EN_USBHOST1_DISABLE (0UL << 0)\r
+#define CM_FCLKEN_USBHOST_EN_USBHOST1_ENABLE  BIT0\r
+\r
+#define CM_ICLKEN_USBHOST_EN_USBHOST_MASK     BIT0\r
+#define CM_ICLKEN_USBHOST_EN_USBHOST_DISABLE  (0UL << 0)\r
+#define CM_ICLKEN_USBHOST_EN_USBHOST_ENABLE   BIT0\r
+\r
+//Wakeup functional clock\r
+#define CM_FCLKEN_WKUP_EN_GPIO1_DISABLE       (0UL << 3)\r
+#define CM_FCLKEN_WKUP_EN_GPIO1_ENABLE        BIT3\r
+\r
+#define CM_FCLKEN_WKUP_EN_WDT2_DISABLE        (0UL << 5)\r
+#define CM_FCLKEN_WKUP_EN_WDT2_ENABLE         BIT5\r
+\r
+//Wakeup interface clock\r
+#define CM_ICLKEN_WKUP_EN_GPIO1_DISABLE       (0UL << 3)\r
+#define CM_ICLKEN_WKUP_EN_GPIO1_ENABLE        BIT3\r
+\r
+#define CM_ICLKEN_WKUP_EN_WDT2_DISABLE        (0UL << 5)\r
+#define CM_ICLKEN_WKUP_EN_WDT2_ENABLE         BIT5\r
+\r
+//Peripheral functional clock\r
+#define CM_FCLKEN_PER_EN_GPT3_DISABLE         (0UL << 4)\r
+#define CM_FCLKEN_PER_EN_GPT3_ENABLE          BIT4\r
+\r
+#define CM_FCLKEN_PER_EN_GPT4_DISABLE         (0UL << 5)\r
+#define CM_FCLKEN_PER_EN_GPT4_ENABLE          BIT5\r
+\r
+#define CM_FCLKEN_PER_EN_UART3_DISABLE        (0UL << 11)\r
+#define CM_FCLKEN_PER_EN_UART3_ENABLE         BIT11\r
+\r
+#define CM_FCLKEN_PER_EN_GPIO2_DISABLE        (0UL << 13)\r
+#define CM_FCLKEN_PER_EN_GPIO2_ENABLE         BIT13\r
+\r
+#define CM_FCLKEN_PER_EN_GPIO3_DISABLE        (0UL << 14)\r
+#define CM_FCLKEN_PER_EN_GPIO3_ENABLE         BIT14\r
+\r
+#define CM_FCLKEN_PER_EN_GPIO4_DISABLE        (0UL << 15)\r
+#define CM_FCLKEN_PER_EN_GPIO4_ENABLE         BIT15\r
+\r
+#define CM_FCLKEN_PER_EN_GPIO5_DISABLE        (0UL << 16)\r
+#define CM_FCLKEN_PER_EN_GPIO5_ENABLE         BIT16\r
+\r
+#define CM_FCLKEN_PER_EN_GPIO6_DISABLE        (0UL << 17)\r
+#define CM_FCLKEN_PER_EN_GPIO6_ENABLE         BIT17\r
+\r
+//Peripheral interface clock\r
+#define CM_ICLKEN_PER_EN_GPT3_DISABLE         (0UL << 4)\r
+#define CM_ICLKEN_PER_EN_GPT3_ENABLE          BIT4\r
+\r
+#define CM_ICLKEN_PER_EN_GPT4_DISABLE         (0UL << 5)\r
+#define CM_ICLKEN_PER_EN_GPT4_ENABLE          BIT5\r
+\r
+#define CM_ICLKEN_PER_EN_UART3_DISABLE        (0UL << 11)\r
+#define CM_ICLKEN_PER_EN_UART3_ENABLE         BIT11\r
+\r
+#define CM_ICLKEN_PER_EN_GPIO2_DISABLE        (0UL << 13)\r
+#define CM_ICLKEN_PER_EN_GPIO2_ENABLE         BIT13\r
+\r
+#define CM_ICLKEN_PER_EN_GPIO3_DISABLE        (0UL << 14)\r
+#define CM_ICLKEN_PER_EN_GPIO3_ENABLE         BIT14\r
+\r
+#define CM_ICLKEN_PER_EN_GPIO4_DISABLE        (0UL << 15)\r
+#define CM_ICLKEN_PER_EN_GPIO4_ENABLE         BIT15\r
+\r
+#define CM_ICLKEN_PER_EN_GPIO5_DISABLE        (0UL << 16)\r
+#define CM_ICLKEN_PER_EN_GPIO5_ENABLE         BIT16\r
+\r
+#define CM_ICLKEN_PER_EN_GPIO6_DISABLE        (0UL << 17)\r
+#define CM_ICLKEN_PER_EN_GPIO6_ENABLE         BIT17\r
+\r
+//Timer source clock selection\r
+#define CM_CLKSEL_PER_CLKSEL_GPT3_32K         (0UL << 1)\r
+#define CM_CLKSEL_PER_CLKSEL_GPT3_SYS         BIT1\r
+\r
+#define CM_CLKSEL_PER_CLKSEL_GPT4_32K         (0UL << 2)\r
+#define CM_CLKSEL_PER_CLKSEL_GPT4_SYS         BIT2\r
+\r
+//Reset management (Global and Cold reset)\r
+#define RST_GS            BIT1\r
+#define RST_DPLL3         BIT2\r
+#define GLOBAL_SW_RST     BIT1\r
+#define GLOBAL_COLD_RST   (0x0UL << 0)\r
+\r
+#endif // __OMAP3530PRCM_H__\r
+\r
index 5067aaafca36109c22d54cf81a558589d5256f0f..d66da8dc04467fdd1b5d27ef854b0299f163fa6a 100644 (file)
@@ -1,82 +1,82 @@
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __OMAP3530TIMER_H__
-#define __OMAP3530TIMER_H__
-
-#define GPTIMER1_BASE   (0x48313000)
-#define GPTIMER2_BASE   (0x49032000)
-#define GPTIMER3_BASE   (0x49034000)
-#define GPTIMER4_BASE   (0x49036000)
-#define GPTIMER5_BASE   (0x49038000)
-#define GPTIMER6_BASE   (0x4903A000)
-#define GPTIMER7_BASE   (0x4903C000)
-#define GPTIMER8_BASE   (0x4903E000)
-#define GPTIMER9_BASE   (0x49040000)
-#define GPTIMER10_BASE  (0x48086000)
-#define GPTIMER11_BASE  (0x48088000)
-#define GPTIMER12_BASE  (0x48304000)
-#define WDTIMER2_BASE   (0x48314000)
-
-#define GPTIMER_TIOCP_CFG (0x0010)
-#define GPTIMER_TISTAT    (0x0014)
-#define GPTIMER_TISR      (0x0018)
-#define GPTIMER_TIER      (0x001C)
-#define GPTIMER_TWER      (0x0020)
-#define GPTIMER_TCLR      (0x0024)
-#define GPTIMER_TCRR      (0x0028)
-#define GPTIMER_TLDR      (0x002C)
-#define GPTIMER_TTGR      (0x0030)
-#define GPTIMER_TWPS      (0x0034)
-#define GPTIMER_TMAR      (0x0038)
-#define GPTIMER_TCAR1     (0x003C)
-#define GPTIMER_TSICR     (0x0040)
-#define GPTIMER_TCAR2     (0x0044)
-#define GPTIMER_TPIR      (0x0048)
-#define GPTIMER_TNIR      (0x004C)
-#define GPTIMER_TCVR      (0x0050)
-#define GPTIMER_TOCR      (0x0054)
-#define GPTIMER_TOWR      (0x0058)
-
-#define WSPR              (0x048)
-
-#define TISR_TCAR_IT_FLAG_MASK  BIT2
-#define TISR_OVF_IT_FLAG_MASK   BIT1
-#define TISR_MAT_IT_FLAG_MASK   BIT0
-#define TISR_ALL_INTERRUPT_MASK (TISR_TCAR_IT_FLAG_MASK | TISR_OVF_IT_FLAG_MASK | TISR_MAT_IT_FLAG_MASK)
-
-#define TISR_TCAR_IT_FLAG_NOT_PENDING   (0UL << 2)
-#define TISR_OVF_IT_FLAG_NOT_PENDING    (0UL << 1)
-#define TISR_MAT_IT_FLAG_NOT_PENDING    (0UL << 0)
-#define TISR_NO_INTERRUPTS_PENDING      (TISR_TCAR_IT_FLAG_NOT_PENDING | TISR_OVF_IT_FLAG_NOT_PENDING | TISR_MAT_IT_FLAG_NOT_PENDING)
-
-#define TISR_TCAR_IT_FLAG_CLEAR BIT2
-#define TISR_OVF_IT_FLAG_CLEAR  BIT1
-#define TISR_MAT_IT_FLAG_CLEAR  BIT0
-#define TISR_CLEAR_ALL          (TISR_TCAR_IT_FLAG_CLEAR | TISR_OVF_IT_FLAG_CLEAR | TISR_MAT_IT_FLAG_CLEAR)
-
-#define TCLR_AR_AUTORELOAD      BIT1
-#define TCLR_AR_ONESHOT         (0UL << 1)
-#define TCLR_ST_ON              BIT0
-#define TCLR_ST_OFF             (0UL << 0)
-
-#define TIER_TCAR_IT_ENABLE     (BIT2
-#define TIER_TCAR_IT_DISABLE    (0UL << 2)
-#define TIER_OVF_IT_ENABLE      BIT1
-#define TIER_OVF_IT_DISABLE     (0UL << 1)
-#define TIER_MAT_IT_ENABLE      BIT0
-#define TIER_MAT_IT_DISABLE     (0UL << 0)
-
-#endif // __OMAP3530TIMER_H__
-
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __OMAP3530TIMER_H__\r
+#define __OMAP3530TIMER_H__\r
+\r
+#define GPTIMER1_BASE   (0x48313000)\r
+#define GPTIMER2_BASE   (0x49032000)\r
+#define GPTIMER3_BASE   (0x49034000)\r
+#define GPTIMER4_BASE   (0x49036000)\r
+#define GPTIMER5_BASE   (0x49038000)\r
+#define GPTIMER6_BASE   (0x4903A000)\r
+#define GPTIMER7_BASE   (0x4903C000)\r
+#define GPTIMER8_BASE   (0x4903E000)\r
+#define GPTIMER9_BASE   (0x49040000)\r
+#define GPTIMER10_BASE  (0x48086000)\r
+#define GPTIMER11_BASE  (0x48088000)\r
+#define GPTIMER12_BASE  (0x48304000)\r
+#define WDTIMER2_BASE   (0x48314000)\r
+\r
+#define GPTIMER_TIOCP_CFG (0x0010)\r
+#define GPTIMER_TISTAT    (0x0014)\r
+#define GPTIMER_TISR      (0x0018)\r
+#define GPTIMER_TIER      (0x001C)\r
+#define GPTIMER_TWER      (0x0020)\r
+#define GPTIMER_TCLR      (0x0024)\r
+#define GPTIMER_TCRR      (0x0028)\r
+#define GPTIMER_TLDR      (0x002C)\r
+#define GPTIMER_TTGR      (0x0030)\r
+#define GPTIMER_TWPS      (0x0034)\r
+#define GPTIMER_TMAR      (0x0038)\r
+#define GPTIMER_TCAR1     (0x003C)\r
+#define GPTIMER_TSICR     (0x0040)\r
+#define GPTIMER_TCAR2     (0x0044)\r
+#define GPTIMER_TPIR      (0x0048)\r
+#define GPTIMER_TNIR      (0x004C)\r
+#define GPTIMER_TCVR      (0x0050)\r
+#define GPTIMER_TOCR      (0x0054)\r
+#define GPTIMER_TOWR      (0x0058)\r
+\r
+#define WSPR              (0x048)\r
+\r
+#define TISR_TCAR_IT_FLAG_MASK  BIT2\r
+#define TISR_OVF_IT_FLAG_MASK   BIT1\r
+#define TISR_MAT_IT_FLAG_MASK   BIT0\r
+#define TISR_ALL_INTERRUPT_MASK (TISR_TCAR_IT_FLAG_MASK | TISR_OVF_IT_FLAG_MASK | TISR_MAT_IT_FLAG_MASK)\r
+\r
+#define TISR_TCAR_IT_FLAG_NOT_PENDING   (0UL << 2)\r
+#define TISR_OVF_IT_FLAG_NOT_PENDING    (0UL << 1)\r
+#define TISR_MAT_IT_FLAG_NOT_PENDING    (0UL << 0)\r
+#define TISR_NO_INTERRUPTS_PENDING      (TISR_TCAR_IT_FLAG_NOT_PENDING | TISR_OVF_IT_FLAG_NOT_PENDING | TISR_MAT_IT_FLAG_NOT_PENDING)\r
+\r
+#define TISR_TCAR_IT_FLAG_CLEAR BIT2\r
+#define TISR_OVF_IT_FLAG_CLEAR  BIT1\r
+#define TISR_MAT_IT_FLAG_CLEAR  BIT0\r
+#define TISR_CLEAR_ALL          (TISR_TCAR_IT_FLAG_CLEAR | TISR_OVF_IT_FLAG_CLEAR | TISR_MAT_IT_FLAG_CLEAR)\r
+\r
+#define TCLR_AR_AUTORELOAD      BIT1\r
+#define TCLR_AR_ONESHOT         (0UL << 1)\r
+#define TCLR_ST_ON              BIT0\r
+#define TCLR_ST_OFF             (0UL << 0)\r
+\r
+#define TIER_TCAR_IT_ENABLE     (BIT2\r
+#define TIER_TCAR_IT_DISABLE    (0UL << 2)\r
+#define TIER_OVF_IT_ENABLE      BIT1\r
+#define TIER_OVF_IT_DISABLE     (0UL << 1)\r
+#define TIER_MAT_IT_ENABLE      BIT0\r
+#define TIER_MAT_IT_DISABLE     (0UL << 0)\r
+\r
+#endif // __OMAP3530TIMER_H__\r
+\r
index 9cc17ebf32c67f143cce69750fcb13c21a7cc8b7..5d64cafc577d319501cfa9f9a490ad8d30eb4b6e 100644 (file)
@@ -1,48 +1,48 @@
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __OMAP3530USB_H__
-#define __OMAP3530USB_H__
-
-#define USB_BASE            (0x48060000)
-
-#define UHH_SYSCONFIG       (USB_BASE + 0x4010)
-#define UHH_HOSTCONFIG      (USB_BASE + 0x4040)
-#define UHH_SYSSTATUS       (USB_BASE + 0x4014)
-
-#define USB_EHCI_HCCAPBASE  (USB_BASE + 0x4800)
-
-#define UHH_SYSCONFIG_MIDLEMODE_NO_STANDBY  BIT12
-#define UHH_SYSCONFIG_CLOCKACTIVITY_ON      BIT8
-#define UHH_SYSCONFIG_SIDLEMODE_NO_STANDBY  BIT3
-#define UHH_SYSCONFIG_ENAWAKEUP_ENABLE      BIT2
-#define UHH_SYSCONFIG_SOFTRESET             BIT1
-#define UHH_SYSCONFIG_AUTOIDLE_ALWAYS_RUN   (0UL <<  0)
-
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __OMAP3530USB_H__\r
+#define __OMAP3530USB_H__\r
+\r
+#define USB_BASE            (0x48060000)\r
+\r
+#define UHH_SYSCONFIG       (USB_BASE + 0x4010)\r
+#define UHH_HOSTCONFIG      (USB_BASE + 0x4040)\r
+#define UHH_SYSSTATUS       (USB_BASE + 0x4014)\r
+\r
+#define USB_EHCI_HCCAPBASE  (USB_BASE + 0x4800)\r
+\r
+#define UHH_SYSCONFIG_MIDLEMODE_NO_STANDBY  BIT12\r
+#define UHH_SYSCONFIG_CLOCKACTIVITY_ON      BIT8\r
+#define UHH_SYSCONFIG_SIDLEMODE_NO_STANDBY  BIT3\r
+#define UHH_SYSCONFIG_ENAWAKEUP_ENABLE      BIT2\r
+#define UHH_SYSCONFIG_SOFTRESET             BIT1\r
+#define UHH_SYSCONFIG_AUTOIDLE_ALWAYS_RUN   (0UL <<  0)\r
+\r
 #define UHH_HOSTCONFIG_P3_CONNECT_STATUS_DISCONNECT (0UL << 10)\r
 #define UHH_HOSTCONFIG_P2_CONNECT_STATUS_DISCONNECT (0UL <<  9)\r
 #define UHH_HOSTCONFIG_P1_CONNECT_STATUS_DISCONNECT (0UL <<  8)\r
 #define UHH_HOSTCONFIG_ENA_INCR_ALIGN_DISABLE       (0UL <<  5)\r
 #define UHH_HOSTCONFIG_P3_CONNECT_STATUS_DISCONNECT (0UL << 10)\r
 #define UHH_HOSTCONFIG_P2_CONNECT_STATUS_DISCONNECT (0UL <<  9)\r
 #define UHH_HOSTCONFIG_P1_CONNECT_STATUS_DISCONNECT (0UL <<  8)\r
 #define UHH_HOSTCONFIG_ENA_INCR_ALIGN_DISABLE       (0UL <<  5)\r
-#define UHH_HOSTCONFIG_ENA_INCR16_ENABLE            BIT4
-#define UHH_HOSTCONFIG_ENA_INCR8_ENABLE             BIT3
-#define UHH_HOSTCONFIG_ENA_INCR4_ENABLE             BIT2
+#define UHH_HOSTCONFIG_ENA_INCR16_ENABLE            BIT4\r
+#define UHH_HOSTCONFIG_ENA_INCR8_ENABLE             BIT3\r
+#define UHH_HOSTCONFIG_ENA_INCR4_ENABLE             BIT2\r
 #define UHH_HOSTCONFIG_AUTOPPD_ON_OVERCUR_EN_ON     (0UL <<  1)\r
 #define UHH_HOSTCONFIG_AUTOPPD_ON_OVERCUR_EN_ON     (0UL <<  1)\r
-#define UHH_HOSTCONFIG_P1_ULPI_BYPASS_ULPI_MODE     (0UL <<  0)
-
-#define UHH_SYSSTATUS_RESETDONE                (BIT0 | BIT1 | BIT2)
-
-#endif // __OMAP3530USB_H__
-
-
-
+#define UHH_HOSTCONFIG_P1_ULPI_BYPASS_ULPI_MODE     (0UL <<  0)\r
+\r
+#define UHH_SYSSTATUS_RESETDONE                (BIT0 | BIT1 | BIT2)\r
+\r
+#endif // __OMAP3530USB_H__\r
+\r
+\r
+\r
index cd708d9793134e78624e42d88af4e0c0d233625d..20df2319e10274924fa30923df58f26ba06cd618 100644 (file)
@@ -1,80 +1,80 @@
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-
-  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.
-
-**/
-
-#ifndef __TPS65950_H__
-#define __TPS65950_H__
-
-#define EXTERNAL_DEVICE_REGISTER_TO_SLAVE_ADDRESS(x)     (((x) >> 8) & 0xFF)
-#define EXTERNAL_DEVICE_REGISTER_TO_REGISTER(x)          ((x) & 0xFF)
-#define EXTERNAL_DEVICE_REGISTER(SlaveAddress, Register) (((SlaveAddress) & 0xFF) << 8 | ((Register) & 0xFF))
-
-// I2C Address group
-#define I2C_ADDR_GRP_ID1      0x48
-#define I2C_ADDR_GRP_ID2      0x49
-#define I2C_ADDR_GRP_ID3      0x4A
-#define I2C_ADDR_GRP_ID4      0x4B
-#define I2C_ADDR_GRP_ID5      0x12
-
-// MMC definitions.
-#define VMMC1_DEV_GRP         0x82
-#define DEV_GRP_P1            BIT5
-
-#define VMMC1_DEDICATED_REG   0x85 
-#define VSEL_1_85V            0x0
-#define VSEL_2_85V            0x1
-#define VSEL_3_00V            0x2
-#define VSEL_3_15V            0x3
-
-#define TPS65950_GPIO_CTRL    0xaa  //I2C_ADDR_GRP_ID2
-#define CARD_DETECT_ENABLE    (BIT2 | BIT0) // GPIO ON + GPIO CD1 enabled
-
-
-#define GPIODATAIN1           0x98  //I2C_ADDR_GRP_ID2
-#define CARD_DETECT_BIT       BIT0
-
-// LEDEN register
-#define LEDEN                 0xEE
-#define LEDAON                BIT0
-#define LEDBON                BIT1
-#define LEDAPWM               BIT4
-#define LEDBPWM               BIT5
-
-// RTC registers
-#define SECONDS_REG           0x1C
-#define MINUTES_REG           0x1D
-#define HOURS_REG             0x1E
-#define DAYS_REG              0x1F
-#define MONTHS_REG            0x20
-#define YEARS_REG             0x21
-#define WEEKS_REG             0x22
-#define RTC_CTRL_REG          0x29
-
-// USB PHY power
-#define VAUX2_DEDICATED       0x79
-#define VAUX2_DEV_GRP         0x76
-
-#define VAUX_DEV_GRP_NONE     0x00
-#define VAUX_DEV_GRP_P1       0x20
-#define VAUX_DEV_GRP_P2       0x40
-#define VAUX_DEV_GRP_P3       0x80
-#define VAUX_DEDICATED_18V    0x05
-
-// Display subsystem
-#define VPLL2_DEDICATED       0x91
-#define VPLL2_DEV_GRP         0x8E
-
-#define GPIODATADIR1          0x9B
-#define SETGPIODATAOUT1       0xA4
-
-#endif //__TPS65950_H__
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __TPS65950_H__\r
+#define __TPS65950_H__\r
+\r
+#define EXTERNAL_DEVICE_REGISTER_TO_SLAVE_ADDRESS(x)     (((x) >> 8) & 0xFF)\r
+#define EXTERNAL_DEVICE_REGISTER_TO_REGISTER(x)          ((x) & 0xFF)\r
+#define EXTERNAL_DEVICE_REGISTER(SlaveAddress, Register) (((SlaveAddress) & 0xFF) << 8 | ((Register) & 0xFF))\r
+\r
+// I2C Address group\r
+#define I2C_ADDR_GRP_ID1      0x48\r
+#define I2C_ADDR_GRP_ID2      0x49\r
+#define I2C_ADDR_GRP_ID3      0x4A\r
+#define I2C_ADDR_GRP_ID4      0x4B\r
+#define I2C_ADDR_GRP_ID5      0x12\r
+\r
+// MMC definitions.\r
+#define VMMC1_DEV_GRP         0x82\r
+#define DEV_GRP_P1            BIT5\r
+\r
+#define VMMC1_DEDICATED_REG   0x85 \r
+#define VSEL_1_85V            0x0\r
+#define VSEL_2_85V            0x1\r
+#define VSEL_3_00V            0x2\r
+#define VSEL_3_15V            0x3\r
+\r
+#define TPS65950_GPIO_CTRL    0xaa  //I2C_ADDR_GRP_ID2\r
+#define CARD_DETECT_ENABLE    (BIT2 | BIT0) // GPIO ON + GPIO CD1 enabled\r
+\r
+\r
+#define GPIODATAIN1           0x98  //I2C_ADDR_GRP_ID2\r
+#define CARD_DETECT_BIT       BIT0\r
+\r
+// LEDEN register\r
+#define LEDEN                 0xEE\r
+#define LEDAON                BIT0\r
+#define LEDBON                BIT1\r
+#define LEDAPWM               BIT4\r
+#define LEDBPWM               BIT5\r
+\r
+// RTC registers\r
+#define SECONDS_REG           0x1C\r
+#define MINUTES_REG           0x1D\r
+#define HOURS_REG             0x1E\r
+#define DAYS_REG              0x1F\r
+#define MONTHS_REG            0x20\r
+#define YEARS_REG             0x21\r
+#define WEEKS_REG             0x22\r
+#define RTC_CTRL_REG          0x29\r
+\r
+// USB PHY power\r
+#define VAUX2_DEDICATED       0x79\r
+#define VAUX2_DEV_GRP         0x76\r
+\r
+#define VAUX_DEV_GRP_NONE     0x00\r
+#define VAUX_DEV_GRP_P1       0x20\r
+#define VAUX_DEV_GRP_P2       0x40\r
+#define VAUX_DEV_GRP_P3       0x80\r
+#define VAUX_DEDICATED_18V    0x05\r
+\r
+// Display subsystem\r
+#define VPLL2_DEDICATED       0x91\r
+#define VPLL2_DEV_GRP         0x8E\r
+\r
+#define GPIODATADIR1          0x9B\r
+#define SETGPIODATAOUT1       0xA4\r
+\r
+#endif //__TPS65950_H__\r
index 38c84dd88c48036d06e75b17c84eb93786ba9680..9541e7e902d72d2512a92f3b7f88edd642ddb7a8 100644 (file)
-/** @file
-
- Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>
- 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 <PiDxe.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/DevicePathLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/MemoryAllocationLib.h>
-
-#include <Guid/GlobalVariable.h>
-
-#include "LcdGraphicsOutputDxe.h"
-
-extern BOOLEAN mDisplayInitialized;
-
-//
-// Function Definitions
-//
-
-STATIC
-EFI_STATUS
-VideoCopyNoHorizontalOverlap (
-  IN UINTN          BitsPerPixel,
-  IN volatile VOID  *FrameBufferBase,
-  IN UINT32         HorizontalResolution,
-  IN UINTN          SourceX,
-  IN UINTN          SourceY,
-  IN UINTN          DestinationX,
-  IN UINTN          DestinationY,
-  IN UINTN          Width,
-  IN UINTN          Height
-  )
-{
-  EFI_STATUS    Status = EFI_SUCCESS;
-  UINTN         SourceLine;
-  UINTN         DestinationLine;
-  UINTN         WidthInBytes;
-  UINTN         LineCount;
-  INTN          Step;
-  VOID          *SourceAddr;
-  VOID          *DestinationAddr;
-
-  if( DestinationY <= SourceY ) {
-    // scrolling up (or horizontally but without overlap)
-    SourceLine       = SourceY;
-    DestinationLine  = DestinationY;
-    Step             = 1;
-  } else {
-    // scrolling down
-    SourceLine       = SourceY + Height;
-    DestinationLine  = DestinationY + Height;
-    Step             = -1;
-  }
-
-  WidthInBytes = Width * 2;
-
-  for( LineCount = 0; LineCount < Height; LineCount++ ) {
-    // Update the start addresses of source & destination using 16bit pointer arithmetic
-    SourceAddr      = (VOID *)((UINT16 *)FrameBufferBase + SourceLine      * HorizontalResolution + SourceX     );
-    DestinationAddr = (VOID *)((UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationX);
-
-    // Copy the entire line Y from video ram to the temp buffer
-    CopyMem( DestinationAddr, SourceAddr, WidthInBytes);
-
-    // Update the line numbers
-    SourceLine      += Step;
-    DestinationLine += Step;
-  }
-
-  return Status;
-}
-
-STATIC
-EFI_STATUS
-VideoCopyHorizontalOverlap (
-  IN UINTN          BitsPerPixel,
-  IN volatile VOID  *FrameBufferBase,
-  UINT32            HorizontalResolution,
-  IN UINTN          SourceX,
-  IN UINTN          SourceY,
-  IN UINTN          DestinationX,
-  IN UINTN          DestinationY,
-  IN UINTN          Width,
-  IN UINTN          Height
-  )
-{
-  EFI_STATUS      Status = EFI_SUCCESS;
-
-  UINT16 *PixelBuffer16bit;
-  UINT16 *SourcePixel16bit;
-  UINT16 *DestinationPixel16bit;
-
-  UINT32          SourcePixelY;
-  UINT32          DestinationPixelY;
-  UINTN           SizeIn16Bits;
-
-  // Allocate a temporary buffer
-  PixelBuffer16bit = (UINT16 *) AllocatePool((Height * Width) * sizeof(UINT16));
-
-  if (PixelBuffer16bit == NULL) {
-    Status = EFI_OUT_OF_RESOURCES;
-    goto EXIT;
-  }
-
-  // Access each pixel inside the source area of the Video Memory and copy it to the temp buffer
-
-  SizeIn16Bits = Width * 2;
-
-  for (SourcePixelY = SourceY, DestinationPixel16bit = PixelBuffer16bit;
-       SourcePixelY < SourceY + Height;
-       SourcePixelY++, DestinationPixel16bit += Width)
-  {
-    // Calculate the source address:
-    SourcePixel16bit = (UINT16 *)FrameBufferBase + SourcePixelY * HorizontalResolution + SourceX;
-
-    // Copy the entire line Y from Video to the temp buffer
-    CopyMem( (VOID *)DestinationPixel16bit, (CONST VOID *)SourcePixel16bit, SizeIn16Bits);
-  }
-
-  // Copy from the temp buffer into the destination area of the Video Memory
-
-  for (DestinationPixelY = DestinationY, SourcePixel16bit = PixelBuffer16bit;
-       DestinationPixelY < DestinationY + Height;
-       DestinationPixelY++, SourcePixel16bit += Width)
-  {
-    // Calculate the target address:
-    DestinationPixel16bit = (UINT16 *)FrameBufferBase + (DestinationPixelY * HorizontalResolution + DestinationX);
-
-    // Copy the entire line Y from the temp buffer to Video
-    CopyMem( (VOID *)DestinationPixel16bit, (CONST VOID *)SourcePixel16bit, SizeIn16Bits);
-  }
-
-  // Free the allocated memory
-  FreePool((VOID *) PixelBuffer16bit);
-
-
-EXIT:
-  return Status;
-}
-
-STATIC
-EFI_STATUS
-BltVideoFill (
-  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,
-  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *EfiSourcePixel,     OPTIONAL
-  IN UINTN                               SourceX,
-  IN UINTN                               SourceY,
-  IN UINTN                               DestinationX,
-  IN UINTN                               DestinationY,
-  IN UINTN                               Width,
-  IN UINTN                               Height,
-  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer
-  )
-{
-  EFI_PIXEL_BITMASK*  PixelInformation;
-  EFI_STATUS          Status;
-  UINT32              HorizontalResolution;
-  VOID                *FrameBufferBase;
-  UINT16              *DestinationPixel16bit;
-  UINT16              Pixel16bit;
-  UINT32              DestinationPixelX;
-  UINT32              DestinationLine;
-
-  Status           = EFI_SUCCESS;
-  PixelInformation = &This->Mode->Info->PixelInformation;
-  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));
-  HorizontalResolution = This->Mode->Info->HorizontalResolution;
-
-  // Convert the EFI pixel at the start of the BltBuffer(0,0) into a video display pixel
-  Pixel16bit = (UINT16) (
-      ( (EfiSourcePixel->Red      <<  8) & PixelInformation->RedMask      )
-    | ( (EfiSourcePixel->Green    <<  3) & PixelInformation->GreenMask    )
-    | ( (EfiSourcePixel->Blue     >>  3) & PixelInformation->BlueMask     )
-   );
-
-  // Copy the SourcePixel into every pixel inside the target rectangle
-  for (DestinationLine = DestinationY;
-       DestinationLine < DestinationY + Height;
-       DestinationLine++)
-  {
-    for (DestinationPixelX = DestinationX;
-         DestinationPixelX < DestinationX + Width;
-         DestinationPixelX++)
-    {
-      // Calculate the target address:
-      DestinationPixel16bit =  (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution  + DestinationPixelX;
-
-      // Copy the pixel into the new target
-      *DestinationPixel16bit = Pixel16bit;
-    }
-  }
-
-
-  return Status;
-}
-
-STATIC
-EFI_STATUS
-BltVideoToBltBuffer (
-  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,
-  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL
-  IN UINTN                               SourceX,
-  IN UINTN                               SourceY,
-  IN UINTN                               DestinationX,
-  IN UINTN                               DestinationY,
-  IN UINTN                               Width,
-  IN UINTN                               Height,
-  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer
-  )
-{
-  EFI_STATUS         Status;
-  UINT32             HorizontalResolution;
-  EFI_PIXEL_BITMASK  *PixelInformation;
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *EfiDestinationPixel;
-  VOID               *FrameBufferBase;
-  UINT16             *SourcePixel16bit;
-  UINT16             Pixel16bit;
-  UINT32             SourcePixelX;
-  UINT32             SourceLine;
-  UINT32             DestinationPixelX;
-  UINT32             DestinationLine;
-  UINT32             BltBufferHorizontalResolution;
-
-  Status = EFI_SUCCESS;
-  PixelInformation = &This->Mode->Info->PixelInformation;
-  HorizontalResolution = This->Mode->Info->HorizontalResolution;
-  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));
-
-  if(( Delta != 0 ) && ( Delta != Width * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {
-    // Delta is not zero and it is different from the width.
-    // Divide it by the size of a pixel to find out the buffer's horizontal resolution.
-    BltBufferHorizontalResolution = (UINT32) (Delta / sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
-  } else {
-    BltBufferHorizontalResolution = Width;
-  }
-
-  // Access each pixel inside the Video Memory
-  for (SourceLine = SourceY, DestinationLine = DestinationY;
-       SourceLine < SourceY + Height;
-       SourceLine++, DestinationLine++)
-  {
-    for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;
-         SourcePixelX < SourceX + Width;
-         SourcePixelX++, DestinationPixelX++)
-    {
-      // Calculate the source and target addresses:
-      SourcePixel16bit = (UINT16 *)FrameBufferBase + SourceLine * HorizontalResolution + SourcePixelX;
-      EfiDestinationPixel = BltBuffer + DestinationLine * BltBufferHorizontalResolution + DestinationPixelX;
-
-      // Snapshot the pixel from the video buffer once, to speed up the operation.
-      // If we were dereferencing the pointer, as it is volatile, we would perform 3 memory read operations.
-      Pixel16bit = *SourcePixel16bit;
-
-      // Copy the pixel into the new target
-      EfiDestinationPixel->Red      = (UINT8) ( (Pixel16bit & PixelInformation->RedMask     ) >>  8 );
-      EfiDestinationPixel->Green    = (UINT8) ( (Pixel16bit & PixelInformation->GreenMask   ) >>  3 );
-      EfiDestinationPixel->Blue     = (UINT8) ( (Pixel16bit & PixelInformation->BlueMask    ) <<  3 );
-    }
-  }
-
-  return Status;
-}
-
-STATIC
-EFI_STATUS
-BltBufferToVideo (
-  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,
-  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL
-  IN UINTN                               SourceX,
-  IN UINTN                               SourceY,
-  IN UINTN                               DestinationX,
-  IN UINTN                               DestinationY,
-  IN UINTN                               Width,
-  IN UINTN                               Height,
-  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer
-  )
-{
-  EFI_STATUS         Status;
-  UINT32             HorizontalResolution;
-  EFI_PIXEL_BITMASK  *PixelInformation;
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *EfiSourcePixel;
-  VOID               *FrameBufferBase;
-  UINT16             *DestinationPixel16bit;
-  UINT32             SourcePixelX;
-  UINT32             SourceLine;
-  UINT32             DestinationPixelX;
-  UINT32             DestinationLine;
-  UINT32             BltBufferHorizontalResolution;
-
-  Status = EFI_SUCCESS;
-  PixelInformation = &This->Mode->Info->PixelInformation;
-  HorizontalResolution = This->Mode->Info->HorizontalResolution;
-  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));
-
-  if(( Delta != 0 ) && ( Delta != Width * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {
-    // Delta is not zero and it is different from the width.
-    // Divide it by the size of a pixel to find out the buffer's horizontal resolution.
-    BltBufferHorizontalResolution = (UINT32) (Delta / sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
-  } else {
-    BltBufferHorizontalResolution = Width;
-  }
-
-  // Access each pixel inside the BltBuffer Memory
-  for (SourceLine = SourceY, DestinationLine = DestinationY;
-       SourceLine < SourceY + Height;
-       SourceLine++, DestinationLine++) {
-
-    for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;
-         SourcePixelX < SourceX + Width;
-         SourcePixelX++, DestinationPixelX++)
-    {
-      // Calculate the source and target addresses:
-      EfiSourcePixel  = BltBuffer + SourceLine * BltBufferHorizontalResolution + SourcePixelX;
-      DestinationPixel16bit = (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationPixelX;
-
-      // Copy the pixel into the new target
-      // Only the most significant bits will be copied across:
-      // To convert from 8 bits to 5 bits per pixel we throw away the 3 least significant bits
-        *DestinationPixel16bit = (UINT16) (
-              ( (EfiSourcePixel->Red      <<  8) & PixelInformation->RedMask      )
-            | ( (EfiSourcePixel->Green    <<  3) & PixelInformation->GreenMask    )
-            | ( (EfiSourcePixel->Blue     >>  3) & PixelInformation->BlueMask     )
-            );
-      }
-    }
-   
-  return Status;
-}
-
-STATIC
-EFI_STATUS
-BltVideoToVideo (
-  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,
-  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL
-  IN UINTN                               SourceX,
-  IN UINTN                               SourceY,
-  IN UINTN                               DestinationX,
-  IN UINTN                               DestinationY,
-  IN UINTN                               Width,
-  IN UINTN                               Height,
-  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer
-  )
-{
-  EFI_STATUS         Status;
-  UINT32             HorizontalResolution;
-  UINTN              BitsPerPixel;
-  VOID               *FrameBufferBase;
-
-  BitsPerPixel = 16;
-
-  HorizontalResolution = This->Mode->Info->HorizontalResolution;
-  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));
-
-  //
-  // BltVideo to BltVideo:
-  //
-  //  Source is the Video Memory,
-  //  Destination is the Video Memory
-
-  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));
-
-  // The UEFI spec currently states:
-  // "There is no limitation on the overlapping of the source and destination rectangles"
-  // Therefore, we must be careful to avoid overwriting the source data
-  if( SourceY == DestinationY ) {
-    // Copying within the same height, e.g. horizontal shift
-    if( SourceX == DestinationX ) {
-      // Nothing to do
-      Status = EFI_SUCCESS;
-    } else if( ((SourceX>DestinationX)?(SourceX - DestinationX):(DestinationX - SourceX)) < Width ) {
-      // There is overlap
-      Status = VideoCopyHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height );
-    } else {
-      // No overlap
-      Status = VideoCopyNoHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height );
-    }
-  } else {
-    // Copying from different heights
-    Status = VideoCopyNoHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height );
-  }
-
-  return Status;
-}
-
-EFI_STATUS
-EFIAPI
-LcdGraphicsBlt (
-  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,
-       IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL
-       IN EFI_GRAPHICS_OUTPUT_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   // Number of BYTES in a row of the BltBuffer
-  )
-{
-  EFI_STATUS    Status;
-       LCD_INSTANCE  *Instance;
-
-       Instance = LCD_INSTANCE_FROM_GOP_THIS(This);
-
-  if (!mDisplayInitialized) {
-    InitializeDisplay (Instance);
-  }
-  
-  switch (BltOperation) {
-         case EfiBltVideoFill:
-           Status = BltVideoFill (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);
-                 break;
-
-         case EfiBltVideoToBltBuffer:
-           Status = BltVideoToBltBuffer (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);
-      break;
-
-    case EfiBltBufferToVideo:
-      Status = BltBufferToVideo (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);
-                 break;
-
-         case EfiBltVideoToVideo:
-           Status = BltVideoToVideo (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);
-                 break;
-
-         case EfiGraphicsOutputBltOperationMax:
-         default:
-                 DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: Invalid Operation\n"));
-                 Status = EFI_INVALID_PARAMETER;
-                 break;
-       }
-
-  return Status;
-}
+/** @file\r
+\r
+ Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution.  The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ **/\r
+\r
+#include <PiDxe.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+#include <Guid/GlobalVariable.h>\r
+\r
+#include "LcdGraphicsOutputDxe.h"\r
+\r
+extern BOOLEAN mDisplayInitialized;\r
+\r
+//\r
+// Function Definitions\r
+//\r
+\r
+STATIC\r
+EFI_STATUS\r
+VideoCopyNoHorizontalOverlap (\r
+  IN UINTN          BitsPerPixel,\r
+  IN volatile VOID  *FrameBufferBase,\r
+  IN UINT32         HorizontalResolution,\r
+  IN UINTN          SourceX,\r
+  IN UINTN          SourceY,\r
+  IN UINTN          DestinationX,\r
+  IN UINTN          DestinationY,\r
+  IN UINTN          Width,\r
+  IN UINTN          Height\r
+  )\r
+{\r
+  EFI_STATUS    Status = EFI_SUCCESS;\r
+  UINTN         SourceLine;\r
+  UINTN         DestinationLine;\r
+  UINTN         WidthInBytes;\r
+  UINTN         LineCount;\r
+  INTN          Step;\r
+  VOID          *SourceAddr;\r
+  VOID          *DestinationAddr;\r
+\r
+  if( DestinationY <= SourceY ) {\r
+    // scrolling up (or horizontally but without overlap)\r
+    SourceLine       = SourceY;\r
+    DestinationLine  = DestinationY;\r
+    Step             = 1;\r
+  } else {\r
+    // scrolling down\r
+    SourceLine       = SourceY + Height;\r
+    DestinationLine  = DestinationY + Height;\r
+    Step             = -1;\r
+  }\r
+\r
+  WidthInBytes = Width * 2;\r
+\r
+  for( LineCount = 0; LineCount < Height; LineCount++ ) {\r
+    // Update the start addresses of source & destination using 16bit pointer arithmetic\r
+    SourceAddr      = (VOID *)((UINT16 *)FrameBufferBase + SourceLine      * HorizontalResolution + SourceX     );\r
+    DestinationAddr = (VOID *)((UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationX);\r
+\r
+    // Copy the entire line Y from video ram to the temp buffer\r
+    CopyMem( DestinationAddr, SourceAddr, WidthInBytes);\r
+\r
+    // Update the line numbers\r
+    SourceLine      += Step;\r
+    DestinationLine += Step;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+VideoCopyHorizontalOverlap (\r
+  IN UINTN          BitsPerPixel,\r
+  IN volatile VOID  *FrameBufferBase,\r
+  UINT32            HorizontalResolution,\r
+  IN UINTN          SourceX,\r
+  IN UINTN          SourceY,\r
+  IN UINTN          DestinationX,\r
+  IN UINTN          DestinationY,\r
+  IN UINTN          Width,\r
+  IN UINTN          Height\r
+  )\r
+{\r
+  EFI_STATUS      Status = EFI_SUCCESS;\r
+\r
+  UINT16 *PixelBuffer16bit;\r
+  UINT16 *SourcePixel16bit;\r
+  UINT16 *DestinationPixel16bit;\r
+\r
+  UINT32          SourcePixelY;\r
+  UINT32          DestinationPixelY;\r
+  UINTN           SizeIn16Bits;\r
+\r
+  // Allocate a temporary buffer\r
+  PixelBuffer16bit = (UINT16 *) AllocatePool((Height * Width) * sizeof(UINT16));\r
+\r
+  if (PixelBuffer16bit == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto EXIT;\r
+  }\r
+\r
+  // Access each pixel inside the source area of the Video Memory and copy it to the temp buffer\r
+\r
+  SizeIn16Bits = Width * 2;\r
+\r
+  for (SourcePixelY = SourceY, DestinationPixel16bit = PixelBuffer16bit;\r
+       SourcePixelY < SourceY + Height;\r
+       SourcePixelY++, DestinationPixel16bit += Width)\r
+  {\r
+    // Calculate the source address:\r
+    SourcePixel16bit = (UINT16 *)FrameBufferBase + SourcePixelY * HorizontalResolution + SourceX;\r
+\r
+    // Copy the entire line Y from Video to the temp buffer\r
+    CopyMem( (VOID *)DestinationPixel16bit, (CONST VOID *)SourcePixel16bit, SizeIn16Bits);\r
+  }\r
+\r
+  // Copy from the temp buffer into the destination area of the Video Memory\r
+\r
+  for (DestinationPixelY = DestinationY, SourcePixel16bit = PixelBuffer16bit;\r
+       DestinationPixelY < DestinationY + Height;\r
+       DestinationPixelY++, SourcePixel16bit += Width)\r
+  {\r
+    // Calculate the target address:\r
+    DestinationPixel16bit = (UINT16 *)FrameBufferBase + (DestinationPixelY * HorizontalResolution + DestinationX);\r
+\r
+    // Copy the entire line Y from the temp buffer to Video\r
+    CopyMem( (VOID *)DestinationPixel16bit, (CONST VOID *)SourcePixel16bit, SizeIn16Bits);\r
+  }\r
+\r
+  // Free the allocated memory\r
+  FreePool((VOID *) PixelBuffer16bit);\r
+\r
+\r
+EXIT:\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+BltVideoFill (\r
+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,\r
+  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *EfiSourcePixel,     OPTIONAL\r
+  IN UINTN                               SourceX,\r
+  IN UINTN                               SourceY,\r
+  IN UINTN                               DestinationX,\r
+  IN UINTN                               DestinationY,\r
+  IN UINTN                               Width,\r
+  IN UINTN                               Height,\r
+  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer\r
+  )\r
+{\r
+  EFI_PIXEL_BITMASK*  PixelInformation;\r
+  EFI_STATUS          Status;\r
+  UINT32              HorizontalResolution;\r
+  VOID                *FrameBufferBase;\r
+  UINT16              *DestinationPixel16bit;\r
+  UINT16              Pixel16bit;\r
+  UINT32              DestinationPixelX;\r
+  UINT32              DestinationLine;\r
+\r
+  Status           = EFI_SUCCESS;\r
+  PixelInformation = &This->Mode->Info->PixelInformation;\r
+  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));\r
+  HorizontalResolution = This->Mode->Info->HorizontalResolution;\r
+\r
+  // Convert the EFI pixel at the start of the BltBuffer(0,0) into a video display pixel\r
+  Pixel16bit = (UINT16) (\r
+      ( (EfiSourcePixel->Red      <<  8) & PixelInformation->RedMask      )\r
+    | ( (EfiSourcePixel->Green    <<  3) & PixelInformation->GreenMask    )\r
+    | ( (EfiSourcePixel->Blue     >>  3) & PixelInformation->BlueMask     )\r
+   );\r
+\r
+  // Copy the SourcePixel into every pixel inside the target rectangle\r
+  for (DestinationLine = DestinationY;\r
+       DestinationLine < DestinationY + Height;\r
+       DestinationLine++)\r
+  {\r
+    for (DestinationPixelX = DestinationX;\r
+         DestinationPixelX < DestinationX + Width;\r
+         DestinationPixelX++)\r
+    {\r
+      // Calculate the target address:\r
+      DestinationPixel16bit =  (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution  + DestinationPixelX;\r
+\r
+      // Copy the pixel into the new target\r
+      *DestinationPixel16bit = Pixel16bit;\r
+    }\r
+  }\r
+\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+BltVideoToBltBuffer (\r
+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,\r
+  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL\r
+  IN UINTN                               SourceX,\r
+  IN UINTN                               SourceY,\r
+  IN UINTN                               DestinationX,\r
+  IN UINTN                               DestinationY,\r
+  IN UINTN                               Width,\r
+  IN UINTN                               Height,\r
+  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer\r
+  )\r
+{\r
+  EFI_STATUS         Status;\r
+  UINT32             HorizontalResolution;\r
+  EFI_PIXEL_BITMASK  *PixelInformation;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *EfiDestinationPixel;\r
+  VOID               *FrameBufferBase;\r
+  UINT16             *SourcePixel16bit;\r
+  UINT16             Pixel16bit;\r
+  UINT32             SourcePixelX;\r
+  UINT32             SourceLine;\r
+  UINT32             DestinationPixelX;\r
+  UINT32             DestinationLine;\r
+  UINT32             BltBufferHorizontalResolution;\r
+\r
+  Status = EFI_SUCCESS;\r
+  PixelInformation = &This->Mode->Info->PixelInformation;\r
+  HorizontalResolution = This->Mode->Info->HorizontalResolution;\r
+  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));\r
+\r
+  if(( Delta != 0 ) && ( Delta != Width * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {\r
+    // Delta is not zero and it is different from the width.\r
+    // Divide it by the size of a pixel to find out the buffer's horizontal resolution.\r
+    BltBufferHorizontalResolution = (UINT32) (Delta / sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
+  } else {\r
+    BltBufferHorizontalResolution = Width;\r
+  }\r
+\r
+  // Access each pixel inside the Video Memory\r
+  for (SourceLine = SourceY, DestinationLine = DestinationY;\r
+       SourceLine < SourceY + Height;\r
+       SourceLine++, DestinationLine++)\r
+  {\r
+    for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;\r
+         SourcePixelX < SourceX + Width;\r
+         SourcePixelX++, DestinationPixelX++)\r
+    {\r
+      // Calculate the source and target addresses:\r
+      SourcePixel16bit = (UINT16 *)FrameBufferBase + SourceLine * HorizontalResolution + SourcePixelX;\r
+      EfiDestinationPixel = BltBuffer + DestinationLine * BltBufferHorizontalResolution + DestinationPixelX;\r
+\r
+      // Snapshot the pixel from the video buffer once, to speed up the operation.\r
+      // If we were dereferencing the pointer, as it is volatile, we would perform 3 memory read operations.\r
+      Pixel16bit = *SourcePixel16bit;\r
+\r
+      // Copy the pixel into the new target\r
+      EfiDestinationPixel->Red      = (UINT8) ( (Pixel16bit & PixelInformation->RedMask     ) >>  8 );\r
+      EfiDestinationPixel->Green    = (UINT8) ( (Pixel16bit & PixelInformation->GreenMask   ) >>  3 );\r
+      EfiDestinationPixel->Blue     = (UINT8) ( (Pixel16bit & PixelInformation->BlueMask    ) <<  3 );\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+BltBufferToVideo (\r
+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,\r
+  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL\r
+  IN UINTN                               SourceX,\r
+  IN UINTN                               SourceY,\r
+  IN UINTN                               DestinationX,\r
+  IN UINTN                               DestinationY,\r
+  IN UINTN                               Width,\r
+  IN UINTN                               Height,\r
+  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer\r
+  )\r
+{\r
+  EFI_STATUS         Status;\r
+  UINT32             HorizontalResolution;\r
+  EFI_PIXEL_BITMASK  *PixelInformation;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *EfiSourcePixel;\r
+  VOID               *FrameBufferBase;\r
+  UINT16             *DestinationPixel16bit;\r
+  UINT32             SourcePixelX;\r
+  UINT32             SourceLine;\r
+  UINT32             DestinationPixelX;\r
+  UINT32             DestinationLine;\r
+  UINT32             BltBufferHorizontalResolution;\r
+\r
+  Status = EFI_SUCCESS;\r
+  PixelInformation = &This->Mode->Info->PixelInformation;\r
+  HorizontalResolution = This->Mode->Info->HorizontalResolution;\r
+  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));\r
+\r
+  if(( Delta != 0 ) && ( Delta != Width * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {\r
+    // Delta is not zero and it is different from the width.\r
+    // Divide it by the size of a pixel to find out the buffer's horizontal resolution.\r
+    BltBufferHorizontalResolution = (UINT32) (Delta / sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
+  } else {\r
+    BltBufferHorizontalResolution = Width;\r
+  }\r
+\r
+  // Access each pixel inside the BltBuffer Memory\r
+  for (SourceLine = SourceY, DestinationLine = DestinationY;\r
+       SourceLine < SourceY + Height;\r
+       SourceLine++, DestinationLine++) {\r
+\r
+    for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;\r
+         SourcePixelX < SourceX + Width;\r
+         SourcePixelX++, DestinationPixelX++)\r
+    {\r
+      // Calculate the source and target addresses:\r
+      EfiSourcePixel  = BltBuffer + SourceLine * BltBufferHorizontalResolution + SourcePixelX;\r
+      DestinationPixel16bit = (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationPixelX;\r
+\r
+      // Copy the pixel into the new target\r
+      // Only the most significant bits will be copied across:\r
+      // To convert from 8 bits to 5 bits per pixel we throw away the 3 least significant bits\r
+        *DestinationPixel16bit = (UINT16) (\r
+              ( (EfiSourcePixel->Red      <<  8) & PixelInformation->RedMask      )\r
+            | ( (EfiSourcePixel->Green    <<  3) & PixelInformation->GreenMask    )\r
+            | ( (EfiSourcePixel->Blue     >>  3) & PixelInformation->BlueMask     )\r
+            );\r
+      }\r
+    }\r
+   \r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+BltVideoToVideo (\r
+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,\r
+  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL\r
+  IN UINTN                               SourceX,\r
+  IN UINTN                               SourceY,\r
+  IN UINTN                               DestinationX,\r
+  IN UINTN                               DestinationY,\r
+  IN UINTN                               Width,\r
+  IN UINTN                               Height,\r
+  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer\r
+  )\r
+{\r
+  EFI_STATUS         Status;\r
+  UINT32             HorizontalResolution;\r
+  UINTN              BitsPerPixel;\r
+  VOID               *FrameBufferBase;\r
+\r
+  BitsPerPixel = 16;\r
+\r
+  HorizontalResolution = This->Mode->Info->HorizontalResolution;\r
+  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));\r
+\r
+  //\r
+  // BltVideo to BltVideo:\r
+  //\r
+  //  Source is the Video Memory,\r
+  //  Destination is the Video Memory\r
+\r
+  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));\r
+\r
+  // The UEFI spec currently states:\r
+  // "There is no limitation on the overlapping of the source and destination rectangles"\r
+  // Therefore, we must be careful to avoid overwriting the source data\r
+  if( SourceY == DestinationY ) {\r
+    // Copying within the same height, e.g. horizontal shift\r
+    if( SourceX == DestinationX ) {\r
+      // Nothing to do\r
+      Status = EFI_SUCCESS;\r
+    } else if( ((SourceX>DestinationX)?(SourceX - DestinationX):(DestinationX - SourceX)) < Width ) {\r
+      // There is overlap\r
+      Status = VideoCopyHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height );\r
+    } else {\r
+      // No overlap\r
+      Status = VideoCopyNoHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height );\r
+    }\r
+  } else {\r
+    // Copying from different heights\r
+    Status = VideoCopyNoHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+LcdGraphicsBlt (\r
+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,\r
+       IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL\r
+       IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION   BltOperation,\r
+       IN UINTN                               SourceX,\r
+       IN UINTN                               SourceY,\r
+       IN UINTN                               DestinationX,\r
+       IN UINTN                               DestinationY,\r
+       IN UINTN                               Width,\r
+       IN UINTN                               Height,\r
+       IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+       LCD_INSTANCE  *Instance;\r
+\r
+       Instance = LCD_INSTANCE_FROM_GOP_THIS(This);\r
+\r
+  if (!mDisplayInitialized) {\r
+    InitializeDisplay (Instance);\r
+  }\r
+  \r
+  switch (BltOperation) {\r
+         case EfiBltVideoFill:\r
+           Status = BltVideoFill (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);\r
+                 break;\r
+\r
+         case EfiBltVideoToBltBuffer:\r
+           Status = BltVideoToBltBuffer (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);\r
+      break;\r
+\r
+    case EfiBltBufferToVideo:\r
+      Status = BltBufferToVideo (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);\r
+                 break;\r
+\r
+         case EfiBltVideoToVideo:\r
+           Status = BltVideoToVideo (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);\r
+                 break;\r
+\r
+         case EfiGraphicsOutputBltOperationMax:\r
+         default:\r
+                 DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: Invalid Operation\n"));\r
+                 Status = EFI_INVALID_PARAMETER;\r
+                 break;\r
+       }\r
+\r
+  return Status;\r
+}\r
index 6c20575cfe215f4bd71f4d73610b1acc5c957964..e30a679d8433e87af60e265ee694018e095e693e 100644 (file)
-/** @file
-
- Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>
- 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 "LcdGraphicsOutputDxe.h"
-
-BOOLEAN mDisplayInitialized = FALSE;
-
-LCD_MODE LcdModes[] = {
-  {
-    0, 640, 480,
-    9, 4,
-    96, 16, 48,
-    2, 10, 33
-  },
-  {
-    1, 800, 600,
-    11, 2,
-    120, 56, 64,
-    5, 37, 22
-  },
-  {
-    2, 1024, 768,
-    6, 2,
-    96, 16, 48,
-    2, 10, 33
-  },
-};
-
-LCD_INSTANCE mLcdTemplate = {
-  LCD_INSTANCE_SIGNATURE,
-  NULL, // Handle
-  { // ModeInfo
-    0, // Version
-    0, // HorizontalResolution
-    0, // VerticalResolution
-    PixelBltOnly, // PixelFormat
-    {
-      0xF800, //RedMask;
-      0x7E0, //GreenMask;
-      0x1F, //BlueMask;
-      0x0//ReservedMask
-    }, // PixelInformation
-    0, // PixelsPerScanLine
-  },
-  { // Mode
-    3, // MaxMode;
-    0, // Mode;
-    NULL, // Info;
-    0, // SizeOfInfo;
-    0, // FrameBufferBase;
-    0 // FrameBufferSize;
-  },
-  { // Gop
-    LcdGraphicsQueryMode,  // QueryMode
-    LcdGraphicsSetMode,    // SetMode
-    LcdGraphicsBlt,        // Blt
-    NULL                     // *Mode
-  },
-  { // DevicePath
-    {
-      {
-        HARDWARE_DEVICE_PATH, HW_VENDOR_DP,
-        (UINT8) (sizeof(VENDOR_DEVICE_PATH)),
-        (UINT8) ((sizeof(VENDOR_DEVICE_PATH)) >> 8),
-      },
-      // Hardware Device Path for Lcd
-      EFI_CALLER_ID_GUID // Use the driver's GUID
-    },
-
-    {
-      END_DEVICE_PATH_TYPE,
-      END_ENTIRE_DEVICE_PATH_SUBTYPE,
-      sizeof(EFI_DEVICE_PATH_PROTOCOL),
-      0
-    }
-  }
-};
-
-EFI_STATUS
-LcdInstanceContructor (
-  OUT LCD_INSTANCE** NewInstance
-  )
-{
-  LCD_INSTANCE* Instance;
-
-  Instance = AllocateCopyPool (sizeof(LCD_INSTANCE), &mLcdTemplate);
-  if (Instance == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  Instance->Gop.Mode          = &Instance->Mode;
-  Instance->Mode.Info         = &Instance->ModeInfo;
-
-  *NewInstance = Instance;
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-LcdPlatformGetVram (
-  OUT EFI_PHYSICAL_ADDRESS*  VramBaseAddress,
-  OUT UINTN*                 VramSize
-  )
-{
-  EFI_STATUS             Status;
-  EFI_CPU_ARCH_PROTOCOL  *Cpu;
-  UINTN                  MaxSize;
-
-  MaxSize = 0x500000;
-  *VramSize = MaxSize;
-
-  // Allocate VRAM from DRAM
-  Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesData, EFI_SIZE_TO_PAGES((MaxSize)), VramBaseAddress);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  // Ensure the Cpu architectural protocol is already installed
-  Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&Cpu);
-  ASSERT_EFI_ERROR(Status);
-
-  // Mark the VRAM as un-cacheable. The VRAM is inside the DRAM, which is cacheable.
-  Status = Cpu->SetMemoryAttributes (Cpu, *VramBaseAddress, *VramSize, EFI_MEMORY_UC);
-  if (EFI_ERROR(Status)) {
-    gBS->FreePool (VramBaseAddress);
-    return Status;
-  }
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-DssSetMode (
-  UINT32 VramBaseAddress,
-  UINTN  ModeNumber
-  )
-{
-  // Make sure the interface clock is running
-  MmioWrite32 (CM_ICLKEN_DSS, EN_DSS);  
-
-  // Stop the functional clocks
-  MmioAnd32 (CM_FCLKEN_DSS, ~(EN_DSS1 | EN_DSS2 | EN_TV));
-
-  // Program the DSS clock divisor
-  MmioWrite32 (CM_CLKSEL_DSS, 0x1000 | (LcdModes[ModeNumber].DssDivisor));
-  
-  // Start the functional clocks
-  MmioOr32 (CM_FCLKEN_DSS, (EN_DSS1 | EN_DSS2 | EN_TV));
-
-  // Wait for DSS to stabilize
-  gBS->Stall(1);
-
-  // Reset the subsystem
-  MmioWrite32(DSS_SYSCONFIG, DSS_SOFTRESET);
-  while (!(MmioRead32 (DSS_SYSSTATUS) & DSS_RESETDONE));
-  
-  // Configure LCD parameters
-  MmioWrite32 (DISPC_SIZE_LCD,
-               ((LcdModes[ModeNumber].HorizontalResolution - 1) 
-               | ((LcdModes[ModeNumber].VerticalResolution - 1) << 16))
-              );
-  MmioWrite32 (DISPC_TIMING_H,
-               ( (LcdModes[ModeNumber].HSync - 1)
-               | ((LcdModes[ModeNumber].HFrontPorch - 1) << 8)
-               | ((LcdModes[ModeNumber].HBackPorch - 1) << 20))
-              );
-  MmioWrite32 (DISPC_TIMING_V,
-               ( (LcdModes[ModeNumber].VSync - 1)
-               | ((LcdModes[ModeNumber].VFrontPorch - 1) << 8)
-               | ((LcdModes[ModeNumber].VBackPorch - 1) << 20))
-              );
-
-  // Set the framebuffer to only load frames (no gamma tables)
-  MmioAnd32 (DISPC_CONFIG, CLEARLOADMODE);
-  MmioOr32  (DISPC_CONFIG, LOAD_FRAME_ONLY);
-
-  // Divisor for the pixel clock
-  MmioWrite32(DISPC_DIVISOR, ((1 << 16) | LcdModes[ModeNumber].DispcDivisor) );
-
-  // Set up the graphics layer
-  MmioWrite32 (DISPC_GFX_PRELD, 0x2D8);
-  MmioWrite32 (DISPC_GFX_BA0, VramBaseAddress);
-  MmioWrite32 (DISPC_GFX_SIZE,
-               ((LcdModes[ModeNumber].HorizontalResolution - 1) 
-               | ((LcdModes[ModeNumber].VerticalResolution - 1) << 16))
-              );
-
-  MmioWrite32(DISPC_GFX_ATTR, (GFXENABLE | RGB16 | BURSTSIZE16));
-
-  // Start it all
-  MmioOr32 (DISPC_CONTROL, (LCDENABLE | ACTIVEMATRIX | DATALINES24 | BYPASS_MODE | LCDENABLESIGNAL));
-  MmioOr32 (DISPC_CONTROL, GOLCD);
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-HwInitializeDisplay (
-  UINTN VramBaseAddress,
-  UINTN VramSize
-  )
-{
-  EFI_STATUS    Status;
-  UINT8         Data;
-  EFI_TPL       OldTpl;
-  EMBEDDED_EXTERNAL_DEVICE   *gTPS65950;
-
-  // Enable power lines used by TFP410
-  Status = gBS->LocateProtocol (&gEmbeddedExternalDeviceProtocolGuid, NULL, (VOID **)&gTPS65950);
-  ASSERT_EFI_ERROR (Status);  
-
-  OldTpl = gBS->RaiseTPL(TPL_NOTIFY);
-  Data = VAUX_DEV_GRP_P1;
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VPLL2_DEV_GRP), 1, &Data);
-  ASSERT_EFI_ERROR(Status);
-
-  Data = VAUX_DEDICATED_18V;
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VPLL2_DEDICATED), 1, &Data);
-  ASSERT_EFI_ERROR (Status);  
-
-  // Power up TFP410 (set GPIO2 on TPS - for BeagleBoard-xM)
-  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID2, GPIODATADIR1), 1, &Data);
-  ASSERT_EFI_ERROR (Status);
-  Data |= BIT2;
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID2, GPIODATADIR1), 1, &Data);
-  ASSERT_EFI_ERROR (Status);
-
-  Data = BIT2;
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID2, SETGPIODATAOUT1), 1, &Data);
-  ASSERT_EFI_ERROR (Status);
-
-  gBS->RestoreTPL(OldTpl);
-
-  // Power up TFP410 (set GPIO 170 - for older BeagleBoards)
-  MmioAnd32 (GPIO6_BASE + GPIO_OE, ~BIT10);
-  MmioOr32  (GPIO6_BASE + GPIO_SETDATAOUT, BIT10);  
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-InitializeDisplay (
-  IN LCD_INSTANCE* Instance
-  )
-{
-  EFI_STATUS           Status; 
-  UINTN                VramSize;
-  EFI_PHYSICAL_ADDRESS VramBaseAddress;
-
-  Status = LcdPlatformGetVram (&VramBaseAddress, &VramSize);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  Instance->Mode.FrameBufferBase = VramBaseAddress;
-  Instance->Mode.FrameBufferSize = VramSize;
-
-  Status = HwInitializeDisplay((UINTN)VramBaseAddress, VramSize);
-  if (!EFI_ERROR (Status)) {
-    mDisplayInitialized = TRUE;
-  }
-
-  return Status;
-}
-
-EFI_STATUS
-EFIAPI
-LcdGraphicsQueryMode (
-  IN EFI_GRAPHICS_OUTPUT_PROTOCOL            *This,
-       IN UINT32                                  ModeNumber,
-       OUT UINTN                                  *SizeOfInfo,
-       OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION   **Info
-       )
-{
-       LCD_INSTANCE  *Instance;
-
-       Instance = LCD_INSTANCE_FROM_GOP_THIS(This);
-
-  if (!mDisplayInitialized) {
-    InitializeDisplay (Instance);
-  }
-
-  // Error checking
-       if ( (This == NULL) || (Info == NULL) || (SizeOfInfo == NULL) || (ModeNumber >= This->Mode->MaxMode) ) {
-         DEBUG((DEBUG_ERROR, "LcdGraphicsQueryMode: ERROR - For mode number %d : Invalid Parameter.\n", ModeNumber ));
-               return EFI_INVALID_PARAMETER;
-       }
-
-  *Info = AllocateCopyPool(sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION), &Instance->ModeInfo);
-  if (*Info == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  *SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
-
-  (*Info)->Version = 0;
-  (*Info)->HorizontalResolution = LcdModes[ModeNumber].HorizontalResolution;
-  (*Info)->VerticalResolution = LcdModes[ModeNumber].VerticalResolution;
-  (*Info)->PixelFormat = PixelBltOnly;
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-LcdGraphicsSetMode (
-  IN EFI_GRAPHICS_OUTPUT_PROTOCOL   *This,
-       IN UINT32                         ModeNumber
-       )
-{
-       LCD_INSTANCE  *Instance;
-
-       Instance = LCD_INSTANCE_FROM_GOP_THIS(This);
-
-  if (ModeNumber >= Instance->Mode.MaxMode) {
-    return EFI_UNSUPPORTED;
-  }
-
-  if (!mDisplayInitialized) {
-    InitializeDisplay (Instance);
-  }
-
-  DssSetMode((UINT32)Instance->Mode.FrameBufferBase, ModeNumber);
-
-  Instance->Mode.Mode = ModeNumber;
-  Instance->ModeInfo.HorizontalResolution = LcdModes[ModeNumber].HorizontalResolution;
-  Instance->ModeInfo.VerticalResolution = LcdModes[ModeNumber].VerticalResolution;
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-LcdGraphicsOutputDxeInitialize (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
-  )
-{
-  EFI_STATUS Status = EFI_SUCCESS;
-  LCD_INSTANCE* Instance;
-
-  Status = LcdInstanceContructor (&Instance);
-  if (EFI_ERROR(Status)) {
-    goto EXIT;
-  }
-
-       // Install the Graphics Output Protocol and the Device Path
-       Status = gBS->InstallMultipleProtocolInterfaces(
-                       &Instance->Handle,
-                       &gEfiGraphicsOutputProtocolGuid, &Instance->Gop,
-                       &gEfiDevicePathProtocolGuid,     &Instance->DevicePath,
-                       NULL
-          );
-
-       if (EFI_ERROR(Status)) {
-         DEBUG((DEBUG_ERROR, "GraphicsOutputDxeInitialize: Can not install the protocol. Exit Status=%r\n", Status));
-               goto EXIT;
-       }
-
-  // Register for an ExitBootServicesEvent
-       // When ExitBootServices starts, this function here will make sure that the graphics driver will shut down properly,
-       // i.e. it will free up all allocated memory and perform any necessary hardware re-configuration.
-       /*Status = gBS->CreateEvent (
-           EVT_SIGNAL_EXIT_BOOT_SERVICES,
-           TPL_NOTIFY,
-           LcdGraphicsExitBootServicesEvent, NULL,
-                       &Instance->ExitBootServicesEvent
-                       );
-
-       if (EFI_ERROR(Status)) {
-         DEBUG((DEBUG_ERROR, "GraphicsOutputDxeInitialize: Can not install the ExitBootServicesEvent handler. Exit Status=%r\n", Status));
-               goto EXIT_ERROR_UNINSTALL_PROTOCOL;
-       }*/
-
-       // To get here, everything must be fine, so just exit
-       goto EXIT;
-
-//EXIT_ERROR_UNINSTALL_PROTOCOL:
-       /* The following function could return an error message,
-        * however, to get here something must have gone wrong already,
-        * so preserve the original error, i.e. don't change
-        * the Status variable, even it fails to uninstall the protocol.
-        */
-/*     gBS->UninstallMultipleProtocolInterfaces (
-           Instance->Handle,
-           &gEfiGraphicsOutputProtocolGuid, &Instance->Gop, // Uninstall Graphics Output protocol
-           &gEfiDevicePathProtocolGuid,     &Instance->DevicePath,     // Uninstall device path
-           NULL
-           );*/
-
-EXIT:
-       return Status;
-
-}
+/** @file\r
+\r
+ Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution.  The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "LcdGraphicsOutputDxe.h"\r
+\r
+BOOLEAN mDisplayInitialized = FALSE;\r
+\r
+LCD_MODE LcdModes[] = {\r
+  {\r
+    0, 640, 480,\r
+    9, 4,\r
+    96, 16, 48,\r
+    2, 10, 33\r
+  },\r
+  {\r
+    1, 800, 600,\r
+    11, 2,\r
+    120, 56, 64,\r
+    5, 37, 22\r
+  },\r
+  {\r
+    2, 1024, 768,\r
+    6, 2,\r
+    96, 16, 48,\r
+    2, 10, 33\r
+  },\r
+};\r
+\r
+LCD_INSTANCE mLcdTemplate = {\r
+  LCD_INSTANCE_SIGNATURE,\r
+  NULL, // Handle\r
+  { // ModeInfo\r
+    0, // Version\r
+    0, // HorizontalResolution\r
+    0, // VerticalResolution\r
+    PixelBltOnly, // PixelFormat\r
+    {\r
+      0xF800, //RedMask;\r
+      0x7E0, //GreenMask;\r
+      0x1F, //BlueMask;\r
+      0x0//ReservedMask\r
+    }, // PixelInformation\r
+    0, // PixelsPerScanLine\r
+  },\r
+  { // Mode\r
+    3, // MaxMode;\r
+    0, // Mode;\r
+    NULL, // Info;\r
+    0, // SizeOfInfo;\r
+    0, // FrameBufferBase;\r
+    0 // FrameBufferSize;\r
+  },\r
+  { // Gop\r
+    LcdGraphicsQueryMode,  // QueryMode\r
+    LcdGraphicsSetMode,    // SetMode\r
+    LcdGraphicsBlt,        // Blt\r
+    NULL                     // *Mode\r
+  },\r
+  { // DevicePath\r
+    {\r
+      {\r
+        HARDWARE_DEVICE_PATH, HW_VENDOR_DP,\r
+        (UINT8) (sizeof(VENDOR_DEVICE_PATH)),\r
+        (UINT8) ((sizeof(VENDOR_DEVICE_PATH)) >> 8),\r
+      },\r
+      // Hardware Device Path for Lcd\r
+      EFI_CALLER_ID_GUID // Use the driver's GUID\r
+    },\r
+\r
+    {\r
+      END_DEVICE_PATH_TYPE,\r
+      END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+      sizeof(EFI_DEVICE_PATH_PROTOCOL),\r
+      0\r
+    }\r
+  }\r
+};\r
+\r
+EFI_STATUS\r
+LcdInstanceContructor (\r
+  OUT LCD_INSTANCE** NewInstance\r
+  )\r
+{\r
+  LCD_INSTANCE* Instance;\r
+\r
+  Instance = AllocateCopyPool (sizeof(LCD_INSTANCE), &mLcdTemplate);\r
+  if (Instance == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Instance->Gop.Mode          = &Instance->Mode;\r
+  Instance->Mode.Info         = &Instance->ModeInfo;\r
+\r
+  *NewInstance = Instance;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+LcdPlatformGetVram (\r
+  OUT EFI_PHYSICAL_ADDRESS*  VramBaseAddress,\r
+  OUT UINTN*                 VramSize\r
+  )\r
+{\r
+  EFI_STATUS             Status;\r
+  EFI_CPU_ARCH_PROTOCOL  *Cpu;\r
+  UINTN                  MaxSize;\r
+\r
+  MaxSize = 0x500000;\r
+  *VramSize = MaxSize;\r
+\r
+  // Allocate VRAM from DRAM\r
+  Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesData, EFI_SIZE_TO_PAGES((MaxSize)), VramBaseAddress);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  // Ensure the Cpu architectural protocol is already installed\r
+  Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&Cpu);\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  // Mark the VRAM as un-cacheable. The VRAM is inside the DRAM, which is cacheable.\r
+  Status = Cpu->SetMemoryAttributes (Cpu, *VramBaseAddress, *VramSize, EFI_MEMORY_UC);\r
+  if (EFI_ERROR(Status)) {\r
+    gBS->FreePool (VramBaseAddress);\r
+    return Status;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+DssSetMode (\r
+  UINT32 VramBaseAddress,\r
+  UINTN  ModeNumber\r
+  )\r
+{\r
+  // Make sure the interface clock is running\r
+  MmioWrite32 (CM_ICLKEN_DSS, EN_DSS);  \r
+\r
+  // Stop the functional clocks\r
+  MmioAnd32 (CM_FCLKEN_DSS, ~(EN_DSS1 | EN_DSS2 | EN_TV));\r
+\r
+  // Program the DSS clock divisor\r
+  MmioWrite32 (CM_CLKSEL_DSS, 0x1000 | (LcdModes[ModeNumber].DssDivisor));\r
+  \r
+  // Start the functional clocks\r
+  MmioOr32 (CM_FCLKEN_DSS, (EN_DSS1 | EN_DSS2 | EN_TV));\r
+\r
+  // Wait for DSS to stabilize\r
+  gBS->Stall(1);\r
+\r
+  // Reset the subsystem\r
+  MmioWrite32(DSS_SYSCONFIG, DSS_SOFTRESET);\r
+  while (!(MmioRead32 (DSS_SYSSTATUS) & DSS_RESETDONE));\r
+  \r
+  // Configure LCD parameters\r
+  MmioWrite32 (DISPC_SIZE_LCD,\r
+               ((LcdModes[ModeNumber].HorizontalResolution - 1) \r
+               | ((LcdModes[ModeNumber].VerticalResolution - 1) << 16))\r
+              );\r
+  MmioWrite32 (DISPC_TIMING_H,\r
+               ( (LcdModes[ModeNumber].HSync - 1)\r
+               | ((LcdModes[ModeNumber].HFrontPorch - 1) << 8)\r
+               | ((LcdModes[ModeNumber].HBackPorch - 1) << 20))\r
+              );\r
+  MmioWrite32 (DISPC_TIMING_V,\r
+               ( (LcdModes[ModeNumber].VSync - 1)\r
+               | ((LcdModes[ModeNumber].VFrontPorch - 1) << 8)\r
+               | ((LcdModes[ModeNumber].VBackPorch - 1) << 20))\r
+              );\r
+\r
+  // Set the framebuffer to only load frames (no gamma tables)\r
+  MmioAnd32 (DISPC_CONFIG, CLEARLOADMODE);\r
+  MmioOr32  (DISPC_CONFIG, LOAD_FRAME_ONLY);\r
+\r
+  // Divisor for the pixel clock\r
+  MmioWrite32(DISPC_DIVISOR, ((1 << 16) | LcdModes[ModeNumber].DispcDivisor) );\r
+\r
+  // Set up the graphics layer\r
+  MmioWrite32 (DISPC_GFX_PRELD, 0x2D8);\r
+  MmioWrite32 (DISPC_GFX_BA0, VramBaseAddress);\r
+  MmioWrite32 (DISPC_GFX_SIZE,\r
+               ((LcdModes[ModeNumber].HorizontalResolution - 1) \r
+               | ((LcdModes[ModeNumber].VerticalResolution - 1) << 16))\r
+              );\r
+\r
+  MmioWrite32(DISPC_GFX_ATTR, (GFXENABLE | RGB16 | BURSTSIZE16));\r
+\r
+  // Start it all\r
+  MmioOr32 (DISPC_CONTROL, (LCDENABLE | ACTIVEMATRIX | DATALINES24 | BYPASS_MODE | LCDENABLESIGNAL));\r
+  MmioOr32 (DISPC_CONTROL, GOLCD);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+HwInitializeDisplay (\r
+  UINTN VramBaseAddress,\r
+  UINTN VramSize\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  UINT8         Data;\r
+  EFI_TPL       OldTpl;\r
+  EMBEDDED_EXTERNAL_DEVICE   *gTPS65950;\r
+\r
+  // Enable power lines used by TFP410\r
+  Status = gBS->LocateProtocol (&gEmbeddedExternalDeviceProtocolGuid, NULL, (VOID **)&gTPS65950);\r
+  ASSERT_EFI_ERROR (Status);  \r
+\r
+  OldTpl = gBS->RaiseTPL(TPL_NOTIFY);\r
+  Data = VAUX_DEV_GRP_P1;\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VPLL2_DEV_GRP), 1, &Data);\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  Data = VAUX_DEDICATED_18V;\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VPLL2_DEDICATED), 1, &Data);\r
+  ASSERT_EFI_ERROR (Status);  \r
+\r
+  // Power up TFP410 (set GPIO2 on TPS - for BeagleBoard-xM)\r
+  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID2, GPIODATADIR1), 1, &Data);\r
+  ASSERT_EFI_ERROR (Status);\r
+  Data |= BIT2;\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID2, GPIODATADIR1), 1, &Data);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Data = BIT2;\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID2, SETGPIODATAOUT1), 1, &Data);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  gBS->RestoreTPL(OldTpl);\r
+\r
+  // Power up TFP410 (set GPIO 170 - for older BeagleBoards)\r
+  MmioAnd32 (GPIO6_BASE + GPIO_OE, ~BIT10);\r
+  MmioOr32  (GPIO6_BASE + GPIO_SETDATAOUT, BIT10);  \r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+InitializeDisplay (\r
+  IN LCD_INSTANCE* Instance\r
+  )\r
+{\r
+  EFI_STATUS           Status; \r
+  UINTN                VramSize;\r
+  EFI_PHYSICAL_ADDRESS VramBaseAddress;\r
+\r
+  Status = LcdPlatformGetVram (&VramBaseAddress, &VramSize);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Instance->Mode.FrameBufferBase = VramBaseAddress;\r
+  Instance->Mode.FrameBufferSize = VramSize;\r
+\r
+  Status = HwInitializeDisplay((UINTN)VramBaseAddress, VramSize);\r
+  if (!EFI_ERROR (Status)) {\r
+    mDisplayInitialized = TRUE;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+LcdGraphicsQueryMode (\r
+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL            *This,\r
+       IN UINT32                                  ModeNumber,\r
+       OUT UINTN                                  *SizeOfInfo,\r
+       OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION   **Info\r
+       )\r
+{\r
+       LCD_INSTANCE  *Instance;\r
+\r
+       Instance = LCD_INSTANCE_FROM_GOP_THIS(This);\r
+\r
+  if (!mDisplayInitialized) {\r
+    InitializeDisplay (Instance);\r
+  }\r
+\r
+  // Error checking\r
+       if ( (This == NULL) || (Info == NULL) || (SizeOfInfo == NULL) || (ModeNumber >= This->Mode->MaxMode) ) {\r
+         DEBUG((DEBUG_ERROR, "LcdGraphicsQueryMode: ERROR - For mode number %d : Invalid Parameter.\n", ModeNumber ));\r
+               return EFI_INVALID_PARAMETER;\r
+       }\r
+\r
+  *Info = AllocateCopyPool(sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION), &Instance->ModeInfo);\r
+  if (*Info == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  *SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
+\r
+  (*Info)->Version = 0;\r
+  (*Info)->HorizontalResolution = LcdModes[ModeNumber].HorizontalResolution;\r
+  (*Info)->VerticalResolution = LcdModes[ModeNumber].VerticalResolution;\r
+  (*Info)->PixelFormat = PixelBltOnly;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+LcdGraphicsSetMode (\r
+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL   *This,\r
+       IN UINT32                         ModeNumber\r
+       )\r
+{\r
+       LCD_INSTANCE  *Instance;\r
+\r
+       Instance = LCD_INSTANCE_FROM_GOP_THIS(This);\r
+\r
+  if (ModeNumber >= Instance->Mode.MaxMode) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (!mDisplayInitialized) {\r
+    InitializeDisplay (Instance);\r
+  }\r
+\r
+  DssSetMode((UINT32)Instance->Mode.FrameBufferBase, ModeNumber);\r
+\r
+  Instance->Mode.Mode = ModeNumber;\r
+  Instance->ModeInfo.HorizontalResolution = LcdModes[ModeNumber].HorizontalResolution;\r
+  Instance->ModeInfo.VerticalResolution = LcdModes[ModeNumber].VerticalResolution;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+LcdGraphicsOutputDxeInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS Status = EFI_SUCCESS;\r
+  LCD_INSTANCE* Instance;\r
+\r
+  Status = LcdInstanceContructor (&Instance);\r
+  if (EFI_ERROR(Status)) {\r
+    goto EXIT;\r
+  }\r
+\r
+       // Install the Graphics Output Protocol and the Device Path\r
+       Status = gBS->InstallMultipleProtocolInterfaces(\r
+                       &Instance->Handle,\r
+                       &gEfiGraphicsOutputProtocolGuid, &Instance->Gop,\r
+                       &gEfiDevicePathProtocolGuid,     &Instance->DevicePath,\r
+                       NULL\r
+          );\r
+\r
+       if (EFI_ERROR(Status)) {\r
+         DEBUG((DEBUG_ERROR, "GraphicsOutputDxeInitialize: Can not install the protocol. Exit Status=%r\n", Status));\r
+               goto EXIT;\r
+       }\r
+\r
+  // Register for an ExitBootServicesEvent\r
+       // When ExitBootServices starts, this function here will make sure that the graphics driver will shut down properly,\r
+       // i.e. it will free up all allocated memory and perform any necessary hardware re-configuration.\r
+       /*Status = gBS->CreateEvent (\r
+           EVT_SIGNAL_EXIT_BOOT_SERVICES,\r
+           TPL_NOTIFY,\r
+           LcdGraphicsExitBootServicesEvent, NULL,\r
+                       &Instance->ExitBootServicesEvent\r
+                       );\r
+\r
+       if (EFI_ERROR(Status)) {\r
+         DEBUG((DEBUG_ERROR, "GraphicsOutputDxeInitialize: Can not install the ExitBootServicesEvent handler. Exit Status=%r\n", Status));\r
+               goto EXIT_ERROR_UNINSTALL_PROTOCOL;\r
+       }*/\r
+\r
+       // To get here, everything must be fine, so just exit\r
+       goto EXIT;\r
+\r
+//EXIT_ERROR_UNINSTALL_PROTOCOL:\r
+       /* The following function could return an error message,\r
+        * however, to get here something must have gone wrong already,\r
+        * so preserve the original error, i.e. don't change\r
+        * the Status variable, even it fails to uninstall the protocol.\r
+        */\r
+/*     gBS->UninstallMultipleProtocolInterfaces (\r
+           Instance->Handle,\r
+           &gEfiGraphicsOutputProtocolGuid, &Instance->Gop, // Uninstall Graphics Output protocol\r
+           &gEfiDevicePathProtocolGuid,     &Instance->DevicePath,     // Uninstall device path\r
+           NULL\r
+           );*/\r
+\r
+EXIT:\r
+       return Status;\r
+\r
+}\r
index 39e69478a1c2e201753da32f9718fb9d670f0f49..520e28e670e567be53793a9f14ffef0181617091 100644 (file)
-/** @file
-
- Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>
- 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.
-
-**/
-
-#ifndef __OMAP3_DSS_GRAPHICS__
-#define __OMAP3_DSS_GRAPHICS__
-
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiLib.h>
-#include <Library/DebugLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/IoLib.h>
-
-#include <Protocol/DevicePathToText.h>
-#include <Protocol/EmbeddedExternalDevice.h>
-#include <Protocol/Cpu.h>
-
-#include <Guid/GlobalVariable.h>
-
-#include <Omap3530/Omap3530.h>
-#include <TPS65950.h>
-
-typedef struct {
-  VENDOR_DEVICE_PATH            Guid;
-  EFI_DEVICE_PATH_PROTOCOL      End;
-} LCD_GRAPHICS_DEVICE_PATH;
-
-typedef struct {
-  UINTN                                 Signature;
-  EFI_HANDLE                            Handle;
-  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  ModeInfo;
-  EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE     Mode;
-  EFI_GRAPHICS_OUTPUT_PROTOCOL          Gop;
-  LCD_GRAPHICS_DEVICE_PATH              DevicePath;
-//  EFI_EVENT                             ExitBootServicesEvent;
-} LCD_INSTANCE;
-
-#define LCD_INSTANCE_SIGNATURE  SIGNATURE_32('l', 'c', 'd', '0')
-#define LCD_INSTANCE_FROM_GOP_THIS(a)     CR (a, LCD_INSTANCE, Gop, LCD_INSTANCE_SIGNATURE)
-
-typedef struct {
-  UINTN             Mode;
-  UINTN             HorizontalResolution;
-  UINTN             VerticalResolution;
-
-  UINT32            DssDivisor;
-  UINT32            DispcDivisor;
-
-  UINT32            HSync;
-  UINT32            HFrontPorch;
-  UINT32            HBackPorch;
-
-  UINT32            VSync;
-  UINT32            VFrontPorch;
-  UINT32            VBackPorch;
-} LCD_MODE;
-
-EFI_STATUS
-InitializeDisplay (
-  IN LCD_INSTANCE* Instance
-);
-
-EFI_STATUS
-EFIAPI
-LcdGraphicsQueryMode (
-  IN  EFI_GRAPHICS_OUTPUT_PROTOCOL          *This,
-  IN  UINT32                                ModeNumber,
-  OUT UINTN                                 *SizeOfInfo,
-  OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  **Info
-);
-
-EFI_STATUS
-EFIAPI
-LcdGraphicsSetMode (
-  IN EFI_GRAPHICS_OUTPUT_PROTOCOL  *This,
-  IN UINT32                        ModeNumber
-);
-
-EFI_STATUS
-EFIAPI
-LcdGraphicsBlt (
-  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,
-       IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL
-       IN EFI_GRAPHICS_OUTPUT_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   // Number of BYTES in a row of the BltBuffer
-);
-
-// HW registers
-#define CM_FCLKEN_DSS   0x48004E00
-#define CM_ICLKEN_DSS   0x48004E10
-
-#define DSS_CONTROL     0x48050040
-#define DSS_SYSCONFIG   0x48050010
-#define DSS_SYSSTATUS   0x48050014
-
-#define DISPC_CONTROL   0x48050440
-#define DISPC_CONFIG    0x48050444
-#define DISPC_SIZE_LCD  0x4805047C
-#define DISPC_TIMING_H  0x48050464
-#define DISPC_TIMING_V  0x48050468
-
-#define CM_CLKSEL_DSS   0x48004E40
-#define DISPC_DIVISOR   0x48050470
-#define DISPC_POL_FREQ  0x4805046C
-
-#define DISPC_GFX_TABLE_BA 0x480504B8
-#define DISPC_GFX_BA0   0x48050480
-#define DISPC_GFX_BA1   0x48050484
-#define DISPC_GFX_POS   0x48050488
-#define DISPC_GFX_SIZE  0x4805048C
-#define DISPC_GFX_ATTR  0x480504A0
-#define DISPC_GFX_PRELD 0x4805062C
-
-#define DISPC_DEFAULT_COLOR_0 0x4805044C
-
-//#define DISPC_IRQSTATUS
-
-// Bits
-#define EN_TV           0x4
-#define EN_DSS2         0x2
-#define EN_DSS1         0x1
-#define EN_DSS          0x1
-
-#define DSS_SOFTRESET   0x2
-#define DSS_RESETDONE   0x1
-
-#define BYPASS_MODE     (BIT15 | BIT16)
-
-#define LCDENABLE       BIT0
-#define ACTIVEMATRIX    BIT3
-#define GOLCD           BIT5
-#define DATALINES24     (BIT8 | BIT9)   
-#define LCDENABLESIGNAL BIT28
-
-#define GFXENABLE       BIT0
-#define RGB16           (0x6 << 1)
-#define BURSTSIZE16     (0x2 << 6)
-
-#define CLEARLOADMODE   ~(BIT2 | BIT1)
-#define LOAD_FRAME_ONLY BIT2
-
-#endif
+/** @file\r
+\r
+ Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution.  The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __OMAP3_DSS_GRAPHICS__\r
+#define __OMAP3_DSS_GRAPHICS__\r
+\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/IoLib.h>\r
+\r
+#include <Protocol/DevicePathToText.h>\r
+#include <Protocol/EmbeddedExternalDevice.h>\r
+#include <Protocol/Cpu.h>\r
+\r
+#include <Guid/GlobalVariable.h>\r
+\r
+#include <Omap3530/Omap3530.h>\r
+#include <TPS65950.h>\r
+\r
+typedef struct {\r
+  VENDOR_DEVICE_PATH            Guid;\r
+  EFI_DEVICE_PATH_PROTOCOL      End;\r
+} LCD_GRAPHICS_DEVICE_PATH;\r
+\r
+typedef struct {\r
+  UINTN                                 Signature;\r
+  EFI_HANDLE                            Handle;\r
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  ModeInfo;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE     Mode;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL          Gop;\r
+  LCD_GRAPHICS_DEVICE_PATH              DevicePath;\r
+//  EFI_EVENT                             ExitBootServicesEvent;\r
+} LCD_INSTANCE;\r
+\r
+#define LCD_INSTANCE_SIGNATURE  SIGNATURE_32('l', 'c', 'd', '0')\r
+#define LCD_INSTANCE_FROM_GOP_THIS(a)     CR (a, LCD_INSTANCE, Gop, LCD_INSTANCE_SIGNATURE)\r
+\r
+typedef struct {\r
+  UINTN             Mode;\r
+  UINTN             HorizontalResolution;\r
+  UINTN             VerticalResolution;\r
+\r
+  UINT32            DssDivisor;\r
+  UINT32            DispcDivisor;\r
+\r
+  UINT32            HSync;\r
+  UINT32            HFrontPorch;\r
+  UINT32            HBackPorch;\r
+\r
+  UINT32            VSync;\r
+  UINT32            VFrontPorch;\r
+  UINT32            VBackPorch;\r
+} LCD_MODE;\r
+\r
+EFI_STATUS\r
+InitializeDisplay (\r
+  IN LCD_INSTANCE* Instance\r
+);\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+LcdGraphicsQueryMode (\r
+  IN  EFI_GRAPHICS_OUTPUT_PROTOCOL          *This,\r
+  IN  UINT32                                ModeNumber,\r
+  OUT UINTN                                 *SizeOfInfo,\r
+  OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  **Info\r
+);\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+LcdGraphicsSetMode (\r
+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL  *This,\r
+  IN UINT32                        ModeNumber\r
+);\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+LcdGraphicsBlt (\r
+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,\r
+       IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL\r
+       IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION   BltOperation,\r
+       IN UINTN                               SourceX,\r
+       IN UINTN                               SourceY,\r
+       IN UINTN                               DestinationX,\r
+       IN UINTN                               DestinationY,\r
+       IN UINTN                               Width,\r
+       IN UINTN                               Height,\r
+       IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer\r
+);\r
+\r
+// HW registers\r
+#define CM_FCLKEN_DSS   0x48004E00\r
+#define CM_ICLKEN_DSS   0x48004E10\r
+\r
+#define DSS_CONTROL     0x48050040\r
+#define DSS_SYSCONFIG   0x48050010\r
+#define DSS_SYSSTATUS   0x48050014\r
+\r
+#define DISPC_CONTROL   0x48050440\r
+#define DISPC_CONFIG    0x48050444\r
+#define DISPC_SIZE_LCD  0x4805047C\r
+#define DISPC_TIMING_H  0x48050464\r
+#define DISPC_TIMING_V  0x48050468\r
+\r
+#define CM_CLKSEL_DSS   0x48004E40\r
+#define DISPC_DIVISOR   0x48050470\r
+#define DISPC_POL_FREQ  0x4805046C\r
+\r
+#define DISPC_GFX_TABLE_BA 0x480504B8\r
+#define DISPC_GFX_BA0   0x48050480\r
+#define DISPC_GFX_BA1   0x48050484\r
+#define DISPC_GFX_POS   0x48050488\r
+#define DISPC_GFX_SIZE  0x4805048C\r
+#define DISPC_GFX_ATTR  0x480504A0\r
+#define DISPC_GFX_PRELD 0x4805062C\r
+\r
+#define DISPC_DEFAULT_COLOR_0 0x4805044C\r
+\r
+//#define DISPC_IRQSTATUS\r
+\r
+// Bits\r
+#define EN_TV           0x4\r
+#define EN_DSS2         0x2\r
+#define EN_DSS1         0x1\r
+#define EN_DSS          0x1\r
+\r
+#define DSS_SOFTRESET   0x2\r
+#define DSS_RESETDONE   0x1\r
+\r
+#define BYPASS_MODE     (BIT15 | BIT16)\r
+\r
+#define LCDENABLE       BIT0\r
+#define ACTIVEMATRIX    BIT3\r
+#define GOLCD           BIT5\r
+#define DATALINES24     (BIT8 | BIT9)   \r
+#define LCDENABLESIGNAL BIT28\r
+\r
+#define GFXENABLE       BIT0\r
+#define RGB16           (0x6 << 1)\r
+#define BURSTSIZE16     (0x2 << 6)\r
+\r
+#define CLEARLOADMODE   ~(BIT2 | BIT1)\r
+#define LOAD_FRAME_ONLY BIT2\r
+\r
+#endif\r
index f595bb39edbc03c926e417804c9e304226ce9983..ac026f435634172167ff02ad44e3e63307d49a8b 100644 (file)
@@ -1,52 +1,52 @@
-#/** @file
-#  
-#  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>
-#  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                      = LcdGraphicsDxe
-  FILE_GUID                      = E68088EF-D1A4-4336-C1DB-4D3A204730A6
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-  ENTRY_POINT                    = LcdGraphicsOutputDxeInitialize
-
-[Sources.common]
-  LcdGraphicsOutputDxe.c
-  LcdGraphicsOutputBlt.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-  ArmPkg/ArmPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-  Omap35xxPkg/Omap35xxPkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-
-[LibraryClasses]
-  ArmLib
-  UefiLib
-  BaseLib
-  DebugLib
-  TimerLib
-  UefiDriverEntryPoint
-  UefiBootServicesTableLib
-  IoLib
-  BaseMemoryLib
-
-[Protocols]
-  gEfiDevicePathProtocolGuid
-  gEfiGraphicsOutputProtocolGuid
-  gEfiDevicePathToTextProtocolGuid
-  gEmbeddedExternalDeviceProtocolGuid
-
-[Depex]
-  gEfiCpuArchProtocolGuid AND gEfiTimerArchProtocolGuid
+#/** @file\r
+#  \r
+#  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = LcdGraphicsDxe\r
+  FILE_GUID                      = E68088EF-D1A4-4336-C1DB-4D3A204730A6\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = LcdGraphicsOutputDxeInitialize\r
+\r
+[Sources.common]\r
+  LcdGraphicsOutputDxe.c\r
+  LcdGraphicsOutputBlt.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+  Omap35xxPkg/Omap35xxPkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+\r
+[LibraryClasses]\r
+  ArmLib\r
+  UefiLib\r
+  BaseLib\r
+  DebugLib\r
+  TimerLib\r
+  UefiDriverEntryPoint\r
+  UefiBootServicesTableLib\r
+  IoLib\r
+  BaseMemoryLib\r
+\r
+[Protocols]\r
+  gEfiDevicePathProtocolGuid\r
+  gEfiGraphicsOutputProtocolGuid\r
+  gEfiDevicePathToTextProtocolGuid\r
+  gEmbeddedExternalDeviceProtocolGuid\r
+\r
+[Depex]\r
+  gEfiCpuArchProtocolGuid AND gEfiTimerArchProtocolGuid\r
index 76c13d5527285bbfa961390ee8d68d5d4b8b9359..b3da7366a921e38466d5c358ff081405485990c1 100755 (executable)
 \r
 **/\r
 #include <Base.h>\r
 \r
 **/\r
 #include <Base.h>\r
-#include <Library/BaseLib.h>
-#include <Library/IoLib.h>
-#include <Library/OmapLib.h>
+#include <Library/BaseLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/OmapLib.h>\r
 #include <Library/ArmLib.h>\r
 #include <Library/ArmLib.h>\r
-#include <Library/PcdLib.h>
+#include <Library/PcdLib.h>\r
 \r
 \r
-#include <Omap3530/Omap3530.h>
+#include <Omap3530/Omap3530.h>\r
 \r
 \r
 volatile UINT32 gVector;\r
 \r
 \r
 volatile UINT32 gVector;\r
-
-// Cached registers
-volatile UINT32 gTISR;
-volatile UINT32 gTCLR;
-volatile UINT32 gTLDR;
-volatile UINT32 gTCRR;
-volatile UINT32 gTIER;
+\r
+// Cached registers\r
+volatile UINT32 gTISR;\r
+volatile UINT32 gTCLR;\r
+volatile UINT32 gTLDR;\r
+volatile UINT32 gTCRR;\r
+volatile UINT32 gTIER;\r
 \r
 VOID\r
 EnableInterruptSource (\r
 \r
 VOID\r
 EnableInterruptSource (\r
@@ -80,15 +80,15 @@ DebugAgentTimerIntialize (
   UINT32      TimerNumber;\r
 \r
   TimerNumber = PcdGet32(PcdOmap35xxDebugAgentTimer);\r
   UINT32      TimerNumber;\r
 \r
   TimerNumber = PcdGet32(PcdOmap35xxDebugAgentTimer);\r
-  gVector = InterruptVectorForTimer (TimerNumber);
+  gVector = InterruptVectorForTimer (TimerNumber);\r
 \r
 \r
-  // Set up the timer registers
-  TimerBaseAddress = TimerBase (TimerNumber);
-  gTISR = TimerBaseAddress + GPTIMER_TISR;
-  gTCLR = TimerBaseAddress + GPTIMER_TCLR;
-  gTLDR = TimerBaseAddress + GPTIMER_TLDR;
-  gTCRR = TimerBaseAddress + GPTIMER_TCRR;
-  gTIER = TimerBaseAddress + GPTIMER_TIER;
+  // Set up the timer registers\r
+  TimerBaseAddress = TimerBase (TimerNumber);\r
+  gTISR = TimerBaseAddress + GPTIMER_TISR;\r
+  gTCLR = TimerBaseAddress + GPTIMER_TCLR;\r
+  gTLDR = TimerBaseAddress + GPTIMER_TLDR;\r
+  gTCRR = TimerBaseAddress + GPTIMER_TCRR;\r
+  gTIER = TimerBaseAddress + GPTIMER_TIER;\r
 \r
   if ((TimerNumber < 2) || (TimerNumber > 9)) {\r
     // This code assumes one the General Purpose timers is used\r
 \r
   if ((TimerNumber < 2) || (TimerNumber > 9)) {\r
     // This code assumes one the General Purpose timers is used\r
@@ -113,31 +113,31 @@ DebugAgentTimerSetPeriod (
   IN  UINT32  TimerPeriodMilliseconds\r
   )\r
 {\r
   IN  UINT32  TimerPeriodMilliseconds\r
   )\r
 {\r
-  UINT64      TimerCount;
-  INT32       LoadValue;
-  
-  if (TimerPeriodMilliseconds == 0) {
-    // Turn off GPTIMER3
-    MmioWrite32 (gTCLR, TCLR_ST_OFF);
-    
-    DisableInterruptSource ();
-  } else {  
-    // Calculate required timer count
-    TimerCount = DivU64x32(TimerPeriodMilliseconds * 1000000, PcdGet32(PcdDebugAgentTimerFreqNanoSeconds));
-
-    // Set GPTIMER5 Load register
-    LoadValue = (INT32) -TimerCount;
-    MmioWrite32 (gTLDR, LoadValue);
-    MmioWrite32 (gTCRR, LoadValue);
-
-    // Enable Overflow interrupt
-    MmioWrite32 (gTIER, TIER_TCAR_IT_DISABLE | TIER_OVF_IT_ENABLE | TIER_MAT_IT_DISABLE);
-
-    // Turn on GPTIMER3, it will reload at overflow
-    MmioWrite32 (gTCLR, TCLR_AR_AUTORELOAD | TCLR_ST_ON);
-
-    EnableInterruptSource ();
-  }
+  UINT64      TimerCount;\r
+  INT32       LoadValue;\r
+  \r
+  if (TimerPeriodMilliseconds == 0) {\r
+    // Turn off GPTIMER3\r
+    MmioWrite32 (gTCLR, TCLR_ST_OFF);\r
+    \r
+    DisableInterruptSource ();\r
+  } else {  \r
+    // Calculate required timer count\r
+    TimerCount = DivU64x32(TimerPeriodMilliseconds * 1000000, PcdGet32(PcdDebugAgentTimerFreqNanoSeconds));\r
+\r
+    // Set GPTIMER5 Load register\r
+    LoadValue = (INT32) -TimerCount;\r
+    MmioWrite32 (gTLDR, LoadValue);\r
+    MmioWrite32 (gTCRR, LoadValue);\r
+\r
+    // Enable Overflow interrupt\r
+    MmioWrite32 (gTIER, TIER_TCAR_IT_DISABLE | TIER_OVF_IT_ENABLE | TIER_MAT_IT_DISABLE);\r
+\r
+    // Turn on GPTIMER3, it will reload at overflow\r
+    MmioWrite32 (gTCLR, TCLR_AR_AUTORELOAD | TCLR_ST_ON);\r
+\r
+    EnableInterruptSource ();\r
+  }\r
 }\r
   \r
 \r
 }\r
   \r
 \r
@@ -152,10 +152,10 @@ DebugAgentTimerEndOfInterrupt (
   VOID\r
   )\r
 {\r
   VOID\r
   )\r
 {\r
-   // Clear all timer interrupts
-  MmioWrite32 (gTISR, TISR_CLEAR_ALL);  
-
-  // Poll interrupt status bits to ensure clearing
+   // Clear all timer interrupts\r
+  MmioWrite32 (gTISR, TISR_CLEAR_ALL);  \r
+\r
+  // Poll interrupt status bits to ensure clearing\r
   while ((MmioRead32 (gTISR) & TISR_ALL_INTERRUPT_MASK) != TISR_NO_INTERRUPTS_PENDING);\r
 \r
   MmioWrite32 (INTCPS_CONTROL, INTCPS_CONTROL_NEWFIQAGR);\r
   while ((MmioRead32 (gTISR) & TISR_ALL_INTERRUPT_MASK) != TISR_NO_INTERRUPTS_PENDING);\r
 \r
   MmioWrite32 (INTCPS_CONTROL, INTCPS_CONTROL_NEWFIQAGR);\r
@@ -163,4 +163,4 @@ DebugAgentTimerEndOfInterrupt (
 \r
 }\r
 \r
 \r
 }\r
 \r
-  
\ No newline at end of file
+  \r
\ No newline at end of file
index e1685b58abef828924c31956e3ebbbcd38ce48f8..551aee5385dd7cb2c9fd7b507b4202c910998853 100755 (executable)
@@ -31,9 +31,9 @@
 [Packages]\r
   MdePkg/MdePkg.dec\r
   EmbeddedPkg/EmbeddedPkg.dec\r
 [Packages]\r
   MdePkg/MdePkg.dec\r
   EmbeddedPkg/EmbeddedPkg.dec\r
-  Omap35xxPkg/Omap35xxPkg.dec
-  ArmPkg/ArmPkg.dec
-  
+  Omap35xxPkg/Omap35xxPkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  \r
 \r
 [LibraryClasses]\r
   BaseLib\r
 \r
 [LibraryClasses]\r
   BaseLib\r
@@ -44,4 +44,4 @@
 [Pcd]\r
   gOmap35xxTokenSpaceGuid.PcdOmap35xxDebugAgentTimer\r
   gOmap35xxTokenSpaceGuid.PcdDebugAgentTimerFreqNanoSeconds\r
 [Pcd]\r
   gOmap35xxTokenSpaceGuid.PcdOmap35xxDebugAgentTimer\r
   gOmap35xxTokenSpaceGuid.PcdDebugAgentTimerFreqNanoSeconds\r
-  
\ No newline at end of file
+  \r
\ No newline at end of file
index b306355d5fafaea4d24db872b614a42c50232b71..54247e42e6fee48bf41512ab523589b1180c85f3 100644 (file)
-/** @file
-  Basic serial IO abstaction for GDB
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <Uefi.h>
-#include <Library/GdbSerialLib.h>
-#include <Library/PcdLib.h>
-#include <Library/IoLib.h>
-#include <Library/DebugLib.h>
-#include <Library/OmapLib.h>
-#include <Omap3530/Omap3530.h>
-
-RETURN_STATUS
-EFIAPI
-GdbSerialLibConstructor (
-  VOID
-  )
-{
-  return RETURN_SUCCESS;
-}
-
-RETURN_STATUS
-EFIAPI
-GdbSerialInit (
-  IN UINT64     BaudRate, 
-  IN UINT8      Parity, 
-  IN UINT8      DataBits, 
-  IN UINT8      StopBits 
-  )
-{
-  return RETURN_SUCCESS;
-}
-
-BOOLEAN
-EFIAPI
-GdbIsCharAvailable (
-  VOID
-  )  
-{
-  UINT32 LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;
-
-  if ((MmioRead8(LSR) & UART_LSR_RX_FIFO_E_MASK) == UART_LSR_RX_FIFO_E_NOT_EMPTY) {
-    return TRUE;
-  } else {
-    return FALSE;
-  }
-}
-
-CHAR8
-EFIAPI
-GdbGetChar (
-  VOID
-  )
-{
-  UINT32  LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;
-  UINT32  RBR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_RBR_REG;
-  CHAR8   Char;
-    
-  while ((MmioRead8(LSR) & UART_LSR_RX_FIFO_E_MASK) == UART_LSR_RX_FIFO_E_EMPTY);
-  Char = MmioRead8(RBR);
-
-  return Char;
-}
-
-VOID
-EFIAPI
-GdbPutChar (
-  IN  CHAR8   Char
-  )
-{
-  UINT32  LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;
-  UINT32  THR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_THR_REG;
-    
-  while ((MmioRead8(LSR) & UART_LSR_TX_FIFO_E_MASK) == UART_LSR_TX_FIFO_E_NOT_EMPTY);
-  MmioWrite8(THR, Char);
-}
-
-VOID
-GdbPutString (
-  IN CHAR8  *String
-  )
-{
-  while (*String != '\0') {
-    GdbPutChar (*String);
-    String++;
-  }
-}
-
-
-
-
+/** @file\r
+  Basic serial IO abstaction for GDB\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+#include <Library/GdbSerialLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/OmapLib.h>\r
+#include <Omap3530/Omap3530.h>\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+GdbSerialLibConstructor (\r
+  VOID\r
+  )\r
+{\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+GdbSerialInit (\r
+  IN UINT64     BaudRate, \r
+  IN UINT8      Parity, \r
+  IN UINT8      DataBits, \r
+  IN UINT8      StopBits \r
+  )\r
+{\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+BOOLEAN\r
+EFIAPI\r
+GdbIsCharAvailable (\r
+  VOID\r
+  )  \r
+{\r
+  UINT32 LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;\r
+\r
+  if ((MmioRead8(LSR) & UART_LSR_RX_FIFO_E_MASK) == UART_LSR_RX_FIFO_E_NOT_EMPTY) {\r
+    return TRUE;\r
+  } else {\r
+    return FALSE;\r
+  }\r
+}\r
+\r
+CHAR8\r
+EFIAPI\r
+GdbGetChar (\r
+  VOID\r
+  )\r
+{\r
+  UINT32  LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;\r
+  UINT32  RBR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_RBR_REG;\r
+  CHAR8   Char;\r
+    \r
+  while ((MmioRead8(LSR) & UART_LSR_RX_FIFO_E_MASK) == UART_LSR_RX_FIFO_E_EMPTY);\r
+  Char = MmioRead8(RBR);\r
+\r
+  return Char;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+GdbPutChar (\r
+  IN  CHAR8   Char\r
+  )\r
+{\r
+  UINT32  LSR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_LSR_REG;\r
+  UINT32  THR = UartBase(PcdGet32(PcdOmap35xxConsoleUart)) + UART_THR_REG;\r
+    \r
+  while ((MmioRead8(LSR) & UART_LSR_TX_FIFO_E_MASK) == UART_LSR_TX_FIFO_E_NOT_EMPTY);\r
+  MmioWrite8(THR, Char);\r
+}\r
+\r
+VOID\r
+GdbPutString (\r
+  IN CHAR8  *String\r
+  )\r
+{\r
+  while (*String != '\0') {\r
+    GdbPutChar (*String);\r
+    String++;\r
+  }\r
+}\r
+\r
+\r
+\r
+\r
index 7e949c2f9db62c1fa39d25194f65a6a821943027..3ab26bb90d952251b439e3dc68dc9d94cd03c1b2 100644 (file)
@@ -1,41 +1,41 @@
-#/** @file
-#  
-#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-#  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                      = GdbSerialLib
-  FILE_GUID                      = E2423349-EF5D-439B-95F5-8B8D8E3B443F
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = GdbSerialLib
-
-  CONSTRUCTOR                    = GdbSerialLibConstructor
-
-
-[Sources.common]
-  GdbSerialLib.c
-
-
-[Packages]
-  MdePkg/MdePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  Omap35xxPkg/Omap35xxPkg.dec
-
-[LibraryClasses]
-  DebugLib
-  IoLib
-  OmapLib    
-
-[FixedPcd]
-  gOmap35xxTokenSpaceGuid.PcdOmap35xxConsoleUart
-
+#/** @file\r
+#  \r
+#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = GdbSerialLib\r
+  FILE_GUID                      = E2423349-EF5D-439B-95F5-8B8D8E3B443F\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = GdbSerialLib\r
+\r
+  CONSTRUCTOR                    = GdbSerialLibConstructor\r
+\r
+\r
+[Sources.common]\r
+  GdbSerialLib.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  Omap35xxPkg/Omap35xxPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  IoLib\r
+  OmapLib    \r
+\r
+[FixedPcd]\r
+  gOmap35xxTokenSpaceGuid.PcdOmap35xxConsoleUart\r
+\r
index 4356853bbce97f33c15ea70190b39ac6ddc95647..d94ddf98678697f742b7abb0ca1c8fd5e28134a0 100755 (executable)
@@ -47,4 +47,4 @@
 [Pcd]\r
 \r
 [Depex]\r
 [Pcd]\r
 \r
 [Depex]\r
-  gEfiCpuArchProtocolGuid
\ No newline at end of file
+  gEfiCpuArchProtocolGuid\r
\ No newline at end of file
index e1d5c9ca1c4080273086feb229128cb9a5def2c7..0b9c70bc575bb3475cfe0655aca84e8ff878e938 100755 (executable)
-/** @file
-*
-*  Copyright (c) 2011, ARM Limited. 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 <Uefi.h>
-
-#include <Library/BaseMemoryLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/DebugLib.h>
-#include <Library/IoLib.h>
-
-#include <Protocol/RealTimeClock.h>
-#include <Protocol/EmbeddedExternalDevice.h>
-
-#include <Omap3530/Omap3530.h>
-#include <TPS65950.h>
-
-
-EMBEDDED_EXTERNAL_DEVICE   *gTPS65950;
-INT16                      TimeZone = EFI_UNSPECIFIED_TIMEZONE;
-
-/**
-  Returns the current time and date information, and the time-keeping capabilities
-  of the hardware platform.
-
-  @param  Time                  A pointer to storage to receive a snapshot of the current time.
-  @param  Capabilities          An optional pointer to a buffer to receive the real time clock
-                                device's capabilities.
-
-  @retval EFI_SUCCESS           The operation completed successfully.
-  @retval EFI_INVALID_PARAMETER Time is NULL.
-  @retval EFI_DEVICE_ERROR      The time could not be retrieved due to hardware error.
-
-**/
-EFI_STATUS
-EFIAPI
-LibGetTime (
-  OUT EFI_TIME                *Time,
-  OUT EFI_TIME_CAPABILITIES   *Capabilities
-  )
-{
-  EFI_STATUS            Status;
-  UINT8                 Data;
-  EFI_TPL               OldTpl;
-
-  if (Time == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  OldTpl = gBS->RaiseTPL(TPL_NOTIFY);
-
-  /* Get time and date */
-  ZeroMem(Time, sizeof(EFI_TIME));
-
-  // Latch values
-  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, RTC_CTRL_REG), 1, &Data);
-  if (Status != EFI_SUCCESS) goto EXIT;
-  Data |= BIT6;
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, RTC_CTRL_REG), 1, &Data);
-  if (Status != EFI_SUCCESS) goto EXIT;
-
-  // Read registers
-  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, YEARS_REG), 1, &Data);
-  if (Status != EFI_SUCCESS) goto EXIT;
-  Time->Year = 2000 + ((Data >> 4) & 0xF) * 10 + (Data & 0xF);
-
-  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, MONTHS_REG), 1, &Data);
-  if (Status != EFI_SUCCESS) goto EXIT;
-  Time->Month = ((Data >> 4) & 0x1) * 10 + (Data & 0xF);
-
-  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, DAYS_REG), 1, &Data);
-  if (Status != EFI_SUCCESS) goto EXIT;
-  Time->Day = ((Data >> 4) & 0x3) * 10 + (Data & 0xF);
-
-  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, HOURS_REG), 1, &Data);
-  if (Status != EFI_SUCCESS) goto EXIT;
-  Time->Hour = ((Data >> 4) & 0x3) * 10 + (Data & 0xF);
-
-  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, MINUTES_REG), 1, &Data);
-  if (Status != EFI_SUCCESS) goto EXIT;
-  Time->Minute = ((Data >> 4) & 0x7) * 10 + (Data & 0xF);
-
-  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, SECONDS_REG), 1, &Data);
-  if (Status != EFI_SUCCESS) goto EXIT;
-  Time->Second = ((Data >> 4) & 0x7) * 10 + (Data & 0xF);
-
-  Time->TimeZone = TimeZone;
-  // TODO: check what to use here
-  Time->Daylight = EFI_TIME_ADJUST_DAYLIGHT;
-
-  // Set capabilities
-
-  // TODO: Set real capabilities
-  if (Capabilities != NULL) {
-    Capabilities->Resolution = 1;
-    Capabilities->Accuracy = 50000000;
-    Capabilities->SetsToZero = FALSE;
-  }
-
-EXIT:
-  gBS->RestoreTPL(OldTpl);
-
-  return (Status == EFI_SUCCESS) ? Status : EFI_DEVICE_ERROR;
-}
-
-/**
-  Sets the current local time and date information.
-
-  @param  Time                  A pointer to the current time.
-
-  @retval EFI_SUCCESS           The operation completed successfully.
-  @retval EFI_INVALID_PARAMETER A time field is out of range.
-  @retval EFI_DEVICE_ERROR      The time could not be set due due to hardware error.
-
-**/
-EFI_STATUS
-EFIAPI
-LibSetTime (
-  IN EFI_TIME                *Time
-  )
-{
-  EFI_STATUS Status;
-  UINT8      Data;
-  UINT8      MonthDayCount[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
-  EFI_TPL    OldTpl;
-
-  // Input validation according both to UEFI spec and hardware constraints
-  // UEFI spec says valid year range is 1900-9999 but TPS only supports 2000-2099
-  if ( (Time == NULL)
-    || (Time->Year < 2000 || Time->Year > 2099)
-    || (Time->Month < 1 || Time->Month > 12)
-    || (Time->Day < 1 || Time->Day > MonthDayCount[Time->Month])
-    || (Time->Hour > 23)
-    || (Time->Minute > 59)
-    || (Time->Second > 59)
-    || (Time->Nanosecond > 999999999)
-    || ((Time->TimeZone < -1440 || Time->TimeZone > 1440) && Time->TimeZone != 2047)
-  ) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  OldTpl = gBS->RaiseTPL(TPL_NOTIFY);
-
-  Data = Time->Year - 2000;
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, YEARS_REG), 1, &Data);
-  if (Status != EFI_SUCCESS) goto EXIT;
-
-  Data = ((Time->Month / 10) << 4) | (Time->Month % 10);
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, MONTHS_REG), 1, &Data);
-  if (Status != EFI_SUCCESS) goto EXIT;
-
-  Data = ((Time->Day / 10) << 4) | (Time->Day % 10);
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, DAYS_REG), 1, &Data);
-  if (Status != EFI_SUCCESS) goto EXIT;
-
-  Data = ((Time->Hour / 10) << 4) | (Time->Hour % 10);
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, HOURS_REG), 1, &Data);
-  if (Status != EFI_SUCCESS) goto EXIT;
-
-  Data = ((Time->Minute / 10) << 4) | (Time->Minute % 10);
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, MINUTES_REG), 1, &Data);
-  if (Status != EFI_SUCCESS) goto EXIT;
-
-  Data = ((Time->Second / 10) << 4) | (Time->Second % 10);
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, SECONDS_REG), 1, &Data);
-  if (Status != EFI_SUCCESS) goto EXIT;
-
-  TimeZone = Time->TimeZone;
-
-EXIT:
-  gBS->RestoreTPL(OldTpl);
-
-  return (Status == EFI_SUCCESS) ? Status : EFI_DEVICE_ERROR;
-}
-
-/**
-  Returns the current wakeup alarm clock setting.
-
-  @param  Enabled               Indicates if the alarm is currently enabled or disabled.
-  @param  Pending               Indicates if the alarm signal is pending and requires acknowledgement.
-  @param  Time                  The current alarm setting.
-
-  @retval EFI_SUCCESS           The alarm settings were returned.
-  @retval EFI_INVALID_PARAMETER Any parameter is NULL.
-  @retval EFI_DEVICE_ERROR      The wakeup time could not be retrieved due to a hardware error.
-
-**/
-EFI_STATUS
-EFIAPI
-LibGetWakeupTime (
-  OUT BOOLEAN     *Enabled,
-  OUT BOOLEAN     *Pending,
-  OUT EFI_TIME    *Time
-  )
-{
-  return EFI_UNSUPPORTED;
-}
-
-/**
-  Sets the system wakeup alarm clock time.
-
-  @param  Enabled               Enable or disable the wakeup alarm.
-  @param  Time                  If Enable is TRUE, the time to set the wakeup alarm for.
-
-  @retval EFI_SUCCESS           If Enable is TRUE, then the wakeup alarm was enabled. If
-                                Enable is FALSE, then the wakeup alarm was disabled.
-  @retval EFI_INVALID_PARAMETER A time field is out of range.
-  @retval EFI_DEVICE_ERROR      The wakeup time could not be set due to a hardware error.
-  @retval EFI_UNSUPPORTED       A wakeup timer is not supported on this platform.
-
-**/
-EFI_STATUS
-EFIAPI
-LibSetWakeupTime (
-  IN BOOLEAN      Enabled,
-  OUT EFI_TIME    *Time
-  )
-{
-  return EFI_UNSUPPORTED;
-}
-
-/**
-  This is the declaration of an EFI image entry point. This can be the entry point to an application
-  written to this specification, an EFI boot service driver, or an EFI runtime driver.
-
-  @param  ImageHandle           Handle that identifies the loaded image.
-  @param  SystemTable           System Table for this image.
-
-  @retval EFI_SUCCESS           The operation completed successfully.
-
-**/
-EFI_STATUS
-EFIAPI
-LibRtcInitialize (
-  IN EFI_HANDLE                            ImageHandle,
-  IN EFI_SYSTEM_TABLE                      *SystemTable
-  )
-{
-  EFI_STATUS    Status;
-  EFI_HANDLE    Handle;
-  UINT8         Data;
-  EFI_TPL       OldTpl;
-
-  Status = gBS->LocateProtocol (&gEmbeddedExternalDeviceProtocolGuid, NULL, (VOID **)&gTPS65950);
-  ASSERT_EFI_ERROR(Status);
-
-  OldTpl = gBS->RaiseTPL(TPL_NOTIFY);
-  Data = 1;
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, RTC_CTRL_REG), 1, &Data);
-  ASSERT_EFI_ERROR(Status);
-  gBS->RestoreTPL(OldTpl);
-
-  // Setup the setters and getters
-  gRT->GetTime       = LibGetTime;
-  gRT->SetTime       = LibSetTime;
-  gRT->GetWakeupTime = LibGetWakeupTime;
-  gRT->SetWakeupTime = LibSetWakeupTime;
-
-  // Install the protocol
-  Handle = NULL;
-  Status = gBS->InstallMultipleProtocolInterfaces (
-                  &Handle,
-                  &gEfiRealTimeClockArchProtocolGuid,  NULL,
-                  NULL
-                 );
-
-  return Status;
-}
-
-/**
-  Fixup internal data so that EFI can be call in virtual mode.
-  Call the passed in Child Notify event and convert any pointers in
-  lib to virtual mode.
-
-  @param[in]    Event   The Event that is being processed
-  @param[in]    Context Event Context
-**/
-VOID
-EFIAPI
-LibRtcVirtualNotifyEvent (
-  IN EFI_EVENT        Event,
-  IN VOID             *Context
-  )
-{
-  return;
-}
+/** @file\r
+*\r
+*  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/IoLib.h>\r
+\r
+#include <Protocol/RealTimeClock.h>\r
+#include <Protocol/EmbeddedExternalDevice.h>\r
+\r
+#include <Omap3530/Omap3530.h>\r
+#include <TPS65950.h>\r
+\r
+\r
+EMBEDDED_EXTERNAL_DEVICE   *gTPS65950;\r
+INT16                      TimeZone = EFI_UNSPECIFIED_TIMEZONE;\r
+\r
+/**\r
+  Returns the current time and date information, and the time-keeping capabilities\r
+  of the hardware platform.\r
+\r
+  @param  Time                  A pointer to storage to receive a snapshot of the current time.\r
+  @param  Capabilities          An optional pointer to a buffer to receive the real time clock\r
+                                device's capabilities.\r
+\r
+  @retval EFI_SUCCESS           The operation completed successfully.\r
+  @retval EFI_INVALID_PARAMETER Time is NULL.\r
+  @retval EFI_DEVICE_ERROR      The time could not be retrieved due to hardware error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LibGetTime (\r
+  OUT EFI_TIME                *Time,\r
+  OUT EFI_TIME_CAPABILITIES   *Capabilities\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  UINT8                 Data;\r
+  EFI_TPL               OldTpl;\r
+\r
+  if (Time == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL(TPL_NOTIFY);\r
+\r
+  /* Get time and date */\r
+  ZeroMem(Time, sizeof(EFI_TIME));\r
+\r
+  // Latch values\r
+  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, RTC_CTRL_REG), 1, &Data);\r
+  if (Status != EFI_SUCCESS) goto EXIT;\r
+  Data |= BIT6;\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, RTC_CTRL_REG), 1, &Data);\r
+  if (Status != EFI_SUCCESS) goto EXIT;\r
+\r
+  // Read registers\r
+  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, YEARS_REG), 1, &Data);\r
+  if (Status != EFI_SUCCESS) goto EXIT;\r
+  Time->Year = 2000 + ((Data >> 4) & 0xF) * 10 + (Data & 0xF);\r
+\r
+  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, MONTHS_REG), 1, &Data);\r
+  if (Status != EFI_SUCCESS) goto EXIT;\r
+  Time->Month = ((Data >> 4) & 0x1) * 10 + (Data & 0xF);\r
+\r
+  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, DAYS_REG), 1, &Data);\r
+  if (Status != EFI_SUCCESS) goto EXIT;\r
+  Time->Day = ((Data >> 4) & 0x3) * 10 + (Data & 0xF);\r
+\r
+  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, HOURS_REG), 1, &Data);\r
+  if (Status != EFI_SUCCESS) goto EXIT;\r
+  Time->Hour = ((Data >> 4) & 0x3) * 10 + (Data & 0xF);\r
+\r
+  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, MINUTES_REG), 1, &Data);\r
+  if (Status != EFI_SUCCESS) goto EXIT;\r
+  Time->Minute = ((Data >> 4) & 0x7) * 10 + (Data & 0xF);\r
+\r
+  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, SECONDS_REG), 1, &Data);\r
+  if (Status != EFI_SUCCESS) goto EXIT;\r
+  Time->Second = ((Data >> 4) & 0x7) * 10 + (Data & 0xF);\r
+\r
+  Time->TimeZone = TimeZone;\r
+  // TODO: check what to use here\r
+  Time->Daylight = EFI_TIME_ADJUST_DAYLIGHT;\r
+\r
+  // Set capabilities\r
+\r
+  // TODO: Set real capabilities\r
+  if (Capabilities != NULL) {\r
+    Capabilities->Resolution = 1;\r
+    Capabilities->Accuracy = 50000000;\r
+    Capabilities->SetsToZero = FALSE;\r
+  }\r
+\r
+EXIT:\r
+  gBS->RestoreTPL(OldTpl);\r
+\r
+  return (Status == EFI_SUCCESS) ? Status : EFI_DEVICE_ERROR;\r
+}\r
+\r
+/**\r
+  Sets the current local time and date information.\r
+\r
+  @param  Time                  A pointer to the current time.\r
+\r
+  @retval EFI_SUCCESS           The operation completed successfully.\r
+  @retval EFI_INVALID_PARAMETER A time field is out of range.\r
+  @retval EFI_DEVICE_ERROR      The time could not be set due due to hardware error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LibSetTime (\r
+  IN EFI_TIME                *Time\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  UINT8      Data;\r
+  UINT8      MonthDayCount[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r
+  EFI_TPL    OldTpl;\r
+\r
+  // Input validation according both to UEFI spec and hardware constraints\r
+  // UEFI spec says valid year range is 1900-9999 but TPS only supports 2000-2099\r
+  if ( (Time == NULL)\r
+    || (Time->Year < 2000 || Time->Year > 2099)\r
+    || (Time->Month < 1 || Time->Month > 12)\r
+    || (Time->Day < 1 || Time->Day > MonthDayCount[Time->Month])\r
+    || (Time->Hour > 23)\r
+    || (Time->Minute > 59)\r
+    || (Time->Second > 59)\r
+    || (Time->Nanosecond > 999999999)\r
+    || ((Time->TimeZone < -1440 || Time->TimeZone > 1440) && Time->TimeZone != 2047)\r
+  ) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL(TPL_NOTIFY);\r
+\r
+  Data = Time->Year - 2000;\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, YEARS_REG), 1, &Data);\r
+  if (Status != EFI_SUCCESS) goto EXIT;\r
+\r
+  Data = ((Time->Month / 10) << 4) | (Time->Month % 10);\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, MONTHS_REG), 1, &Data);\r
+  if (Status != EFI_SUCCESS) goto EXIT;\r
+\r
+  Data = ((Time->Day / 10) << 4) | (Time->Day % 10);\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, DAYS_REG), 1, &Data);\r
+  if (Status != EFI_SUCCESS) goto EXIT;\r
+\r
+  Data = ((Time->Hour / 10) << 4) | (Time->Hour % 10);\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, HOURS_REG), 1, &Data);\r
+  if (Status != EFI_SUCCESS) goto EXIT;\r
+\r
+  Data = ((Time->Minute / 10) << 4) | (Time->Minute % 10);\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, MINUTES_REG), 1, &Data);\r
+  if (Status != EFI_SUCCESS) goto EXIT;\r
+\r
+  Data = ((Time->Second / 10) << 4) | (Time->Second % 10);\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, SECONDS_REG), 1, &Data);\r
+  if (Status != EFI_SUCCESS) goto EXIT;\r
+\r
+  TimeZone = Time->TimeZone;\r
+\r
+EXIT:\r
+  gBS->RestoreTPL(OldTpl);\r
+\r
+  return (Status == EFI_SUCCESS) ? Status : EFI_DEVICE_ERROR;\r
+}\r
+\r
+/**\r
+  Returns the current wakeup alarm clock setting.\r
+\r
+  @param  Enabled               Indicates if the alarm is currently enabled or disabled.\r
+  @param  Pending               Indicates if the alarm signal is pending and requires acknowledgement.\r
+  @param  Time                  The current alarm setting.\r
+\r
+  @retval EFI_SUCCESS           The alarm settings were returned.\r
+  @retval EFI_INVALID_PARAMETER Any parameter is NULL.\r
+  @retval EFI_DEVICE_ERROR      The wakeup time could not be retrieved due to a hardware error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LibGetWakeupTime (\r
+  OUT BOOLEAN     *Enabled,\r
+  OUT BOOLEAN     *Pending,\r
+  OUT EFI_TIME    *Time\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Sets the system wakeup alarm clock time.\r
+\r
+  @param  Enabled               Enable or disable the wakeup alarm.\r
+  @param  Time                  If Enable is TRUE, the time to set the wakeup alarm for.\r
+\r
+  @retval EFI_SUCCESS           If Enable is TRUE, then the wakeup alarm was enabled. If\r
+                                Enable is FALSE, then the wakeup alarm was disabled.\r
+  @retval EFI_INVALID_PARAMETER A time field is out of range.\r
+  @retval EFI_DEVICE_ERROR      The wakeup time could not be set due to a hardware error.\r
+  @retval EFI_UNSUPPORTED       A wakeup timer is not supported on this platform.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LibSetWakeupTime (\r
+  IN BOOLEAN      Enabled,\r
+  OUT EFI_TIME    *Time\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  This is the declaration of an EFI image entry point. This can be the entry point to an application\r
+  written to this specification, an EFI boot service driver, or an EFI runtime driver.\r
+\r
+  @param  ImageHandle           Handle that identifies the loaded image.\r
+  @param  SystemTable           System Table for this image.\r
+\r
+  @retval EFI_SUCCESS           The operation completed successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LibRtcInitialize (\r
+  IN EFI_HANDLE                            ImageHandle,\r
+  IN EFI_SYSTEM_TABLE                      *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  EFI_HANDLE    Handle;\r
+  UINT8         Data;\r
+  EFI_TPL       OldTpl;\r
+\r
+  Status = gBS->LocateProtocol (&gEmbeddedExternalDeviceProtocolGuid, NULL, (VOID **)&gTPS65950);\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  OldTpl = gBS->RaiseTPL(TPL_NOTIFY);\r
+  Data = 1;\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, RTC_CTRL_REG), 1, &Data);\r
+  ASSERT_EFI_ERROR(Status);\r
+  gBS->RestoreTPL(OldTpl);\r
+\r
+  // Setup the setters and getters\r
+  gRT->GetTime       = LibGetTime;\r
+  gRT->SetTime       = LibSetTime;\r
+  gRT->GetWakeupTime = LibGetWakeupTime;\r
+  gRT->SetWakeupTime = LibSetWakeupTime;\r
+\r
+  // Install the protocol\r
+  Handle = NULL;\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Handle,\r
+                  &gEfiRealTimeClockArchProtocolGuid,  NULL,\r
+                  NULL\r
+                 );\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Fixup internal data so that EFI can be call in virtual mode.\r
+  Call the passed in Child Notify event and convert any pointers in\r
+  lib to virtual mode.\r
+\r
+  @param[in]    Event   The Event that is being processed\r
+  @param[in]    Context Event Context\r
+**/\r
+VOID\r
+EFIAPI\r
+LibRtcVirtualNotifyEvent (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  )\r
+{\r
+  return;\r
+}\r
index c62257df7e86eb7976303bab994ef2ceeefa0201..7c4911c385c45ebaf35d3c45fd8df6da3ef60b67 100755 (executable)
@@ -1,38 +1,38 @@
-#  Copyright (c) 2011, ARM Limited. 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                      = RealTimeClockLib 
-  FILE_GUID                      = EC1713DB-7DB5-4c99-8FE2-6F52F95A1132
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = RealTimeClockLib
-
-[Sources.common]
-  RealTimeClockLib.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  Omap35xxPkg/Omap35xxPkg.dec
-  
-[LibraryClasses]
-  IoLib
-  UefiLib
-  DebugLib
-  PcdLib
-
-[Protocols]
-  gEmbeddedExternalDeviceProtocolGuid
-
-[depex]
-  gEmbeddedExternalDeviceProtocolGuid
+#  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = RealTimeClockLib \r
+  FILE_GUID                      = EC1713DB-7DB5-4c99-8FE2-6F52F95A1132\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = RealTimeClockLib\r
+\r
+[Sources.common]\r
+  RealTimeClockLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  Omap35xxPkg/Omap35xxPkg.dec\r
+  \r
+[LibraryClasses]\r
+  IoLib\r
+  UefiLib\r
+  DebugLib\r
+  PcdLib\r
+\r
+[Protocols]\r
+  gEmbeddedExternalDeviceProtocolGuid\r
+\r
+[depex]\r
+  gEmbeddedExternalDeviceProtocolGuid\r
index 786bc882731d276656c1caf111c022f1fc954fe9..7d4e22f5246aad7fb22c06cb32229475718aa28f 100644 (file)
-/** @file
-  MMC/SD Card driver for OMAP 35xx (SDIO not supported)
-
-  This driver always produces a BlockIo protocol but it starts off with no Media
-  present. A TimerCallBack detects when media is inserted or removed and after 
-  a media change event a call to BlockIo ReadBlocks/WriteBlocks will cause the 
-  media to be detected (or removed) and the BlockIo Media structure will get
-  updated. No MMC/SD Card harward registers are updated until the first BlockIo
-  ReadBlocks/WriteBlocks after media has been insterted (booting with a card 
-  plugged in counts as an insertion event). 
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 "MMCHS.h"
-
-EFI_BLOCK_IO_MEDIA gMMCHSMedia = {
-  SIGNATURE_32('s','d','i','o'),            // MediaId
-  TRUE,                                     // RemovableMedia
-  FALSE,                                    // MediaPresent
-  FALSE,                                    // LogicalPartition
-  FALSE,                                    // ReadOnly
-  FALSE,                                    // WriteCaching
-  512,                                      // BlockSize
-  4,                                        // IoAlign
-  0,                                        // Pad
-  0                                         // LastBlock
-};
-
-typedef struct {
-  VENDOR_DEVICE_PATH  Mmc;
-  EFI_DEVICE_PATH     End;
-} MMCHS_DEVICE_PATH;
-
-MMCHS_DEVICE_PATH gMmcHsDevicePath = {
-  {
-    HARDWARE_DEVICE_PATH,
-    HW_VENDOR_DP,
-    (UINT8)(sizeof(VENDOR_DEVICE_PATH)),
-    (UINT8)((sizeof(VENDOR_DEVICE_PATH)) >> 8),
-    0xb615f1f5, 0x5088, 0x43cd, 0x80, 0x9c, 0xa1, 0x6e, 0x52, 0x48, 0x7d, 0x00 
-  },
-  {
-    END_DEVICE_PATH_TYPE,
-    END_ENTIRE_DEVICE_PATH_SUBTYPE,
-    sizeof (EFI_DEVICE_PATH_PROTOCOL),
-    0
-  }
-};
-
-CARD_INFO                  gCardInfo;
-EMBEDDED_EXTERNAL_DEVICE   *gTPS65950;
-EFI_EVENT                  gTimerEvent;
-BOOLEAN                    gMediaChange = FALSE;
-
-//
-// Internal Functions
-//
-
-
-VOID
-ParseCardCIDData (
-  UINT32 Response0, 
-  UINT32 Response1, 
-  UINT32 Response2,
-  UINT32 Response3
-  )
-{
-  gCardInfo.CIDData.MDT = ((Response0 >> 8) & 0xFFF);
-  gCardInfo.CIDData.PSN = (((Response0 >> 24) & 0xFF) | ((Response1 & 0xFFFFFF) << 8));
-  gCardInfo.CIDData.PRV = ((Response1 >> 24) & 0xFF);
-  gCardInfo.CIDData.PNM[4] = ((Response2) & 0xFF);
-  gCardInfo.CIDData.PNM[3] = ((Response2 >> 8) & 0xFF);
-  gCardInfo.CIDData.PNM[2] = ((Response2 >> 16) & 0xFF);
-  gCardInfo.CIDData.PNM[1] = ((Response2 >> 24) & 0xFF);
-  gCardInfo.CIDData.PNM[0] = ((Response3) & 0xFF);
-  gCardInfo.CIDData.OID = ((Response3 >> 8) & 0xFFFF);
-  gCardInfo.CIDData.MID = ((Response3 >> 24) & 0xFF);
-}
-
-
-VOID
-UpdateMMCHSClkFrequency (
-  UINTN NewCLKD
-  )
-{
-  //Set Clock enable to 0x0 to not provide the clock to the card
-  MmioAnd32 (MMCHS_SYSCTL, ~CEN);
-
-  //Set new clock frequency.
-  MmioAndThenOr32 (MMCHS_SYSCTL, ~CLKD_MASK, NewCLKD << 6); 
-
-  //Poll till Internal Clock Stable
-  while ((MmioRead32 (MMCHS_SYSCTL) & ICS_MASK) != ICS);
-
-  //Set Clock enable to 0x1 to provide the clock to the card
-  MmioOr32 (MMCHS_SYSCTL, CEN);
-}
-
-
-EFI_STATUS
-SendCmd (
-  UINTN Cmd,
-  UINTN CmdInterruptEnableVal,
-  UINTN CmdArgument
-  )
-{
-  UINTN MmcStatus;
-  UINTN RetryCount = 0;
-
-  //Check if command line is in use or not. Poll till command line is available.
-  while ((MmioRead32 (MMCHS_PSTATE) & DATI_MASK) == DATI_NOT_ALLOWED);
-
-  //Provide the block size.
-  MmioWrite32 (MMCHS_BLK, BLEN_512BYTES);
-
-  //Setting Data timeout counter value to max value.
-  MmioAndThenOr32 (MMCHS_SYSCTL, ~DTO_MASK, DTO_VAL);
-
-  //Clear Status register.
-  MmioWrite32 (MMCHS_STAT, 0xFFFFFFFF);
-
-  //Set command argument register
-  MmioWrite32 (MMCHS_ARG, CmdArgument);
-
-  //Enable interrupt enable events to occur
-  MmioWrite32 (MMCHS_IE, CmdInterruptEnableVal);
-
-  //Send a command
-  MmioWrite32 (MMCHS_CMD, Cmd);
-
-  //Check for the command status.
-  while (RetryCount < MAX_RETRY_COUNT) {
-    do {
-      MmcStatus = MmioRead32 (MMCHS_STAT);
-    } while (MmcStatus == 0);
-
-    //Read status of command response
-    if ((MmcStatus & ERRI) != 0) {
-
-      //Perform soft-reset for mmci_cmd line.
-      MmioOr32 (MMCHS_SYSCTL, SRC);
-      while ((MmioRead32 (MMCHS_SYSCTL) & SRC));
-
-      DEBUG ((EFI_D_INFO, "MmcStatus: %x\n", MmcStatus));
-      return EFI_DEVICE_ERROR;
-    }
-
-    //Check if command is completed.
-    if ((MmcStatus & CC) == CC) {
-      MmioWrite32 (MMCHS_STAT, CC);
-      break;
-    }
-
-    RetryCount++;
-  }
-
-  if (RetryCount == MAX_RETRY_COUNT) {
-    return EFI_TIMEOUT;
-  }
-
-  return EFI_SUCCESS;
-}
-
-
-VOID
-GetBlockInformation (
-  UINTN *BlockSize,
-  UINTN *NumBlocks
-  )
-{
-  CSD_SDV2 *CsdSDV2Data;
-  UINTN    CardSize;
-
-  if (gCardInfo.CardType == SD_CARD_2_HIGH) {
-    CsdSDV2Data = (CSD_SDV2 *)&gCardInfo.CSDData;
-
-    //Populate BlockSize.
-    *BlockSize = (0x1UL << CsdSDV2Data->READ_BL_LEN);
-
-    //Calculate Total number of blocks.
-    CardSize = CsdSDV2Data->C_SIZELow16 | (CsdSDV2Data->C_SIZEHigh6 << 2);
-    *NumBlocks = ((CardSize + 1) * 1024);
-  } else {
-    //Populate BlockSize.
-    *BlockSize = (0x1UL << gCardInfo.CSDData.READ_BL_LEN);
-
-    //Calculate Total number of blocks.
-    CardSize = gCardInfo.CSDData.C_SIZELow2 | (gCardInfo.CSDData.C_SIZEHigh10 << 2);
-    *NumBlocks = (CardSize + 1) * (1 << (gCardInfo.CSDData.C_SIZE_MULT + 2));
-  }
-
-  //For >=2G card, BlockSize may be 1K, but the transfer size is 512 bytes.
-  if (*BlockSize > 512) {
-    *NumBlocks = MultU64x32(*NumBlocks, *BlockSize/2);
-    *BlockSize = 512;
-  }
-
-  DEBUG ((EFI_D_INFO, "Card type: %x, BlockSize: %x, NumBlocks: %x\n", gCardInfo.CardType, *BlockSize, *NumBlocks));
-}
-
-
-VOID
-CalculateCardCLKD (
-  UINTN *ClockFrequencySelect
-  )
-{
-  UINT8    MaxDataTransferRate;
-  UINTN    TransferRateValue = 0;
-  UINTN    TimeValue = 0 ;
-  UINTN    Frequency = 0;
-
-  MaxDataTransferRate = gCardInfo.CSDData.TRAN_SPEED;
-
-  // For SD Cards  we would need to send CMD6 to set
-  // speeds abouve 25MHz. High Speed mode 50 MHz and up
-
-  //Calculate Transfer rate unit (Bits 2:0 of TRAN_SPEED)
-  switch (MaxDataTransferRate & 0x7) {
-    case 0:
-      TransferRateValue = 100 * 1000;
-      break;
-
-    case 1:
-      TransferRateValue = 1 * 1000 * 1000;
-      break;
-
-    case 2:
-      TransferRateValue = 10 * 1000 * 1000;
-      break;
-
-    case 3:
-      TransferRateValue = 100 * 1000 * 1000;
-      break;
-
-    default:
-      DEBUG((EFI_D_ERROR, "Invalid parameter.\n"));
-      ASSERT(FALSE);
-  }
-
-  //Calculate Time value (Bits 6:3 of TRAN_SPEED)
-  switch ((MaxDataTransferRate >> 3) & 0xF) {
-    case 1:
-      TimeValue = 10;
-      break;
-
-    case 2:
-      TimeValue = 12;
-      break;
-
-    case 3:
-      TimeValue = 13;
-      break;
-
-    case 4:
-      TimeValue = 15;
-      break;
-
-    case 5:
-      TimeValue = 20;
-      break;
-
-    case 6:
-      TimeValue = 25;
-      break;
-
-    case 7:
-      TimeValue = 30;
-      break;
-
-    case 8:
-      TimeValue = 35;
-      break;
-
-    case 9:
-      TimeValue = 40;
-      break;
-
-    case 10:
-      TimeValue = 45;
-      break;
-
-    case 11:
-      TimeValue = 50;
-      break;
-
-    case 12:
-      TimeValue = 55;
-      break;
-
-    case 13:
-      TimeValue = 60;
-      break;
-
-    case 14:
-      TimeValue = 70;
-      break;
-
-    case 15:
-      TimeValue = 80;
-      break;
-
-    default:
-      DEBUG((EFI_D_ERROR, "Invalid parameter.\n"));
-      ASSERT(FALSE);
-  }
-
-  Frequency = TransferRateValue * TimeValue/10;
-
-  //Calculate Clock divider value to program in MMCHS_SYSCTL[CLKD] field.
-  *ClockFrequencySelect = ((MMC_REFERENCE_CLK/Frequency) + 1);
-
-  DEBUG ((EFI_D_INFO, "MaxDataTransferRate: 0x%x, Frequency: %d KHz, ClockFrequencySelect: %x\n", MaxDataTransferRate, Frequency/1000, *ClockFrequencySelect));
-}
-
-
-VOID
-GetCardConfigurationData (
-  VOID
-  )
-{
-  UINTN  BlockSize;
-  UINTN  NumBlocks;
-  UINTN  ClockFrequencySelect;
-
-  //Calculate BlockSize and Total number of blocks in the detected card.
-  GetBlockInformation(&BlockSize, &NumBlocks);
-  gCardInfo.BlockSize = BlockSize;
-  gCardInfo.NumBlocks = NumBlocks;
-
-  //Calculate Card clock divider value.
-  CalculateCardCLKD(&ClockFrequencySelect);
-  gCardInfo.ClockFrequencySelect = ClockFrequencySelect;
-}
-
-
-EFI_STATUS
-InitializeMMCHS (
-  VOID
-  )
-{
-  UINT8      Data = 0;
-  EFI_STATUS Status;
-
-  //Select Device group to belong to P1 device group in Power IC.
-  Data = DEV_GRP_P1;
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VMMC1_DEV_GRP), 1, &Data);
-  ASSERT_EFI_ERROR(Status);
-
-  //Configure voltage regulator for MMC1 in Power IC to output 3.0 voltage.
-  Data = VSEL_3_00V;
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VMMC1_DEDICATED_REG), 1, &Data);
-  ASSERT_EFI_ERROR(Status);
-  
-  //After ramping up voltage, set VDDS stable bit to indicate that voltage level is stable.
-  MmioOr32 (CONTROL_PBIAS_LITE, (PBIASLITEVMODE0 | PBIASLITEPWRDNZ0 | PBIASSPEEDCTRL0 | PBIASLITEVMODE1 | PBIASLITEWRDNZ1));
-
-  // Enable WP GPIO
-  MmioAndThenOr32 (GPIO1_BASE + GPIO_OE, ~BIT23, BIT23);
-
-  // Enable Card Detect
-  Data = CARD_DETECT_ENABLE;
-  gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID2, TPS65950_GPIO_CTRL), 1, &Data);
-
-
-  return Status;
-}
-
-
-EFI_STATUS
-PerformCardIdenfication (
-  VOID
-  )
-{
-  EFI_STATUS Status;
-  UINTN      CmdArgument = 0;
-  UINTN      Response = 0;
-  UINTN      RetryCount = 0;
-  BOOLEAN    SDCmd8Supported = FALSE;
-
-  //Enable interrupts.
-  MmioWrite32 (MMCHS_IE, (BADA_EN | CERR_EN | DEB_EN | DCRC_EN | DTO_EN | CIE_EN |
-    CEB_EN | CCRC_EN | CTO_EN | BRR_EN | BWR_EN | TC_EN | CC_EN));
-
-  //Controller INIT procedure start.
-  MmioOr32 (MMCHS_CON, INIT);
-  MmioWrite32 (MMCHS_CMD, 0x00000000);
-  while (!(MmioRead32 (MMCHS_STAT) & CC));
-
-  //Wait for 1 ms
-  gBS->Stall(1000);
-
-  //Set CC bit to 0x1 to clear the flag
-  MmioOr32 (MMCHS_STAT, CC);
-
-  //Retry INIT procedure.
-  MmioWrite32 (MMCHS_CMD, 0x00000000);
-  while (!(MmioRead32 (MMCHS_STAT) & CC));
-
-  //End initialization sequence
-  MmioAnd32 (MMCHS_CON, ~INIT);
-
-  MmioOr32 (MMCHS_HCTL, (SDVS_3_0_V | DTW_1_BIT | SDBP_ON));
-
-  //Change clock frequency to 400KHz to fit protocol
-  UpdateMMCHSClkFrequency(CLKD_400KHZ);
-
-  MmioOr32 (MMCHS_CON, OD);
-
-  //Send CMD0 command.
-  Status = SendCmd (CMD0, CMD0_INT_EN, CmdArgument);
-  if (EFI_ERROR(Status)) {
-    DEBUG ((EFI_D_ERROR, "Cmd0 fails.\n"));
-    return Status;
-  }
-
-  DEBUG ((EFI_D_INFO, "CMD0 response: %x\n", MmioRead32 (MMCHS_RSP10)));
-
-  //Send CMD5 command. 
-  Status = SendCmd (CMD5, CMD5_INT_EN, CmdArgument);
-  if (Status == EFI_SUCCESS) {
-    DEBUG ((EFI_D_ERROR, "CMD5 Success. SDIO card. Follow SDIO card specification.\n"));
-    DEBUG ((EFI_D_INFO, "CMD5 response: %x\n", MmioRead32 (MMCHS_RSP10)));
-    //NOTE: Returning unsupported error for now. Need to implement SDIO specification.
-    return EFI_UNSUPPORTED; 
-  } else {
-    DEBUG ((EFI_D_INFO, "CMD5 fails. Not an SDIO card.\n"));
-  }
-
-  MmioOr32 (MMCHS_SYSCTL, SRC);
-  gBS->Stall(1000);
-  while ((MmioRead32 (MMCHS_SYSCTL) & SRC));
-
-  //Send CMD8 command. (New v2.00 command for Voltage check)
-  //Only 2.7V - 3.6V is supported for SD2.0, only SD 2.0 card can pass.
-  //MMC & SD1.1 card will fail this command.
-  CmdArgument = CMD8_ARG;
-  Status = SendCmd (CMD8, CMD8_INT_EN, CmdArgument);
-  if (Status == EFI_SUCCESS) {
-    Response = MmioRead32 (MMCHS_RSP10);
-    DEBUG ((EFI_D_INFO, "CMD8 success. CMD8 response: %x\n", Response));
-    if (Response != CmdArgument) {
-      return EFI_DEVICE_ERROR;
-    }
-    DEBUG ((EFI_D_INFO, "Card is SD2.0\n"));
-    SDCmd8Supported = TRUE; //Supports high capacity.
-  } else {
-    DEBUG ((EFI_D_INFO, "CMD8 fails. Not an SD2.0 card.\n"));
-  }
-
-  MmioOr32 (MMCHS_SYSCTL, SRC);
-  gBS->Stall(1000);
-  while ((MmioRead32 (MMCHS_SYSCTL) & SRC));
-
-  //Poll till card is busy
-  while (RetryCount < MAX_RETRY_COUNT) {
-    //Send CMD55 command. 
-    CmdArgument = 0;
-    Status = SendCmd (CMD55, CMD55_INT_EN, CmdArgument);
-    if (Status == EFI_SUCCESS) {
-      DEBUG ((EFI_D_INFO, "CMD55 success. CMD55 response: %x\n", MmioRead32 (MMCHS_RSP10)));
-      gCardInfo.CardType = SD_CARD;
-    } else {
-      DEBUG ((EFI_D_INFO, "CMD55 fails.\n"));
-      gCardInfo.CardType = MMC_CARD;
-    }
-
-    //Send appropriate command for the card type which got detected.
-    if (gCardInfo.CardType == SD_CARD) {
-      CmdArgument = ((UINTN *) &(gCardInfo.OCRData))[0];
-
-      //Set HCS bit.
-      if (SDCmd8Supported) {
-        CmdArgument |= HCS;
-      }
-
-      Status = SendCmd (ACMD41, ACMD41_INT_EN, CmdArgument);
-      if (EFI_ERROR(Status)) {
-        DEBUG ((EFI_D_INFO, "ACMD41 fails.\n"));
-        return Status;
-      }
-      ((UINT32 *) &(gCardInfo.OCRData))[0] = MmioRead32 (MMCHS_RSP10);
-      DEBUG ((EFI_D_INFO, "SD card detected. ACMD41 OCR: %x\n", ((UINT32 *) &(gCardInfo.OCRData))[0]));
-    } else if (gCardInfo.CardType == MMC_CARD) {
-      CmdArgument = 0;
-      Status = SendCmd (CMD1, CMD1_INT_EN, CmdArgument);
-      if (EFI_ERROR(Status)) {
-        DEBUG ((EFI_D_INFO, "CMD1 fails.\n"));
-        return Status;
-      }
-      Response = MmioRead32 (MMCHS_RSP10);
-      DEBUG ((EFI_D_INFO, "MMC card detected.. CMD1 response: %x\n", Response));
-
-      //NOTE: For now, I am skipping this since I only have an SD card.
-      //Compare card OCR and host OCR (Section 22.6.1.3.2.4)
-      return EFI_UNSUPPORTED; //For now, MMC is not supported.
-    }
-
-    //Poll the card until it is out of its power-up sequence.
-    if (gCardInfo.OCRData.Busy == 1) {
-
-      if (SDCmd8Supported) {
-        gCardInfo.CardType = SD_CARD_2;
-      }
-
-      //Card is ready. Check CCS (Card capacity status) bit (bit#30).
-      //SD 2.0 standard card will response with CCS 0, SD high capacity card will respond with CCS 1.
-      if (gCardInfo.OCRData.AccessMode & BIT1) {
-        gCardInfo.CardType = SD_CARD_2_HIGH;
-        DEBUG ((EFI_D_INFO, "High capacity card.\n"));
-      } else {
-        DEBUG ((EFI_D_INFO, "Standard capacity card.\n"));
-      }
-
-      break;
-    }
-
-    gBS->Stall(1000);
-    RetryCount++;
-  }
-
-  if (RetryCount == MAX_RETRY_COUNT) {
-    DEBUG ((EFI_D_ERROR, "Timeout error. RetryCount: %d\n", RetryCount));
-    return EFI_TIMEOUT;
-  }
-
-  //Read CID data.
-  CmdArgument = 0;
-  Status = SendCmd (CMD2, CMD2_INT_EN, CmdArgument);
-  if (EFI_ERROR(Status)) {
-    DEBUG ((EFI_D_ERROR, "CMD2 fails. Status: %x\n", Status));
-    return Status;
-  }
-
-  DEBUG ((EFI_D_INFO, "CMD2 response: %x %x %x %x\n", MmioRead32 (MMCHS_RSP10), MmioRead32 (MMCHS_RSP32), MmioRead32 (MMCHS_RSP54), MmioRead32 (MMCHS_RSP76)));
-
-  //Parse CID register data.
-  ParseCardCIDData(MmioRead32 (MMCHS_RSP10), MmioRead32 (MMCHS_RSP32), MmioRead32 (MMCHS_RSP54), MmioRead32 (MMCHS_RSP76));
-
-  //Read RCA
-  CmdArgument = 0;
-  Status = SendCmd (CMD3, CMD3_INT_EN, CmdArgument);
-  if (EFI_ERROR(Status)) {
-    DEBUG ((EFI_D_ERROR, "CMD3 fails. Status: %x\n", Status));
-    return Status;
-  }
-
-  //Set RCA for the detected card. RCA is CMD3 response.
-  gCardInfo.RCA = (MmioRead32 (MMCHS_RSP10) >> 16);
-  DEBUG ((EFI_D_INFO, "CMD3 response: RCA %x\n", gCardInfo.RCA));
-
-  //MMC Bus setting change after card identification.
-  MmioAnd32 (MMCHS_CON, ~OD);
-  MmioOr32 (MMCHS_HCTL, SDVS_3_0_V);
-  UpdateMMCHSClkFrequency(CLKD_400KHZ); //Set the clock frequency to 400KHz.
-
-  return EFI_SUCCESS;
-}
-
-
-EFI_STATUS
-GetCardSpecificData (
-  VOID
-  )
-{
-  EFI_STATUS Status;
-  UINTN      CmdArgument;
-
-  //Send CMD9 to retrieve CSD.
-  CmdArgument = gCardInfo.RCA << 16;
-  Status = SendCmd (CMD9, CMD9_INT_EN, CmdArgument);
-  if (EFI_ERROR(Status)) {
-    DEBUG ((EFI_D_ERROR, "CMD9 fails. Status: %x\n", Status));
-    return Status;
-  }
-
-  //Populate 128-bit CSD register data.
-  ((UINT32 *)&(gCardInfo.CSDData))[0] = MmioRead32 (MMCHS_RSP10);
-  ((UINT32 *)&(gCardInfo.CSDData))[1] = MmioRead32 (MMCHS_RSP32);
-  ((UINT32 *)&(gCardInfo.CSDData))[2] = MmioRead32 (MMCHS_RSP54);
-  ((UINT32 *)&(gCardInfo.CSDData))[3] = MmioRead32 (MMCHS_RSP76);
-
-  DEBUG ((EFI_D_INFO, "CMD9 response: %x %x %x %x\n", MmioRead32 (MMCHS_RSP10), MmioRead32 (MMCHS_RSP32), MmioRead32 (MMCHS_RSP54), MmioRead32 (MMCHS_RSP76)));
-
-  //Calculate total number of blocks and max. data transfer rate supported by the detected card.
-  GetCardConfigurationData();
-
-  return Status;
-}
-
-
-EFI_STATUS
-PerformCardConfiguration (
-  VOID
-  )
-{
-  UINTN      CmdArgument = 0;
-  EFI_STATUS Status;
-
-  //Send CMD7
-  CmdArgument = gCardInfo.RCA << 16;
-  Status = SendCmd (CMD7, CMD7_INT_EN, CmdArgument);
-  if (EFI_ERROR(Status)) {
-    DEBUG ((EFI_D_ERROR, "CMD7 fails. Status: %x\n", Status));
-    return Status;
-  }
-
-  if ((gCardInfo.CardType != UNKNOWN_CARD) && (gCardInfo.CardType != MMC_CARD)) {
-    // We could read SCR register, but SD Card Phys spec stats any SD Card shall
-    // set SCR.SD_BUS_WIDTHS to support 4-bit mode, so why bother?
-    // Send ACMD6 (application specific commands must be prefixed with CMD55)
-    Status = SendCmd (CMD55, CMD55_INT_EN, CmdArgument);
-    if (!EFI_ERROR (Status)) {
-      // set device into 4-bit data bus mode
-      Status = SendCmd (ACMD6, ACMD6_INT_EN, 0x2);
-      if (!EFI_ERROR (Status)) {
-        // Set host controler into 4-bit mode
-        MmioOr32 (MMCHS_HCTL, DTW_4_BIT);
-        DEBUG ((EFI_D_INFO, "SD Memory Card set to 4-bit mode\n"));
-      }
-    }
-  }
-
-  //Send CMD16 to set the block length
-  CmdArgument = gCardInfo.BlockSize;
-  Status = SendCmd (CMD16, CMD16_INT_EN, CmdArgument);
-  if (EFI_ERROR(Status)) {
-    DEBUG ((EFI_D_ERROR, "CMD16 fails. Status: %x\n", Status));
-    return Status;
-  }
-
-  //Change MMCHS clock frequency to what detected card can support.
-  UpdateMMCHSClkFrequency(gCardInfo.ClockFrequencySelect);
-
-  return EFI_SUCCESS;
-}
-
-
-EFI_STATUS
-ReadBlockData (
-  IN  EFI_BLOCK_IO_PROTOCOL       *This,
-  OUT VOID                        *Buffer
-  )
-{
-  UINTN MmcStatus;
-  UINTN *DataBuffer = Buffer;
-  UINTN DataSize = This->Media->BlockSize/4;
-  UINTN Count;
-  UINTN RetryCount = 0;
-
-  //Check controller status to make sure there is no error.
-  while (RetryCount < MAX_RETRY_COUNT) {
-    do {
-      //Read Status.
-      MmcStatus = MmioRead32 (MMCHS_STAT);
-    } while(MmcStatus == 0);
-
-    //Check if Buffer read ready (BRR) bit is set?
-    if (MmcStatus & BRR) {
-
-      //Clear BRR bit
-      MmioOr32 (MMCHS_STAT, BRR);
-
-      //Read block worth of data.
-      for (Count = 0; Count < DataSize; Count++) {
-        *DataBuffer++ = MmioRead32 (MMCHS_DATA);
-      }
-      break;
-    }
-    RetryCount++;
-  }
-
-  if (RetryCount == MAX_RETRY_COUNT) {
-    return EFI_TIMEOUT;
-  }
-
-  return EFI_SUCCESS;
-}
-
-
-EFI_STATUS
-WriteBlockData (
-  IN  EFI_BLOCK_IO_PROTOCOL       *This,
-  OUT VOID                        *Buffer
-  )
-{
-  UINTN MmcStatus;
-  UINTN *DataBuffer = Buffer;
-  UINTN DataSize = This->Media->BlockSize/4;
-  UINTN Count;
-  UINTN RetryCount = 0;
-
-  //Check controller status to make sure there is no error.
-  while (RetryCount < MAX_RETRY_COUNT) {
-    do {
-      //Read Status.
-      MmcStatus = MmioRead32 (MMCHS_STAT);
-    } while(MmcStatus == 0);
-
-    //Check if Buffer write ready (BWR) bit is set?
-    if (MmcStatus & BWR) {
-
-      //Clear BWR bit
-      MmioOr32 (MMCHS_STAT, BWR);
-
-      //Write block worth of data.
-      for (Count = 0; Count < DataSize; Count++) {
-        MmioWrite32 (MMCHS_DATA, *DataBuffer++);
-      }
-
-      break;
-    }
-    RetryCount++;
-  }
-
-  if (RetryCount == MAX_RETRY_COUNT) {
-    return EFI_TIMEOUT;
-  }
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-DmaBlocks (
-  IN EFI_BLOCK_IO_PROTOCOL        *This,
-  IN  UINTN                       Lba,
-  IN OUT VOID                     *Buffer,
-  IN  UINTN                       BlockCount,
-  IN  OPERATION_TYPE              OperationType
-  )
-{
-  EFI_STATUS            Status;
-  UINTN                 DmaSize = 0;
-  UINTN                 Cmd = 0;
-  UINTN                 CmdInterruptEnable;
-  UINTN                 CmdArgument;
-  VOID                  *BufferMap;
-  EFI_PHYSICAL_ADDRESS  BufferAddress;
-  OMAP_DMA4             Dma4;
-  DMA_MAP_OPERATION     DmaOperation;
-  EFI_STATUS            MmcStatus;
-  UINTN                 RetryCount = 0;
-
-CpuDeadLoop ();
-  // Map passed in buffer for DMA xfer
-  DmaSize = BlockCount * This->Media->BlockSize;
-  Status = DmaMap (DmaOperation, Buffer, &DmaSize, &BufferAddress, &BufferMap);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  ZeroMem (&DmaOperation, sizeof (DMA_MAP_OPERATION));
-  
-
-  Dma4.DataType = 2;                      // DMA4_CSDPi[1:0]   32-bit elements from MMCHS_DATA
-
-  Dma4.SourceEndiansim = 0;               // DMA4_CSDPi[21]    
-
-  Dma4.DestinationEndianism = 0;          // DMA4_CSDPi[19]
-
-  Dma4.SourcePacked = 0;                  // DMA4_CSDPi[6]
-
-  Dma4.DestinationPacked = 0;             // DMA4_CSDPi[13]
-
-  Dma4.NumberOfElementPerFrame = This->Media->BlockSize/4; // DMA4_CENi  (TRM 4K is optimum value)  
-
-  Dma4.NumberOfFramePerTransferBlock = BlockCount;         // DMA4_CFNi    
-
-  Dma4.ReadPriority = 0;                  // DMA4_CCRi[6]      Low priority read  
-
-  Dma4.WritePriority = 0;                 // DMA4_CCRi[23]     Prefetech disabled
-
-
-  //Populate the command information based on the operation type.
-  if (OperationType == READ) {
-    Cmd = CMD18; //Multiple block read
-    CmdInterruptEnable = CMD18_INT_EN;
-    DmaOperation = MapOperationBusMasterCommonBuffer;
-
-    Dma4.ReadPortAccessType =0 ;            // DMA4_CSDPi[8:7]   Can not burst MMCHS_DATA reg
-
-    Dma4.WritePortAccessType = 3;           // DMA4_CSDPi[15:14] Memory burst 16x32
-
-    Dma4.WriteMode = 1;                     // DMA4_CSDPi[17:16] Write posted
-
-    
-
-    Dma4.SourceStartAddress = MMCHS_DATA;                   // DMA4_CSSAi
-
-    Dma4.DestinationStartAddress = (UINT32)BufferAddress;   // DMA4_CDSAi
-
-    Dma4.SourceElementIndex = 1;                            // DMA4_CSEi
-
-    Dma4.SourceFrameIndex = 0x200;                          // DMA4_CSFi
-
-    Dma4.DestinationElementIndex = 1;                       // DMA4_CDEi
-
-    Dma4.DestinationFrameIndex = 0;                         // DMA4_CDFi
-
-
-
-    Dma4.ReadPortAccessMode = 0;            // DMA4_CCRi[13:12]  Always read MMCHS_DATA
-
-    Dma4.WritePortAccessMode = 1;           // DMA4_CCRi[15:14]  Post increment memory address
-
-    Dma4.ReadRequestNumber = 0x1e;          // DMA4_CCRi[4:0]    Syncro with MMCA_DMA_RX (61)  
-
-    Dma4.WriteRequestNumber = 1;            // DMA4_CCRi[20:19]  Syncro upper 0x3e == 62 (one based)
-
-  } else if (OperationType == WRITE) { 
-    Cmd = CMD25; //Multiple block write
-    CmdInterruptEnable = CMD25_INT_EN;
-    DmaOperation = MapOperationBusMasterRead;
-
-    Dma4.ReadPortAccessType = 3;            // DMA4_CSDPi[8:7]   Memory burst 16x32
-
-    Dma4.WritePortAccessType = 0;           // DMA4_CSDPi[15:14] Can not burst MMCHS_DATA reg
-
-    Dma4.WriteMode = 1;                     // DMA4_CSDPi[17:16] Write posted ???
-
-    
-
-    Dma4.SourceStartAddress = (UINT32)BufferAddress;        // DMA4_CSSAi
-
-    Dma4.DestinationStartAddress = MMCHS_DATA;              // DMA4_CDSAi
-
-    Dma4.SourceElementIndex = 1;                            // DMA4_CSEi
-
-    Dma4.SourceFrameIndex = 0x200;                          // DMA4_CSFi
-
-    Dma4.DestinationElementIndex = 1;                       // DMA4_CDEi
-
-    Dma4.DestinationFrameIndex = 0;                         // DMA4_CDFi
-
-
-
-    Dma4.ReadPortAccessMode = 1;            // DMA4_CCRi[13:12]  Post increment memory address
-
-    Dma4.WritePortAccessMode = 0;           // DMA4_CCRi[15:14]  Always write MMCHS_DATA
-
-    Dma4.ReadRequestNumber = 0x1d;          // DMA4_CCRi[4:0]    Syncro with MMCA_DMA_TX (60)  
-
-    Dma4.WriteRequestNumber = 1;            // DMA4_CCRi[20:19]  Syncro upper 0x3d == 61 (one based)
-
-  } else {
-    return EFI_INVALID_PARAMETER;
-  }
-
-
-  EnableDmaChannel (2, &Dma4);
-  
-
-  //Set command argument based on the card access mode (Byte mode or Block mode)
-  if (gCardInfo.OCRData.AccessMode & BIT1) {
-    CmdArgument = Lba;
-  } else {
-    CmdArgument = Lba * This->Media->BlockSize;
-  }
-
-  //Send Command.
-  Status = SendCmd (Cmd, CmdInterruptEnable, CmdArgument);
-  if (EFI_ERROR (Status)) {
-    DEBUG ((EFI_D_ERROR, "CMD fails. Status: %x\n", Status));
-    return Status;
-  }
-
-    //Check for the Transfer completion.
-  while (RetryCount < MAX_RETRY_COUNT) {
-    //Read Status
-    do {
-      MmcStatus = MmioRead32 (MMCHS_STAT);
-    } while (MmcStatus == 0);
-
-    //Check if Transfer complete (TC) bit is set?
-    if (MmcStatus & TC) {
-      break;
-    } else {
-      DEBUG ((EFI_D_ERROR, "MmcStatus for TC: %x\n", MmcStatus));
-      //Check if DEB, DCRC or DTO interrupt occured.
-      if ((MmcStatus & DEB) | (MmcStatus & DCRC) | (MmcStatus & DTO)) {
-        //There was an error during the data transfer.
-
-        //Set SRD bit to 1 and wait until it return to 0x0.
-        MmioOr32 (MMCHS_SYSCTL, SRD);
-        while((MmioRead32 (MMCHS_SYSCTL) & SRD) != 0x0);
-
-        DisableDmaChannel (2, DMA4_CSR_BLOCK, DMA4_CSR_ERR);
-        DmaUnmap (BufferMap);
-        return EFI_DEVICE_ERROR;
-      }
-    }
-    RetryCount++;
-  } 
-
-  DisableDmaChannel (2, DMA4_CSR_BLOCK, DMA4_CSR_ERR);
-  Status = DmaUnmap (BufferMap);
-
-  if (RetryCount == MAX_RETRY_COUNT) {
-    DEBUG ((EFI_D_ERROR, "TransferBlockData timed out.\n"));
-    return EFI_TIMEOUT;
-  }
-
-  return Status;
-}
-
-
-EFI_STATUS
-TransferBlock (
-  IN EFI_BLOCK_IO_PROTOCOL        *This,
-  IN  UINTN                       Lba,
-  IN OUT VOID                     *Buffer,
-  IN  OPERATION_TYPE              OperationType
-  )
-{
-  EFI_STATUS Status;
-  UINTN      MmcStatus;
-  UINTN      RetryCount = 0;
-  UINTN      Cmd = 0;
-  UINTN      CmdInterruptEnable = 0;
-  UINTN      CmdArgument = 0;
-
-
-  //Populate the command information based on the operation type.
-  if (OperationType == READ) {
-    Cmd = CMD17; //Single block read
-    CmdInterruptEnable = CMD18_INT_EN;
-  } else if (OperationType == WRITE) { 
-    Cmd = CMD24; //Single block write
-    CmdInterruptEnable = CMD24_INT_EN;
-  }
-
-  //Set command argument based on the card access mode (Byte mode or Block mode)
-  if (gCardInfo.OCRData.AccessMode & BIT1) {
-    CmdArgument = Lba;
-  } else {
-    CmdArgument = Lba * This->Media->BlockSize;
-  }
-
-  //Send Command.
-  Status = SendCmd (Cmd, CmdInterruptEnable, CmdArgument);
-  if (EFI_ERROR(Status)) {
-    DEBUG ((EFI_D_ERROR, "CMD fails. Status: %x\n", Status));
-    return Status;
-  }
-
-  //Read or Write data.
-  if (OperationType == READ) {
-    Status = ReadBlockData (This, Buffer);
-    if (EFI_ERROR(Status)) {
-      DEBUG((EFI_D_ERROR, "ReadBlockData fails.\n"));
-      return Status;
-    }
-  } else if (OperationType == WRITE) {
-    Status = WriteBlockData (This, Buffer);
-    if (EFI_ERROR(Status)) {
-      DEBUG((EFI_D_ERROR, "WriteBlockData fails.\n"));
-      return Status;
-    }
-  }
-
-  //Check for the Transfer completion.
-  while (RetryCount < MAX_RETRY_COUNT) {
-    //Read Status
-    do {
-      MmcStatus = MmioRead32 (MMCHS_STAT);
-    } while (MmcStatus == 0);
-
-    //Check if Transfer complete (TC) bit is set?
-    if (MmcStatus & TC) {
-      break;
-    } else {
-      DEBUG ((EFI_D_ERROR, "MmcStatus for TC: %x\n", MmcStatus));
-      //Check if DEB, DCRC or DTO interrupt occured.
-      if ((MmcStatus & DEB) | (MmcStatus & DCRC) | (MmcStatus & DTO)) {
-        //There was an error during the data transfer.
-
-        //Set SRD bit to 1 and wait until it return to 0x0.
-        MmioOr32 (MMCHS_SYSCTL, SRD);
-        while((MmioRead32 (MMCHS_SYSCTL) & SRD) != 0x0);
-
-        return EFI_DEVICE_ERROR;
-      }
-    }
-    RetryCount++;
-  } 
-
-  if (RetryCount == MAX_RETRY_COUNT) {
-    DEBUG ((EFI_D_ERROR, "TransferBlockData timed out.\n"));
-    return EFI_TIMEOUT;
-  }
-
-  return EFI_SUCCESS;
-}
-
-BOOLEAN
-CardPresent (
-  VOID
-  )
-{
-  EFI_STATUS  Status;
-  UINT8       Data;
-
-  //
-  // Card detect is a GPIO0 on the TPS65950
-  //
-  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID2, GPIODATAIN1), 1, &Data);
-  if (EFI_ERROR (Status)) {
-    return FALSE;
-  }
-
-  if ((Data & CARD_DETECT_BIT) == CARD_DETECT_BIT) {
-    // No Card present
-    return FALSE;
-  } else {
-    return TRUE;
-  }
-}
-
-EFI_STATUS
-DetectCard (
-  VOID
-  )
-{
-  EFI_STATUS    Status;
-
-  if (!CardPresent ()) {
-    return EFI_NO_MEDIA;
-  }
-
-  //Initialize MMC host controller clocks.
-  Status = InitializeMMCHS ();
-  if (EFI_ERROR(Status)) {
-    DEBUG ((EFI_D_ERROR, "Initialize MMC host controller fails. Status: %x\n", Status));
-    return Status;
-  }
-
-  //Software reset of the MMCHS host controller.
-  MmioWrite32 (MMCHS_SYSCONFIG, SOFTRESET);
-  gBS->Stall(1000);
-  while ((MmioRead32 (MMCHS_SYSSTATUS) & RESETDONE_MASK) != RESETDONE);
-
-  //Soft reset for all.
-  MmioWrite32 (MMCHS_SYSCTL, SRA);
-  gBS->Stall(1000);
-  while ((MmioRead32 (MMCHS_SYSCTL) & SRA) != 0x0);
-
-  //Voltage capabilities initialization. Activate VS18 and VS30.
-  MmioOr32 (MMCHS_CAPA, (VS30 | VS18));
-
-  //Wakeup configuration
-  MmioOr32 (MMCHS_SYSCONFIG, ENAWAKEUP);
-  MmioOr32 (MMCHS_HCTL, IWE);
-
-  //MMCHS Controller default initialization
-  MmioOr32 (MMCHS_CON, (OD | DW8_1_4_BIT | CEATA_OFF));
-
-  MmioWrite32 (MMCHS_HCTL, (SDVS_3_0_V | DTW_1_BIT | SDBP_OFF));
-
-  //Enable internal clock
-  MmioOr32 (MMCHS_SYSCTL, ICE);
-
-  //Set the clock frequency to 80KHz.
-  UpdateMMCHSClkFrequency (CLKD_80KHZ);
-
-  //Enable SD bus power.
-  MmioOr32 (MMCHS_HCTL, (SDBP_ON));
-
-  //Poll till SD bus power bit is set.
-  while ((MmioRead32 (MMCHS_HCTL) & SDBP_MASK) != SDBP_ON);
-
-  //Card idenfication
-  Status = PerformCardIdenfication ();
-  if (EFI_ERROR(Status)) {
-    DEBUG ((EFI_D_ERROR, "No MMC/SD card detected.\n"));
-    return Status;
-  }
-  
-  //Get CSD (Card specific data) for the detected card.
-  Status = GetCardSpecificData();
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-  
-  //Configure the card in data transfer mode.
-  Status = PerformCardConfiguration();
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  //Patch the Media structure.
-  gMMCHSMedia.LastBlock    = (gCardInfo.NumBlocks - 1);
-  gMMCHSMedia.BlockSize    = gCardInfo.BlockSize;
-  gMMCHSMedia.ReadOnly     = (MmioRead32 (GPIO1_BASE + GPIO_DATAIN) & BIT23) == BIT23;
-  gMMCHSMedia.MediaPresent = TRUE; 
-  gMMCHSMedia.MediaId++; 
-
-  DEBUG ((EFI_D_INFO, "SD Card Media Change on Handle 0x%08x\n", gImageHandle));
-
-  return Status;
-}
-
-#define MAX_MMCHS_TRANSFER_SIZE  0x4000
-
-EFI_STATUS
-SdReadWrite (
-  IN EFI_BLOCK_IO_PROTOCOL    *This,
-  IN  UINTN                   Lba, 
-  OUT VOID                    *Buffer, 
-  IN  UINTN                   BufferSize,
-  IN  OPERATION_TYPE          OperationType
-  )
-{
-  EFI_STATUS Status = EFI_SUCCESS;
-  UINTN      RetryCount = 0;
-  UINTN      BlockCount;
-  UINTN      BytesToBeTranferedThisPass = 0;
-  UINTN      BytesRemainingToBeTransfered;
-  EFI_TPL    OldTpl;
-
-  BOOLEAN    Update;
-
-
-  
-  Update               = FALSE;
-
-  if (gMediaChange) {
-    Update = TRUE;
-    Status = DetectCard  ();
-    if (EFI_ERROR (Status)) {
-      // We detected a removal
-      gMMCHSMedia.MediaPresent = FALSE;
-      gMMCHSMedia.LastBlock    = 0;
-      gMMCHSMedia.BlockSize    = 512;  // Should be zero but there is a bug in DiskIo
-      gMMCHSMedia.ReadOnly     = FALSE; 
-    }
-    gMediaChange             = FALSE;
-  } else if (!gMMCHSMedia.MediaPresent) {
-    Status = EFI_NO_MEDIA;
-    goto Done;
-  }
-
-  if (Update) {
-    DEBUG ((EFI_D_INFO, "SD Card ReinstallProtocolInterface ()\n"));
-    gBS->ReinstallProtocolInterface (
-          gImageHandle,
-          &gEfiBlockIoProtocolGuid,
-          &gBlockIo,
-          &gBlockIo
-          );
-    return EFI_MEDIA_CHANGED;
-  }
-
-  if (EFI_ERROR (Status)) {
-    goto Done;
-  }
-
-  if (Buffer == NULL) {
-    Status = EFI_INVALID_PARAMETER;
-    goto Done;
-  }
-
-  if (Lba > This->Media->LastBlock) {
-    Status = EFI_INVALID_PARAMETER;
-    goto Done;
-  }
-  
-  if ((BufferSize % This->Media->BlockSize) != 0) {
-    Status = EFI_BAD_BUFFER_SIZE;
-    goto Done;
-  }
-
-  //Check if the data lines are not in use.
-  while ((RetryCount++ < MAX_RETRY_COUNT) && ((MmioRead32 (MMCHS_PSTATE) & DATI_MASK) != DATI_ALLOWED));
-  if (RetryCount == MAX_RETRY_COUNT) {
-    Status = EFI_TIMEOUT;
-    goto Done;
-  }
-
-  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
-
-  BytesRemainingToBeTransfered = BufferSize;
-  while (BytesRemainingToBeTransfered > 0) {
-
-    if (gMediaChange) {
-      Status = EFI_NO_MEDIA;
-      DEBUG ((EFI_D_INFO, "SdReadWrite() EFI_NO_MEDIA due to gMediaChange\n"));
-      goto DoneRestoreTPL;
-    }
-
-    // Turn OFF DMA path until it is debugged
-    // BytesToBeTranferedThisPass = (BytesToBeTranferedThisPass >= MAX_MMCHS_TRANSFER_SIZE) ? MAX_MMCHS_TRANSFER_SIZE : BytesRemainingToBeTransfered;
-    BytesToBeTranferedThisPass   = This->Media->BlockSize;
-
-    BlockCount = BytesToBeTranferedThisPass/This->Media->BlockSize;
-
-    if (BlockCount > 1) {
-      Status = DmaBlocks (This, Lba, Buffer, BlockCount, OperationType);
-    } else {
-      //Transfer a block worth of data.
-      Status = TransferBlock (This, Lba, Buffer, OperationType);
-    }
-
-    if (EFI_ERROR(Status)) {
-      DEBUG ((EFI_D_ERROR, "TransferBlockData fails. %x\n", Status));
-      goto DoneRestoreTPL;
-    }
-
-    BytesRemainingToBeTransfered -= BytesToBeTranferedThisPass;
-    Lba    += BlockCount;
-    Buffer = (UINT8 *)Buffer + This->Media->BlockSize;
-  }
-
-DoneRestoreTPL:
-
-  gBS->RestoreTPL (OldTpl);
-
-Done:
-
-  return Status;
-
-}
-
-
-/**
-
-  Reset the Block Device.
-
-
-
-  @param  This                 Indicates a pointer to the calling context.
-
-  @param  ExtendedVerification Driver may perform diagnostics on reset.
-
-
-
-  @retval EFI_SUCCESS          The device was reset.
-
-  @retval EFI_DEVICE_ERROR     The device is not functioning properly and could
-
-                               not be reset.
-
-
-
-**/
-EFI_STATUS
-EFIAPI
-MMCHSReset (
-  IN EFI_BLOCK_IO_PROTOCOL          *This,
-  IN BOOLEAN                        ExtendedVerification
-  )
-{
-  return EFI_SUCCESS; 
-}
-
-
-/**
-
-  Read BufferSize bytes from Lba into Buffer.
-
-
-
-  @param  This       Indicates a pointer to the calling context.
-
-  @param  MediaId    Id of the media, changes every time the media is replaced.
-
-  @param  Lba        The starting Logical Block Address to read from
-
-  @param  BufferSize Size of Buffer, must be a multiple of device block size.
-
-  @param  Buffer     A pointer to the destination buffer for the data. The caller is
-
-                     responsible for either having implicit or explicit ownership of the buffer.
-
-
-
-  @retval EFI_SUCCESS           The data was read correctly from the device.
-
-  @retval EFI_DEVICE_ERROR      The device reported an error while performing the read.
-
-  @retval EFI_NO_MEDIA          There is no media in the device.
-
-  @retval EFI_MEDIA_CHANGED     The MediaId does not matched the current device.
-
-  @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.
-
-  @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid, 
-
-                                or the buffer is not on proper alignment.
-
-EFI_STATUS
-
-**/
-EFI_STATUS
-EFIAPI
-MMCHSReadBlocks (
-  IN EFI_BLOCK_IO_PROTOCOL          *This,
-  IN UINT32                         MediaId,
-  IN EFI_LBA                        Lba,
-  IN UINTN                          BufferSize,
-  OUT VOID                          *Buffer
-  )
-{
-  EFI_STATUS Status;
-
-  //Perform Read operation.
-  Status = SdReadWrite (This, (UINTN)Lba, Buffer, BufferSize, READ);
-
-  return Status;
-
-}
-
-
-/**
-
-  Write BufferSize bytes from Lba into Buffer.
-
-
-
-  @param  This       Indicates a pointer to the calling context.
-
-  @param  MediaId    The media ID that the write request is for.
-
-  @param  Lba        The starting logical block address to be written. The caller is
-
-                     responsible for writing to only legitimate locations.
-
-  @param  BufferSize Size of Buffer, must be a multiple of device block size.
-
-  @param  Buffer     A pointer to the source buffer for the data.
-
-
-
-  @retval EFI_SUCCESS           The data was written correctly to the device.
-
-  @retval EFI_WRITE_PROTECTED   The device can not be written to.
-
-  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.
-
-  @retval EFI_NO_MEDIA          There is no media in the device.
-
-  @retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.
-
-  @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.
-
-  @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid, 
-
-                                or the buffer is not on proper alignment.
-
-
-
-**/
-EFI_STATUS
-EFIAPI
-MMCHSWriteBlocks (
-  IN EFI_BLOCK_IO_PROTOCOL          *This,
-  IN UINT32                         MediaId,
-  IN EFI_LBA                        Lba,
-  IN UINTN                          BufferSize,
-  IN VOID                           *Buffer
-  )
-{
-  EFI_STATUS  Status;
-
-  //Perform write operation.
-  Status = SdReadWrite (This, (UINTN)Lba, Buffer, BufferSize, WRITE);
-
-
-  return Status;
-
-}
-
-
-/**
-
-  Flush the Block Device.
-
-
-
-  @param  This              Indicates a pointer to the calling context.
-
-
-
-  @retval EFI_SUCCESS       All outstanding data was written to the device
-
-  @retval EFI_DEVICE_ERROR  The device reported an error while writting back the data
-
-  @retval EFI_NO_MEDIA      There is no media in the device.
-
-
-
-**/
-EFI_STATUS
-EFIAPI
-MMCHSFlushBlocks (
-  IN EFI_BLOCK_IO_PROTOCOL  *This
-  )
-{
-  return EFI_SUCCESS;
-}
-
-
-EFI_BLOCK_IO_PROTOCOL gBlockIo = {
-  EFI_BLOCK_IO_INTERFACE_REVISION,   // Revision
-  &gMMCHSMedia,                      // *Media
-  MMCHSReset,                        // Reset
-  MMCHSReadBlocks,                   // ReadBlocks
-  MMCHSWriteBlocks,                  // WriteBlocks
-  MMCHSFlushBlocks                   // FlushBlocks
-};
-
-
-/**
-
-  Timer callback to convert card present hardware into a boolean that indicates
-
-  a media change event has happened. If you just check the GPIO you could see 
-
-  card 1 and then check again after card 1 was removed and card 2 was inserted
-
-  and you would still see media present. Thus you need the timer tick to catch
-
-  the toggle event.
-
-
-
-  @param  Event                 Event whose notification function is being invoked.
-
-  @param  Context               The pointer to the notification function's context,
-
-                                which is implementation-dependent. Not used.
-
-
-
-**/
-VOID
-EFIAPI
-TimerCallback (
-  IN  EFI_EVENT   Event,
-  IN  VOID        *Context
-  )
-{
-  BOOLEAN Present;
-
-  Present = CardPresent ();
-  if (gMMCHSMedia.MediaPresent) {
-    if (!Present && !gMediaChange) {
-      gMediaChange = TRUE;
-    }
-  } else {
-    if (Present && !gMediaChange) {
-      gMediaChange = TRUE;    
-    }
-  }
-}
-
-
-EFI_STATUS
-EFIAPI
-MMCHSInitialize (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
-  )
-{
-  EFI_STATUS  Status;
-
-  Status = gBS->LocateProtocol (&gEmbeddedExternalDeviceProtocolGuid, NULL, (VOID **)&gTPS65950);
-  ASSERT_EFI_ERROR(Status);
-
-  ZeroMem (&gCardInfo, sizeof (CARD_INFO));
-
-  Status = gBS->CreateEvent (EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK, TimerCallback, NULL, &gTimerEvent);
-  ASSERT_EFI_ERROR (Status);
-  Status = gBS->SetTimer (gTimerEvent, TimerPeriodic, FixedPcdGet32 (PcdMmchsTimerFreq100NanoSeconds)); 
-  ASSERT_EFI_ERROR (Status);
-
-  //Publish BlockIO.
-  Status = gBS->InstallMultipleProtocolInterfaces (
-                  &ImageHandle, 
-                  &gEfiBlockIoProtocolGuid,    &gBlockIo, 
-                  &gEfiDevicePathProtocolGuid, &gMmcHsDevicePath,
-                  NULL
-                  );
-  return Status;
-}
+/** @file\r
+  MMC/SD Card driver for OMAP 35xx (SDIO not supported)\r
+\r
+  This driver always produces a BlockIo protocol but it starts off with no Media\r
+  present. A TimerCallBack detects when media is inserted or removed and after \r
+  a media change event a call to BlockIo ReadBlocks/WriteBlocks will cause the \r
+  media to be detected (or removed) and the BlockIo Media structure will get\r
+  updated. No MMC/SD Card harward registers are updated until the first BlockIo\r
+  ReadBlocks/WriteBlocks after media has been insterted (booting with a card \r
+  plugged in counts as an insertion event). \r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "MMCHS.h"\r
+\r
+EFI_BLOCK_IO_MEDIA gMMCHSMedia = {\r
+  SIGNATURE_32('s','d','i','o'),            // MediaId\r
+  TRUE,                                     // RemovableMedia\r
+  FALSE,                                    // MediaPresent\r
+  FALSE,                                    // LogicalPartition\r
+  FALSE,                                    // ReadOnly\r
+  FALSE,                                    // WriteCaching\r
+  512,                                      // BlockSize\r
+  4,                                        // IoAlign\r
+  0,                                        // Pad\r
+  0                                         // LastBlock\r
+};\r
+\r
+typedef struct {\r
+  VENDOR_DEVICE_PATH  Mmc;\r
+  EFI_DEVICE_PATH     End;\r
+} MMCHS_DEVICE_PATH;\r
+\r
+MMCHS_DEVICE_PATH gMmcHsDevicePath = {\r
+  {\r
+    HARDWARE_DEVICE_PATH,\r
+    HW_VENDOR_DP,\r
+    (UINT8)(sizeof(VENDOR_DEVICE_PATH)),\r
+    (UINT8)((sizeof(VENDOR_DEVICE_PATH)) >> 8),\r
+    0xb615f1f5, 0x5088, 0x43cd, 0x80, 0x9c, 0xa1, 0x6e, 0x52, 0x48, 0x7d, 0x00 \r
+  },\r
+  {\r
+    END_DEVICE_PATH_TYPE,\r
+    END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+    sizeof (EFI_DEVICE_PATH_PROTOCOL),\r
+    0\r
+  }\r
+};\r
+\r
+CARD_INFO                  gCardInfo;\r
+EMBEDDED_EXTERNAL_DEVICE   *gTPS65950;\r
+EFI_EVENT                  gTimerEvent;\r
+BOOLEAN                    gMediaChange = FALSE;\r
+\r
+//\r
+// Internal Functions\r
+//\r
+\r
+\r
+VOID\r
+ParseCardCIDData (\r
+  UINT32 Response0, \r
+  UINT32 Response1, \r
+  UINT32 Response2,\r
+  UINT32 Response3\r
+  )\r
+{\r
+  gCardInfo.CIDData.MDT = ((Response0 >> 8) & 0xFFF);\r
+  gCardInfo.CIDData.PSN = (((Response0 >> 24) & 0xFF) | ((Response1 & 0xFFFFFF) << 8));\r
+  gCardInfo.CIDData.PRV = ((Response1 >> 24) & 0xFF);\r
+  gCardInfo.CIDData.PNM[4] = ((Response2) & 0xFF);\r
+  gCardInfo.CIDData.PNM[3] = ((Response2 >> 8) & 0xFF);\r
+  gCardInfo.CIDData.PNM[2] = ((Response2 >> 16) & 0xFF);\r
+  gCardInfo.CIDData.PNM[1] = ((Response2 >> 24) & 0xFF);\r
+  gCardInfo.CIDData.PNM[0] = ((Response3) & 0xFF);\r
+  gCardInfo.CIDData.OID = ((Response3 >> 8) & 0xFFFF);\r
+  gCardInfo.CIDData.MID = ((Response3 >> 24) & 0xFF);\r
+}\r
+\r
+\r
+VOID\r
+UpdateMMCHSClkFrequency (\r
+  UINTN NewCLKD\r
+  )\r
+{\r
+  //Set Clock enable to 0x0 to not provide the clock to the card\r
+  MmioAnd32 (MMCHS_SYSCTL, ~CEN);\r
+\r
+  //Set new clock frequency.\r
+  MmioAndThenOr32 (MMCHS_SYSCTL, ~CLKD_MASK, NewCLKD << 6); \r
+\r
+  //Poll till Internal Clock Stable\r
+  while ((MmioRead32 (MMCHS_SYSCTL) & ICS_MASK) != ICS);\r
+\r
+  //Set Clock enable to 0x1 to provide the clock to the card\r
+  MmioOr32 (MMCHS_SYSCTL, CEN);\r
+}\r
+\r
+\r
+EFI_STATUS\r
+SendCmd (\r
+  UINTN Cmd,\r
+  UINTN CmdInterruptEnableVal,\r
+  UINTN CmdArgument\r
+  )\r
+{\r
+  UINTN MmcStatus;\r
+  UINTN RetryCount = 0;\r
+\r
+  //Check if command line is in use or not. Poll till command line is available.\r
+  while ((MmioRead32 (MMCHS_PSTATE) & DATI_MASK) == DATI_NOT_ALLOWED);\r
+\r
+  //Provide the block size.\r
+  MmioWrite32 (MMCHS_BLK, BLEN_512BYTES);\r
+\r
+  //Setting Data timeout counter value to max value.\r
+  MmioAndThenOr32 (MMCHS_SYSCTL, ~DTO_MASK, DTO_VAL);\r
+\r
+  //Clear Status register.\r
+  MmioWrite32 (MMCHS_STAT, 0xFFFFFFFF);\r
+\r
+  //Set command argument register\r
+  MmioWrite32 (MMCHS_ARG, CmdArgument);\r
+\r
+  //Enable interrupt enable events to occur\r
+  MmioWrite32 (MMCHS_IE, CmdInterruptEnableVal);\r
+\r
+  //Send a command\r
+  MmioWrite32 (MMCHS_CMD, Cmd);\r
+\r
+  //Check for the command status.\r
+  while (RetryCount < MAX_RETRY_COUNT) {\r
+    do {\r
+      MmcStatus = MmioRead32 (MMCHS_STAT);\r
+    } while (MmcStatus == 0);\r
+\r
+    //Read status of command response\r
+    if ((MmcStatus & ERRI) != 0) {\r
+\r
+      //Perform soft-reset for mmci_cmd line.\r
+      MmioOr32 (MMCHS_SYSCTL, SRC);\r
+      while ((MmioRead32 (MMCHS_SYSCTL) & SRC));\r
+\r
+      DEBUG ((EFI_D_INFO, "MmcStatus: %x\n", MmcStatus));\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+\r
+    //Check if command is completed.\r
+    if ((MmcStatus & CC) == CC) {\r
+      MmioWrite32 (MMCHS_STAT, CC);\r
+      break;\r
+    }\r
+\r
+    RetryCount++;\r
+  }\r
+\r
+  if (RetryCount == MAX_RETRY_COUNT) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+VOID\r
+GetBlockInformation (\r
+  UINTN *BlockSize,\r
+  UINTN *NumBlocks\r
+  )\r
+{\r
+  CSD_SDV2 *CsdSDV2Data;\r
+  UINTN    CardSize;\r
+\r
+  if (gCardInfo.CardType == SD_CARD_2_HIGH) {\r
+    CsdSDV2Data = (CSD_SDV2 *)&gCardInfo.CSDData;\r
+\r
+    //Populate BlockSize.\r
+    *BlockSize = (0x1UL << CsdSDV2Data->READ_BL_LEN);\r
+\r
+    //Calculate Total number of blocks.\r
+    CardSize = CsdSDV2Data->C_SIZELow16 | (CsdSDV2Data->C_SIZEHigh6 << 2);\r
+    *NumBlocks = ((CardSize + 1) * 1024);\r
+  } else {\r
+    //Populate BlockSize.\r
+    *BlockSize = (0x1UL << gCardInfo.CSDData.READ_BL_LEN);\r
+\r
+    //Calculate Total number of blocks.\r
+    CardSize = gCardInfo.CSDData.C_SIZELow2 | (gCardInfo.CSDData.C_SIZEHigh10 << 2);\r
+    *NumBlocks = (CardSize + 1) * (1 << (gCardInfo.CSDData.C_SIZE_MULT + 2));\r
+  }\r
+\r
+  //For >=2G card, BlockSize may be 1K, but the transfer size is 512 bytes.\r
+  if (*BlockSize > 512) {\r
+    *NumBlocks = MultU64x32(*NumBlocks, *BlockSize/2);\r
+    *BlockSize = 512;\r
+  }\r
+\r
+  DEBUG ((EFI_D_INFO, "Card type: %x, BlockSize: %x, NumBlocks: %x\n", gCardInfo.CardType, *BlockSize, *NumBlocks));\r
+}\r
+\r
+\r
+VOID\r
+CalculateCardCLKD (\r
+  UINTN *ClockFrequencySelect\r
+  )\r
+{\r
+  UINT8    MaxDataTransferRate;\r
+  UINTN    TransferRateValue = 0;\r
+  UINTN    TimeValue = 0 ;\r
+  UINTN    Frequency = 0;\r
+\r
+  MaxDataTransferRate = gCardInfo.CSDData.TRAN_SPEED;\r
+\r
+  // For SD Cards  we would need to send CMD6 to set\r
+  // speeds abouve 25MHz. High Speed mode 50 MHz and up\r
+\r
+  //Calculate Transfer rate unit (Bits 2:0 of TRAN_SPEED)\r
+  switch (MaxDataTransferRate & 0x7) {\r
+    case 0:\r
+      TransferRateValue = 100 * 1000;\r
+      break;\r
+\r
+    case 1:\r
+      TransferRateValue = 1 * 1000 * 1000;\r
+      break;\r
+\r
+    case 2:\r
+      TransferRateValue = 10 * 1000 * 1000;\r
+      break;\r
+\r
+    case 3:\r
+      TransferRateValue = 100 * 1000 * 1000;\r
+      break;\r
+\r
+    default:\r
+      DEBUG((EFI_D_ERROR, "Invalid parameter.\n"));\r
+      ASSERT(FALSE);\r
+  }\r
+\r
+  //Calculate Time value (Bits 6:3 of TRAN_SPEED)\r
+  switch ((MaxDataTransferRate >> 3) & 0xF) {\r
+    case 1:\r
+      TimeValue = 10;\r
+      break;\r
+\r
+    case 2:\r
+      TimeValue = 12;\r
+      break;\r
+\r
+    case 3:\r
+      TimeValue = 13;\r
+      break;\r
+\r
+    case 4:\r
+      TimeValue = 15;\r
+      break;\r
+\r
+    case 5:\r
+      TimeValue = 20;\r
+      break;\r
+\r
+    case 6:\r
+      TimeValue = 25;\r
+      break;\r
+\r
+    case 7:\r
+      TimeValue = 30;\r
+      break;\r
+\r
+    case 8:\r
+      TimeValue = 35;\r
+      break;\r
+\r
+    case 9:\r
+      TimeValue = 40;\r
+      break;\r
+\r
+    case 10:\r
+      TimeValue = 45;\r
+      break;\r
+\r
+    case 11:\r
+      TimeValue = 50;\r
+      break;\r
+\r
+    case 12:\r
+      TimeValue = 55;\r
+      break;\r
+\r
+    case 13:\r
+      TimeValue = 60;\r
+      break;\r
+\r
+    case 14:\r
+      TimeValue = 70;\r
+      break;\r
+\r
+    case 15:\r
+      TimeValue = 80;\r
+      break;\r
+\r
+    default:\r
+      DEBUG((EFI_D_ERROR, "Invalid parameter.\n"));\r
+      ASSERT(FALSE);\r
+  }\r
+\r
+  Frequency = TransferRateValue * TimeValue/10;\r
+\r
+  //Calculate Clock divider value to program in MMCHS_SYSCTL[CLKD] field.\r
+  *ClockFrequencySelect = ((MMC_REFERENCE_CLK/Frequency) + 1);\r
+\r
+  DEBUG ((EFI_D_INFO, "MaxDataTransferRate: 0x%x, Frequency: %d KHz, ClockFrequencySelect: %x\n", MaxDataTransferRate, Frequency/1000, *ClockFrequencySelect));\r
+}\r
+\r
+\r
+VOID\r
+GetCardConfigurationData (\r
+  VOID\r
+  )\r
+{\r
+  UINTN  BlockSize;\r
+  UINTN  NumBlocks;\r
+  UINTN  ClockFrequencySelect;\r
+\r
+  //Calculate BlockSize and Total number of blocks in the detected card.\r
+  GetBlockInformation(&BlockSize, &NumBlocks);\r
+  gCardInfo.BlockSize = BlockSize;\r
+  gCardInfo.NumBlocks = NumBlocks;\r
+\r
+  //Calculate Card clock divider value.\r
+  CalculateCardCLKD(&ClockFrequencySelect);\r
+  gCardInfo.ClockFrequencySelect = ClockFrequencySelect;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+InitializeMMCHS (\r
+  VOID\r
+  )\r
+{\r
+  UINT8      Data = 0;\r
+  EFI_STATUS Status;\r
+\r
+  //Select Device group to belong to P1 device group in Power IC.\r
+  Data = DEV_GRP_P1;\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VMMC1_DEV_GRP), 1, &Data);\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  //Configure voltage regulator for MMC1 in Power IC to output 3.0 voltage.\r
+  Data = VSEL_3_00V;\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VMMC1_DEDICATED_REG), 1, &Data);\r
+  ASSERT_EFI_ERROR(Status);\r
+  \r
+  //After ramping up voltage, set VDDS stable bit to indicate that voltage level is stable.\r
+  MmioOr32 (CONTROL_PBIAS_LITE, (PBIASLITEVMODE0 | PBIASLITEPWRDNZ0 | PBIASSPEEDCTRL0 | PBIASLITEVMODE1 | PBIASLITEWRDNZ1));\r
+\r
+  // Enable WP GPIO\r
+  MmioAndThenOr32 (GPIO1_BASE + GPIO_OE, ~BIT23, BIT23);\r
+\r
+  // Enable Card Detect\r
+  Data = CARD_DETECT_ENABLE;\r
+  gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID2, TPS65950_GPIO_CTRL), 1, &Data);\r
+\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+PerformCardIdenfication (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  UINTN      CmdArgument = 0;\r
+  UINTN      Response = 0;\r
+  UINTN      RetryCount = 0;\r
+  BOOLEAN    SDCmd8Supported = FALSE;\r
+\r
+  //Enable interrupts.\r
+  MmioWrite32 (MMCHS_IE, (BADA_EN | CERR_EN | DEB_EN | DCRC_EN | DTO_EN | CIE_EN |\r
+    CEB_EN | CCRC_EN | CTO_EN | BRR_EN | BWR_EN | TC_EN | CC_EN));\r
+\r
+  //Controller INIT procedure start.\r
+  MmioOr32 (MMCHS_CON, INIT);\r
+  MmioWrite32 (MMCHS_CMD, 0x00000000);\r
+  while (!(MmioRead32 (MMCHS_STAT) & CC));\r
+\r
+  //Wait for 1 ms\r
+  gBS->Stall(1000);\r
+\r
+  //Set CC bit to 0x1 to clear the flag\r
+  MmioOr32 (MMCHS_STAT, CC);\r
+\r
+  //Retry INIT procedure.\r
+  MmioWrite32 (MMCHS_CMD, 0x00000000);\r
+  while (!(MmioRead32 (MMCHS_STAT) & CC));\r
+\r
+  //End initialization sequence\r
+  MmioAnd32 (MMCHS_CON, ~INIT);\r
+\r
+  MmioOr32 (MMCHS_HCTL, (SDVS_3_0_V | DTW_1_BIT | SDBP_ON));\r
+\r
+  //Change clock frequency to 400KHz to fit protocol\r
+  UpdateMMCHSClkFrequency(CLKD_400KHZ);\r
+\r
+  MmioOr32 (MMCHS_CON, OD);\r
+\r
+  //Send CMD0 command.\r
+  Status = SendCmd (CMD0, CMD0_INT_EN, CmdArgument);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG ((EFI_D_ERROR, "Cmd0 fails.\n"));\r
+    return Status;\r
+  }\r
+\r
+  DEBUG ((EFI_D_INFO, "CMD0 response: %x\n", MmioRead32 (MMCHS_RSP10)));\r
+\r
+  //Send CMD5 command. \r
+  Status = SendCmd (CMD5, CMD5_INT_EN, CmdArgument);\r
+  if (Status == EFI_SUCCESS) {\r
+    DEBUG ((EFI_D_ERROR, "CMD5 Success. SDIO card. Follow SDIO card specification.\n"));\r
+    DEBUG ((EFI_D_INFO, "CMD5 response: %x\n", MmioRead32 (MMCHS_RSP10)));\r
+    //NOTE: Returning unsupported error for now. Need to implement SDIO specification.\r
+    return EFI_UNSUPPORTED; \r
+  } else {\r
+    DEBUG ((EFI_D_INFO, "CMD5 fails. Not an SDIO card.\n"));\r
+  }\r
+\r
+  MmioOr32 (MMCHS_SYSCTL, SRC);\r
+  gBS->Stall(1000);\r
+  while ((MmioRead32 (MMCHS_SYSCTL) & SRC));\r
+\r
+  //Send CMD8 command. (New v2.00 command for Voltage check)\r
+  //Only 2.7V - 3.6V is supported for SD2.0, only SD 2.0 card can pass.\r
+  //MMC & SD1.1 card will fail this command.\r
+  CmdArgument = CMD8_ARG;\r
+  Status = SendCmd (CMD8, CMD8_INT_EN, CmdArgument);\r
+  if (Status == EFI_SUCCESS) {\r
+    Response = MmioRead32 (MMCHS_RSP10);\r
+    DEBUG ((EFI_D_INFO, "CMD8 success. CMD8 response: %x\n", Response));\r
+    if (Response != CmdArgument) {\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+    DEBUG ((EFI_D_INFO, "Card is SD2.0\n"));\r
+    SDCmd8Supported = TRUE; //Supports high capacity.\r
+  } else {\r
+    DEBUG ((EFI_D_INFO, "CMD8 fails. Not an SD2.0 card.\n"));\r
+  }\r
+\r
+  MmioOr32 (MMCHS_SYSCTL, SRC);\r
+  gBS->Stall(1000);\r
+  while ((MmioRead32 (MMCHS_SYSCTL) & SRC));\r
+\r
+  //Poll till card is busy\r
+  while (RetryCount < MAX_RETRY_COUNT) {\r
+    //Send CMD55 command. \r
+    CmdArgument = 0;\r
+    Status = SendCmd (CMD55, CMD55_INT_EN, CmdArgument);\r
+    if (Status == EFI_SUCCESS) {\r
+      DEBUG ((EFI_D_INFO, "CMD55 success. CMD55 response: %x\n", MmioRead32 (MMCHS_RSP10)));\r
+      gCardInfo.CardType = SD_CARD;\r
+    } else {\r
+      DEBUG ((EFI_D_INFO, "CMD55 fails.\n"));\r
+      gCardInfo.CardType = MMC_CARD;\r
+    }\r
+\r
+    //Send appropriate command for the card type which got detected.\r
+    if (gCardInfo.CardType == SD_CARD) {\r
+      CmdArgument = ((UINTN *) &(gCardInfo.OCRData))[0];\r
+\r
+      //Set HCS bit.\r
+      if (SDCmd8Supported) {\r
+        CmdArgument |= HCS;\r
+      }\r
+\r
+      Status = SendCmd (ACMD41, ACMD41_INT_EN, CmdArgument);\r
+      if (EFI_ERROR(Status)) {\r
+        DEBUG ((EFI_D_INFO, "ACMD41 fails.\n"));\r
+        return Status;\r
+      }\r
+      ((UINT32 *) &(gCardInfo.OCRData))[0] = MmioRead32 (MMCHS_RSP10);\r
+      DEBUG ((EFI_D_INFO, "SD card detected. ACMD41 OCR: %x\n", ((UINT32 *) &(gCardInfo.OCRData))[0]));\r
+    } else if (gCardInfo.CardType == MMC_CARD) {\r
+      CmdArgument = 0;\r
+      Status = SendCmd (CMD1, CMD1_INT_EN, CmdArgument);\r
+      if (EFI_ERROR(Status)) {\r
+        DEBUG ((EFI_D_INFO, "CMD1 fails.\n"));\r
+        return Status;\r
+      }\r
+      Response = MmioRead32 (MMCHS_RSP10);\r
+      DEBUG ((EFI_D_INFO, "MMC card detected.. CMD1 response: %x\n", Response));\r
+\r
+      //NOTE: For now, I am skipping this since I only have an SD card.\r
+      //Compare card OCR and host OCR (Section 22.6.1.3.2.4)\r
+      return EFI_UNSUPPORTED; //For now, MMC is not supported.\r
+    }\r
+\r
+    //Poll the card until it is out of its power-up sequence.\r
+    if (gCardInfo.OCRData.Busy == 1) {\r
+\r
+      if (SDCmd8Supported) {\r
+        gCardInfo.CardType = SD_CARD_2;\r
+      }\r
+\r
+      //Card is ready. Check CCS (Card capacity status) bit (bit#30).\r
+      //SD 2.0 standard card will response with CCS 0, SD high capacity card will respond with CCS 1.\r
+      if (gCardInfo.OCRData.AccessMode & BIT1) {\r
+        gCardInfo.CardType = SD_CARD_2_HIGH;\r
+        DEBUG ((EFI_D_INFO, "High capacity card.\n"));\r
+      } else {\r
+        DEBUG ((EFI_D_INFO, "Standard capacity card.\n"));\r
+      }\r
+\r
+      break;\r
+    }\r
+\r
+    gBS->Stall(1000);\r
+    RetryCount++;\r
+  }\r
+\r
+  if (RetryCount == MAX_RETRY_COUNT) {\r
+    DEBUG ((EFI_D_ERROR, "Timeout error. RetryCount: %d\n", RetryCount));\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  //Read CID data.\r
+  CmdArgument = 0;\r
+  Status = SendCmd (CMD2, CMD2_INT_EN, CmdArgument);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG ((EFI_D_ERROR, "CMD2 fails. Status: %x\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  DEBUG ((EFI_D_INFO, "CMD2 response: %x %x %x %x\n", MmioRead32 (MMCHS_RSP10), MmioRead32 (MMCHS_RSP32), MmioRead32 (MMCHS_RSP54), MmioRead32 (MMCHS_RSP76)));\r
+\r
+  //Parse CID register data.\r
+  ParseCardCIDData(MmioRead32 (MMCHS_RSP10), MmioRead32 (MMCHS_RSP32), MmioRead32 (MMCHS_RSP54), MmioRead32 (MMCHS_RSP76));\r
+\r
+  //Read RCA\r
+  CmdArgument = 0;\r
+  Status = SendCmd (CMD3, CMD3_INT_EN, CmdArgument);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG ((EFI_D_ERROR, "CMD3 fails. Status: %x\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  //Set RCA for the detected card. RCA is CMD3 response.\r
+  gCardInfo.RCA = (MmioRead32 (MMCHS_RSP10) >> 16);\r
+  DEBUG ((EFI_D_INFO, "CMD3 response: RCA %x\n", gCardInfo.RCA));\r
+\r
+  //MMC Bus setting change after card identification.\r
+  MmioAnd32 (MMCHS_CON, ~OD);\r
+  MmioOr32 (MMCHS_HCTL, SDVS_3_0_V);\r
+  UpdateMMCHSClkFrequency(CLKD_400KHZ); //Set the clock frequency to 400KHz.\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+GetCardSpecificData (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  UINTN      CmdArgument;\r
+\r
+  //Send CMD9 to retrieve CSD.\r
+  CmdArgument = gCardInfo.RCA << 16;\r
+  Status = SendCmd (CMD9, CMD9_INT_EN, CmdArgument);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG ((EFI_D_ERROR, "CMD9 fails. Status: %x\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  //Populate 128-bit CSD register data.\r
+  ((UINT32 *)&(gCardInfo.CSDData))[0] = MmioRead32 (MMCHS_RSP10);\r
+  ((UINT32 *)&(gCardInfo.CSDData))[1] = MmioRead32 (MMCHS_RSP32);\r
+  ((UINT32 *)&(gCardInfo.CSDData))[2] = MmioRead32 (MMCHS_RSP54);\r
+  ((UINT32 *)&(gCardInfo.CSDData))[3] = MmioRead32 (MMCHS_RSP76);\r
+\r
+  DEBUG ((EFI_D_INFO, "CMD9 response: %x %x %x %x\n", MmioRead32 (MMCHS_RSP10), MmioRead32 (MMCHS_RSP32), MmioRead32 (MMCHS_RSP54), MmioRead32 (MMCHS_RSP76)));\r
+\r
+  //Calculate total number of blocks and max. data transfer rate supported by the detected card.\r
+  GetCardConfigurationData();\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+PerformCardConfiguration (\r
+  VOID\r
+  )\r
+{\r
+  UINTN      CmdArgument = 0;\r
+  EFI_STATUS Status;\r
+\r
+  //Send CMD7\r
+  CmdArgument = gCardInfo.RCA << 16;\r
+  Status = SendCmd (CMD7, CMD7_INT_EN, CmdArgument);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG ((EFI_D_ERROR, "CMD7 fails. Status: %x\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  if ((gCardInfo.CardType != UNKNOWN_CARD) && (gCardInfo.CardType != MMC_CARD)) {\r
+    // We could read SCR register, but SD Card Phys spec stats any SD Card shall\r
+    // set SCR.SD_BUS_WIDTHS to support 4-bit mode, so why bother?\r
\r
+    // Send ACMD6 (application specific commands must be prefixed with CMD55)\r
+    Status = SendCmd (CMD55, CMD55_INT_EN, CmdArgument);\r
+    if (!EFI_ERROR (Status)) {\r
+      // set device into 4-bit data bus mode\r
+      Status = SendCmd (ACMD6, ACMD6_INT_EN, 0x2);\r
+      if (!EFI_ERROR (Status)) {\r
+        // Set host controler into 4-bit mode\r
+        MmioOr32 (MMCHS_HCTL, DTW_4_BIT);\r
+        DEBUG ((EFI_D_INFO, "SD Memory Card set to 4-bit mode\n"));\r
+      }\r
+    }\r
+  }\r
+\r
+  //Send CMD16 to set the block length\r
+  CmdArgument = gCardInfo.BlockSize;\r
+  Status = SendCmd (CMD16, CMD16_INT_EN, CmdArgument);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG ((EFI_D_ERROR, "CMD16 fails. Status: %x\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  //Change MMCHS clock frequency to what detected card can support.\r
+  UpdateMMCHSClkFrequency(gCardInfo.ClockFrequencySelect);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+ReadBlockData (\r
+  IN  EFI_BLOCK_IO_PROTOCOL       *This,\r
+  OUT VOID                        *Buffer\r
+  )\r
+{\r
+  UINTN MmcStatus;\r
+  UINTN *DataBuffer = Buffer;\r
+  UINTN DataSize = This->Media->BlockSize/4;\r
+  UINTN Count;\r
+  UINTN RetryCount = 0;\r
+\r
+  //Check controller status to make sure there is no error.\r
+  while (RetryCount < MAX_RETRY_COUNT) {\r
+    do {\r
+      //Read Status.\r
+      MmcStatus = MmioRead32 (MMCHS_STAT);\r
+    } while(MmcStatus == 0);\r
+\r
+    //Check if Buffer read ready (BRR) bit is set?\r
+    if (MmcStatus & BRR) {\r
+\r
+      //Clear BRR bit\r
+      MmioOr32 (MMCHS_STAT, BRR);\r
+\r
+      //Read block worth of data.\r
+      for (Count = 0; Count < DataSize; Count++) {\r
+        *DataBuffer++ = MmioRead32 (MMCHS_DATA);\r
+      }\r
+      break;\r
+    }\r
+    RetryCount++;\r
+  }\r
+\r
+  if (RetryCount == MAX_RETRY_COUNT) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+WriteBlockData (\r
+  IN  EFI_BLOCK_IO_PROTOCOL       *This,\r
+  OUT VOID                        *Buffer\r
+  )\r
+{\r
+  UINTN MmcStatus;\r
+  UINTN *DataBuffer = Buffer;\r
+  UINTN DataSize = This->Media->BlockSize/4;\r
+  UINTN Count;\r
+  UINTN RetryCount = 0;\r
+\r
+  //Check controller status to make sure there is no error.\r
+  while (RetryCount < MAX_RETRY_COUNT) {\r
+    do {\r
+      //Read Status.\r
+      MmcStatus = MmioRead32 (MMCHS_STAT);\r
+    } while(MmcStatus == 0);\r
+\r
+    //Check if Buffer write ready (BWR) bit is set?\r
+    if (MmcStatus & BWR) {\r
+\r
+      //Clear BWR bit\r
+      MmioOr32 (MMCHS_STAT, BWR);\r
+\r
+      //Write block worth of data.\r
+      for (Count = 0; Count < DataSize; Count++) {\r
+        MmioWrite32 (MMCHS_DATA, *DataBuffer++);\r
+      }\r
+\r
+      break;\r
+    }\r
+    RetryCount++;\r
+  }\r
+\r
+  if (RetryCount == MAX_RETRY_COUNT) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+DmaBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL        *This,\r
+  IN  UINTN                       Lba,\r
+  IN OUT VOID                     *Buffer,\r
+  IN  UINTN                       BlockCount,\r
+  IN  OPERATION_TYPE              OperationType\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  UINTN                 DmaSize = 0;\r
+  UINTN                 Cmd = 0;\r
+  UINTN                 CmdInterruptEnable;\r
+  UINTN                 CmdArgument;\r
+  VOID                  *BufferMap;\r
+  EFI_PHYSICAL_ADDRESS  BufferAddress;\r
+  OMAP_DMA4             Dma4;\r
+  DMA_MAP_OPERATION     DmaOperation;\r
+  EFI_STATUS            MmcStatus;\r
+  UINTN                 RetryCount = 0;\r
+\r
+CpuDeadLoop ();\r
+  // Map passed in buffer for DMA xfer\r
+  DmaSize = BlockCount * This->Media->BlockSize;\r
+  Status = DmaMap (DmaOperation, Buffer, &DmaSize, &BufferAddress, &BufferMap);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  ZeroMem (&DmaOperation, sizeof (DMA_MAP_OPERATION));\r
+  \r
+\r
+  Dma4.DataType = 2;                      // DMA4_CSDPi[1:0]   32-bit elements from MMCHS_DATA\r
+\r
+  Dma4.SourceEndiansim = 0;               // DMA4_CSDPi[21]    \r
+\r
+  Dma4.DestinationEndianism = 0;          // DMA4_CSDPi[19]\r
+\r
+  Dma4.SourcePacked = 0;                  // DMA4_CSDPi[6]\r
+\r
+  Dma4.DestinationPacked = 0;             // DMA4_CSDPi[13]\r
+\r
+  Dma4.NumberOfElementPerFrame = This->Media->BlockSize/4; // DMA4_CENi  (TRM 4K is optimum value)  \r
+\r
+  Dma4.NumberOfFramePerTransferBlock = BlockCount;         // DMA4_CFNi    \r
+\r
+  Dma4.ReadPriority = 0;                  // DMA4_CCRi[6]      Low priority read  \r
+\r
+  Dma4.WritePriority = 0;                 // DMA4_CCRi[23]     Prefetech disabled\r
+\r
+\r
+  //Populate the command information based on the operation type.\r
+  if (OperationType == READ) {\r
+    Cmd = CMD18; //Multiple block read\r
+    CmdInterruptEnable = CMD18_INT_EN;\r
+    DmaOperation = MapOperationBusMasterCommonBuffer;\r
+\r
+    Dma4.ReadPortAccessType =0 ;            // DMA4_CSDPi[8:7]   Can not burst MMCHS_DATA reg\r
+\r
+    Dma4.WritePortAccessType = 3;           // DMA4_CSDPi[15:14] Memory burst 16x32\r
+\r
+    Dma4.WriteMode = 1;                     // DMA4_CSDPi[17:16] Write posted\r
+\r
+    \r
+\r
+    Dma4.SourceStartAddress = MMCHS_DATA;                   // DMA4_CSSAi\r
+\r
+    Dma4.DestinationStartAddress = (UINT32)BufferAddress;   // DMA4_CDSAi\r
+\r
+    Dma4.SourceElementIndex = 1;                            // DMA4_CSEi\r
+\r
+    Dma4.SourceFrameIndex = 0x200;                          // DMA4_CSFi\r
+\r
+    Dma4.DestinationElementIndex = 1;                       // DMA4_CDEi\r
+\r
+    Dma4.DestinationFrameIndex = 0;                         // DMA4_CDFi\r
+\r
+\r
+\r
+    Dma4.ReadPortAccessMode = 0;            // DMA4_CCRi[13:12]  Always read MMCHS_DATA\r
+\r
+    Dma4.WritePortAccessMode = 1;           // DMA4_CCRi[15:14]  Post increment memory address\r
+\r
+    Dma4.ReadRequestNumber = 0x1e;          // DMA4_CCRi[4:0]    Syncro with MMCA_DMA_RX (61)  \r
+\r
+    Dma4.WriteRequestNumber = 1;            // DMA4_CCRi[20:19]  Syncro upper 0x3e == 62 (one based)\r
+\r
+  } else if (OperationType == WRITE) { \r
+    Cmd = CMD25; //Multiple block write\r
+    CmdInterruptEnable = CMD25_INT_EN;\r
+    DmaOperation = MapOperationBusMasterRead;\r
+\r
+    Dma4.ReadPortAccessType = 3;            // DMA4_CSDPi[8:7]   Memory burst 16x32\r
+\r
+    Dma4.WritePortAccessType = 0;           // DMA4_CSDPi[15:14] Can not burst MMCHS_DATA reg\r
+\r
+    Dma4.WriteMode = 1;                     // DMA4_CSDPi[17:16] Write posted ???\r
+\r
+    \r
+\r
+    Dma4.SourceStartAddress = (UINT32)BufferAddress;        // DMA4_CSSAi\r
+\r
+    Dma4.DestinationStartAddress = MMCHS_DATA;              // DMA4_CDSAi\r
+\r
+    Dma4.SourceElementIndex = 1;                            // DMA4_CSEi\r
+\r
+    Dma4.SourceFrameIndex = 0x200;                          // DMA4_CSFi\r
+\r
+    Dma4.DestinationElementIndex = 1;                       // DMA4_CDEi\r
+\r
+    Dma4.DestinationFrameIndex = 0;                         // DMA4_CDFi\r
+\r
+\r
+\r
+    Dma4.ReadPortAccessMode = 1;            // DMA4_CCRi[13:12]  Post increment memory address\r
+\r
+    Dma4.WritePortAccessMode = 0;           // DMA4_CCRi[15:14]  Always write MMCHS_DATA\r
+\r
+    Dma4.ReadRequestNumber = 0x1d;          // DMA4_CCRi[4:0]    Syncro with MMCA_DMA_TX (60)  \r
+\r
+    Dma4.WriteRequestNumber = 1;            // DMA4_CCRi[20:19]  Syncro upper 0x3d == 61 (one based)\r
+\r
+  } else {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+\r
+  EnableDmaChannel (2, &Dma4);\r
+  \r
+\r
+  //Set command argument based on the card access mode (Byte mode or Block mode)\r
+  if (gCardInfo.OCRData.AccessMode & BIT1) {\r
+    CmdArgument = Lba;\r
+  } else {\r
+    CmdArgument = Lba * This->Media->BlockSize;\r
+  }\r
+\r
+  //Send Command.\r
+  Status = SendCmd (Cmd, CmdInterruptEnable, CmdArgument);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "CMD fails. Status: %x\n", Status));\r
+    return Status;\r
+  }\r
+\r
+    //Check for the Transfer completion.\r
+  while (RetryCount < MAX_RETRY_COUNT) {\r
+    //Read Status\r
+    do {\r
+      MmcStatus = MmioRead32 (MMCHS_STAT);\r
+    } while (MmcStatus == 0);\r
+\r
+    //Check if Transfer complete (TC) bit is set?\r
+    if (MmcStatus & TC) {\r
+      break;\r
+    } else {\r
+      DEBUG ((EFI_D_ERROR, "MmcStatus for TC: %x\n", MmcStatus));\r
+      //Check if DEB, DCRC or DTO interrupt occured.\r
+      if ((MmcStatus & DEB) | (MmcStatus & DCRC) | (MmcStatus & DTO)) {\r
+        //There was an error during the data transfer.\r
+\r
+        //Set SRD bit to 1 and wait until it return to 0x0.\r
+        MmioOr32 (MMCHS_SYSCTL, SRD);\r
+        while((MmioRead32 (MMCHS_SYSCTL) & SRD) != 0x0);\r
+\r
+        DisableDmaChannel (2, DMA4_CSR_BLOCK, DMA4_CSR_ERR);\r
+        DmaUnmap (BufferMap);\r
+        return EFI_DEVICE_ERROR;\r
+      }\r
+    }\r
+    RetryCount++;\r
+  } \r
+\r
+  DisableDmaChannel (2, DMA4_CSR_BLOCK, DMA4_CSR_ERR);\r
+  Status = DmaUnmap (BufferMap);\r
+\r
+  if (RetryCount == MAX_RETRY_COUNT) {\r
+    DEBUG ((EFI_D_ERROR, "TransferBlockData timed out.\n"));\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+TransferBlock (\r
+  IN EFI_BLOCK_IO_PROTOCOL        *This,\r
+  IN  UINTN                       Lba,\r
+  IN OUT VOID                     *Buffer,\r
+  IN  OPERATION_TYPE              OperationType\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  UINTN      MmcStatus;\r
+  UINTN      RetryCount = 0;\r
+  UINTN      Cmd = 0;\r
+  UINTN      CmdInterruptEnable = 0;\r
+  UINTN      CmdArgument = 0;\r
+\r
+\r
+  //Populate the command information based on the operation type.\r
+  if (OperationType == READ) {\r
+    Cmd = CMD17; //Single block read\r
+    CmdInterruptEnable = CMD18_INT_EN;\r
+  } else if (OperationType == WRITE) { \r
+    Cmd = CMD24; //Single block write\r
+    CmdInterruptEnable = CMD24_INT_EN;\r
+  }\r
+\r
+  //Set command argument based on the card access mode (Byte mode or Block mode)\r
+  if (gCardInfo.OCRData.AccessMode & BIT1) {\r
+    CmdArgument = Lba;\r
+  } else {\r
+    CmdArgument = Lba * This->Media->BlockSize;\r
+  }\r
+\r
+  //Send Command.\r
+  Status = SendCmd (Cmd, CmdInterruptEnable, CmdArgument);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG ((EFI_D_ERROR, "CMD fails. Status: %x\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  //Read or Write data.\r
+  if (OperationType == READ) {\r
+    Status = ReadBlockData (This, Buffer);\r
+    if (EFI_ERROR(Status)) {\r
+      DEBUG((EFI_D_ERROR, "ReadBlockData fails.\n"));\r
+      return Status;\r
+    }\r
+  } else if (OperationType == WRITE) {\r
+    Status = WriteBlockData (This, Buffer);\r
+    if (EFI_ERROR(Status)) {\r
+      DEBUG((EFI_D_ERROR, "WriteBlockData fails.\n"));\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  //Check for the Transfer completion.\r
+  while (RetryCount < MAX_RETRY_COUNT) {\r
+    //Read Status\r
+    do {\r
+      MmcStatus = MmioRead32 (MMCHS_STAT);\r
+    } while (MmcStatus == 0);\r
+\r
+    //Check if Transfer complete (TC) bit is set?\r
+    if (MmcStatus & TC) {\r
+      break;\r
+    } else {\r
+      DEBUG ((EFI_D_ERROR, "MmcStatus for TC: %x\n", MmcStatus));\r
+      //Check if DEB, DCRC or DTO interrupt occured.\r
+      if ((MmcStatus & DEB) | (MmcStatus & DCRC) | (MmcStatus & DTO)) {\r
+        //There was an error during the data transfer.\r
+\r
+        //Set SRD bit to 1 and wait until it return to 0x0.\r
+        MmioOr32 (MMCHS_SYSCTL, SRD);\r
+        while((MmioRead32 (MMCHS_SYSCTL) & SRD) != 0x0);\r
+\r
+        return EFI_DEVICE_ERROR;\r
+      }\r
+    }\r
+    RetryCount++;\r
+  } \r
+\r
+  if (RetryCount == MAX_RETRY_COUNT) {\r
+    DEBUG ((EFI_D_ERROR, "TransferBlockData timed out.\n"));\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+BOOLEAN\r
+CardPresent (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       Data;\r
+\r
+  //\r
+  // Card detect is a GPIO0 on the TPS65950\r
+  //\r
+  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID2, GPIODATAIN1), 1, &Data);\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+\r
+  if ((Data & CARD_DETECT_BIT) == CARD_DETECT_BIT) {\r
+    // No Card present\r
+    return FALSE;\r
+  } else {\r
+    return TRUE;\r
+  }\r
+}\r
+\r
+EFI_STATUS\r
+DetectCard (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+\r
+  if (!CardPresent ()) {\r
+    return EFI_NO_MEDIA;\r
+  }\r
+\r
+  //Initialize MMC host controller clocks.\r
+  Status = InitializeMMCHS ();\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG ((EFI_D_ERROR, "Initialize MMC host controller fails. Status: %x\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  //Software reset of the MMCHS host controller.\r
+  MmioWrite32 (MMCHS_SYSCONFIG, SOFTRESET);\r
+  gBS->Stall(1000);\r
+  while ((MmioRead32 (MMCHS_SYSSTATUS) & RESETDONE_MASK) != RESETDONE);\r
+\r
+  //Soft reset for all.\r
+  MmioWrite32 (MMCHS_SYSCTL, SRA);\r
+  gBS->Stall(1000);\r
+  while ((MmioRead32 (MMCHS_SYSCTL) & SRA) != 0x0);\r
+\r
+  //Voltage capabilities initialization. Activate VS18 and VS30.\r
+  MmioOr32 (MMCHS_CAPA, (VS30 | VS18));\r
+\r
+  //Wakeup configuration\r
+  MmioOr32 (MMCHS_SYSCONFIG, ENAWAKEUP);\r
+  MmioOr32 (MMCHS_HCTL, IWE);\r
+\r
+  //MMCHS Controller default initialization\r
+  MmioOr32 (MMCHS_CON, (OD | DW8_1_4_BIT | CEATA_OFF));\r
+\r
+  MmioWrite32 (MMCHS_HCTL, (SDVS_3_0_V | DTW_1_BIT | SDBP_OFF));\r
+\r
+  //Enable internal clock\r
+  MmioOr32 (MMCHS_SYSCTL, ICE);\r
+\r
+  //Set the clock frequency to 80KHz.\r
+  UpdateMMCHSClkFrequency (CLKD_80KHZ);\r
+\r
+  //Enable SD bus power.\r
+  MmioOr32 (MMCHS_HCTL, (SDBP_ON));\r
+\r
+  //Poll till SD bus power bit is set.\r
+  while ((MmioRead32 (MMCHS_HCTL) & SDBP_MASK) != SDBP_ON);\r
+\r
+  //Card idenfication\r
+  Status = PerformCardIdenfication ();\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG ((EFI_D_ERROR, "No MMC/SD card detected.\n"));\r
+    return Status;\r
+  }\r
+  \r
+  //Get CSD (Card specific data) for the detected card.\r
+  Status = GetCardSpecificData();\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+  \r
+  //Configure the card in data transfer mode.\r
+  Status = PerformCardConfiguration();\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //Patch the Media structure.\r
+  gMMCHSMedia.LastBlock    = (gCardInfo.NumBlocks - 1);\r
+  gMMCHSMedia.BlockSize    = gCardInfo.BlockSize;\r
+  gMMCHSMedia.ReadOnly     = (MmioRead32 (GPIO1_BASE + GPIO_DATAIN) & BIT23) == BIT23;\r
+  gMMCHSMedia.MediaPresent = TRUE; \r
+  gMMCHSMedia.MediaId++; \r
+\r
+  DEBUG ((EFI_D_INFO, "SD Card Media Change on Handle 0x%08x\n", gImageHandle));\r
+\r
+  return Status;\r
+}\r
+\r
+#define MAX_MMCHS_TRANSFER_SIZE  0x4000\r
+\r
+EFI_STATUS\r
+SdReadWrite (\r
+  IN EFI_BLOCK_IO_PROTOCOL    *This,\r
+  IN  UINTN                   Lba, \r
+  OUT VOID                    *Buffer, \r
+  IN  UINTN                   BufferSize,\r
+  IN  OPERATION_TYPE          OperationType\r
+  )\r
+{\r
+  EFI_STATUS Status = EFI_SUCCESS;\r
+  UINTN      RetryCount = 0;\r
+  UINTN      BlockCount;\r
+  UINTN      BytesToBeTranferedThisPass = 0;\r
+  UINTN      BytesRemainingToBeTransfered;\r
+  EFI_TPL    OldTpl;\r
+\r
+  BOOLEAN    Update;\r
+\r
+\r
+  \r
+  Update               = FALSE;\r
+\r
+  if (gMediaChange) {\r
+    Update = TRUE;\r
+    Status = DetectCard  ();\r
+    if (EFI_ERROR (Status)) {\r
+      // We detected a removal\r
+      gMMCHSMedia.MediaPresent = FALSE;\r
+      gMMCHSMedia.LastBlock    = 0;\r
+      gMMCHSMedia.BlockSize    = 512;  // Should be zero but there is a bug in DiskIo\r
+      gMMCHSMedia.ReadOnly     = FALSE; \r
+    }\r
+    gMediaChange             = FALSE;\r
+  } else if (!gMMCHSMedia.MediaPresent) {\r
+    Status = EFI_NO_MEDIA;\r
+    goto Done;\r
+  }\r
+\r
+  if (Update) {\r
+    DEBUG ((EFI_D_INFO, "SD Card ReinstallProtocolInterface ()\n"));\r
+    gBS->ReinstallProtocolInterface (\r
+          gImageHandle,\r
+          &gEfiBlockIoProtocolGuid,\r
+          &gBlockIo,\r
+          &gBlockIo\r
+          );\r
+    return EFI_MEDIA_CHANGED;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  if (Buffer == NULL) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto Done;\r
+  }\r
+\r
+  if (Lba > This->Media->LastBlock) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto Done;\r
+  }\r
+  \r
+  if ((BufferSize % This->Media->BlockSize) != 0) {\r
+    Status = EFI_BAD_BUFFER_SIZE;\r
+    goto Done;\r
+  }\r
+\r
+  //Check if the data lines are not in use.\r
+  while ((RetryCount++ < MAX_RETRY_COUNT) && ((MmioRead32 (MMCHS_PSTATE) & DATI_MASK) != DATI_ALLOWED));\r
+  if (RetryCount == MAX_RETRY_COUNT) {\r
+    Status = EFI_TIMEOUT;\r
+    goto Done;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  BytesRemainingToBeTransfered = BufferSize;\r
+  while (BytesRemainingToBeTransfered > 0) {\r
+\r
+    if (gMediaChange) {\r
+      Status = EFI_NO_MEDIA;\r
+      DEBUG ((EFI_D_INFO, "SdReadWrite() EFI_NO_MEDIA due to gMediaChange\n"));\r
+      goto DoneRestoreTPL;\r
+    }\r
+\r
+    // Turn OFF DMA path until it is debugged\r
+    // BytesToBeTranferedThisPass = (BytesToBeTranferedThisPass >= MAX_MMCHS_TRANSFER_SIZE) ? MAX_MMCHS_TRANSFER_SIZE : BytesRemainingToBeTransfered;\r
+    BytesToBeTranferedThisPass   = This->Media->BlockSize;\r
+\r
+    BlockCount = BytesToBeTranferedThisPass/This->Media->BlockSize;\r
+\r
+    if (BlockCount > 1) {\r
+      Status = DmaBlocks (This, Lba, Buffer, BlockCount, OperationType);\r
+    } else {\r
+      //Transfer a block worth of data.\r
+      Status = TransferBlock (This, Lba, Buffer, OperationType);\r
+    }\r
+\r
+    if (EFI_ERROR(Status)) {\r
+      DEBUG ((EFI_D_ERROR, "TransferBlockData fails. %x\n", Status));\r
+      goto DoneRestoreTPL;\r
+    }\r
+\r
+    BytesRemainingToBeTransfered -= BytesToBeTranferedThisPass;\r
+    Lba    += BlockCount;\r
+    Buffer = (UINT8 *)Buffer + This->Media->BlockSize;\r
+  }\r
+\r
+DoneRestoreTPL:\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+Done:\r
+\r
+  return Status;\r
+\r
+}\r
+\r
+\r
+/**\r
+\r
+  Reset the Block Device.\r
+\r
+\r
+\r
+  @param  This                 Indicates a pointer to the calling context.\r
+\r
+  @param  ExtendedVerification Driver may perform diagnostics on reset.\r
+\r
+\r
+\r
+  @retval EFI_SUCCESS          The device was reset.\r
+\r
+  @retval EFI_DEVICE_ERROR     The device is not functioning properly and could\r
+\r
+                               not be reset.\r
+\r
+\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MMCHSReset (\r
+  IN EFI_BLOCK_IO_PROTOCOL          *This,\r
+  IN BOOLEAN                        ExtendedVerification\r
+  )\r
+{\r
+  return EFI_SUCCESS; \r
+}\r
+\r
+\r
+/**\r
+\r
+  Read BufferSize bytes from Lba into Buffer.\r
+\r
+\r
+\r
+  @param  This       Indicates a pointer to the calling context.\r
+\r
+  @param  MediaId    Id of the media, changes every time the media is replaced.\r
+\r
+  @param  Lba        The starting Logical Block Address to read from\r
+\r
+  @param  BufferSize Size of Buffer, must be a multiple of device block size.\r
+\r
+  @param  Buffer     A pointer to the destination buffer for the data. The caller is\r
+\r
+                     responsible for either having implicit or explicit ownership of the buffer.\r
+\r
+\r
+\r
+  @retval EFI_SUCCESS           The data was read correctly from the device.\r
+\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the read.\r
+\r
+  @retval EFI_NO_MEDIA          There is no media in the device.\r
+\r
+  @retval EFI_MEDIA_CHANGED     The MediaId does not matched the current device.\r
+\r
+  @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
+\r
+  @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid, \r
+\r
+                                or the buffer is not on proper alignment.\r
+\r
+EFI_STATUS\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MMCHSReadBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL          *This,\r
+  IN UINT32                         MediaId,\r
+  IN EFI_LBA                        Lba,\r
+  IN UINTN                          BufferSize,\r
+  OUT VOID                          *Buffer\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  //Perform Read operation.\r
+  Status = SdReadWrite (This, (UINTN)Lba, Buffer, BufferSize, READ);\r
+\r
+  return Status;\r
+\r
+}\r
+\r
+\r
+/**\r
+\r
+  Write BufferSize bytes from Lba into Buffer.\r
+\r
+\r
+\r
+  @param  This       Indicates a pointer to the calling context.\r
+\r
+  @param  MediaId    The media ID that the write request is for.\r
+\r
+  @param  Lba        The starting logical block address to be written. The caller is\r
+\r
+                     responsible for writing to only legitimate locations.\r
+\r
+  @param  BufferSize Size of Buffer, must be a multiple of device block size.\r
+\r
+  @param  Buffer     A pointer to the source buffer for the data.\r
+\r
+\r
+\r
+  @retval EFI_SUCCESS           The data was written correctly to the device.\r
+\r
+  @retval EFI_WRITE_PROTECTED   The device can not be written to.\r
+\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.\r
+\r
+  @retval EFI_NO_MEDIA          There is no media in the device.\r
+\r
+  @retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.\r
+\r
+  @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
+\r
+  @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid, \r
+\r
+                                or the buffer is not on proper alignment.\r
+\r
+\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MMCHSWriteBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL          *This,\r
+  IN UINT32                         MediaId,\r
+  IN EFI_LBA                        Lba,\r
+  IN UINTN                          BufferSize,\r
+  IN VOID                           *Buffer\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //Perform write operation.\r
+  Status = SdReadWrite (This, (UINTN)Lba, Buffer, BufferSize, WRITE);\r
+\r
+\r
+  return Status;\r
+\r
+}\r
+\r
+\r
+/**\r
+\r
+  Flush the Block Device.\r
+\r
+\r
+\r
+  @param  This              Indicates a pointer to the calling context.\r
+\r
+\r
+\r
+  @retval EFI_SUCCESS       All outstanding data was written to the device\r
+\r
+  @retval EFI_DEVICE_ERROR  The device reported an error while writting back the data\r
+\r
+  @retval EFI_NO_MEDIA      There is no media in the device.\r
+\r
+\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MMCHSFlushBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_BLOCK_IO_PROTOCOL gBlockIo = {\r
+  EFI_BLOCK_IO_INTERFACE_REVISION,   // Revision\r
+  &gMMCHSMedia,                      // *Media\r
+  MMCHSReset,                        // Reset\r
+  MMCHSReadBlocks,                   // ReadBlocks\r
+  MMCHSWriteBlocks,                  // WriteBlocks\r
+  MMCHSFlushBlocks                   // FlushBlocks\r
+};\r
+\r
+\r
+/**\r
+\r
+  Timer callback to convert card present hardware into a boolean that indicates\r
+\r
+  a media change event has happened. If you just check the GPIO you could see \r
+\r
+  card 1 and then check again after card 1 was removed and card 2 was inserted\r
+\r
+  and you would still see media present. Thus you need the timer tick to catch\r
+\r
+  the toggle event.\r
+\r
+\r
+\r
+  @param  Event                 Event whose notification function is being invoked.\r
+\r
+  @param  Context               The pointer to the notification function's context,\r
+\r
+                                which is implementation-dependent. Not used.\r
+\r
+\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+TimerCallback (\r
+  IN  EFI_EVENT   Event,\r
+  IN  VOID        *Context\r
+  )\r
+{\r
+  BOOLEAN Present;\r
+\r
+  Present = CardPresent ();\r
+  if (gMMCHSMedia.MediaPresent) {\r
+    if (!Present && !gMediaChange) {\r
+      gMediaChange = TRUE;\r
+    }\r
+  } else {\r
+    if (Present && !gMediaChange) {\r
+      gMediaChange = TRUE;    \r
+    }\r
+  }\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+MMCHSInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  Status = gBS->LocateProtocol (&gEmbeddedExternalDeviceProtocolGuid, NULL, (VOID **)&gTPS65950);\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  ZeroMem (&gCardInfo, sizeof (CARD_INFO));\r
+\r
+  Status = gBS->CreateEvent (EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK, TimerCallback, NULL, &gTimerEvent);\r
+  ASSERT_EFI_ERROR (Status);\r
\r
+  Status = gBS->SetTimer (gTimerEvent, TimerPeriodic, FixedPcdGet32 (PcdMmchsTimerFreq100NanoSeconds)); \r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //Publish BlockIO.\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &ImageHandle, \r
+                  &gEfiBlockIoProtocolGuid,    &gBlockIo, \r
+                  &gEfiDevicePathProtocolGuid, &gMmcHsDevicePath,\r
+                  NULL\r
+                  );\r
+  return Status;\r
+}\r
index 2cda5679be0521ef13f84b0b53c573d928dade64..e19607bae0d77db7f8c86b090ab591360cc93fe0 100644 (file)
 #ifndef _MMCHS_H_\r
 #define _MMCHS_H_\r
 \r
 #ifndef _MMCHS_H_\r
 #define _MMCHS_H_\r
 \r
-#include <Uefi.h>
-\r
-#include <Library/BaseLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/DebugLib.h>
-#include <Library/IoLib.h>
-#include <Library/PcdLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/OmapLib.h>
-#include <Library/OmapDmaLib.h>
-#include <Library/DmaLib.h>
-
+#include <Uefi.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/OmapLib.h>\r
+#include <Library/OmapDmaLib.h>\r
+#include <Library/DmaLib.h>\r
+\r
 #include <Protocol/EmbeddedExternalDevice.h>\r
 #include <Protocol/EmbeddedExternalDevice.h>\r
-#include <Protocol/BlockIo.h>
-#include <Protocol/DevicePath.h>
-
+#include <Protocol/BlockIo.h>\r
+#include <Protocol/DevicePath.h>\r
+\r
 #include <Omap3530/Omap3530.h>\r
 #include <TPS65950.h>\r
 \r
 #include <Omap3530/Omap3530.h>\r
 #include <TPS65950.h>\r
 \r
-#define MAX_RETRY_COUNT  (100*5)
-
+#define MAX_RETRY_COUNT  (100*5)\r
+\r
 #define HCS               BIT30 //Host capacity support/1 = Supporting high capacity\r
 #define CCS               BIT30 //Card capacity status/1 = High capacity card\r
 typedef struct {\r
 #define HCS               BIT30 //Host capacity support/1 = Supporting high capacity\r
 #define CCS               BIT30 //Card capacity status/1 = High capacity card\r
 typedef struct {\r
@@ -141,12 +141,12 @@ typedef struct {
   UINT8   CSD_STRUCTURE:      2; // CSD structure [127:126]\r
 }CSD_SDV2;\r
 \r
   UINT8   CSD_STRUCTURE:      2; // CSD structure [127:126]\r
 }CSD_SDV2;\r
 \r
-typedef enum {
-  UNKNOWN_CARD,
-  MMC_CARD,              //MMC card
-  SD_CARD,               //SD 1.1 card
-  SD_CARD_2,             //SD 2.0 or above standard card
-  SD_CARD_2_HIGH         //SD 2.0 or above high capacity card
+typedef enum {\r
+  UNKNOWN_CARD,\r
+  MMC_CARD,              //MMC card\r
+  SD_CARD,               //SD 1.1 card\r
+  SD_CARD_2,             //SD 2.0 or above standard card\r
+  SD_CARD_2_HIGH         //SD 2.0 or above high capacity card\r
 } CARD_TYPE;\r
 \r
 typedef enum {\r
 } CARD_TYPE;\r
 \r
 typedef enum {\r
@@ -165,9 +165,9 @@ typedef struct  {
   CSD       CSDData;\r
 } CARD_INFO;\r
 \r
   CSD       CSDData;\r
 } CARD_INFO;\r
 \r
-EFI_STATUS
-DetectCard (
-  VOID
+EFI_STATUS\r
+DetectCard (\r
+  VOID\r
   );\r
 \r
 extern EFI_BLOCK_IO_PROTOCOL gBlockIo;\r
   );\r
 \r
 extern EFI_BLOCK_IO_PROTOCOL gBlockIo;\r
index 0931112e955069dc0942738b556c152fa3fcd795..cc753c2a2116ef22230221fd79fc42990fd1ae4c 100644 (file)
@@ -1,54 +1,54 @@
-#/** @file
-#  
-#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-#  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                      = MMCHS
-  FILE_GUID                      = 100c2cfa-b586-4198-9b4c-1683d195b1da
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-
-  ENTRY_POINT                    = MMCHSInitialize
-
-
-[Sources.common]
-  MMCHS.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  Omap35xxPkg/Omap35xxPkg.dec
-
-[LibraryClasses]
-  PcdLib
-  UefiLib
-  UefiDriverEntryPoint
-  MemoryAllocationLib
-  IoLib
-  OmapDmaLib
-  DmaLib
-
-[Guids]
-  
-[Protocols]
-  gEfiBlockIoProtocolGuid
-  gEfiCpuArchProtocolGuid
-  gEfiDevicePathProtocolGuid
-  gEmbeddedExternalDeviceProtocolGuid
-
-[Pcd]
-  gOmap35xxTokenSpaceGuid.PcdOmap35xxMMCHS1Base
-  gOmap35xxTokenSpaceGuid.PcdMmchsTimerFreq100NanoSeconds
-
-[depex]
-  gEmbeddedExternalDeviceProtocolGuid
+#/** @file\r
+#  \r
+#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = MMCHS\r
+  FILE_GUID                      = 100c2cfa-b586-4198-9b4c-1683d195b1da\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = MMCHSInitialize\r
+\r
+\r
+[Sources.common]\r
+  MMCHS.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  Omap35xxPkg/Omap35xxPkg.dec\r
+\r
+[LibraryClasses]\r
+  PcdLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  MemoryAllocationLib\r
+  IoLib\r
+  OmapDmaLib\r
+  DmaLib\r
+\r
+[Guids]\r
+  \r
+[Protocols]\r
+  gEfiBlockIoProtocolGuid\r
+  gEfiCpuArchProtocolGuid\r
+  gEfiDevicePathProtocolGuid\r
+  gEmbeddedExternalDeviceProtocolGuid\r
+\r
+[Pcd]\r
+  gOmap35xxTokenSpaceGuid.PcdOmap35xxMMCHS1Base\r
+  gOmap35xxTokenSpaceGuid.PcdMmchsTimerFreq100NanoSeconds\r
+\r
+[depex]\r
+  gEmbeddedExternalDeviceProtocolGuid\r
index 17ebf8d7086a9a85813e885cf39ae171af0386f1..0cbd82bd44d8593a8b045d4a772ea6078ea0fe57 100755 (executable)
-/** @file
-*
-*  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
-*  Copyright (c) 2011, ARM Limited. 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 "MmcHostDxe.h"
-
-EMBEDDED_EXTERNAL_DEVICE   *gTPS65950;
-UINT8                      mMaxDataTransferRate = 0;
-UINT32                     mRca = 0;
-BOOLEAN                    mBitModeSet = FALSE;
-
-
-typedef struct {
-  VENDOR_DEVICE_PATH  Mmc;
-  EFI_DEVICE_PATH     End;
-} MMCHS_DEVICE_PATH;
-
-MMCHS_DEVICE_PATH gMMCDevicePath = {
-  {
-    HARDWARE_DEVICE_PATH,
-    HW_VENDOR_DP,
-    (UINT8)(sizeof(VENDOR_DEVICE_PATH)),
-    (UINT8)((sizeof(VENDOR_DEVICE_PATH)) >> 8),
-    0xb615f1f5, 0x5088, 0x43cd, 0x80, 0x9c, 0xa1, 0x6e, 0x52, 0x48, 0x7d, 0x00 
-  },
-  {
-    END_DEVICE_PATH_TYPE,
-    END_ENTIRE_DEVICE_PATH_SUBTYPE,
-    sizeof (EFI_DEVICE_PATH_PROTOCOL),
-    0
-  }
-};
-
-BOOLEAN
-IgnoreCommand (
-  UINT32 Command
-  )
-{
-  switch(Command) {
-    case MMC_CMD12:
-      return TRUE;
-    case MMC_CMD13:
-      return TRUE;
-    default:
-      return FALSE;
-  }
-}
-
-UINT32
-TranslateCommand (
-  UINT32 Command
-  )
-{
-  UINT32 Translation;
-
-  switch(Command) {
-    case MMC_CMD2:
-      Translation = CMD2;
-      break;
-    case MMC_CMD3:
-      Translation = CMD3;
-      break;
-    /*case MMC_CMD6:
-      Translation = CMD6;
-      break;*/
-    case MMC_CMD7:
-      Translation = CMD7;
-      break;
-    case MMC_CMD8:
-      Translation = CMD8;
-      break;
-    case MMC_CMD9:
-      Translation = CMD9;
-      break;
-    /*case MMC_CMD12:
-      Translation = CMD12;
-      break;
-    case MMC_CMD13:
-      Translation = CMD13;
-      break;*/
-    case MMC_CMD16:
-      Translation = CMD16;
-      break;
-    case MMC_CMD17:
-      Translation = 0x113A0014;//CMD17;
-      break;
-    case MMC_CMD24:
-      Translation = CMD24 | 4;
-      break;
-    case MMC_CMD55:
-      Translation = CMD55;
-      break;
-    case MMC_ACMD41:
-      Translation = ACMD41;
-      break;
-    default:
-      Translation = Command;
-  }
-
-  return Translation;
-}
-
-VOID
-CalculateCardCLKD (
-  UINTN *ClockFrequencySelect
-  )
-{
-  UINTN    TransferRateValue = 0;
-  UINTN    TimeValue = 0 ;
-  UINTN    Frequency = 0;
-
-  DEBUG ((DEBUG_BLKIO, "CalculateCardCLKD()\n"));
-
-  // For SD Cards  we would need to send CMD6 to set
-  // speeds abouve 25MHz. High Speed mode 50 MHz and up
-
-  // Calculate Transfer rate unit (Bits 2:0 of TRAN_SPEED)
-  switch (mMaxDataTransferRate & 0x7) { // 2
-    case 0:
-      TransferRateValue = 100 * 1000;
-      break;
-
-    case 1:
-      TransferRateValue = 1 * 1000 * 1000;
-      break;
-
-    case 2:
-      TransferRateValue = 10 * 1000 * 1000;
-      break;
-
-    case 3:
-      TransferRateValue = 100 * 1000 * 1000;
-      break;
-
-    default:
-      DEBUG ((DEBUG_BLKIO, "Invalid parameter.\n"));
-      ASSERT(FALSE);
-      return;
-  }
-
-  //Calculate Time value (Bits 6:3 of TRAN_SPEED)
-  switch ((mMaxDataTransferRate >> 3) & 0xF) { // 6
-    case 1:
-      TimeValue = 10;
-      break;
-
-    case 2:
-      TimeValue = 12;
-      break;
-
-    case 3:
-      TimeValue = 13;
-      break;
-
-    case 4:
-      TimeValue = 15;
-      break;
-
-    case 5:
-      TimeValue = 20;
-      break;
-
-    case 6:
-      TimeValue = 25;
-      break;
-
-    case 7:
-      TimeValue = 30;
-      break;
-
-    case 8:
-      TimeValue = 35;
-      break;
-
-    case 9:
-      TimeValue = 40;
-      break;
-
-    case 10:
-      TimeValue = 45;
-      break;
-
-    case 11:
-      TimeValue = 50;
-      break;
-
-    case 12:
-      TimeValue = 55;
-      break;
-
-    case 13:
-      TimeValue = 60;
-      break;
-
-    case 14:
-      TimeValue = 70;
-      break;
-
-    case 15:
-      TimeValue = 80;
-      break;
-
-    default:
-      DEBUG ((DEBUG_BLKIO, "Invalid parameter.\n"));
-      ASSERT(FALSE);
-      return;
-  }
-
-  Frequency = TransferRateValue * TimeValue/10;
-
-  // Calculate Clock divider value to program in MMCHS_SYSCTL[CLKD] field.
-  *ClockFrequencySelect = ((MMC_REFERENCE_CLK/Frequency) + 1);
-
-  DEBUG ((DEBUG_BLKIO, "mMaxDataTransferRate: 0x%x, Frequency: %d KHz, ClockFrequencySelect: %x\n", mMaxDataTransferRate, Frequency/1000, *ClockFrequencySelect));
-}
-
-VOID
-UpdateMMCHSClkFrequency (
-  UINTN NewCLKD
-  )
-{
-  DEBUG ((DEBUG_BLKIO, "UpdateMMCHSClkFrequency()\n"));
-
-  // Set Clock enable to 0x0 to not provide the clock to the card
-  MmioAnd32 (MMCHS_SYSCTL, ~CEN);
-
-  // Set new clock frequency.
-  MmioAndThenOr32 (MMCHS_SYSCTL, ~CLKD_MASK, NewCLKD << 6); 
-
-  // Poll till Internal Clock Stable
-  while ((MmioRead32 (MMCHS_SYSCTL) & ICS_MASK) != ICS);
-
-  // Set Clock enable to 0x1 to provide the clock to the card
-  MmioOr32 (MMCHS_SYSCTL, CEN);
-}
-
-EFI_STATUS
-InitializeMMCHS (
-  VOID
-  )
-{
-  UINT8      Data;
-  EFI_STATUS Status;
-
-  DEBUG ((DEBUG_BLKIO, "InitializeMMCHS()\n"));
-
-  // Select Device group to belong to P1 device group in Power IC.
-  Data = DEV_GRP_P1;
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VMMC1_DEV_GRP), 1, &Data);
-  ASSERT_EFI_ERROR(Status);
-
-  // Configure voltage regulator for MMC1 in Power IC to output 3.0 voltage.
-  Data = VSEL_3_00V;
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VMMC1_DEDICATED_REG), 1, &Data);
-  ASSERT_EFI_ERROR(Status);
-  
-  // After ramping up voltage, set VDDS stable bit to indicate that voltage level is stable.
-  MmioOr32 (CONTROL_PBIAS_LITE, (PBIASLITEVMODE0 | PBIASLITEPWRDNZ0 | PBIASSPEEDCTRL0 | PBIASLITEVMODE1 | PBIASLITEWRDNZ1));
-
-  // Enable WP GPIO
-  MmioAndThenOr32 (GPIO1_BASE + GPIO_OE, ~BIT23, BIT23);
-
-  // Enable Card Detect
-  Data = CARD_DETECT_ENABLE;
-  gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID2, TPS65950_GPIO_CTRL), 1, &Data);
-
-  return Status;
-}
-
-BOOLEAN
-MMCIsCardPresent (
-  IN EFI_MMC_HOST_PROTOCOL     *This
-  )
-{
-  EFI_STATUS  Status;
-  UINT8       Data;
-
-  //
-  // Card detect is a GPIO0 on the TPS65950
-  //
-  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID2, GPIODATAIN1), 1, &Data);
-  if (EFI_ERROR (Status)) {
-    return FALSE;
-  }
-
-  return !(Data & CARD_DETECT_BIT);
-}
-
-BOOLEAN
-MMCIsReadOnly (
-  IN EFI_MMC_HOST_PROTOCOL     *This
-  )
-{
-  /* Note:
-   * On our BeagleBoard the SD card WP pin is always read as TRUE. 
-   * Probably something wrong with GPIO configuration.
-   * BeagleBoard-xM uses microSD cards so there is no write protect at all.
-   * Hence commenting out SD card WP pin read status.  
-   */
-  //return (MmioRead32 (GPIO1_BASE + GPIO_DATAIN) & BIT23) == BIT23;
-  return 0;
-
-}
-
-// TODO
-EFI_GUID mPL180MciDevicePathGuid = EFI_CALLER_ID_GUID;
-
-EFI_STATUS
-MMCBuildDevicePath (
-  IN EFI_MMC_HOST_PROTOCOL     *This,
-  IN EFI_DEVICE_PATH_PROTOCOL  **DevicePath
-  )
-{
-  EFI_DEVICE_PATH_PROTOCOL    *NewDevicePathNode;
-
-  NewDevicePathNode = CreateDeviceNode(HARDWARE_DEVICE_PATH,HW_VENDOR_DP,sizeof(VENDOR_DEVICE_PATH));
-  CopyGuid(&((VENDOR_DEVICE_PATH*)NewDevicePathNode)->Guid,&mPL180MciDevicePathGuid);
-  *DevicePath = NewDevicePathNode;
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-MMCSendCommand (
-  IN EFI_MMC_HOST_PROTOCOL     *This,
-  IN MMC_CMD                   MmcCmd,
-  IN UINT32                    Argument
-  )
-{
-  UINTN MmcStatus;
-  UINTN RetryCount = 0;
-
-  if (IgnoreCommand(MmcCmd))
-    return EFI_SUCCESS;
-
-  MmcCmd = TranslateCommand(MmcCmd);
-
-  //DEBUG ((EFI_D_ERROR, "MMCSendCommand(%d)\n", MmcCmd));
-
-  // Check if command line is in use or not. Poll till command line is available.
-  while ((MmioRead32 (MMCHS_PSTATE) & DATI_MASK) == DATI_NOT_ALLOWED);
-
-  // Provide the block size.
-  MmioWrite32 (MMCHS_BLK, BLEN_512BYTES);
-
-  // Setting Data timeout counter value to max value.
-  MmioAndThenOr32 (MMCHS_SYSCTL, ~DTO_MASK, DTO_VAL);
-
-  // Clear Status register.
-  MmioWrite32 (MMCHS_STAT, 0xFFFFFFFF);
-
-  // Set command argument register
-  MmioWrite32 (MMCHS_ARG, Argument);
-
-  //TODO: fix this
-  //Enable interrupt enable events to occur
-  //MmioWrite32 (MMCHS_IE, CmdInterruptEnableVal);
-
-  // Send a command
-  MmioWrite32 (MMCHS_CMD, MmcCmd);
-
-  // Check for the command status.
-  while (RetryCount < MAX_RETRY_COUNT) {
-    do {
-      MmcStatus = MmioRead32 (MMCHS_STAT);
-    } while (MmcStatus == 0);
-
-    // Read status of command response
-    if ((MmcStatus & ERRI) != 0) {
-
-      // Perform soft-reset for mmci_cmd line.
-      MmioOr32 (MMCHS_SYSCTL, SRC);
-      while ((MmioRead32 (MMCHS_SYSCTL) & SRC));
-
-      //DEBUG ((EFI_D_INFO, "MmcStatus: 0x%x\n", MmcStatus));
-      return EFI_DEVICE_ERROR;
-    }
-
-    // Check if command is completed.
-    if ((MmcStatus & CC) == CC) {
-      MmioWrite32 (MMCHS_STAT, CC);
-      break;
-    }
-
-    RetryCount++;
-  }
-
-  if (RetryCount == MAX_RETRY_COUNT) {
-    DEBUG ((DEBUG_BLKIO, "MMCSendCommand: Timeout\n"));
-    return EFI_TIMEOUT;
-  }
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-MMCNotifyState (
-  IN EFI_MMC_HOST_PROTOCOL    *This,
-  IN MMC_STATE                State
-  )
-{
-  EFI_STATUS              Status;
-  UINTN                   FreqSel;
-
-  switch(State) {
-    case MmcInvalidState:
-      ASSERT(0);
-      break;
-    case MmcHwInitializationState:
-      mBitModeSet = FALSE;
-
-      DEBUG ((DEBUG_BLKIO, "MMCHwInitializationState()\n"));
-      Status = InitializeMMCHS ();
-      if (EFI_ERROR(Status)) {
-        DEBUG ((DEBUG_BLKIO, "Initialize MMC host controller fails. Status: %x\n", Status));
-        return Status;
-      }
-
-      // Software reset of the MMCHS host controller.
-      MmioWrite32 (MMCHS_SYSCONFIG, SOFTRESET);
-      gBS->Stall(1000);
-      while ((MmioRead32 (MMCHS_SYSSTATUS) & RESETDONE_MASK) != RESETDONE);
-
-      // Soft reset for all.
-      MmioWrite32 (MMCHS_SYSCTL, SRA);
-      gBS->Stall(1000);
-      while ((MmioRead32 (MMCHS_SYSCTL) & SRA) != 0x0);
-
-      //Voltage capabilities initialization. Activate VS18 and VS30.
-      MmioOr32 (MMCHS_CAPA, (VS30 | VS18));
-
-      // Wakeup configuration
-      MmioOr32 (MMCHS_SYSCONFIG, ENAWAKEUP);
-      MmioOr32 (MMCHS_HCTL, IWE);
-
-      // MMCHS Controller default initialization
-      MmioOr32 (MMCHS_CON, (OD | DW8_1_4_BIT | CEATA_OFF));
-
-      MmioWrite32 (MMCHS_HCTL, (SDVS_3_0_V | DTW_1_BIT | SDBP_OFF));
-
-      // Enable internal clock
-      MmioOr32 (MMCHS_SYSCTL, ICE);
-
-      // Set the clock frequency to 80KHz.
-      UpdateMMCHSClkFrequency (CLKD_80KHZ);
-
-      // Enable SD bus power.
-      MmioOr32 (MMCHS_HCTL, (SDBP_ON));
-
-      // Poll till SD bus power bit is set.
-      while ((MmioRead32 (MMCHS_HCTL) & SDBP_MASK) != SDBP_ON);
-
-      // Enable interrupts.
-      MmioWrite32 (MMCHS_IE, (BADA_EN | CERR_EN | DEB_EN | DCRC_EN | DTO_EN | CIE_EN |
-        CEB_EN | CCRC_EN | CTO_EN | BRR_EN | BWR_EN | TC_EN | CC_EN));
-
-      // Controller INIT procedure start.
-      MmioOr32 (MMCHS_CON, INIT);
-      MmioWrite32 (MMCHS_CMD, 0x00000000);
-      while (!(MmioRead32 (MMCHS_STAT) & CC));
-
-      // Wait for 1 ms
-      gBS->Stall (1000);
-
-      // Set CC bit to 0x1 to clear the flag
-      MmioOr32 (MMCHS_STAT, CC);
-
-      // Retry INIT procedure.
-      MmioWrite32 (MMCHS_CMD, 0x00000000);
-      while (!(MmioRead32 (MMCHS_STAT) & CC));
-
-      // End initialization sequence
-      MmioAnd32 (MMCHS_CON, ~INIT);
-
-      MmioOr32 (MMCHS_HCTL, (SDVS_3_0_V | DTW_1_BIT | SDBP_ON));
-
-      // Change clock frequency to 400KHz to fit protocol
-      UpdateMMCHSClkFrequency(CLKD_400KHZ);
-
-      MmioOr32 (MMCHS_CON, OD);
-      break;
-    case MmcIdleState:
-      break;
-    case MmcReadyState:
-      break;
-    case MmcIdentificationState:
-      break;
-    case MmcStandByState:
-      CalculateCardCLKD (&FreqSel);
-      UpdateMMCHSClkFrequency (FreqSel);
-      break;
-    case MmcTransferState:
-      if (!mBitModeSet) {
-        Status = MMCSendCommand (This, CMD55, mRca << 16);
-        if (!EFI_ERROR (Status)) {
-          // Set device into 4-bit data bus mode
-          Status = MMCSendCommand (This, ACMD6, 0x2);
-          if (!EFI_ERROR (Status)) {
-            // Set host controler into 4-bit mode
-            MmioOr32 (MMCHS_HCTL, DTW_4_BIT);
-            DEBUG ((DEBUG_BLKIO, "SD Memory Card set to 4-bit mode\n"));
-            mBitModeSet = TRUE;
-          }
-        }
-      }
-      break;
-    case MmcSendingDataState:
-      break;
-    case MmcReceiveDataState:
-      break;
-    case MmcProgrammingState:
-      break;
-    case MmcDisconnectState:
-    default:
-      ASSERT(0);
-  }
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-MMCReceiveResponse (
-  IN EFI_MMC_HOST_PROTOCOL     *This,
-  IN MMC_RESPONSE_TYPE         Type,
-  IN UINT32*                   Buffer
-  )
-{
-  if (Buffer == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  if (Type == MMC_RESPONSE_TYPE_R2) {
-    Buffer[0] = MmioRead32 (MMCHS_RSP10);
-    Buffer[1] = MmioRead32 (MMCHS_RSP32);
-    Buffer[2] = MmioRead32 (MMCHS_RSP54);
-    Buffer[3] = MmioRead32 (MMCHS_RSP76);
-  } else {
-    Buffer[0] = MmioRead32 (MMCHS_RSP10);
-  }
-
-  if (Type == MMC_RESPONSE_TYPE_CSD) {
-    mMaxDataTransferRate = Buffer[3] & 0xFF;
-  } else if (Type == MMC_RESPONSE_TYPE_RCA) {
-    mRca = Buffer[0] >> 16;
-  }
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-MMCReadBlockData (
-  IN EFI_MMC_HOST_PROTOCOL      *This,
-  IN EFI_LBA                    Lba,
-  IN UINTN                      Length,
-  IN UINT32*                    Buffer
-  )
-{
-  UINTN MmcStatus;
-  UINTN Count;
-  UINTN RetryCount = 0;
-
-  DEBUG ((DEBUG_BLKIO, "MMCReadBlockData(LBA: 0x%x, Length: 0x%x, Buffer: 0x%x)\n", Lba, Length, Buffer));
-
-  // Check controller status to make sure there is no error.
-  while (RetryCount < MAX_RETRY_COUNT) {
-    do {
-      // Read Status.
-      MmcStatus = MmioRead32 (MMCHS_STAT);
-    } while(MmcStatus == 0);
-
-    // Check if Buffer read ready (BRR) bit is set?
-    if (MmcStatus & BRR) {
-
-      // Clear BRR bit
-      MmioOr32 (MMCHS_STAT, BRR);
-
-      for (Count = 0; Count < Length / 4; Count++) {
-        *Buffer++ = MmioRead32(MMCHS_DATA);
-      }
-      break;
-    }
-    RetryCount++;
-  }
-
-  if (RetryCount == MAX_RETRY_COUNT) {
-    return EFI_TIMEOUT;
-  }
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-MMCWriteBlockData (
-  IN EFI_MMC_HOST_PROTOCOL    *This,
-  IN EFI_LBA                  Lba,
-  IN UINTN                    Length,
-  IN UINT32*                  Buffer
-  )
-{
-  UINTN MmcStatus;
-  UINTN Count;
-  UINTN RetryCount = 0;
-
-  // Check controller status to make sure there is no error.
-  while (RetryCount < MAX_RETRY_COUNT) {
-    do {
-      // Read Status.
-      MmcStatus = MmioRead32 (MMCHS_STAT);
-    } while(MmcStatus == 0);
-
-    // Check if Buffer write ready (BWR) bit is set?
-    if (MmcStatus & BWR) {
-
-      // Clear BWR bit
-      MmioOr32 (MMCHS_STAT, BWR);
-
-      // Write block worth of data.
-      for (Count = 0; Count < Length / 4; Count++) {
-        MmioWrite32 (MMCHS_DATA, *Buffer++);
-      }
-
-      break;
-    }
-    RetryCount++;
-  }
-
-  if (RetryCount == MAX_RETRY_COUNT) {
-    return EFI_TIMEOUT;
-  }
-
-  return EFI_SUCCESS;
-}
-
-EFI_MMC_HOST_PROTOCOL gMMCHost = {
-  MMC_HOST_PROTOCOL_REVISION,
-  MMCIsCardPresent,
-  MMCIsReadOnly,
-  MMCBuildDevicePath,
-  MMCNotifyState,
-  MMCSendCommand,
-  MMCReceiveResponse,
-  MMCReadBlockData,
-  MMCWriteBlockData
-};
-
-EFI_STATUS
-MMCInitialize (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
-  )
-{
-  EFI_STATUS    Status;
-  EFI_HANDLE    Handle = NULL;
-
-  DEBUG ((DEBUG_BLKIO, "MMCInitialize()\n"));
-
-  Status = gBS->LocateProtocol (&gEmbeddedExternalDeviceProtocolGuid, NULL, (VOID **)&gTPS65950);
-  ASSERT_EFI_ERROR(Status);
-
-  Status = gBS->InstallMultipleProtocolInterfaces (
-                  &Handle, 
-                  &gEfiMmcHostProtocolGuid,         &gMMCHost,
-                  NULL
-                  );
-  ASSERT_EFI_ERROR (Status);
-
-  return Status;
-}
+/** @file\r
+*\r
+*  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.\r
+*  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include "MmcHostDxe.h"\r
+\r
+EMBEDDED_EXTERNAL_DEVICE   *gTPS65950;\r
+UINT8                      mMaxDataTransferRate = 0;\r
+UINT32                     mRca = 0;\r
+BOOLEAN                    mBitModeSet = FALSE;\r
+\r
+\r
+typedef struct {\r
+  VENDOR_DEVICE_PATH  Mmc;\r
+  EFI_DEVICE_PATH     End;\r
+} MMCHS_DEVICE_PATH;\r
+\r
+MMCHS_DEVICE_PATH gMMCDevicePath = {\r
+  {\r
+    HARDWARE_DEVICE_PATH,\r
+    HW_VENDOR_DP,\r
+    (UINT8)(sizeof(VENDOR_DEVICE_PATH)),\r
+    (UINT8)((sizeof(VENDOR_DEVICE_PATH)) >> 8),\r
+    0xb615f1f5, 0x5088, 0x43cd, 0x80, 0x9c, 0xa1, 0x6e, 0x52, 0x48, 0x7d, 0x00 \r
+  },\r
+  {\r
+    END_DEVICE_PATH_TYPE,\r
+    END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+    sizeof (EFI_DEVICE_PATH_PROTOCOL),\r
+    0\r
+  }\r
+};\r
+\r
+BOOLEAN\r
+IgnoreCommand (\r
+  UINT32 Command\r
+  )\r
+{\r
+  switch(Command) {\r
+    case MMC_CMD12:\r
+      return TRUE;\r
+    case MMC_CMD13:\r
+      return TRUE;\r
+    default:\r
+      return FALSE;\r
+  }\r
+}\r
+\r
+UINT32\r
+TranslateCommand (\r
+  UINT32 Command\r
+  )\r
+{\r
+  UINT32 Translation;\r
+\r
+  switch(Command) {\r
+    case MMC_CMD2:\r
+      Translation = CMD2;\r
+      break;\r
+    case MMC_CMD3:\r
+      Translation = CMD3;\r
+      break;\r
+    /*case MMC_CMD6:\r
+      Translation = CMD6;\r
+      break;*/\r
+    case MMC_CMD7:\r
+      Translation = CMD7;\r
+      break;\r
+    case MMC_CMD8:\r
+      Translation = CMD8;\r
+      break;\r
+    case MMC_CMD9:\r
+      Translation = CMD9;\r
+      break;\r
+    /*case MMC_CMD12:\r
+      Translation = CMD12;\r
+      break;\r
+    case MMC_CMD13:\r
+      Translation = CMD13;\r
+      break;*/\r
+    case MMC_CMD16:\r
+      Translation = CMD16;\r
+      break;\r
+    case MMC_CMD17:\r
+      Translation = 0x113A0014;//CMD17;\r
+      break;\r
+    case MMC_CMD24:\r
+      Translation = CMD24 | 4;\r
+      break;\r
+    case MMC_CMD55:\r
+      Translation = CMD55;\r
+      break;\r
+    case MMC_ACMD41:\r
+      Translation = ACMD41;\r
+      break;\r
+    default:\r
+      Translation = Command;\r
+  }\r
+\r
+  return Translation;\r
+}\r
+\r
+VOID\r
+CalculateCardCLKD (\r
+  UINTN *ClockFrequencySelect\r
+  )\r
+{\r
+  UINTN    TransferRateValue = 0;\r
+  UINTN    TimeValue = 0 ;\r
+  UINTN    Frequency = 0;\r
+\r
+  DEBUG ((DEBUG_BLKIO, "CalculateCardCLKD()\n"));\r
+\r
+  // For SD Cards  we would need to send CMD6 to set\r
+  // speeds abouve 25MHz. High Speed mode 50 MHz and up\r
+\r
+  // Calculate Transfer rate unit (Bits 2:0 of TRAN_SPEED)\r
+  switch (mMaxDataTransferRate & 0x7) { // 2\r
+    case 0:\r
+      TransferRateValue = 100 * 1000;\r
+      break;\r
+\r
+    case 1:\r
+      TransferRateValue = 1 * 1000 * 1000;\r
+      break;\r
+\r
+    case 2:\r
+      TransferRateValue = 10 * 1000 * 1000;\r
+      break;\r
+\r
+    case 3:\r
+      TransferRateValue = 100 * 1000 * 1000;\r
+      break;\r
+\r
+    default:\r
+      DEBUG ((DEBUG_BLKIO, "Invalid parameter.\n"));\r
+      ASSERT(FALSE);\r
+      return;\r
+  }\r
+\r
+  //Calculate Time value (Bits 6:3 of TRAN_SPEED)\r
+  switch ((mMaxDataTransferRate >> 3) & 0xF) { // 6\r
+    case 1:\r
+      TimeValue = 10;\r
+      break;\r
+\r
+    case 2:\r
+      TimeValue = 12;\r
+      break;\r
+\r
+    case 3:\r
+      TimeValue = 13;\r
+      break;\r
+\r
+    case 4:\r
+      TimeValue = 15;\r
+      break;\r
+\r
+    case 5:\r
+      TimeValue = 20;\r
+      break;\r
+\r
+    case 6:\r
+      TimeValue = 25;\r
+      break;\r
+\r
+    case 7:\r
+      TimeValue = 30;\r
+      break;\r
+\r
+    case 8:\r
+      TimeValue = 35;\r
+      break;\r
+\r
+    case 9:\r
+      TimeValue = 40;\r
+      break;\r
+\r
+    case 10:\r
+      TimeValue = 45;\r
+      break;\r
+\r
+    case 11:\r
+      TimeValue = 50;\r
+      break;\r
+\r
+    case 12:\r
+      TimeValue = 55;\r
+      break;\r
+\r
+    case 13:\r
+      TimeValue = 60;\r
+      break;\r
+\r
+    case 14:\r
+      TimeValue = 70;\r
+      break;\r
+\r
+    case 15:\r
+      TimeValue = 80;\r
+      break;\r
+\r
+    default:\r
+      DEBUG ((DEBUG_BLKIO, "Invalid parameter.\n"));\r
+      ASSERT(FALSE);\r
+      return;\r
+  }\r
+\r
+  Frequency = TransferRateValue * TimeValue/10;\r
+\r
+  // Calculate Clock divider value to program in MMCHS_SYSCTL[CLKD] field.\r
+  *ClockFrequencySelect = ((MMC_REFERENCE_CLK/Frequency) + 1);\r
+\r
+  DEBUG ((DEBUG_BLKIO, "mMaxDataTransferRate: 0x%x, Frequency: %d KHz, ClockFrequencySelect: %x\n", mMaxDataTransferRate, Frequency/1000, *ClockFrequencySelect));\r
+}\r
+\r
+VOID\r
+UpdateMMCHSClkFrequency (\r
+  UINTN NewCLKD\r
+  )\r
+{\r
+  DEBUG ((DEBUG_BLKIO, "UpdateMMCHSClkFrequency()\n"));\r
+\r
+  // Set Clock enable to 0x0 to not provide the clock to the card\r
+  MmioAnd32 (MMCHS_SYSCTL, ~CEN);\r
+\r
+  // Set new clock frequency.\r
+  MmioAndThenOr32 (MMCHS_SYSCTL, ~CLKD_MASK, NewCLKD << 6); \r
+\r
+  // Poll till Internal Clock Stable\r
+  while ((MmioRead32 (MMCHS_SYSCTL) & ICS_MASK) != ICS);\r
+\r
+  // Set Clock enable to 0x1 to provide the clock to the card\r
+  MmioOr32 (MMCHS_SYSCTL, CEN);\r
+}\r
+\r
+EFI_STATUS\r
+InitializeMMCHS (\r
+  VOID\r
+  )\r
+{\r
+  UINT8      Data;\r
+  EFI_STATUS Status;\r
+\r
+  DEBUG ((DEBUG_BLKIO, "InitializeMMCHS()\n"));\r
+\r
+  // Select Device group to belong to P1 device group in Power IC.\r
+  Data = DEV_GRP_P1;\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VMMC1_DEV_GRP), 1, &Data);\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  // Configure voltage regulator for MMC1 in Power IC to output 3.0 voltage.\r
+  Data = VSEL_3_00V;\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VMMC1_DEDICATED_REG), 1, &Data);\r
+  ASSERT_EFI_ERROR(Status);\r
+  \r
+  // After ramping up voltage, set VDDS stable bit to indicate that voltage level is stable.\r
+  MmioOr32 (CONTROL_PBIAS_LITE, (PBIASLITEVMODE0 | PBIASLITEPWRDNZ0 | PBIASSPEEDCTRL0 | PBIASLITEVMODE1 | PBIASLITEWRDNZ1));\r
+\r
+  // Enable WP GPIO\r
+  MmioAndThenOr32 (GPIO1_BASE + GPIO_OE, ~BIT23, BIT23);\r
+\r
+  // Enable Card Detect\r
+  Data = CARD_DETECT_ENABLE;\r
+  gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID2, TPS65950_GPIO_CTRL), 1, &Data);\r
+\r
+  return Status;\r
+}\r
+\r
+BOOLEAN\r
+MMCIsCardPresent (\r
+  IN EFI_MMC_HOST_PROTOCOL     *This\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       Data;\r
+\r
+  //\r
+  // Card detect is a GPIO0 on the TPS65950\r
+  //\r
+  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID2, GPIODATAIN1), 1, &Data);\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+\r
+  return !(Data & CARD_DETECT_BIT);\r
+}\r
+\r
+BOOLEAN\r
+MMCIsReadOnly (\r
+  IN EFI_MMC_HOST_PROTOCOL     *This\r
+  )\r
+{\r
+  /* Note:\r
+   * On our BeagleBoard the SD card WP pin is always read as TRUE. \r
+   * Probably something wrong with GPIO configuration.\r
+   * BeagleBoard-xM uses microSD cards so there is no write protect at all.\r
+   * Hence commenting out SD card WP pin read status.  \r
+   */\r
+  //return (MmioRead32 (GPIO1_BASE + GPIO_DATAIN) & BIT23) == BIT23;\r
+  return 0;\r
+\r
+}\r
+\r
+// TODO\r
+EFI_GUID mPL180MciDevicePathGuid = EFI_CALLER_ID_GUID;\r
+\r
+EFI_STATUS\r
+MMCBuildDevicePath (\r
+  IN EFI_MMC_HOST_PROTOCOL     *This,\r
+  IN EFI_DEVICE_PATH_PROTOCOL  **DevicePath\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL    *NewDevicePathNode;\r
+\r
+  NewDevicePathNode = CreateDeviceNode(HARDWARE_DEVICE_PATH,HW_VENDOR_DP,sizeof(VENDOR_DEVICE_PATH));\r
+  CopyGuid(&((VENDOR_DEVICE_PATH*)NewDevicePathNode)->Guid,&mPL180MciDevicePathGuid);\r
+  *DevicePath = NewDevicePathNode;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+MMCSendCommand (\r
+  IN EFI_MMC_HOST_PROTOCOL     *This,\r
+  IN MMC_CMD                   MmcCmd,\r
+  IN UINT32                    Argument\r
+  )\r
+{\r
+  UINTN MmcStatus;\r
+  UINTN RetryCount = 0;\r
+\r
+  if (IgnoreCommand(MmcCmd))\r
+    return EFI_SUCCESS;\r
+\r
+  MmcCmd = TranslateCommand(MmcCmd);\r
+\r
+  //DEBUG ((EFI_D_ERROR, "MMCSendCommand(%d)\n", MmcCmd));\r
+\r
+  // Check if command line is in use or not. Poll till command line is available.\r
+  while ((MmioRead32 (MMCHS_PSTATE) & DATI_MASK) == DATI_NOT_ALLOWED);\r
+\r
+  // Provide the block size.\r
+  MmioWrite32 (MMCHS_BLK, BLEN_512BYTES);\r
+\r
+  // Setting Data timeout counter value to max value.\r
+  MmioAndThenOr32 (MMCHS_SYSCTL, ~DTO_MASK, DTO_VAL);\r
+\r
+  // Clear Status register.\r
+  MmioWrite32 (MMCHS_STAT, 0xFFFFFFFF);\r
+\r
+  // Set command argument register\r
+  MmioWrite32 (MMCHS_ARG, Argument);\r
+\r
+  //TODO: fix this\r
+  //Enable interrupt enable events to occur\r
+  //MmioWrite32 (MMCHS_IE, CmdInterruptEnableVal);\r
+\r
+  // Send a command\r
+  MmioWrite32 (MMCHS_CMD, MmcCmd);\r
+\r
+  // Check for the command status.\r
+  while (RetryCount < MAX_RETRY_COUNT) {\r
+    do {\r
+      MmcStatus = MmioRead32 (MMCHS_STAT);\r
+    } while (MmcStatus == 0);\r
+\r
+    // Read status of command response\r
+    if ((MmcStatus & ERRI) != 0) {\r
+\r
+      // Perform soft-reset for mmci_cmd line.\r
+      MmioOr32 (MMCHS_SYSCTL, SRC);\r
+      while ((MmioRead32 (MMCHS_SYSCTL) & SRC));\r
+\r
+      //DEBUG ((EFI_D_INFO, "MmcStatus: 0x%x\n", MmcStatus));\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+\r
+    // Check if command is completed.\r
+    if ((MmcStatus & CC) == CC) {\r
+      MmioWrite32 (MMCHS_STAT, CC);\r
+      break;\r
+    }\r
+\r
+    RetryCount++;\r
+  }\r
+\r
+  if (RetryCount == MAX_RETRY_COUNT) {\r
+    DEBUG ((DEBUG_BLKIO, "MMCSendCommand: Timeout\n"));\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+MMCNotifyState (\r
+  IN EFI_MMC_HOST_PROTOCOL    *This,\r
+  IN MMC_STATE                State\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  UINTN                   FreqSel;\r
+\r
+  switch(State) {\r
+    case MmcInvalidState:\r
+      ASSERT(0);\r
+      break;\r
+    case MmcHwInitializationState:\r
+      mBitModeSet = FALSE;\r
+\r
+      DEBUG ((DEBUG_BLKIO, "MMCHwInitializationState()\n"));\r
+      Status = InitializeMMCHS ();\r
+      if (EFI_ERROR(Status)) {\r
+        DEBUG ((DEBUG_BLKIO, "Initialize MMC host controller fails. Status: %x\n", Status));\r
+        return Status;\r
+      }\r
+\r
+      // Software reset of the MMCHS host controller.\r
+      MmioWrite32 (MMCHS_SYSCONFIG, SOFTRESET);\r
+      gBS->Stall(1000);\r
+      while ((MmioRead32 (MMCHS_SYSSTATUS) & RESETDONE_MASK) != RESETDONE);\r
+\r
+      // Soft reset for all.\r
+      MmioWrite32 (MMCHS_SYSCTL, SRA);\r
+      gBS->Stall(1000);\r
+      while ((MmioRead32 (MMCHS_SYSCTL) & SRA) != 0x0);\r
+\r
+      //Voltage capabilities initialization. Activate VS18 and VS30.\r
+      MmioOr32 (MMCHS_CAPA, (VS30 | VS18));\r
+\r
+      // Wakeup configuration\r
+      MmioOr32 (MMCHS_SYSCONFIG, ENAWAKEUP);\r
+      MmioOr32 (MMCHS_HCTL, IWE);\r
+\r
+      // MMCHS Controller default initialization\r
+      MmioOr32 (MMCHS_CON, (OD | DW8_1_4_BIT | CEATA_OFF));\r
+\r
+      MmioWrite32 (MMCHS_HCTL, (SDVS_3_0_V | DTW_1_BIT | SDBP_OFF));\r
+\r
+      // Enable internal clock\r
+      MmioOr32 (MMCHS_SYSCTL, ICE);\r
+\r
+      // Set the clock frequency to 80KHz.\r
+      UpdateMMCHSClkFrequency (CLKD_80KHZ);\r
+\r
+      // Enable SD bus power.\r
+      MmioOr32 (MMCHS_HCTL, (SDBP_ON));\r
+\r
+      // Poll till SD bus power bit is set.\r
+      while ((MmioRead32 (MMCHS_HCTL) & SDBP_MASK) != SDBP_ON);\r
+\r
+      // Enable interrupts.\r
+      MmioWrite32 (MMCHS_IE, (BADA_EN | CERR_EN | DEB_EN | DCRC_EN | DTO_EN | CIE_EN |\r
+        CEB_EN | CCRC_EN | CTO_EN | BRR_EN | BWR_EN | TC_EN | CC_EN));\r
+\r
+      // Controller INIT procedure start.\r
+      MmioOr32 (MMCHS_CON, INIT);\r
+      MmioWrite32 (MMCHS_CMD, 0x00000000);\r
+      while (!(MmioRead32 (MMCHS_STAT) & CC));\r
+\r
+      // Wait for 1 ms\r
+      gBS->Stall (1000);\r
+\r
+      // Set CC bit to 0x1 to clear the flag\r
+      MmioOr32 (MMCHS_STAT, CC);\r
+\r
+      // Retry INIT procedure.\r
+      MmioWrite32 (MMCHS_CMD, 0x00000000);\r
+      while (!(MmioRead32 (MMCHS_STAT) & CC));\r
+\r
+      // End initialization sequence\r
+      MmioAnd32 (MMCHS_CON, ~INIT);\r
+\r
+      MmioOr32 (MMCHS_HCTL, (SDVS_3_0_V | DTW_1_BIT | SDBP_ON));\r
+\r
+      // Change clock frequency to 400KHz to fit protocol\r
+      UpdateMMCHSClkFrequency(CLKD_400KHZ);\r
+\r
+      MmioOr32 (MMCHS_CON, OD);\r
+      break;\r
+    case MmcIdleState:\r
+      break;\r
+    case MmcReadyState:\r
+      break;\r
+    case MmcIdentificationState:\r
+      break;\r
+    case MmcStandByState:\r
+      CalculateCardCLKD (&FreqSel);\r
+      UpdateMMCHSClkFrequency (FreqSel);\r
+      break;\r
+    case MmcTransferState:\r
+      if (!mBitModeSet) {\r
+        Status = MMCSendCommand (This, CMD55, mRca << 16);\r
+        if (!EFI_ERROR (Status)) {\r
+          // Set device into 4-bit data bus mode\r
+          Status = MMCSendCommand (This, ACMD6, 0x2);\r
+          if (!EFI_ERROR (Status)) {\r
+            // Set host controler into 4-bit mode\r
+            MmioOr32 (MMCHS_HCTL, DTW_4_BIT);\r
+            DEBUG ((DEBUG_BLKIO, "SD Memory Card set to 4-bit mode\n"));\r
+            mBitModeSet = TRUE;\r
+          }\r
+        }\r
+      }\r
+      break;\r
+    case MmcSendingDataState:\r
+      break;\r
+    case MmcReceiveDataState:\r
+      break;\r
+    case MmcProgrammingState:\r
+      break;\r
+    case MmcDisconnectState:\r
+    default:\r
+      ASSERT(0);\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+MMCReceiveResponse (\r
+  IN EFI_MMC_HOST_PROTOCOL     *This,\r
+  IN MMC_RESPONSE_TYPE         Type,\r
+  IN UINT32*                   Buffer\r
+  )\r
+{\r
+  if (Buffer == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (Type == MMC_RESPONSE_TYPE_R2) {\r
+    Buffer[0] = MmioRead32 (MMCHS_RSP10);\r
+    Buffer[1] = MmioRead32 (MMCHS_RSP32);\r
+    Buffer[2] = MmioRead32 (MMCHS_RSP54);\r
+    Buffer[3] = MmioRead32 (MMCHS_RSP76);\r
+  } else {\r
+    Buffer[0] = MmioRead32 (MMCHS_RSP10);\r
+  }\r
+\r
+  if (Type == MMC_RESPONSE_TYPE_CSD) {\r
+    mMaxDataTransferRate = Buffer[3] & 0xFF;\r
+  } else if (Type == MMC_RESPONSE_TYPE_RCA) {\r
+    mRca = Buffer[0] >> 16;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+MMCReadBlockData (\r
+  IN EFI_MMC_HOST_PROTOCOL      *This,\r
+  IN EFI_LBA                    Lba,\r
+  IN UINTN                      Length,\r
+  IN UINT32*                    Buffer\r
+  )\r
+{\r
+  UINTN MmcStatus;\r
+  UINTN Count;\r
+  UINTN RetryCount = 0;\r
+\r
+  DEBUG ((DEBUG_BLKIO, "MMCReadBlockData(LBA: 0x%x, Length: 0x%x, Buffer: 0x%x)\n", Lba, Length, Buffer));\r
+\r
+  // Check controller status to make sure there is no error.\r
+  while (RetryCount < MAX_RETRY_COUNT) {\r
+    do {\r
+      // Read Status.\r
+      MmcStatus = MmioRead32 (MMCHS_STAT);\r
+    } while(MmcStatus == 0);\r
+\r
+    // Check if Buffer read ready (BRR) bit is set?\r
+    if (MmcStatus & BRR) {\r
+\r
+      // Clear BRR bit\r
+      MmioOr32 (MMCHS_STAT, BRR);\r
+\r
+      for (Count = 0; Count < Length / 4; Count++) {\r
+        *Buffer++ = MmioRead32(MMCHS_DATA);\r
+      }\r
+      break;\r
+    }\r
+    RetryCount++;\r
+  }\r
+\r
+  if (RetryCount == MAX_RETRY_COUNT) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+MMCWriteBlockData (\r
+  IN EFI_MMC_HOST_PROTOCOL    *This,\r
+  IN EFI_LBA                  Lba,\r
+  IN UINTN                    Length,\r
+  IN UINT32*                  Buffer\r
+  )\r
+{\r
+  UINTN MmcStatus;\r
+  UINTN Count;\r
+  UINTN RetryCount = 0;\r
+\r
+  // Check controller status to make sure there is no error.\r
+  while (RetryCount < MAX_RETRY_COUNT) {\r
+    do {\r
+      // Read Status.\r
+      MmcStatus = MmioRead32 (MMCHS_STAT);\r
+    } while(MmcStatus == 0);\r
+\r
+    // Check if Buffer write ready (BWR) bit is set?\r
+    if (MmcStatus & BWR) {\r
+\r
+      // Clear BWR bit\r
+      MmioOr32 (MMCHS_STAT, BWR);\r
+\r
+      // Write block worth of data.\r
+      for (Count = 0; Count < Length / 4; Count++) {\r
+        MmioWrite32 (MMCHS_DATA, *Buffer++);\r
+      }\r
+\r
+      break;\r
+    }\r
+    RetryCount++;\r
+  }\r
+\r
+  if (RetryCount == MAX_RETRY_COUNT) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_MMC_HOST_PROTOCOL gMMCHost = {\r
+  MMC_HOST_PROTOCOL_REVISION,\r
+  MMCIsCardPresent,\r
+  MMCIsReadOnly,\r
+  MMCBuildDevicePath,\r
+  MMCNotifyState,\r
+  MMCSendCommand,\r
+  MMCReceiveResponse,\r
+  MMCReadBlockData,\r
+  MMCWriteBlockData\r
+};\r
+\r
+EFI_STATUS\r
+MMCInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  EFI_HANDLE    Handle = NULL;\r
+\r
+  DEBUG ((DEBUG_BLKIO, "MMCInitialize()\n"));\r
+\r
+  Status = gBS->LocateProtocol (&gEmbeddedExternalDeviceProtocolGuid, NULL, (VOID **)&gTPS65950);\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Handle, \r
+                  &gEfiMmcHostProtocolGuid,         &gMMCHost,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
index 940087f2668152422cc3d7b5c67230d06d89b211..ec55234db2eeaca79a7d21933d6417391c857d06 100755 (executable)
@@ -1,44 +1,44 @@
-/** @file
-*
-*  Copyright (c) 2011, ARM Limited. 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.             
-*
-**/
-
-#ifndef _MMC_HOST_DXE_H_
-#define _MMC_HOST_DXE_H_
-
-#include <Uefi.h>
-
-#include <Library/BaseLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/DebugLib.h>
-#include <Library/DevicePathLib.h>
-#include <Library/IoLib.h>
-#include <Library/PcdLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/OmapLib.h>
-#include <Library/OmapDmaLib.h>
-#include <Library/DmaLib.h>
-
-#include <Protocol/EmbeddedExternalDevice.h>
-#include <Protocol/BlockIo.h>
-#include <Protocol/DevicePath.h>
-#include <Protocol/MmcHost.h>
-
-#include <Omap3530/Omap3530.h>
-#include <TPS65950.h>
-
-#define MAX_RETRY_COUNT  (100*5)
-
-extern EFI_BLOCK_IO_PROTOCOL gBlockIo;
-
-#endif
+/** @file\r
+*\r
+*  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#ifndef _MMC_HOST_DXE_H_\r
+#define _MMC_HOST_DXE_H_\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/OmapLib.h>\r
+#include <Library/OmapDmaLib.h>\r
+#include <Library/DmaLib.h>\r
+\r
+#include <Protocol/EmbeddedExternalDevice.h>\r
+#include <Protocol/BlockIo.h>\r
+#include <Protocol/DevicePath.h>\r
+#include <Protocol/MmcHost.h>\r
+\r
+#include <Omap3530/Omap3530.h>\r
+#include <TPS65950.h>\r
+\r
+#define MAX_RETRY_COUNT  (100*5)\r
+\r
+extern EFI_BLOCK_IO_PROTOCOL gBlockIo;\r
+\r
+#endif\r
index a15b6f703de5ce2cd0a15bac1e5f4a6e46b8026d..8c95c0f2d92e8721a170f048894fc22ba4645ca7 100755 (executable)
@@ -1,53 +1,53 @@
-#  Copyright (c) 2011, ARM Limited. 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                      = MMC
-  FILE_GUID                      = 100c2cfa-b586-4198-9b4c-1683d195b1da
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-
-  ENTRY_POINT                    = MMCInitialize
-
-
-[Sources.common]
-  MmcHostDxe.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  Omap35xxPkg/Omap35xxPkg.dec
-
-[LibraryClasses]
-  PcdLib
-  UefiLib
-  UefiDriverEntryPoint
-  MemoryAllocationLib
-  IoLib
-  OmapDmaLib
-  DmaLib
-
-[Guids]
-  
-[Protocols]
-  gEfiBlockIoProtocolGuid
-  gEfiCpuArchProtocolGuid
-  gEfiDevicePathProtocolGuid
-  gEmbeddedExternalDeviceProtocolGuid
-  gEfiMmcHostProtocolGuid
-
-[Pcd]
-  gOmap35xxTokenSpaceGuid.PcdOmap35xxMMCHS1Base
-  gOmap35xxTokenSpaceGuid.PcdMmchsTimerFreq100NanoSeconds
-
-[depex]
-  gEmbeddedExternalDeviceProtocolGuid
+#  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+#  \r
+#  This program and the accompanying materials                          \r
+#  are licensed and made available under the terms and conditions of the BSD License         \r
+#  which accompanies this distribution.  The full text of the license may be found at        \r
+#  http://opensource.org/licenses/bsd-license.php                                            \r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+#\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = MMC\r
+  FILE_GUID                      = 100c2cfa-b586-4198-9b4c-1683d195b1da\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = MMCInitialize\r
+\r
+\r
+[Sources.common]\r
+  MmcHostDxe.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  Omap35xxPkg/Omap35xxPkg.dec\r
+\r
+[LibraryClasses]\r
+  PcdLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  MemoryAllocationLib\r
+  IoLib\r
+  OmapDmaLib\r
+  DmaLib\r
+\r
+[Guids]\r
+  \r
+[Protocols]\r
+  gEfiBlockIoProtocolGuid\r
+  gEfiCpuArchProtocolGuid\r
+  gEfiDevicePathProtocolGuid\r
+  gEmbeddedExternalDeviceProtocolGuid\r
+  gEfiMmcHostProtocolGuid\r
+\r
+[Pcd]\r
+  gOmap35xxTokenSpaceGuid.PcdOmap35xxMMCHS1Base\r
+  gOmap35xxTokenSpaceGuid.PcdMmchsTimerFreq100NanoSeconds\r
+\r
+[depex]\r
+  gEmbeddedExternalDeviceProtocolGuid\r
index 1666a683d5d6b5c7a7016e7e2c5fe9a0d3ad4924..075dd6ae99901d47383586063b886c585abf749e 100644 (file)
-#/** @file
-# Omap35xx SoC package.
-#
-# Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>
-#
-#    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                  = Omap35xxPkg
-  PLATFORM_GUID                  = D196A631-B7B7-4953-A3EE-0F773CBABF20
-  PLATFORM_VERSION               = 0.1
-  DSC_SPECIFICATION              = 0x00010005
-  OUTPUT_DIRECTORY               = Build/Omap35xxPkg
-  SUPPORTED_ARCHITECTURES        = ARM
-  BUILD_TARGETS                  = DEBUG|RELEASE
-  SKUID_IDENTIFIER               = DEFAULT
-  DEFINE TARGET_HACK             = DEBUG
-
-
-[LibraryClasses.common]
-  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
-
-  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf
-  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
-  
-  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
-  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
-
-  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
-  
-  CacheMaintenanceLib|ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf
-  DefaultExceptioHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf
-  CpuExceptionHandlerLib|MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.inf
-  PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf
-  
-  RealTimeClockLib|EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf
-
-  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
-  OmapLib|Omap35xxPkg/Library/OmapLib/OmapLib.inf
-  OmapDmaLib|Omap35xxPkg/Library/OmapDmaLib/OmapDmaLib.inf
-  
-  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
-  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
-  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
-  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
-  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
-
-  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
-  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
-  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
-  DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
-
-#
-# Assume everything is fixed at build
-#
-  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
-
-  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
-    
- # UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf
-  UncachedMemoryAllocationLib|ArmPkg/Library/DebugUncachedMemoryAllocationLib/DebugUncachedMemoryAllocationLib.inf
-
-  CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
-
-
-[LibraryClasses.common.DXE_DRIVER]
-  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
-
-
-[LibraryClasses.ARM]
-  #
-  # Note: This NULL library feature is not yet in the edk2/BaseTools, but it is checked in to 
-  # the BaseTools project. So you need to build with the BaseTools project util this feature gets synced.
-  #
-  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
-
-
-[BuildOptions]
-  XCODE:*_*_ARM_ARCHCC_FLAGS     == -arch armv7 -march=armv7
-  XCODE:*_*_ARM_ARCHASM_FLAGS    == -arch armv7
-  XCODE:*_*_ARM_ARCHDLINK_FLAGS  == -arch armv7
-
-  GCC:*_*_ARM_ARCHCC_FLAGS     == -march=armv7-a -mthumb
-  GCC:*_*_ARM_ARCHASM_FLAGS    == -march=armv7-a
-
-  RVCT:*_*_ARM_ARCHCC_FLAGS     == --cpu 7-A
-  RVCT:*_*_ARM_ARCHASM_FLAGS    == --cpu 7-A
-
-################################################################################
-#
-# Pcd Section - list of all EDK II PCD Entries defined by this Platform
-#
-################################################################################
-
-  
-[PcdsFixedAtBuild.common]
-
-# DEBUG_ASSERT_ENABLED       0x01
-# DEBUG_PRINT_ENABLED        0x02
-# DEBUG_CODE_ENABLED         0x04
-# CLEAR_MEMORY_ENABLED       0x08
-# ASSERT_BREAKPOINT_ENABLED  0x10
-# ASSERT_DEADLOOP_ENABLED    0x20
-  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2f
-
-#  DEBUG_INIT      0x00000001  // Initialization
-#  DEBUG_WARN      0x00000002  // Warnings
-#  DEBUG_LOAD      0x00000004  // Load events
-#  DEBUG_FS        0x00000008  // EFI File system
-#  DEBUG_POOL      0x00000010  // Alloc & Free's
-#  DEBUG_PAGE      0x00000020  // Alloc & Free's
-#  DEBUG_INFO      0x00000040  // Verbose
-#  DEBUG_DISPATCH  0x00000080  // PEI/DXE Dispatchers
-#  DEBUG_VARIABLE  0x00000100  // Variable
-#  DEBUG_BM        0x00000400  // Boot Manager
-#  DEBUG_BLKIO     0x00001000  // BlkIo Driver
-#  DEBUG_NET       0x00004000  // SNI Driver
-#  DEBUG_UNDI      0x00010000  // UNDI Driver
-#  DEBUG_LOADFILE  0x00020000  // UNDI Driver
-#  DEBUG_EVENT     0x00080000  // Event messages
-#  DEBUG_ERROR     0x80000000  // Error
-  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000004
-
-  gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07
-  
-  gEmbeddedTokenSpaceGuid.PcdPrePiTempMemorySize|0
-  gEmbeddedTokenSpaceGuid.PcdPrePiBfvBaseAddress|0
-  gEmbeddedTokenSpaceGuid.PcdPrePiBfvSize|0
-  gEmbeddedTokenSpaceGuid.PcdFlashFvMainBase|0
-  gEmbeddedTokenSpaceGuid.PcdFlashFvMainSize|0
-  gEmbeddedTokenSpaceGuid.PcdPrePiHobBase|0x80001000
-  gEmbeddedTokenSpaceGuid.PcdPrePiStackBase|0x87FE0000 # stack at top of memory
-  gEmbeddedTokenSpaceGuid.PcdPrePiStackSize|0x20000  # 128K stack
-  gArmTokenSpaceGuid.PcdCpuVectorBaseAddress|0x80000000
-  gArmTokenSpaceGuid.PcdCpuResetAddress|0x80008000
-  
-  gOmap35xxTokenSpaceGuid.PcdOmap35xxGpmcOffset|0x6E000000
-  gOmap35xxTokenSpaceGuid.PcdOmap35xxMMCHS1Base|0x4809C000
-
-  # Console  
-  gOmap35xxTokenSpaceGuid.PcdOmap35xxConsoleUart|3
-  
-  # Timers
-  gOmap35xxTokenSpaceGuid.PcdOmap35xxArchTimer|3
-  gOmap35xxTokenSpaceGuid.PcdOmap35xxFreeTimer|4
-  gEmbeddedTokenSpaceGuid.PcdTimerPeriod|100000
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterPeriodInNanoseconds|77
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterFrequencyInHz|13000000
-  
-  #
-  # ARM Pcds
-  #
-  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000
-
-################################################################################
-#
-# Components Section - list of all EDK II Modules needed by this Platform
-#
-################################################################################
-[Components.common]
-  Omap35xxPkg/Library/Omap35xxTimerLib/Omap35xxTimerLib.inf  
-  Omap35xxPkg/Library/OmapLib/OmapLib.inf
-  Omap35xxPkg/Library/OmapDmaLib/OmapDmaLib.inf
-  
-  Omap35xxPkg/Flash/Flash.inf
-  Omap35xxPkg/MMCHSDxe/MMCHS.inf
-  Omap35xxPkg/SmbusDxe/Smbus.inf
-  Omap35xxPkg/Gpio/Gpio.inf
-  Omap35xxPkg/InterruptDxe/InterruptDxe.inf
-  Omap35xxPkg/TimerDxe/TimerDxe.inf 
-  Omap35xxPkg/TPS65950Dxe/TPS65950.inf
-  
-  
-
+#/** @file\r
+# Omap35xx SoC package.\r
+#\r
+# Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>\r
+#\r
+#    This program and the accompanying materials\r
+#    are licensed and made available under the terms and conditions of the BSD License\r
+#    which accompanies this distribution. The full text of the license may be found at\r
+#    http://opensource.org/licenses/bsd-license.php\r
+#\r
+#    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  PLATFORM_NAME                  = Omap35xxPkg\r
+  PLATFORM_GUID                  = D196A631-B7B7-4953-A3EE-0F773CBABF20\r
+  PLATFORM_VERSION               = 0.1\r
+  DSC_SPECIFICATION              = 0x00010005\r
+  OUTPUT_DIRECTORY               = Build/Omap35xxPkg\r
+  SUPPORTED_ARCHITECTURES        = ARM\r
+  BUILD_TARGETS                  = DEBUG|RELEASE\r
+  SKUID_IDENTIFIER               = DEFAULT\r
+  DEFINE TARGET_HACK             = DEBUG\r
+\r
+\r
+[LibraryClasses.common]\r
+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
+\r
+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf\r
+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
+  \r
+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf\r
+  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf\r
+\r
+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf\r
+  \r
+  CacheMaintenanceLib|ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf\r
+  DefaultExceptioHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf\r
+  CpuExceptionHandlerLib|MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.inf\r
+  PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf\r
+  \r
+  RealTimeClockLib|EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf\r
+\r
+  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf\r
+  OmapLib|Omap35xxPkg/Library/OmapLib/OmapLib.inf\r
+  OmapDmaLib|Omap35xxPkg/Library/OmapDmaLib/OmapDmaLib.inf\r
+  \r
+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
+\r
+  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
+  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf\r
+  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf\r
+  DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf\r
+\r
+#\r
+# Assume everything is fixed at build\r
+#\r
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+\r
+  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf\r
+    \r
+ # UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf\r
+  UncachedMemoryAllocationLib|ArmPkg/Library/DebugUncachedMemoryAllocationLib/DebugUncachedMemoryAllocationLib.inf\r
+\r
+  CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf\r
+\r
+\r
+[LibraryClasses.common.DXE_DRIVER]\r
+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf\r
+\r
+\r
+[LibraryClasses.ARM]\r
+  #\r
+  # Note: This NULL library feature is not yet in the edk2/BaseTools, but it is checked in to \r
+  # the BaseTools project. So you need to build with the BaseTools project util this feature gets synced.\r
+  #\r
+  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf\r
+\r
+\r
+[BuildOptions]\r
+  XCODE:*_*_ARM_ARCHCC_FLAGS     == -arch armv7 -march=armv7\r
+  XCODE:*_*_ARM_ARCHASM_FLAGS    == -arch armv7\r
+  XCODE:*_*_ARM_ARCHDLINK_FLAGS  == -arch armv7\r
+\r
+  GCC:*_*_ARM_ARCHCC_FLAGS     == -march=armv7-a -mthumb\r
+  GCC:*_*_ARM_ARCHASM_FLAGS    == -march=armv7-a\r
+\r
+  RVCT:*_*_ARM_ARCHCC_FLAGS     == --cpu 7-A\r
+  RVCT:*_*_ARM_ARCHASM_FLAGS    == --cpu 7-A\r
\r
+\r
+################################################################################\r
+#\r
+# Pcd Section - list of all EDK II PCD Entries defined by this Platform\r
+#\r
+################################################################################\r
+\r
+  \r
+[PcdsFixedAtBuild.common]\r
+\r
+# DEBUG_ASSERT_ENABLED       0x01\r
+# DEBUG_PRINT_ENABLED        0x02\r
+# DEBUG_CODE_ENABLED         0x04\r
+# CLEAR_MEMORY_ENABLED       0x08\r
+# ASSERT_BREAKPOINT_ENABLED  0x10\r
+# ASSERT_DEADLOOP_ENABLED    0x20\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2f\r
+\r
+#  DEBUG_INIT      0x00000001  // Initialization\r
+#  DEBUG_WARN      0x00000002  // Warnings\r
+#  DEBUG_LOAD      0x00000004  // Load events\r
+#  DEBUG_FS        0x00000008  // EFI File system\r
+#  DEBUG_POOL      0x00000010  // Alloc & Free's\r
+#  DEBUG_PAGE      0x00000020  // Alloc & Free's\r
+#  DEBUG_INFO      0x00000040  // Verbose\r
+#  DEBUG_DISPATCH  0x00000080  // PEI/DXE Dispatchers\r
+#  DEBUG_VARIABLE  0x00000100  // Variable\r
+#  DEBUG_BM        0x00000400  // Boot Manager\r
+#  DEBUG_BLKIO     0x00001000  // BlkIo Driver\r
+#  DEBUG_NET       0x00004000  // SNI Driver\r
+#  DEBUG_UNDI      0x00010000  // UNDI Driver\r
+#  DEBUG_LOADFILE  0x00020000  // UNDI Driver\r
+#  DEBUG_EVENT     0x00080000  // Event messages\r
+#  DEBUG_ERROR     0x80000000  // Error\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000004\r
+\r
+  gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07\r
+  \r
+  gEmbeddedTokenSpaceGuid.PcdPrePiTempMemorySize|0\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiBfvBaseAddress|0\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiBfvSize|0\r
+  gEmbeddedTokenSpaceGuid.PcdFlashFvMainBase|0\r
+  gEmbeddedTokenSpaceGuid.PcdFlashFvMainSize|0\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiHobBase|0x80001000\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiStackBase|0x87FE0000 # stack at top of memory\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiStackSize|0x20000  # 128K stack\r
+  gArmTokenSpaceGuid.PcdCpuVectorBaseAddress|0x80000000\r
+  gArmTokenSpaceGuid.PcdCpuResetAddress|0x80008000\r
+  \r
+  gOmap35xxTokenSpaceGuid.PcdOmap35xxGpmcOffset|0x6E000000\r
+  gOmap35xxTokenSpaceGuid.PcdOmap35xxMMCHS1Base|0x4809C000\r
+\r
+  # Console  \r
+  gOmap35xxTokenSpaceGuid.PcdOmap35xxConsoleUart|3\r
+  \r
+  # Timers\r
+  gOmap35xxTokenSpaceGuid.PcdOmap35xxArchTimer|3\r
+  gOmap35xxTokenSpaceGuid.PcdOmap35xxFreeTimer|4\r
+  gEmbeddedTokenSpaceGuid.PcdTimerPeriod|100000\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterPeriodInNanoseconds|77\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterFrequencyInHz|13000000\r
+  \r
+  #\r
+  # ARM Pcds\r
+  #\r
+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000\r
+\r
+################################################################################\r
+#\r
+# Components Section - list of all EDK II Modules needed by this Platform\r
+#\r
+################################################################################\r
+[Components.common]\r
+  Omap35xxPkg/Library/Omap35xxTimerLib/Omap35xxTimerLib.inf  \r
+  Omap35xxPkg/Library/OmapLib/OmapLib.inf\r
+  Omap35xxPkg/Library/OmapDmaLib/OmapDmaLib.inf\r
+  \r
+  Omap35xxPkg/Flash/Flash.inf\r
+  Omap35xxPkg/MMCHSDxe/MMCHS.inf\r
+  Omap35xxPkg/SmbusDxe/Smbus.inf\r
+  Omap35xxPkg/Gpio/Gpio.inf\r
+  Omap35xxPkg/InterruptDxe/InterruptDxe.inf\r
+  Omap35xxPkg/TimerDxe/TimerDxe.inf \r
+  Omap35xxPkg/TPS65950Dxe/TPS65950.inf\r
+  \r
+  \r
+\r
index 6b5528cea429e45dc713f1245a31966a4fe0f6d8..0cc0faa42c69bd7b3b8a8afcc91d03a9e0e57e7e 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 "PciEmulation.h"
-
-EMBEDDED_EXTERNAL_DEVICE   *gTPS65950;
-
-#define HOST_CONTROLLER_OPERATION_REG_SIZE  0x44
-
-typedef struct {
-  ACPI_HID_DEVICE_PATH      AcpiDevicePath;
-  PCI_DEVICE_PATH           PciDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;
-} EFI_PCI_IO_DEVICE_PATH;
-
-typedef struct {
-  UINT32                  Signature;
-  EFI_PCI_IO_DEVICE_PATH  DevicePath;
-  EFI_PCI_IO_PROTOCOL     PciIoProtocol;
-  PCI_TYPE00              *ConfigSpace;
-  PCI_ROOT_BRIDGE         RootBridge;
-  UINTN                   Segment;
-} EFI_PCI_IO_PRIVATE_DATA;
-
-#define EFI_PCI_IO_PRIVATE_DATA_SIGNATURE     SIGNATURE_32('p', 'c', 'i', 'o')
-#define EFI_PCI_IO_PRIVATE_DATA_FROM_THIS(a)  CR(a, EFI_PCI_IO_PRIVATE_DATA, PciIoProtocol, EFI_PCI_IO_PRIVATE_DATA_SIGNATURE)
-
-EFI_PCI_IO_DEVICE_PATH PciIoDevicePathTemplate = 
-{
-  {
-    { ACPI_DEVICE_PATH, ACPI_DP, sizeof (ACPI_HID_DEVICE_PATH), 0},
-    EISA_PNP_ID(0x0A03),  // HID
-    0                     // UID
-  },
-  {
-    { HARDWARE_DEVICE_PATH, HW_PCI_DP, sizeof (PCI_DEVICE_PATH), 0},
-    0,
-    0
-  },
-  { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, sizeof (EFI_DEVICE_PATH_PROTOCOL), 0}
-};
-
-STATIC
-VOID
-ConfigureUSBHost (
-  VOID
-  )
-{
-  EFI_STATUS Status;
-  UINT8      Data = 0;
-
-  // Take USB host out of force-standby mode
-  MmioWrite32 (UHH_SYSCONFIG, UHH_SYSCONFIG_MIDLEMODE_NO_STANDBY
-                            | UHH_SYSCONFIG_CLOCKACTIVITY_ON
-                            | UHH_SYSCONFIG_SIDLEMODE_NO_STANDBY
-                            | UHH_SYSCONFIG_ENAWAKEUP_ENABLE
-                            | UHH_SYSCONFIG_AUTOIDLE_ALWAYS_RUN);
-  MmioWrite32 (UHH_HOSTCONFIG, UHH_HOSTCONFIG_P3_CONNECT_STATUS_DISCONNECT
-                             | UHH_HOSTCONFIG_P2_CONNECT_STATUS_DISCONNECT
-                             | UHH_HOSTCONFIG_P1_CONNECT_STATUS_DISCONNECT
-                             | UHH_HOSTCONFIG_ENA_INCR_ALIGN_DISABLE
-                             | UHH_HOSTCONFIG_ENA_INCR16_ENABLE
-                             | UHH_HOSTCONFIG_ENA_INCR8_ENABLE
-                             | UHH_HOSTCONFIG_ENA_INCR4_ENABLE
-                             | UHH_HOSTCONFIG_AUTOPPD_ON_OVERCUR_EN_ON
-                             | UHH_HOSTCONFIG_P1_ULPI_BYPASS_ULPI_MODE);
-
-  // USB reset (GPIO 147 - Port 5 pin 19) output high
-  MmioAnd32 (GPIO5_BASE + GPIO_OE, ~BIT19);
-  MmioWrite32 (GPIO5_BASE + GPIO_SETDATAOUT, BIT19);
-
-  // Get the Power IC protocol
-  Status = gBS->LocateProtocol (&gEmbeddedExternalDeviceProtocolGuid, NULL, (VOID **)&gTPS65950);
-  ASSERT_EFI_ERROR (Status);  
-
-  // Power the USB PHY
-  Data = VAUX_DEV_GRP_P1;
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VAUX2_DEV_GRP), 1, &Data);
-  ASSERT_EFI_ERROR(Status);
-
-  Data = VAUX_DEDICATED_18V;
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VAUX2_DEDICATED), 1, &Data);
-  ASSERT_EFI_ERROR (Status);  
-
-  // Enable power to the USB hub
-  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID3, LEDEN), 1, &Data);
-  ASSERT_EFI_ERROR (Status);
-
-  // LEDAON controls the power to the USB host, PWM is disabled
-  Data &= ~LEDAPWM;
-  Data |= LEDAON;
-
-  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID3, LEDEN), 1, &Data);
-  ASSERT_EFI_ERROR (Status);
-}
-
-
-EFI_STATUS
-PciIoPollMem (
-  IN EFI_PCI_IO_PROTOCOL           *This,
-  IN  EFI_PCI_IO_PROTOCOL_WIDTH    Width,
-  IN  UINT8                        BarIndex,
-  IN  UINT64                       Offset,
-  IN  UINT64                       Mask,
-  IN  UINT64                       Value,
-  IN  UINT64                       Delay,
-  OUT UINT64                       *Result
-  )
-{
-  ASSERT (FALSE);
-  return EFI_UNSUPPORTED;
-}
-
-EFI_STATUS
-PciIoPollIo (
-  IN EFI_PCI_IO_PROTOCOL           *This,
-  IN  EFI_PCI_IO_PROTOCOL_WIDTH    Width,
-  IN  UINT8                        BarIndex,
-  IN  UINT64                       Offset,
-  IN  UINT64                       Mask,
-  IN  UINT64                       Value,
-  IN  UINT64                       Delay,
-  OUT UINT64                       *Result
-  )
-{
-  ASSERT (FALSE);
-  return EFI_UNSUPPORTED;
-}
-
-EFI_STATUS
-PciIoMemRead (
-  IN EFI_PCI_IO_PROTOCOL              *This,
-  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,
-  IN     UINT8                        BarIndex,
-  IN     UINT64                       Offset,
-  IN     UINTN                        Count,
-  IN OUT VOID                         *Buffer
-  )
-{
-  EFI_PCI_IO_PRIVATE_DATA *Private = EFI_PCI_IO_PRIVATE_DATA_FROM_THIS(This);
-
-  return PciRootBridgeIoMemRead (&Private->RootBridge.Io, 
-                                (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,
-                                Private->ConfigSpace->Device.Bar[BarIndex] + Offset,
-                                Count,
-                                Buffer
-                                );
-}
-
-EFI_STATUS
-PciIoMemWrite (
-  IN EFI_PCI_IO_PROTOCOL              *This,
-  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,
-  IN     UINT8                        BarIndex,
-  IN     UINT64                       Offset,
-  IN     UINTN                        Count,
-  IN OUT VOID                         *Buffer
-  )
-{
-  EFI_PCI_IO_PRIVATE_DATA *Private = EFI_PCI_IO_PRIVATE_DATA_FROM_THIS(This);
-
-  return PciRootBridgeIoMemWrite (&Private->RootBridge.Io, 
-                                 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,
-                                 Private->ConfigSpace->Device.Bar[BarIndex] + Offset,
-                                 Count,
-                                 Buffer
-                                 );
-}
-
-EFI_STATUS
-PciIoIoRead (
-  IN EFI_PCI_IO_PROTOCOL              *This,
-  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,
-  IN     UINT8                        BarIndex,
-  IN     UINT64                       Offset,
-  IN     UINTN                        Count,
-  IN OUT VOID                         *Buffer
-  )
-{
-  ASSERT (FALSE);
-  return EFI_UNSUPPORTED;
-}
-
-EFI_STATUS
-PciIoIoWrite (
-  IN EFI_PCI_IO_PROTOCOL              *This,
-  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,
-  IN     UINT8                        BarIndex,
-  IN     UINT64                       Offset,
-  IN     UINTN                        Count,
-  IN OUT VOID                         *Buffer
-  )
-{
-  ASSERT (FALSE);
-  return EFI_UNSUPPORTED;
-}
-
-EFI_STATUS
-PciIoPciRead (
-  IN EFI_PCI_IO_PROTOCOL              *This,
-  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,
-  IN     UINT32                       Offset,
-  IN     UINTN                        Count,
-  IN OUT VOID                         *Buffer
-  )
-{
-  EFI_PCI_IO_PRIVATE_DATA *Private = EFI_PCI_IO_PRIVATE_DATA_FROM_THIS(This);
-
-  return PciRootBridgeIoMemRW ((EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH)Width, 
-                               Count, 
-                               TRUE, 
-                               (PTR)(UINTN)Buffer, 
-                               TRUE, 
-                               (PTR)(UINTN)(((UINT8 *)Private->ConfigSpace) + Offset)
-                              );
-}
-
-EFI_STATUS
-PciIoPciWrite (
-  IN EFI_PCI_IO_PROTOCOL              *This,
-  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,
-  IN     UINT32                       Offset,
-  IN     UINTN                        Count,
-  IN OUT VOID                         *Buffer
-  )
-{
-  EFI_PCI_IO_PRIVATE_DATA *Private = EFI_PCI_IO_PRIVATE_DATA_FROM_THIS(This);
-
-  return PciRootBridgeIoMemRW ((EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width, 
-                               Count, 
-                               TRUE, 
-                               (PTR)(UINTN)(((UINT8 *)Private->ConfigSpace) + Offset), 
-                               TRUE, 
-                               (PTR)(UINTN)Buffer
-                               );
-}
-
-EFI_STATUS
-PciIoCopyMem (
-  IN EFI_PCI_IO_PROTOCOL              *This,
-  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,
-  IN     UINT8                        DestBarIndex,
-  IN     UINT64                       DestOffset,
-  IN     UINT8                        SrcBarIndex,
-  IN     UINT64                       SrcOffset,
-  IN     UINTN                        Count
-  )
-{
-  ASSERT (FALSE);
-  return EFI_UNSUPPORTED;
-}
-
-EFI_STATUS
-PciIoMap (
-  IN EFI_PCI_IO_PROTOCOL                *This,
-  IN     EFI_PCI_IO_PROTOCOL_OPERATION  Operation,
-  IN     VOID                           *HostAddress,
-  IN OUT UINTN                          *NumberOfBytes,
-  OUT    EFI_PHYSICAL_ADDRESS           *DeviceAddress,
-  OUT    VOID                           **Mapping
-  )
-{
-  DMA_MAP_OPERATION   DmaOperation;
-
-  if (Operation == EfiPciIoOperationBusMasterRead) {
-    DmaOperation = MapOperationBusMasterRead;
-  } else if (Operation == EfiPciIoOperationBusMasterWrite) {
-    DmaOperation = MapOperationBusMasterWrite;
-  } else if (Operation == EfiPciIoOperationBusMasterCommonBuffer) {
-    DmaOperation = MapOperationBusMasterCommonBuffer;
-  } else {
-    return EFI_INVALID_PARAMETER;
-  }
-  return DmaMap (DmaOperation, HostAddress, NumberOfBytes, DeviceAddress, Mapping);
-}
-
-EFI_STATUS
-PciIoUnmap (
-  IN EFI_PCI_IO_PROTOCOL           *This,
-  IN  VOID                         *Mapping
-  )
-{
-  return DmaUnmap (Mapping);
-}
-
-EFI_STATUS
-PciIoAllocateBuffer (
-  IN EFI_PCI_IO_PROTOCOL           *This,
-  IN  EFI_ALLOCATE_TYPE            Type,
-  IN  EFI_MEMORY_TYPE              MemoryType,
-  IN  UINTN                        Pages,
-  OUT VOID                         **HostAddress,
-  IN  UINT64                       Attributes
-  )
-{
-  if (Attributes & EFI_PCI_ATTRIBUTE_INVALID_FOR_ALLOCATE_BUFFER) {
-    // Check this
-    return EFI_UNSUPPORTED;
-  }
-
-  return DmaAllocateBuffer (MemoryType, Pages, HostAddress);
-}
-
-
-EFI_STATUS
-PciIoFreeBuffer (
-  IN EFI_PCI_IO_PROTOCOL           *This,
-  IN  UINTN                        Pages,
-  IN  VOID                         *HostAddress
-  )
-{
-  return DmaFreeBuffer (Pages, HostAddress);
-}
-
-
-EFI_STATUS
-PciIoFlush (
-  IN EFI_PCI_IO_PROTOCOL  *This
-  )
-{
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-PciIoGetLocation (
-  IN EFI_PCI_IO_PROTOCOL          *This,
-  OUT UINTN                       *SegmentNumber,
-  OUT UINTN                       *BusNumber,
-  OUT UINTN                       *DeviceNumber,
-  OUT UINTN                       *FunctionNumber
-  )
-{
-  EFI_PCI_IO_PRIVATE_DATA *Private = EFI_PCI_IO_PRIVATE_DATA_FROM_THIS(This);
-
-  if (SegmentNumber != NULL) {
-    *SegmentNumber = Private->Segment;
-  }
-
-  if (BusNumber != NULL) {
-    *BusNumber = 0xff;
-  }
-
-  if (DeviceNumber != NULL) {
-    *DeviceNumber = 0;
-  }
-
-  if (FunctionNumber != NULL) {
-    *FunctionNumber = 0;
-  }
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-PciIoAttributes (
-  IN EFI_PCI_IO_PROTOCOL                       *This,
-  IN  EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION  Operation,
-  IN  UINT64                                   Attributes,
-  OUT UINT64                                   *Result OPTIONAL
-  )
-{
-  switch (Operation) {
-  case EfiPciIoAttributeOperationGet:
-  case EfiPciIoAttributeOperationSupported:
-    if (Result == NULL) {
-      return EFI_INVALID_PARAMETER;
-    }
-    // We are not a real PCI device so just say things we kind of do
-    *Result = EFI_PCI_IO_ATTRIBUTE_MEMORY | EFI_PCI_IO_ATTRIBUTE_BUS_MASTER | EFI_PCI_DEVICE_ENABLE;
-    break;
-
-  case EfiPciIoAttributeOperationSet:
-  case EfiPciIoAttributeOperationEnable:
-  case EfiPciIoAttributeOperationDisable:
-    // Since we are not a real PCI device no enable/set or disable operations exist.
-    return EFI_SUCCESS;
-    
-  default:
-  ASSERT (FALSE);
-    return EFI_INVALID_PARAMETER;
-  };
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS
-PciIoGetBarAttributes (
-  IN EFI_PCI_IO_PROTOCOL             *This,
-  IN  UINT8                          BarIndex,
-  OUT UINT64                         *Supports, OPTIONAL
-  OUT VOID                           **Resources OPTIONAL
-  )
-{
-  ASSERT (FALSE);
-  return EFI_UNSUPPORTED;
-}
-
-EFI_STATUS
-PciIoSetBarAttributes (
-  IN EFI_PCI_IO_PROTOCOL              *This,
-  IN     UINT64                       Attributes,
-  IN     UINT8                        BarIndex,
-  IN OUT UINT64                       *Offset,
-  IN OUT UINT64                       *Length
-  )
-{
-  ASSERT (FALSE);
-  return EFI_UNSUPPORTED;
-}
-
-EFI_PCI_IO_PROTOCOL PciIoTemplate = 
-{
-  PciIoPollMem,
-  PciIoPollIo,
-  PciIoMemRead,
-  PciIoMemWrite,
-  PciIoIoRead,
-  PciIoIoWrite,
-  PciIoPciRead,
-  PciIoPciWrite,
-  PciIoCopyMem,
-  PciIoMap,
-  PciIoUnmap,
-  PciIoAllocateBuffer,
-  PciIoFreeBuffer,
-  PciIoFlush,
-  PciIoGetLocation,
-  PciIoAttributes,
-  PciIoGetBarAttributes,
-  PciIoSetBarAttributes,
-  0,
-  0
-};
-
-EFI_STATUS
-EFIAPI
-PciEmulationEntryPoint (
-  IN EFI_HANDLE       ImageHandle,
-  IN EFI_SYSTEM_TABLE *SystemTable
-  )
-{
-  EFI_STATUS              Status;
-  EFI_HANDLE              Handle;
-  EFI_PCI_IO_PRIVATE_DATA *Private;
-  UINT8                   CapabilityLength;
-  UINT8                   PhysicalPorts;
-  UINTN                   Count;
-
-
-  //Configure USB host for OMAP3530.
-  ConfigureUSBHost();
-
-  // Create a private structure
-  Private = AllocatePool(sizeof(EFI_PCI_IO_PRIVATE_DATA));
-  if (Private == NULL) {
-    Status = EFI_OUT_OF_RESOURCES;
-    return Status;
-  }
-  
-  Private->Signature              = EFI_PCI_IO_PRIVATE_DATA_SIGNATURE;  // Fill in signature
-  Private->RootBridge.Signature   = PCI_ROOT_BRIDGE_SIGNATURE;          // Fake Root Bridge structure needs a signature too
-  Private->RootBridge.MemoryStart = USB_EHCI_HCCAPBASE;                 // Get the USB capability register base
-  Private->Segment                = 0;                                  // Default to segment zero
-
-  // Find out the capability register length and number of physical ports.
-  CapabilityLength = MmioRead8(Private->RootBridge.MemoryStart);
-  PhysicalPorts    = (MmioRead32 (Private->RootBridge.MemoryStart + 0x4)) & 0x0000000F;
-
-  // Calculate the total size of the USB registers.
-  Private->RootBridge.MemorySize = CapabilityLength + (HOST_CONTROLLER_OPERATION_REG_SIZE + ((4 * PhysicalPorts) - 1));
-
-  // Enable Port Power bit in Port status and control registers in EHCI register space.
-  // Port Power Control (PPC) bit in the HCSPARAMS register is already set which indicates
-  // host controller implementation includes port power control.
-  for (Count = 0; Count < PhysicalPorts; Count++) {
-    MmioOr32 ((Private->RootBridge.MemoryStart + CapabilityLength + HOST_CONTROLLER_OPERATION_REG_SIZE + 4*Count), 0x00001000);
-  }
-
-  // Create fake PCI config space.
-  Private->ConfigSpace = AllocateZeroPool(sizeof(PCI_TYPE00));
-  if (Private->ConfigSpace == NULL) {
-    Status = EFI_OUT_OF_RESOURCES;
-    FreePool(Private);
-    return Status;
-  }
-
-  // Configure PCI config space
-  Private->ConfigSpace->Hdr.VendorId = 0x3530;
-  Private->ConfigSpace->Hdr.DeviceId = 0x3530;
-  Private->ConfigSpace->Hdr.ClassCode[0] = 0x20;
-  Private->ConfigSpace->Hdr.ClassCode[1] = 0x03;
-  Private->ConfigSpace->Hdr.ClassCode[2] = 0x0C;
-  Private->ConfigSpace->Device.Bar[0] = Private->RootBridge.MemoryStart;
-
-  Handle = NULL;
-
-  // Unique device path.
-  CopyMem(&Private->DevicePath, &PciIoDevicePathTemplate, sizeof(PciIoDevicePathTemplate));
-  Private->DevicePath.AcpiDevicePath.UID = 0;
-  
-  // Copy protocol structure
-  CopyMem(&Private->PciIoProtocol, &PciIoTemplate, sizeof(PciIoTemplate));
-
-  Status = gBS->InstallMultipleProtocolInterfaces(&Handle,
-                                                  &gEfiPciIoProtocolGuid,       &Private->PciIoProtocol,
-                                                  &gEfiDevicePathProtocolGuid,  &Private->DevicePath,
-                                                  NULL);
-  if (EFI_ERROR(Status)) {
-    DEBUG((EFI_D_ERROR, "PciEmulationEntryPoint InstallMultipleProtocolInterfaces() failed.\n"));
-  }
-
-  return Status;
-}
-
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "PciEmulation.h"\r
+\r
+EMBEDDED_EXTERNAL_DEVICE   *gTPS65950;\r
+\r
+#define HOST_CONTROLLER_OPERATION_REG_SIZE  0x44\r
+\r
+typedef struct {\r
+  ACPI_HID_DEVICE_PATH      AcpiDevicePath;\r
+  PCI_DEVICE_PATH           PciDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} EFI_PCI_IO_DEVICE_PATH;\r
+\r
+typedef struct {\r
+  UINT32                  Signature;\r
+  EFI_PCI_IO_DEVICE_PATH  DevicePath;\r
+  EFI_PCI_IO_PROTOCOL     PciIoProtocol;\r
+  PCI_TYPE00              *ConfigSpace;\r
+  PCI_ROOT_BRIDGE         RootBridge;\r
+  UINTN                   Segment;\r
+} EFI_PCI_IO_PRIVATE_DATA;\r
+\r
+#define EFI_PCI_IO_PRIVATE_DATA_SIGNATURE     SIGNATURE_32('p', 'c', 'i', 'o')\r
+#define EFI_PCI_IO_PRIVATE_DATA_FROM_THIS(a)  CR(a, EFI_PCI_IO_PRIVATE_DATA, PciIoProtocol, EFI_PCI_IO_PRIVATE_DATA_SIGNATURE)\r
+\r
+EFI_PCI_IO_DEVICE_PATH PciIoDevicePathTemplate = \r
+{\r
+  {\r
+    { ACPI_DEVICE_PATH, ACPI_DP, sizeof (ACPI_HID_DEVICE_PATH), 0},\r
+    EISA_PNP_ID(0x0A03),  // HID\r
+    0                     // UID\r
+  },\r
+  {\r
+    { HARDWARE_DEVICE_PATH, HW_PCI_DP, sizeof (PCI_DEVICE_PATH), 0},\r
+    0,\r
+    0\r
+  },\r
+  { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, sizeof (EFI_DEVICE_PATH_PROTOCOL), 0}\r
+};\r
+\r
+STATIC\r
+VOID\r
+ConfigureUSBHost (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  UINT8      Data = 0;\r
+\r
+  // Take USB host out of force-standby mode\r
+  MmioWrite32 (UHH_SYSCONFIG, UHH_SYSCONFIG_MIDLEMODE_NO_STANDBY\r
+                            | UHH_SYSCONFIG_CLOCKACTIVITY_ON\r
+                            | UHH_SYSCONFIG_SIDLEMODE_NO_STANDBY\r
+                            | UHH_SYSCONFIG_ENAWAKEUP_ENABLE\r
+                            | UHH_SYSCONFIG_AUTOIDLE_ALWAYS_RUN);\r
+  MmioWrite32 (UHH_HOSTCONFIG, UHH_HOSTCONFIG_P3_CONNECT_STATUS_DISCONNECT\r
+                             | UHH_HOSTCONFIG_P2_CONNECT_STATUS_DISCONNECT\r
+                             | UHH_HOSTCONFIG_P1_CONNECT_STATUS_DISCONNECT\r
+                             | UHH_HOSTCONFIG_ENA_INCR_ALIGN_DISABLE\r
+                             | UHH_HOSTCONFIG_ENA_INCR16_ENABLE\r
+                             | UHH_HOSTCONFIG_ENA_INCR8_ENABLE\r
+                             | UHH_HOSTCONFIG_ENA_INCR4_ENABLE\r
+                             | UHH_HOSTCONFIG_AUTOPPD_ON_OVERCUR_EN_ON\r
+                             | UHH_HOSTCONFIG_P1_ULPI_BYPASS_ULPI_MODE);\r
+\r
+  // USB reset (GPIO 147 - Port 5 pin 19) output high\r
+  MmioAnd32 (GPIO5_BASE + GPIO_OE, ~BIT19);\r
+  MmioWrite32 (GPIO5_BASE + GPIO_SETDATAOUT, BIT19);\r
+\r
+  // Get the Power IC protocol\r
+  Status = gBS->LocateProtocol (&gEmbeddedExternalDeviceProtocolGuid, NULL, (VOID **)&gTPS65950);\r
+  ASSERT_EFI_ERROR (Status);  \r
+\r
+  // Power the USB PHY\r
+  Data = VAUX_DEV_GRP_P1;\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VAUX2_DEV_GRP), 1, &Data);\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  Data = VAUX_DEDICATED_18V;\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VAUX2_DEDICATED), 1, &Data);\r
+  ASSERT_EFI_ERROR (Status);  \r
+\r
+  // Enable power to the USB hub\r
+  Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID3, LEDEN), 1, &Data);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  // LEDAON controls the power to the USB host, PWM is disabled\r
+  Data &= ~LEDAPWM;\r
+  Data |= LEDAON;\r
+\r
+  Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID3, LEDEN), 1, &Data);\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+\r
+EFI_STATUS\r
+PciIoPollMem (\r
+  IN EFI_PCI_IO_PROTOCOL           *This,\r
+  IN  EFI_PCI_IO_PROTOCOL_WIDTH    Width,\r
+  IN  UINT8                        BarIndex,\r
+  IN  UINT64                       Offset,\r
+  IN  UINT64                       Mask,\r
+  IN  UINT64                       Value,\r
+  IN  UINT64                       Delay,\r
+  OUT UINT64                       *Result\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+PciIoPollIo (\r
+  IN EFI_PCI_IO_PROTOCOL           *This,\r
+  IN  EFI_PCI_IO_PROTOCOL_WIDTH    Width,\r
+  IN  UINT8                        BarIndex,\r
+  IN  UINT64                       Offset,\r
+  IN  UINT64                       Mask,\r
+  IN  UINT64                       Value,\r
+  IN  UINT64                       Delay,\r
+  OUT UINT64                       *Result\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+PciIoMemRead (\r
+  IN EFI_PCI_IO_PROTOCOL              *This,\r
+  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,\r
+  IN     UINT8                        BarIndex,\r
+  IN     UINT64                       Offset,\r
+  IN     UINTN                        Count,\r
+  IN OUT VOID                         *Buffer\r
+  )\r
+{\r
+  EFI_PCI_IO_PRIVATE_DATA *Private = EFI_PCI_IO_PRIVATE_DATA_FROM_THIS(This);\r
+\r
+  return PciRootBridgeIoMemRead (&Private->RootBridge.Io, \r
+                                (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,\r
+                                Private->ConfigSpace->Device.Bar[BarIndex] + Offset,\r
+                                Count,\r
+                                Buffer\r
+                                );\r
+}\r
+\r
+EFI_STATUS\r
+PciIoMemWrite (\r
+  IN EFI_PCI_IO_PROTOCOL              *This,\r
+  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,\r
+  IN     UINT8                        BarIndex,\r
+  IN     UINT64                       Offset,\r
+  IN     UINTN                        Count,\r
+  IN OUT VOID                         *Buffer\r
+  )\r
+{\r
+  EFI_PCI_IO_PRIVATE_DATA *Private = EFI_PCI_IO_PRIVATE_DATA_FROM_THIS(This);\r
+\r
+  return PciRootBridgeIoMemWrite (&Private->RootBridge.Io, \r
+                                 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,\r
+                                 Private->ConfigSpace->Device.Bar[BarIndex] + Offset,\r
+                                 Count,\r
+                                 Buffer\r
+                                 );\r
+}\r
+\r
+EFI_STATUS\r
+PciIoIoRead (\r
+  IN EFI_PCI_IO_PROTOCOL              *This,\r
+  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,\r
+  IN     UINT8                        BarIndex,\r
+  IN     UINT64                       Offset,\r
+  IN     UINTN                        Count,\r
+  IN OUT VOID                         *Buffer\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+PciIoIoWrite (\r
+  IN EFI_PCI_IO_PROTOCOL              *This,\r
+  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,\r
+  IN     UINT8                        BarIndex,\r
+  IN     UINT64                       Offset,\r
+  IN     UINTN                        Count,\r
+  IN OUT VOID                         *Buffer\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+PciIoPciRead (\r
+  IN EFI_PCI_IO_PROTOCOL              *This,\r
+  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,\r
+  IN     UINT32                       Offset,\r
+  IN     UINTN                        Count,\r
+  IN OUT VOID                         *Buffer\r
+  )\r
+{\r
+  EFI_PCI_IO_PRIVATE_DATA *Private = EFI_PCI_IO_PRIVATE_DATA_FROM_THIS(This);\r
+\r
+  return PciRootBridgeIoMemRW ((EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH)Width, \r
+                               Count, \r
+                               TRUE, \r
+                               (PTR)(UINTN)Buffer, \r
+                               TRUE, \r
+                               (PTR)(UINTN)(((UINT8 *)Private->ConfigSpace) + Offset)\r
+                              );\r
+}\r
+\r
+EFI_STATUS\r
+PciIoPciWrite (\r
+  IN EFI_PCI_IO_PROTOCOL              *This,\r
+  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,\r
+  IN     UINT32                       Offset,\r
+  IN     UINTN                        Count,\r
+  IN OUT VOID                         *Buffer\r
+  )\r
+{\r
+  EFI_PCI_IO_PRIVATE_DATA *Private = EFI_PCI_IO_PRIVATE_DATA_FROM_THIS(This);\r
+\r
+  return PciRootBridgeIoMemRW ((EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width, \r
+                               Count, \r
+                               TRUE, \r
+                               (PTR)(UINTN)(((UINT8 *)Private->ConfigSpace) + Offset), \r
+                               TRUE, \r
+                               (PTR)(UINTN)Buffer\r
+                               );\r
+}\r
+\r
+EFI_STATUS\r
+PciIoCopyMem (\r
+  IN EFI_PCI_IO_PROTOCOL              *This,\r
+  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,\r
+  IN     UINT8                        DestBarIndex,\r
+  IN     UINT64                       DestOffset,\r
+  IN     UINT8                        SrcBarIndex,\r
+  IN     UINT64                       SrcOffset,\r
+  IN     UINTN                        Count\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+PciIoMap (\r
+  IN EFI_PCI_IO_PROTOCOL                *This,\r
+  IN     EFI_PCI_IO_PROTOCOL_OPERATION  Operation,\r
+  IN     VOID                           *HostAddress,\r
+  IN OUT UINTN                          *NumberOfBytes,\r
+  OUT    EFI_PHYSICAL_ADDRESS           *DeviceAddress,\r
+  OUT    VOID                           **Mapping\r
+  )\r
+{\r
+  DMA_MAP_OPERATION   DmaOperation;\r
+\r
+  if (Operation == EfiPciIoOperationBusMasterRead) {\r
+    DmaOperation = MapOperationBusMasterRead;\r
+  } else if (Operation == EfiPciIoOperationBusMasterWrite) {\r
+    DmaOperation = MapOperationBusMasterWrite;\r
+  } else if (Operation == EfiPciIoOperationBusMasterCommonBuffer) {\r
+    DmaOperation = MapOperationBusMasterCommonBuffer;\r
+  } else {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  return DmaMap (DmaOperation, HostAddress, NumberOfBytes, DeviceAddress, Mapping);\r
+}\r
+\r
+EFI_STATUS\r
+PciIoUnmap (\r
+  IN EFI_PCI_IO_PROTOCOL           *This,\r
+  IN  VOID                         *Mapping\r
+  )\r
+{\r
+  return DmaUnmap (Mapping);\r
+}\r
+\r
+EFI_STATUS\r
+PciIoAllocateBuffer (\r
+  IN EFI_PCI_IO_PROTOCOL           *This,\r
+  IN  EFI_ALLOCATE_TYPE            Type,\r
+  IN  EFI_MEMORY_TYPE              MemoryType,\r
+  IN  UINTN                        Pages,\r
+  OUT VOID                         **HostAddress,\r
+  IN  UINT64                       Attributes\r
+  )\r
+{\r
+  if (Attributes & EFI_PCI_ATTRIBUTE_INVALID_FOR_ALLOCATE_BUFFER) {\r
+    // Check this\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return DmaAllocateBuffer (MemoryType, Pages, HostAddress);\r
+}\r
+\r
+\r
+EFI_STATUS\r
+PciIoFreeBuffer (\r
+  IN EFI_PCI_IO_PROTOCOL           *This,\r
+  IN  UINTN                        Pages,\r
+  IN  VOID                         *HostAddress\r
+  )\r
+{\r
+  return DmaFreeBuffer (Pages, HostAddress);\r
+}\r
+\r
+\r
+EFI_STATUS\r
+PciIoFlush (\r
+  IN EFI_PCI_IO_PROTOCOL  *This\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+PciIoGetLocation (\r
+  IN EFI_PCI_IO_PROTOCOL          *This,\r
+  OUT UINTN                       *SegmentNumber,\r
+  OUT UINTN                       *BusNumber,\r
+  OUT UINTN                       *DeviceNumber,\r
+  OUT UINTN                       *FunctionNumber\r
+  )\r
+{\r
+  EFI_PCI_IO_PRIVATE_DATA *Private = EFI_PCI_IO_PRIVATE_DATA_FROM_THIS(This);\r
+\r
+  if (SegmentNumber != NULL) {\r
+    *SegmentNumber = Private->Segment;\r
+  }\r
+\r
+  if (BusNumber != NULL) {\r
+    *BusNumber = 0xff;\r
+  }\r
+\r
+  if (DeviceNumber != NULL) {\r
+    *DeviceNumber = 0;\r
+  }\r
+\r
+  if (FunctionNumber != NULL) {\r
+    *FunctionNumber = 0;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+PciIoAttributes (\r
+  IN EFI_PCI_IO_PROTOCOL                       *This,\r
+  IN  EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION  Operation,\r
+  IN  UINT64                                   Attributes,\r
+  OUT UINT64                                   *Result OPTIONAL\r
+  )\r
+{\r
+  switch (Operation) {\r
+  case EfiPciIoAttributeOperationGet:\r
+  case EfiPciIoAttributeOperationSupported:\r
+    if (Result == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    // We are not a real PCI device so just say things we kind of do\r
+    *Result = EFI_PCI_IO_ATTRIBUTE_MEMORY | EFI_PCI_IO_ATTRIBUTE_BUS_MASTER | EFI_PCI_DEVICE_ENABLE;\r
+    break;\r
+\r
+  case EfiPciIoAttributeOperationSet:\r
+  case EfiPciIoAttributeOperationEnable:\r
+  case EfiPciIoAttributeOperationDisable:\r
+    // Since we are not a real PCI device no enable/set or disable operations exist.\r
+    return EFI_SUCCESS;\r
+    \r
+  default:\r
+  ASSERT (FALSE);\r
+    return EFI_INVALID_PARAMETER;\r
+  };\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+PciIoGetBarAttributes (\r
+  IN EFI_PCI_IO_PROTOCOL             *This,\r
+  IN  UINT8                          BarIndex,\r
+  OUT UINT64                         *Supports, OPTIONAL\r
+  OUT VOID                           **Resources OPTIONAL\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+PciIoSetBarAttributes (\r
+  IN EFI_PCI_IO_PROTOCOL              *This,\r
+  IN     UINT64                       Attributes,\r
+  IN     UINT8                        BarIndex,\r
+  IN OUT UINT64                       *Offset,\r
+  IN OUT UINT64                       *Length\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_PCI_IO_PROTOCOL PciIoTemplate = \r
+{\r
+  PciIoPollMem,\r
+  PciIoPollIo,\r
+  PciIoMemRead,\r
+  PciIoMemWrite,\r
+  PciIoIoRead,\r
+  PciIoIoWrite,\r
+  PciIoPciRead,\r
+  PciIoPciWrite,\r
+  PciIoCopyMem,\r
+  PciIoMap,\r
+  PciIoUnmap,\r
+  PciIoAllocateBuffer,\r
+  PciIoFreeBuffer,\r
+  PciIoFlush,\r
+  PciIoGetLocation,\r
+  PciIoAttributes,\r
+  PciIoGetBarAttributes,\r
+  PciIoSetBarAttributes,\r
+  0,\r
+  0\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PciEmulationEntryPoint (\r
+  IN EFI_HANDLE       ImageHandle,\r
+  IN EFI_SYSTEM_TABLE *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_HANDLE              Handle;\r
+  EFI_PCI_IO_PRIVATE_DATA *Private;\r
+  UINT8                   CapabilityLength;\r
+  UINT8                   PhysicalPorts;\r
+  UINTN                   Count;\r
+\r
+\r
+  //Configure USB host for OMAP3530.\r
+  ConfigureUSBHost();\r
+\r
+  // Create a private structure\r
+  Private = AllocatePool(sizeof(EFI_PCI_IO_PRIVATE_DATA));\r
+  if (Private == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    return Status;\r
+  }\r
+  \r
+  Private->Signature              = EFI_PCI_IO_PRIVATE_DATA_SIGNATURE;  // Fill in signature\r
+  Private->RootBridge.Signature   = PCI_ROOT_BRIDGE_SIGNATURE;          // Fake Root Bridge structure needs a signature too\r
+  Private->RootBridge.MemoryStart = USB_EHCI_HCCAPBASE;                 // Get the USB capability register base\r
+  Private->Segment                = 0;                                  // Default to segment zero\r
+\r
+  // Find out the capability register length and number of physical ports.\r
+  CapabilityLength = MmioRead8(Private->RootBridge.MemoryStart);\r
+  PhysicalPorts    = (MmioRead32 (Private->RootBridge.MemoryStart + 0x4)) & 0x0000000F;\r
+\r
+  // Calculate the total size of the USB registers.\r
+  Private->RootBridge.MemorySize = CapabilityLength + (HOST_CONTROLLER_OPERATION_REG_SIZE + ((4 * PhysicalPorts) - 1));\r
+\r
+  // Enable Port Power bit in Port status and control registers in EHCI register space.\r
+  // Port Power Control (PPC) bit in the HCSPARAMS register is already set which indicates\r
+  // host controller implementation includes port power control.\r
+  for (Count = 0; Count < PhysicalPorts; Count++) {\r
+    MmioOr32 ((Private->RootBridge.MemoryStart + CapabilityLength + HOST_CONTROLLER_OPERATION_REG_SIZE + 4*Count), 0x00001000);\r
+  }\r
+\r
+  // Create fake PCI config space.\r
+  Private->ConfigSpace = AllocateZeroPool(sizeof(PCI_TYPE00));\r
+  if (Private->ConfigSpace == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    FreePool(Private);\r
+    return Status;\r
+  }\r
+\r
+  // Configure PCI config space\r
+  Private->ConfigSpace->Hdr.VendorId = 0x3530;\r
+  Private->ConfigSpace->Hdr.DeviceId = 0x3530;\r
+  Private->ConfigSpace->Hdr.ClassCode[0] = 0x20;\r
+  Private->ConfigSpace->Hdr.ClassCode[1] = 0x03;\r
+  Private->ConfigSpace->Hdr.ClassCode[2] = 0x0C;\r
+  Private->ConfigSpace->Device.Bar[0] = Private->RootBridge.MemoryStart;\r
+\r
+  Handle = NULL;\r
+\r
+  // Unique device path.\r
+  CopyMem(&Private->DevicePath, &PciIoDevicePathTemplate, sizeof(PciIoDevicePathTemplate));\r
+  Private->DevicePath.AcpiDevicePath.UID = 0;\r
+  \r
+  // Copy protocol structure\r
+  CopyMem(&Private->PciIoProtocol, &PciIoTemplate, sizeof(PciIoTemplate));\r
+\r
+  Status = gBS->InstallMultipleProtocolInterfaces(&Handle,\r
+                                                  &gEfiPciIoProtocolGuid,       &Private->PciIoProtocol,\r
+                                                  &gEfiDevicePathProtocolGuid,  &Private->DevicePath,\r
+                                                  NULL);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG((EFI_D_ERROR, "PciEmulationEntryPoint InstallMultipleProtocolInterfaces() failed.\n"));\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
index 7db4f330ca4e167af199ff739c9740bdafe8b274..2a381f2f998eed9bee43cbdbf096851bf856a21a 100644 (file)
@@ -40,7 +40,7 @@
 #include <IndustryStandard/Pci22.h>\r
 #include <IndustryStandard/Acpi.h>\r
 \r
 #include <IndustryStandard/Pci22.h>\r
 #include <IndustryStandard/Acpi.h>\r
 \r
-#include <Omap3530/Omap3530.h>
+#include <Omap3530/Omap3530.h>\r
 \r
 \r
 \r
 \r
 \r
 \r
index 8567b693880b51c6521b70d3bc55d8206a7cb053..ab3754179510af9b16298ea79d2684d0315b7ff8 100644 (file)
@@ -54,4 +54,4 @@
 [Depex]\r
   gEfiMetronomeArchProtocolGuid AND \r
   gEmbeddedExternalDeviceProtocolGuid\r
 [Depex]\r
   gEfiMetronomeArchProtocolGuid AND \r
   gEmbeddedExternalDeviceProtocolGuid\r
-  
\ No newline at end of file
+  \r
\ No newline at end of file
index 86dc65c87f8e9431e1f3803f8cb654b0e85a444d..3b88974ae1d17d07c85a4c50e3c2a64167518231 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <Uefi.h>
-#include <Omap3530/Omap3530.h>
-
-#include <Library/DebugLib.h>
-#include <Library/IoLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-
-#include <Protocol/SmbusHc.h>
-
-#define MAX_RETRY  1000
-
-//
-// Internal Functions
-//
-STATIC
-EFI_STATUS
-WaitForBusBusy (
-  VOID
-  )
-{
-  UINTN Retry = 0;
-
-  while (++Retry < MAX_RETRY && (MmioRead16(I2C_STAT) & BB) == 0x1);
-
-  if (Retry == MAX_RETRY) {
-    return EFI_TIMEOUT;
-  }
-
-  return EFI_SUCCESS;
-}
-
-STATIC
-EFI_STATUS
-PollForStatus(
-  UINT16 StatusBit
-  )
-{
-  UINTN Retry = 0;
-
-  while(Retry < MAX_RETRY) {
-    if (MmioRead16(I2C_STAT) & StatusBit) {
-      //Clear particular status bit from Status register.
-      MmioOr16(I2C_STAT, StatusBit);
-      break;
-    }
-    Retry++;
-  }
-
-  if (Retry == MAX_RETRY) {
-    return EFI_TIMEOUT;
-  }
-
-  return EFI_SUCCESS;
-}
-
-STATIC
-EFI_STATUS
-ConfigureI2c (
-  VOID
-  )
-{
-  //Program prescaler to obtain 12-MHz clock
-  MmioWrite16(I2C_PSC, 0x0000);
-
-  //Program SCLL and SCLH 
-  //NOTE: Following values are the register dump after U-Boot code executed. 
-  //We need to figure out how its calculated based on the I2C functional clock and I2C_PSC.
-  MmioWrite16(I2C_SCLL, 0x0035);
-  MmioWrite16(I2C_SCLH, 0x0035);
-
-  //Take the I2C controller out of reset.
-  MmioOr16(I2C_CON, I2C_EN);
-
-  //Initialize the I2C controller.
-
-  //Set I2C controller in Master mode.
-  MmioOr16(I2C_CON, MST);
-
-  //Enable interrupts for receive/transmit mode.
-  MmioOr16(I2C_IE, (XRDY_IE | RRDY_IE | ARDY_IE | NACK_IE));
-
-  return EFI_SUCCESS;
-}
-
-STATIC
-EFI_STATUS
-I2CReadOneByte (
-  UINT8 *Data
-  )
-{
-  EFI_STATUS Status;
-
-  //I2C bus status checking
-  Status = WaitForBusBusy();
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  //Poll till Receive ready bit is set.
-  Status = PollForStatus(RRDY);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  *Data = MmioRead8(I2C_DATA);
-
-  return EFI_SUCCESS;
-}
-
-STATIC
-EFI_STATUS
-I2CWriteOneByte (
-  UINT8 Data    
-  )
-{
-  EFI_STATUS Status;
-
-  //I2C bus status checking
-  Status = WaitForBusBusy();
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  //Data transfer
-  //Poll till Transmit ready bit is set
-  Status = PollForStatus(XRDY);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  MmioWrite8(I2C_DATA, Data);
-
-  //Wait and check if the NACK is not set.
-  gBS->Stall(1000);
-  if (MmioRead16(I2C_STAT) & NACK) {
-    return EFI_DEVICE_ERROR;
-  }
-
-  return EFI_SUCCESS;
-}
-
-STATIC
-EFI_STATUS
-SmbusBlockRead (
-  OUT UINT8       *Buffer,
-  IN  UINTN       Length
-  )
-{
-  UINTN      Index = 0;
-  EFI_STATUS Status = EFI_SUCCESS;
-
-  //Transfer configuration for receiving data.
-  MmioWrite16(I2C_CNT, Length);
-  //Need stop bit before sending data.
-  MmioWrite16(I2C_CON, (I2C_EN | MST | STP | STT));
-
-  while (Index < Length) {
-    //Read a byte
-    Status = I2CReadOneByte(&Buffer[Index++]);
-    if (EFI_ERROR(Status)) {
-      return Status;
-    }
-  }
-
-  //Transfer completion
-  Status = PollForStatus(ARDY);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  return Status;
-}
-
-STATIC
-EFI_STATUS
-SmbusBlockWrite (
-  IN UINT8       *Buffer,
-  IN UINTN       Length
-  )
-{
-  UINTN      Index = 0;
-  EFI_STATUS Status = EFI_SUCCESS;
-
-  //Transfer configuration for transmitting data
-  MmioWrite16(I2C_CNT, Length);
-  MmioWrite16(I2C_CON, (I2C_EN | TRX | MST | STT | STP));
-
-  while (Index < Length) {
-    //Send a byte
-    Status = I2CWriteOneByte(Buffer[Index++]);
-    if (EFI_ERROR(Status)) {
-      return Status;
-    }
-  }
-
-  //Transfer completion
-  Status = PollForStatus(ARDY);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  return Status;
-}
-
-//
-// Public Functions.
-//
-EFI_STATUS
-EFIAPI
-SmbusExecute (
-  IN CONST EFI_SMBUS_HC_PROTOCOL    *This,
-  IN CONST EFI_SMBUS_DEVICE_ADDRESS SlaveAddress,
-  IN CONST EFI_SMBUS_DEVICE_COMMAND Command,
-  IN CONST EFI_SMBUS_OPERATION      Operation,
-  IN CONST BOOLEAN                  PecCheck,
-  IN OUT   UINTN                    *Length,
-  IN OUT   VOID                     *Buffer
-  )
-{
-  UINT8      *ByteBuffer  = Buffer;
-  EFI_STATUS Status       = EFI_SUCCESS;
-  UINT8      SlaveAddr    = (UINT8)(SlaveAddress.SmbusDeviceAddress);
-
-  if (PecCheck) {
-    return EFI_UNSUPPORTED;
-  }
-
-  if ((Operation != EfiSmbusWriteBlock) && (Operation != EfiSmbusReadBlock)) {
-    return EFI_UNSUPPORTED;
-  }
-
-  //Set the Slave address.
-  MmioWrite16(I2C_SA, SlaveAddr);
-
-  if (Operation == EfiSmbusReadBlock) {
-    Status = SmbusBlockRead(ByteBuffer, *Length);
-  } else if (Operation == EfiSmbusWriteBlock) {
-    Status = SmbusBlockWrite(ByteBuffer, *Length);
-  }
-
-  return Status;
-}
-
-EFI_STATUS
-EFIAPI
-SmbusArpDevice (
-  IN CONST EFI_SMBUS_HC_PROTOCOL    *This,
-  IN       BOOLEAN                  ArpAll,
-  IN       EFI_SMBUS_UDID           *SmbusUdid OPTIONAL,
-  IN OUT   EFI_SMBUS_DEVICE_ADDRESS *SlaveAddress OPTIONAL
-  )
-{
-  return EFI_UNSUPPORTED;
-}
-
-
-EFI_STATUS
-EFIAPI
-SmbusGetArpMap (
-  IN CONST EFI_SMBUS_HC_PROTOCOL    *This,
-  IN OUT   UINTN                    *Length,
-  IN OUT   EFI_SMBUS_DEVICE_MAP     **SmbusDeviceMap
-  )
-{
-  return EFI_UNSUPPORTED;
-}
-
-
-EFI_STATUS
-EFIAPI
-SmbusNotify (
-  IN CONST  EFI_SMBUS_HC_PROTOCOL     *This,
-  IN CONST  EFI_SMBUS_DEVICE_ADDRESS  SlaveAddress,
-  IN CONST  UINTN                     Data,
-  IN CONST  EFI_SMBUS_NOTIFY_FUNCTION NotifyFunction
-  )
-{
-  return EFI_UNSUPPORTED;
-}
-
-EFI_SMBUS_HC_PROTOCOL SmbusProtocol =
-{
-  SmbusExecute,
-  SmbusArpDevice,
-  SmbusGetArpMap,
-  SmbusNotify
-};
-
-EFI_STATUS
-InitializeSmbus (
-    IN EFI_HANDLE       ImageHandle,
-    IN EFI_SYSTEM_TABLE *SystemTable
-    )
-{
-  EFI_HANDLE      Handle = NULL;
-  EFI_STATUS      Status;
-
-  //Configure I2C controller.
-  Status = ConfigureI2c();
-  if (EFI_ERROR(Status)) {
-    DEBUG ((EFI_D_ERROR, "InitializeI2c fails.\n"));
-    return Status;
-  }
-
-  // Install the SMBUS interface
-  Status = gBS->InstallMultipleProtocolInterfaces(&Handle, &gEfiSmbusHcProtocolGuid, &SmbusProtocol, NULL);
-  ASSERT_EFI_ERROR(Status);
-  
-  return Status;
-}
-
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+#include <Omap3530/Omap3530.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#include <Protocol/SmbusHc.h>\r
+\r
+#define MAX_RETRY  1000\r
+\r
+//\r
+// Internal Functions\r
+//\r
+STATIC\r
+EFI_STATUS\r
+WaitForBusBusy (\r
+  VOID\r
+  )\r
+{\r
+  UINTN Retry = 0;\r
+\r
+  while (++Retry < MAX_RETRY && (MmioRead16(I2C_STAT) & BB) == 0x1);\r
+\r
+  if (Retry == MAX_RETRY) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+PollForStatus(\r
+  UINT16 StatusBit\r
+  )\r
+{\r
+  UINTN Retry = 0;\r
+\r
+  while(Retry < MAX_RETRY) {\r
+    if (MmioRead16(I2C_STAT) & StatusBit) {\r
+      //Clear particular status bit from Status register.\r
+      MmioOr16(I2C_STAT, StatusBit);\r
+      break;\r
+    }\r
+    Retry++;\r
+  }\r
+\r
+  if (Retry == MAX_RETRY) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+ConfigureI2c (\r
+  VOID\r
+  )\r
+{\r
+  //Program prescaler to obtain 12-MHz clock\r
+  MmioWrite16(I2C_PSC, 0x0000);\r
+\r
+  //Program SCLL and SCLH \r
+  //NOTE: Following values are the register dump after U-Boot code executed. \r
+  //We need to figure out how its calculated based on the I2C functional clock and I2C_PSC.\r
+  MmioWrite16(I2C_SCLL, 0x0035);\r
+  MmioWrite16(I2C_SCLH, 0x0035);\r
+\r
+  //Take the I2C controller out of reset.\r
+  MmioOr16(I2C_CON, I2C_EN);\r
+\r
+  //Initialize the I2C controller.\r
+\r
+  //Set I2C controller in Master mode.\r
+  MmioOr16(I2C_CON, MST);\r
+\r
+  //Enable interrupts for receive/transmit mode.\r
+  MmioOr16(I2C_IE, (XRDY_IE | RRDY_IE | ARDY_IE | NACK_IE));\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+I2CReadOneByte (\r
+  UINT8 *Data\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  //I2C bus status checking\r
+  Status = WaitForBusBusy();\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //Poll till Receive ready bit is set.\r
+  Status = PollForStatus(RRDY);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  *Data = MmioRead8(I2C_DATA);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+I2CWriteOneByte (\r
+  UINT8 Data    \r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  //I2C bus status checking\r
+  Status = WaitForBusBusy();\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //Data transfer\r
+  //Poll till Transmit ready bit is set\r
+  Status = PollForStatus(XRDY);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  MmioWrite8(I2C_DATA, Data);\r
+\r
+  //Wait and check if the NACK is not set.\r
+  gBS->Stall(1000);\r
+  if (MmioRead16(I2C_STAT) & NACK) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+SmbusBlockRead (\r
+  OUT UINT8       *Buffer,\r
+  IN  UINTN       Length\r
+  )\r
+{\r
+  UINTN      Index = 0;\r
+  EFI_STATUS Status = EFI_SUCCESS;\r
+\r
+  //Transfer configuration for receiving data.\r
+  MmioWrite16(I2C_CNT, Length);\r
+  //Need stop bit before sending data.\r
+  MmioWrite16(I2C_CON, (I2C_EN | MST | STP | STT));\r
+\r
+  while (Index < Length) {\r
+    //Read a byte\r
+    Status = I2CReadOneByte(&Buffer[Index++]);\r
+    if (EFI_ERROR(Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  //Transfer completion\r
+  Status = PollForStatus(ARDY);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+SmbusBlockWrite (\r
+  IN UINT8       *Buffer,\r
+  IN UINTN       Length\r
+  )\r
+{\r
+  UINTN      Index = 0;\r
+  EFI_STATUS Status = EFI_SUCCESS;\r
+\r
+  //Transfer configuration for transmitting data\r
+  MmioWrite16(I2C_CNT, Length);\r
+  MmioWrite16(I2C_CON, (I2C_EN | TRX | MST | STT | STP));\r
+\r
+  while (Index < Length) {\r
+    //Send a byte\r
+    Status = I2CWriteOneByte(Buffer[Index++]);\r
+    if (EFI_ERROR(Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  //Transfer completion\r
+  Status = PollForStatus(ARDY);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+//\r
+// Public Functions.\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+SmbusExecute (\r
+  IN CONST EFI_SMBUS_HC_PROTOCOL    *This,\r
+  IN CONST EFI_SMBUS_DEVICE_ADDRESS SlaveAddress,\r
+  IN CONST EFI_SMBUS_DEVICE_COMMAND Command,\r
+  IN CONST EFI_SMBUS_OPERATION      Operation,\r
+  IN CONST BOOLEAN                  PecCheck,\r
+  IN OUT   UINTN                    *Length,\r
+  IN OUT   VOID                     *Buffer\r
+  )\r
+{\r
+  UINT8      *ByteBuffer  = Buffer;\r
+  EFI_STATUS Status       = EFI_SUCCESS;\r
+  UINT8      SlaveAddr    = (UINT8)(SlaveAddress.SmbusDeviceAddress);\r
+\r
+  if (PecCheck) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if ((Operation != EfiSmbusWriteBlock) && (Operation != EfiSmbusReadBlock)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //Set the Slave address.\r
+  MmioWrite16(I2C_SA, SlaveAddr);\r
+\r
+  if (Operation == EfiSmbusReadBlock) {\r
+    Status = SmbusBlockRead(ByteBuffer, *Length);\r
+  } else if (Operation == EfiSmbusWriteBlock) {\r
+    Status = SmbusBlockWrite(ByteBuffer, *Length);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SmbusArpDevice (\r
+  IN CONST EFI_SMBUS_HC_PROTOCOL    *This,\r
+  IN       BOOLEAN                  ArpAll,\r
+  IN       EFI_SMBUS_UDID           *SmbusUdid OPTIONAL,\r
+  IN OUT   EFI_SMBUS_DEVICE_ADDRESS *SlaveAddress OPTIONAL\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SmbusGetArpMap (\r
+  IN CONST EFI_SMBUS_HC_PROTOCOL    *This,\r
+  IN OUT   UINTN                    *Length,\r
+  IN OUT   EFI_SMBUS_DEVICE_MAP     **SmbusDeviceMap\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SmbusNotify (\r
+  IN CONST  EFI_SMBUS_HC_PROTOCOL     *This,\r
+  IN CONST  EFI_SMBUS_DEVICE_ADDRESS  SlaveAddress,\r
+  IN CONST  UINTN                     Data,\r
+  IN CONST  EFI_SMBUS_NOTIFY_FUNCTION NotifyFunction\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_SMBUS_HC_PROTOCOL SmbusProtocol =\r
+{\r
+  SmbusExecute,\r
+  SmbusArpDevice,\r
+  SmbusGetArpMap,\r
+  SmbusNotify\r
+};\r
+\r
+EFI_STATUS\r
+InitializeSmbus (\r
+    IN EFI_HANDLE       ImageHandle,\r
+    IN EFI_SYSTEM_TABLE *SystemTable\r
+    )\r
+{\r
+  EFI_HANDLE      Handle = NULL;\r
+  EFI_STATUS      Status;\r
+\r
+  //Configure I2C controller.\r
+  Status = ConfigureI2c();\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG ((EFI_D_ERROR, "InitializeI2c fails.\n"));\r
+    return Status;\r
+  }\r
+\r
+  // Install the SMBUS interface\r
+  Status = gBS->InstallMultipleProtocolInterfaces(&Handle, &gEfiSmbusHcProtocolGuid, &SmbusProtocol, NULL);\r
+  ASSERT_EFI_ERROR(Status);\r
+  \r
+  return Status;\r
+}\r
+\r
index 6a8a4e9194cac9ccc9b8fd09d7dc757c5797130e..5a4e43ea24705c5e6872fa3544f3e4fd0c895100 100644 (file)
@@ -1,45 +1,45 @@
-#/** @file
-#  
-#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-#  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                      = Smbus
-  FILE_GUID                      = d5125e0f-1226-444f-a218-0085996ed5da
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-
-  ENTRY_POINT                    = InitializeSmbus
-
-[Sources.common]
-  Smbus.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  Omap35xxPkg/Omap35xxPkg.dec
-
-[LibraryClasses]
-  PcdLib
-  UefiLib
-  UefiDriverEntryPoint
-  MemoryAllocationLib
-  IoLib
-
-[Guids]
-  
-[Protocols]
-  gEfiSmbusHcProtocolGuid
-
-[Pcd]
-
-[depex]
-  TRUE
\ No newline at end of file
+#/** @file\r
+#  \r
+#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = Smbus\r
+  FILE_GUID                      = d5125e0f-1226-444f-a218-0085996ed5da\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = InitializeSmbus\r
+\r
+[Sources.common]\r
+  Smbus.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  Omap35xxPkg/Omap35xxPkg.dec\r
+\r
+[LibraryClasses]\r
+  PcdLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  MemoryAllocationLib\r
+  IoLib\r
+\r
+[Guids]\r
+  \r
+[Protocols]\r
+  gEfiSmbusHcProtocolGuid\r
+\r
+[Pcd]\r
+\r
+[depex]\r
+  TRUE\r
\ No newline at end of file
index 6b76da50708bb321fecc5d9af6481ed4cc39a6f8..ed19389d43516497358a0cfce3da759988123907 100644 (file)
-/** @file
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <Uefi.h>
-
-#include <TPS65950.h>
-
-#include <Library/BaseMemoryLib.h>
-#include <Library/DebugLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-
-#include <Protocol/EmbeddedExternalDevice.h>
-#include <Protocol/SmbusHc.h>
-
-EFI_SMBUS_HC_PROTOCOL *Smbus;
-
-EFI_STATUS
-Read (
-  IN  EMBEDDED_EXTERNAL_DEVICE    *This,
-  IN  UINTN                       Register,
-  IN  UINTN                       Length,
-  OUT VOID                        *Buffer
-  )
-{
-  EFI_STATUS               Status;
-  EFI_SMBUS_DEVICE_ADDRESS SlaveAddress; 
-  UINT8                    DeviceRegister;
-  UINTN                    DeviceRegisterLength = 1;
-
-  SlaveAddress.SmbusDeviceAddress = EXTERNAL_DEVICE_REGISTER_TO_SLAVE_ADDRESS(Register);
-  DeviceRegister = (UINT8)EXTERNAL_DEVICE_REGISTER_TO_REGISTER(Register);
-
-  //Write DeviceRegister.
-  Status = Smbus->Execute(Smbus, SlaveAddress, 0, EfiSmbusWriteBlock, FALSE, &DeviceRegisterLength, &DeviceRegister);
-  if (EFI_ERROR(Status)) {
-    return Status;
-  }
-
-  //Read Data
-  Status = Smbus->Execute(Smbus, SlaveAddress, 0, EfiSmbusReadBlock, FALSE, &Length, Buffer);
-  return Status;
-}
-
-EFI_STATUS
-Write (
-  IN EMBEDDED_EXTERNAL_DEVICE   *This,
-  IN UINTN                      Register,
-  IN UINTN                      Length,
-  IN VOID                       *Buffer
-  )
-{
-  EFI_STATUS               Status;
-  EFI_SMBUS_DEVICE_ADDRESS SlaveAddress; 
-  UINT8                    DeviceRegister;
-  UINTN                    DeviceBufferLength = Length + 1;
-  UINT8                    *DeviceBuffer;
-
-  SlaveAddress.SmbusDeviceAddress = EXTERNAL_DEVICE_REGISTER_TO_SLAVE_ADDRESS(Register);
-  DeviceRegister = (UINT8)EXTERNAL_DEVICE_REGISTER_TO_REGISTER(Register);
-
-  //Prepare buffer for writing
-  DeviceBuffer = (UINT8 *)AllocatePool(DeviceBufferLength);
-  if (DeviceBuffer == NULL) {
-    Status = EFI_OUT_OF_RESOURCES;
-    goto exit;
-  }
-
-  //Set Device register followed by data to write.
-  DeviceBuffer[0] = DeviceRegister;
-  CopyMem(&DeviceBuffer[1], Buffer, Length);
-
-  //Write Data
-  Status = Smbus->Execute(Smbus, SlaveAddress, 0, EfiSmbusWriteBlock, FALSE, &DeviceBufferLength, DeviceBuffer);
-  if (EFI_ERROR(Status)) {
-    goto exit;
-  }
-
-exit:
-  if (DeviceBuffer) {
-    FreePool(DeviceBuffer);
-  }
-
-  return Status;
-}
-
-EMBEDDED_EXTERNAL_DEVICE ExternalDevice = {
-  Read,
-  Write
-};
-
-EFI_STATUS
-TPS65950Initialize (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
-  )
-{
-  EFI_STATUS  Status;
-  
-  Status = gBS->LocateProtocol(&gEfiSmbusHcProtocolGuid, NULL, (VOID **)&Smbus);
-  ASSERT_EFI_ERROR(Status);
-  
-  Status = gBS->InstallMultipleProtocolInterfaces(&ImageHandle, &gEmbeddedExternalDeviceProtocolGuid, &ExternalDevice, NULL);
-  return Status;
-}
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+\r
+#include <TPS65950.h>\r
+\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#include <Protocol/EmbeddedExternalDevice.h>\r
+#include <Protocol/SmbusHc.h>\r
+\r
+EFI_SMBUS_HC_PROTOCOL *Smbus;\r
+\r
+EFI_STATUS\r
+Read (\r
+  IN  EMBEDDED_EXTERNAL_DEVICE    *This,\r
+  IN  UINTN                       Register,\r
+  IN  UINTN                       Length,\r
+  OUT VOID                        *Buffer\r
+  )\r
+{\r
+  EFI_STATUS               Status;\r
+  EFI_SMBUS_DEVICE_ADDRESS SlaveAddress; \r
+  UINT8                    DeviceRegister;\r
+  UINTN                    DeviceRegisterLength = 1;\r
+\r
+  SlaveAddress.SmbusDeviceAddress = EXTERNAL_DEVICE_REGISTER_TO_SLAVE_ADDRESS(Register);\r
+  DeviceRegister = (UINT8)EXTERNAL_DEVICE_REGISTER_TO_REGISTER(Register);\r
+\r
+  //Write DeviceRegister.\r
+  Status = Smbus->Execute(Smbus, SlaveAddress, 0, EfiSmbusWriteBlock, FALSE, &DeviceRegisterLength, &DeviceRegister);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //Read Data\r
+  Status = Smbus->Execute(Smbus, SlaveAddress, 0, EfiSmbusReadBlock, FALSE, &Length, Buffer);\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+Write (\r
+  IN EMBEDDED_EXTERNAL_DEVICE   *This,\r
+  IN UINTN                      Register,\r
+  IN UINTN                      Length,\r
+  IN VOID                       *Buffer\r
+  )\r
+{\r
+  EFI_STATUS               Status;\r
+  EFI_SMBUS_DEVICE_ADDRESS SlaveAddress; \r
+  UINT8                    DeviceRegister;\r
+  UINTN                    DeviceBufferLength = Length + 1;\r
+  UINT8                    *DeviceBuffer;\r
+\r
+  SlaveAddress.SmbusDeviceAddress = EXTERNAL_DEVICE_REGISTER_TO_SLAVE_ADDRESS(Register);\r
+  DeviceRegister = (UINT8)EXTERNAL_DEVICE_REGISTER_TO_REGISTER(Register);\r
+\r
+  //Prepare buffer for writing\r
+  DeviceBuffer = (UINT8 *)AllocatePool(DeviceBufferLength);\r
+  if (DeviceBuffer == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto exit;\r
+  }\r
+\r
+  //Set Device register followed by data to write.\r
+  DeviceBuffer[0] = DeviceRegister;\r
+  CopyMem(&DeviceBuffer[1], Buffer, Length);\r
+\r
+  //Write Data\r
+  Status = Smbus->Execute(Smbus, SlaveAddress, 0, EfiSmbusWriteBlock, FALSE, &DeviceBufferLength, DeviceBuffer);\r
+  if (EFI_ERROR(Status)) {\r
+    goto exit;\r
+  }\r
+\r
+exit:\r
+  if (DeviceBuffer) {\r
+    FreePool(DeviceBuffer);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EMBEDDED_EXTERNAL_DEVICE ExternalDevice = {\r
+  Read,\r
+  Write\r
+};\r
+\r
+EFI_STATUS\r
+TPS65950Initialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  \r
+  Status = gBS->LocateProtocol(&gEfiSmbusHcProtocolGuid, NULL, (VOID **)&Smbus);\r
+  ASSERT_EFI_ERROR(Status);\r
+  \r
+  Status = gBS->InstallMultipleProtocolInterfaces(&ImageHandle, &gEmbeddedExternalDeviceProtocolGuid, &ExternalDevice, NULL);\r
+  return Status;\r
+}\r
index d03326bd1edaa4b547ca8d66b846c9af5951a7b2..5fca7a356f3980178f811b246c3dbd23e07a0d86 100644 (file)
@@ -1,48 +1,48 @@
-#/** @file
-#  
-#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-#  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                      = TPS65950
-  FILE_GUID                      = 71fe861a-5450-48b6-bfb0-b93522616f99
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-
-  ENTRY_POINT                    = TPS65950Initialize
-
-
-[Sources.common]
-  TPS65950.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  Omap35xxPkg/Omap35xxPkg.dec
-
-[LibraryClasses]
-  BaseMemoryLib
-  PcdLib
-  UefiLib
-  UefiDriverEntryPoint
-  MemoryAllocationLib
-
-[Guids]
-  
-[Protocols]
-  gEfiSmbusHcProtocolGuid
-  gEmbeddedExternalDeviceProtocolGuid
-
-[Pcd]
-
-[depex]
-  gEfiSmbusHcProtocolGuid
+#/** @file\r
+#  \r
+#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = TPS65950\r
+  FILE_GUID                      = 71fe861a-5450-48b6-bfb0-b93522616f99\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = TPS65950Initialize\r
+\r
+\r
+[Sources.common]\r
+  TPS65950.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  Omap35xxPkg/Omap35xxPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseMemoryLib\r
+  PcdLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  MemoryAllocationLib\r
+\r
+[Guids]\r
+  \r
+[Protocols]\r
+  gEfiSmbusHcProtocolGuid\r
+  gEmbeddedExternalDeviceProtocolGuid\r
+\r
+[Pcd]\r
+\r
+[depex]\r
+  gEfiSmbusHcProtocolGuid\r
index d0ea973509eded94baa5e3b4cc6b0a0115b11269..bc3d9b0abadc0c5e1ab8705719b9437fc2a408a6 100644 (file)
-/** @file
-  Template for Timer Architecture Protocol driver of the ARM flavor
-
-  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-  
-  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 <PiDxe.h>
-
-#include <Library/BaseLib.h>
-#include <Library/DebugLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiLib.h>
-#include <Library/PcdLib.h>
-#include <Library/IoLib.h>
-#include <Library/OmapLib.h>
-
-#include <Protocol/Timer.h>
-#include <Protocol/HardwareInterrupt.h>
-
-#include <Omap3530/Omap3530.h>
-
-
-// The notification function to call on every timer interrupt.
-volatile EFI_TIMER_NOTIFY      mTimerNotifyFunction   = (EFI_TIMER_NOTIFY)NULL;
-
-
-// The current period of the timer interrupt
-volatile UINT64 mTimerPeriod = 0;
-
-// Cached copy of the Hardware Interrupt protocol instance
-EFI_HARDWARE_INTERRUPT_PROTOCOL *gInterrupt = NULL;
-
-// Cached registers
-volatile UINT32 TISR;
-volatile UINT32 TCLR;
-volatile UINT32 TLDR;
-volatile UINT32 TCRR;
-volatile UINT32 TIER;
-
-// Cached interrupt vector
-volatile UINTN  gVector;
-
-
-/**
-
-  C Interrupt Handler calledin the interrupt context when Source interrupt is active.
-
-
-  @param Source         Source of the interrupt. Hardware routing off a specific platform defines
-                        what source means.
-
-  @param SystemContext  Pointer to system register context. Mostly used by debuggers and will
-                        update the system context after the return from the interrupt if 
-                        modified. Don't change these values unless you know what you are doing
-
-**/
-VOID
-EFIAPI
-TimerInterruptHandler (
-  IN  HARDWARE_INTERRUPT_SOURCE   Source,
-  IN  EFI_SYSTEM_CONTEXT          SystemContext       
-  )
-{
-  EFI_TPL OriginalTPL;
-
-
-
-  //
-  // DXE core uses this callback for the EFI timer tick. The DXE core uses locks 
-  // that raise to TPL_HIGH and then restore back to current level. Thus we need
-  // to make sure TPL level is set to TPL_HIGH while we are handling the timer tick. 
-  //
-  OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);
-
-  if (mTimerNotifyFunction) {
-    mTimerNotifyFunction(mTimerPeriod);
-  }
-
-  // Clear all timer interrupts
-  MmioWrite32 (TISR, TISR_CLEAR_ALL);  
-
-  // Poll interrupt status bits to ensure clearing
-  while ((MmioRead32 (TISR) & TISR_ALL_INTERRUPT_MASK) != TISR_NO_INTERRUPTS_PENDING);
-
-  gBS->RestoreTPL (OriginalTPL);
-}
-
-/**
-  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.
-
-  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.
-  @param  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.
-  @retval EFI_SUCCESS           The timer handler was registered.
-  @retval EFI_UNSUPPORTED       The platform does not support timer interrupts.
-  @retval EFI_ALREADY_STARTED   NotifyFunction is not NULL, and a handler is already
-                                registered.
-  @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not
-                                previously registered.
-  @retval EFI_DEVICE_ERROR      The timer handler could not be registered.
-
-**/
-EFI_STATUS
-EFIAPI
-TimerDriverRegisterHandler (
-  IN EFI_TIMER_ARCH_PROTOCOL  *This,
-  IN EFI_TIMER_NOTIFY         NotifyFunction
-  )
-{
-  if ((NotifyFunction == NULL) && (mTimerNotifyFunction == NULL)) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  if ((NotifyFunction != NULL) && (mTimerNotifyFunction != NULL)) {
-    return EFI_ALREADY_STARTED;
-  }
-
-  mTimerNotifyFunction = NotifyFunction;
-
-  return EFI_SUCCESS;
-}
-
-/**
-
-  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. 
-
-  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.
-  @param  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.
-
-
-  @retval EFI_SUCCESS           The timer period was changed.
-  @retval EFI_UNSUPPORTED       The platform cannot change the period of the timer interrupt.
-  @retval EFI_DEVICE_ERROR      The timer period could not be changed due to a device error.
-
-**/
-EFI_STATUS
-EFIAPI
-TimerDriverSetTimerPeriod (
-  IN EFI_TIMER_ARCH_PROTOCOL  *This,
-  IN UINT64                   TimerPeriod
-  )
-{
-  EFI_STATUS  Status;
-  UINT64      TimerCount;
-  INT32       LoadValue;
-  
-  if (TimerPeriod == 0) {
-    // Turn off GPTIMER3
-    MmioWrite32 (TCLR, TCLR_ST_OFF);
-    
-    Status = gInterrupt->DisableInterruptSource(gInterrupt, gVector);    
-  } else {  
-    // Calculate required timer count
-    TimerCount = DivU64x32(TimerPeriod * 100, PcdGet32(PcdEmbeddedPerformanceCounterPeriodInNanoseconds));
-
-    // Set GPTIMER3 Load register
-    LoadValue = (INT32) -TimerCount;
-    MmioWrite32 (TLDR, LoadValue);
-    MmioWrite32 (TCRR, LoadValue);
-
-    // Enable Overflow interrupt
-    MmioWrite32 (TIER, TIER_TCAR_IT_DISABLE | TIER_OVF_IT_ENABLE | TIER_MAT_IT_DISABLE);
-
-    // Turn on GPTIMER3, it will reload at overflow
-    MmioWrite32 (TCLR, TCLR_AR_AUTORELOAD | TCLR_ST_ON);
-
-    Status = gInterrupt->EnableInterruptSource(gInterrupt, gVector);    
-  }
-
-  //
-  // Save the new timer period
-  //
-  mTimerPeriod = TimerPeriod;
-  return Status;
-}
-
-
-/**
-  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.
-
-  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.
-  @param  TimerPeriod      A pointer to the timer period to retrieve in 100 ns units. If
-                           0 is returned, then the timer is currently disabled.
-
-
-  @retval EFI_SUCCESS           The timer period was returned in TimerPeriod.
-  @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
-
-**/
-EFI_STATUS
-EFIAPI
-TimerDriverGetTimerPeriod (
-  IN EFI_TIMER_ARCH_PROTOCOL   *This,
-  OUT UINT64                   *TimerPeriod
-  )
-{
-  if (TimerPeriod == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  *TimerPeriod = mTimerPeriod;
-  return EFI_SUCCESS;
-}
-
-/**
-  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.
-
-  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.
-
-  @retval EFI_SUCCESS           The soft timer interrupt was generated.
-  @retval EFI_UNSUPPORTED       The platform does not support the generation of soft timer interrupts.
-
-**/
-EFI_STATUS
-EFIAPI
-TimerDriverGenerateSoftInterrupt (
-  IN EFI_TIMER_ARCH_PROTOCOL  *This
-  )
-{
-  return EFI_UNSUPPORTED;
-}
-
-
-/**
-  Interface stucture for the Timer Architectural Protocol.
-
-  @par Protocol Description:
-  This protocol provides the services to initialize a periodic timer 
-  interrupt, and to register a handler that is called each time the timer
-  interrupt fires.  It may also provide a service to adjust the rate of the
-  periodic timer interrupt.  When a timer interrupt occurs, the handler is 
-  passed the amount of time that has passed since the previous timer 
-  interrupt.
-
-  @param RegisterHandler
-  Registers a handler that will be called each time the 
-  timer interrupt fires.  TimerPeriod defines the minimum 
-  time between timer interrupts, so TimerPeriod will also 
-  be the minimum time between calls to the registered 
-  handler.
-
-  @param SetTimerPeriod
-  Sets the period of the timer interrupt in 100 nS units.  
-  This function is optional, and may return EFI_UNSUPPORTED.  
-  If this function is supported, then the timer period will 
-  be rounded up to the nearest supported timer period.
-
-
-  @param GetTimerPeriod
-  Retrieves the period of the timer interrupt in 100 nS units.
-
-  @param GenerateSoftInterrupt
-  Generates a soft timer interrupt that simulates the firing of 
-  the timer interrupt. This service can be used to invoke the   registered handler if the timer interrupt has been masked for 
-  a period of time.
-
-**/
-EFI_TIMER_ARCH_PROTOCOL   gTimer = {
-  TimerDriverRegisterHandler,
-  TimerDriverSetTimerPeriod,
-  TimerDriverGetTimerPeriod,
-  TimerDriverGenerateSoftInterrupt
-};
-
-
-/**
-  Initialize the state information for the Timer Architectural Protocol and
-  the Timer Debug support protocol that allows the debugger to break into a
-  running program.
-
-  @param  ImageHandle   of the loaded driver
-  @param  SystemTable   Pointer to the System Table
-
-  @retval EFI_SUCCESS           Protocol registered
-  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure
-  @retval EFI_DEVICE_ERROR      Hardware problems
-
-**/
-EFI_STATUS
-EFIAPI
-TimerInitialize (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
-  )
-{
-  EFI_HANDLE  Handle = NULL;
-  EFI_STATUS  Status;
-  UINT32      TimerBaseAddress;
-
-  // Find the interrupt controller protocol.  ASSERT if not found.
-  Status = gBS->LocateProtocol (&gHardwareInterruptProtocolGuid, NULL, (VOID **)&gInterrupt);
-  ASSERT_EFI_ERROR (Status);
-
-  // Set up the timer registers
-  TimerBaseAddress = TimerBase (FixedPcdGet32(PcdOmap35xxArchTimer));
-  TISR = TimerBaseAddress + GPTIMER_TISR;
-  TCLR = TimerBaseAddress + GPTIMER_TCLR;
-  TLDR = TimerBaseAddress + GPTIMER_TLDR;
-  TCRR = TimerBaseAddress + GPTIMER_TCRR;
-  TIER = TimerBaseAddress + GPTIMER_TIER;
-
-  // Disable the timer
-  Status = TimerDriverSetTimerPeriod (&gTimer, 0);
-  ASSERT_EFI_ERROR (Status);
-
-  // Install interrupt handler
-  gVector = InterruptVectorForTimer (FixedPcdGet32(PcdOmap35xxArchTimer));
-  Status = gInterrupt->RegisterInterruptSource (gInterrupt, gVector, TimerInterruptHandler);
-  ASSERT_EFI_ERROR (Status);
-
-  // Turn on the functional clock for Timer
-  MmioOr32 (CM_FCLKEN_PER, CM_FCLKEN_PER_EN_GPT3_ENABLE);
-
-  // Set up default timer
-  Status = TimerDriverSetTimerPeriod (&gTimer, FixedPcdGet32(PcdTimerPeriod));
-  ASSERT_EFI_ERROR (Status);
-
-  // Install the Timer Architectural Protocol onto a new handle
-  Status = gBS->InstallMultipleProtocolInterfaces (
-                  &Handle,
-                  &gEfiTimerArchProtocolGuid,      &gTimer,
-                  NULL
-                  );
-  ASSERT_EFI_ERROR(Status);
-
-  return Status;
-}
-
+/** @file\r
+  Template for Timer Architecture Protocol driver of the ARM flavor\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials                          \r
+  are licensed and made available under the terms and conditions of the BSD License         \r
+  which accompanies this distribution.  The full text of the license may be found at        \r
+  http://opensource.org/licenses/bsd-license.php                                            \r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+**/\r
+\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/OmapLib.h>\r
+\r
+#include <Protocol/Timer.h>\r
+#include <Protocol/HardwareInterrupt.h>\r
+\r
+#include <Omap3530/Omap3530.h>\r
+\r
+\r
+// The notification function to call on every timer interrupt.\r
+volatile EFI_TIMER_NOTIFY      mTimerNotifyFunction   = (EFI_TIMER_NOTIFY)NULL;\r
+\r
+\r
+// The current period of the timer interrupt\r
+volatile UINT64 mTimerPeriod = 0;\r
+\r
+// Cached copy of the Hardware Interrupt protocol instance\r
+EFI_HARDWARE_INTERRUPT_PROTOCOL *gInterrupt = NULL;\r
+\r
+// Cached registers\r
+volatile UINT32 TISR;\r
+volatile UINT32 TCLR;\r
+volatile UINT32 TLDR;\r
+volatile UINT32 TCRR;\r
+volatile UINT32 TIER;\r
+\r
+// Cached interrupt vector\r
+volatile UINTN  gVector;\r
+\r
+\r
+/**\r
+\r
+  C Interrupt Handler calledin the interrupt context when Source interrupt is active.\r
+\r
+\r
+  @param Source         Source of the interrupt. Hardware routing off a specific platform defines\r
+                        what source means.\r
+\r
+  @param SystemContext  Pointer to system register context. Mostly used by debuggers and will\r
+                        update the system context after the return from the interrupt if \r
+                        modified. Don't change these values unless you know what you are doing\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+TimerInterruptHandler (\r
+  IN  HARDWARE_INTERRUPT_SOURCE   Source,\r
+  IN  EFI_SYSTEM_CONTEXT          SystemContext       \r
+  )\r
+{\r
+  EFI_TPL OriginalTPL;\r
+\r
+\r
+\r
+  //\r
+  // DXE core uses this callback for the EFI timer tick. The DXE core uses locks \r
+  // that raise to TPL_HIGH and then restore back to current level. Thus we need\r
+  // to make sure TPL level is set to TPL_HIGH while we are handling the timer tick. \r
+  //\r
+  OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+\r
+  if (mTimerNotifyFunction) {\r
+    mTimerNotifyFunction(mTimerPeriod);\r
+  }\r
+\r
+  // Clear all timer interrupts\r
+  MmioWrite32 (TISR, TISR_CLEAR_ALL);  \r
+\r
+  // Poll interrupt status bits to ensure clearing\r
+  while ((MmioRead32 (TISR) & TISR_ALL_INTERRUPT_MASK) != TISR_NO_INTERRUPTS_PENDING);\r
+\r
+  gBS->RestoreTPL (OriginalTPL);\r
+}\r
+\r
+/**\r
+  This function registers the handler NotifyFunction so it is called every time \r
+  the timer interrupt fires.  It also passes the amount of time since the last \r
+  handler call to the NotifyFunction.  If NotifyFunction is NULL, then the \r
+  handler is unregistered.  If the handler is registered, then EFI_SUCCESS is \r
+  returned.  If the CPU does not support registering a timer interrupt handler, \r
+  then EFI_UNSUPPORTED is returned.  If an attempt is made to register a handler \r
+  when a handler is already registered, then EFI_ALREADY_STARTED is returned.  \r
+  If an attempt is made to unregister a handler when a handler is not registered, \r
+  then EFI_INVALID_PARAMETER is returned.  If an error occurs attempting to \r
+  register the NotifyFunction with the timer interrupt, then EFI_DEVICE_ERROR \r
+  is returned.\r
+\r
+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param  NotifyFunction   The function to call when a timer interrupt fires. This\r
+                           function executes at TPL_HIGH_LEVEL. The DXE Core will\r
+                           register a handler for the timer interrupt, so it can know\r
+                           how much time has passed. This information is used to\r
+                           signal timer based events. NULL will unregister the handler.\r
+  @retval EFI_SUCCESS           The timer handler was registered.\r
+  @retval EFI_UNSUPPORTED       The platform does not support timer interrupts.\r
+  @retval EFI_ALREADY_STARTED   NotifyFunction is not NULL, and a handler is already\r
+                                registered.\r
+  @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not\r
+                                previously registered.\r
+  @retval EFI_DEVICE_ERROR      The timer handler could not be registered.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverRegisterHandler (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  IN EFI_TIMER_NOTIFY         NotifyFunction\r
+  )\r
+{\r
+  if ((NotifyFunction == NULL) && (mTimerNotifyFunction == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if ((NotifyFunction != NULL) && (mTimerNotifyFunction != NULL)) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  mTimerNotifyFunction = NotifyFunction;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+\r
+  This function adjusts the period of timer interrupts to the value specified \r
+  by TimerPeriod.  If the timer period is updated, then the selected timer \r
+  period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned.  If \r
+  the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.  \r
+  If an error occurs while attempting to update the timer period, then the \r
+  timer hardware will be put back in its state prior to this call, and \r
+  EFI_DEVICE_ERROR is returned.  If TimerPeriod is 0, then the timer interrupt \r
+  is disabled.  This is not the same as disabling the CPU's interrupts.  \r
+  Instead, it must either turn off the timer hardware, or it must adjust the \r
+  interrupt controller so that a CPU interrupt is not generated when the timer \r
+  interrupt fires. \r
+\r
+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param  TimerPeriod      The rate to program the timer interrupt in 100 nS units. If\r
+                           the timer hardware is not programmable, then EFI_UNSUPPORTED is\r
+                           returned. If the timer is programmable, then the timer period\r
+                           will be rounded up to the nearest timer period that is supported\r
+                           by the timer hardware. If TimerPeriod is set to 0, then the\r
+                           timer interrupts will be disabled.\r
+\r
+\r
+  @retval EFI_SUCCESS           The timer period was changed.\r
+  @retval EFI_UNSUPPORTED       The platform cannot change the period of the timer interrupt.\r
+  @retval EFI_DEVICE_ERROR      The timer period could not be changed due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverSetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  IN UINT64                   TimerPeriod\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT64      TimerCount;\r
+  INT32       LoadValue;\r
+  \r
+  if (TimerPeriod == 0) {\r
+    // Turn off GPTIMER3\r
+    MmioWrite32 (TCLR, TCLR_ST_OFF);\r
+    \r
+    Status = gInterrupt->DisableInterruptSource(gInterrupt, gVector);    \r
+  } else {  \r
+    // Calculate required timer count\r
+    TimerCount = DivU64x32(TimerPeriod * 100, PcdGet32(PcdEmbeddedPerformanceCounterPeriodInNanoseconds));\r
+\r
+    // Set GPTIMER3 Load register\r
+    LoadValue = (INT32) -TimerCount;\r
+    MmioWrite32 (TLDR, LoadValue);\r
+    MmioWrite32 (TCRR, LoadValue);\r
+\r
+    // Enable Overflow interrupt\r
+    MmioWrite32 (TIER, TIER_TCAR_IT_DISABLE | TIER_OVF_IT_ENABLE | TIER_MAT_IT_DISABLE);\r
+\r
+    // Turn on GPTIMER3, it will reload at overflow\r
+    MmioWrite32 (TCLR, TCLR_AR_AUTORELOAD | TCLR_ST_ON);\r
+\r
+    Status = gInterrupt->EnableInterruptSource(gInterrupt, gVector);    \r
+  }\r
+\r
+  //\r
+  // Save the new timer period\r
+  //\r
+  mTimerPeriod = TimerPeriod;\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  This function retrieves the period of timer interrupts in 100 ns units, \r
+  returns that value in TimerPeriod, and returns EFI_SUCCESS.  If TimerPeriod \r
+  is NULL, then EFI_INVALID_PARAMETER is returned.  If a TimerPeriod of 0 is \r
+  returned, then the timer is currently disabled.\r
+\r
+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.\r
+  @param  TimerPeriod      A pointer to the timer period to retrieve in 100 ns units. If\r
+                           0 is returned, then the timer is currently disabled.\r
+\r
+\r
+  @retval EFI_SUCCESS           The timer period was returned in TimerPeriod.\r
+  @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverGetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL   *This,\r
+  OUT UINT64                   *TimerPeriod\r
+  )\r
+{\r
+  if (TimerPeriod == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *TimerPeriod = mTimerPeriod;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This function generates a soft timer interrupt. If the platform does not support soft \r
+  timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCESS is returned. \r
+  If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.RegisterHandler() \r
+  service, then a soft timer interrupt will be generated. If the timer interrupt is \r
+  enabled when this service is called, then the registered handler will be invoked. The \r
+  registered handler should not be able to distinguish a hardware-generated timer \r
+  interrupt from a software-generated timer interrupt.\r
+\r
+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.\r
+\r
+  @retval EFI_SUCCESS           The soft timer interrupt was generated.\r
+  @retval EFI_UNSUPPORTED       The platform does not support the generation of soft timer interrupts.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerDriverGenerateSoftInterrupt (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Interface stucture for the Timer Architectural Protocol.\r
+\r
+  @par Protocol Description:\r
+  This protocol provides the services to initialize a periodic timer \r
+  interrupt, and to register a handler that is called each time the timer\r
+  interrupt fires.  It may also provide a service to adjust the rate of the\r
+  periodic timer interrupt.  When a timer interrupt occurs, the handler is \r
+  passed the amount of time that has passed since the previous timer \r
+  interrupt.\r
+\r
+  @param RegisterHandler\r
+  Registers a handler that will be called each time the \r
+  timer interrupt fires.  TimerPeriod defines the minimum \r
+  time between timer interrupts, so TimerPeriod will also \r
+  be the minimum time between calls to the registered \r
+  handler.\r
+\r
+  @param SetTimerPeriod\r
+  Sets the period of the timer interrupt in 100 nS units.  \r
+  This function is optional, and may return EFI_UNSUPPORTED.  \r
+  If this function is supported, then the timer period will \r
+  be rounded up to the nearest supported timer period.\r
+\r
+\r
+  @param GetTimerPeriod\r
+  Retrieves the period of the timer interrupt in 100 nS units.\r
+\r
+  @param GenerateSoftInterrupt\r
+  Generates a soft timer interrupt that simulates the firing of \r
+  the timer interrupt. This service can be used to invoke the   registered handler if the timer interrupt has been masked for \r
+  a period of time.\r
+\r
+**/\r
+EFI_TIMER_ARCH_PROTOCOL   gTimer = {\r
+  TimerDriverRegisterHandler,\r
+  TimerDriverSetTimerPeriod,\r
+  TimerDriverGetTimerPeriod,\r
+  TimerDriverGenerateSoftInterrupt\r
+};\r
+\r
+\r
+/**\r
+  Initialize the state information for the Timer Architectural Protocol and\r
+  the Timer Debug support protocol that allows the debugger to break into a\r
+  running program.\r
+\r
+  @param  ImageHandle   of the loaded driver\r
+  @param  SystemTable   Pointer to the System Table\r
+\r
+  @retval EFI_SUCCESS           Protocol registered\r
+  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure\r
+  @retval EFI_DEVICE_ERROR      Hardware problems\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TimerInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_HANDLE  Handle = NULL;\r
+  EFI_STATUS  Status;\r
+  UINT32      TimerBaseAddress;\r
+\r
+  // Find the interrupt controller protocol.  ASSERT if not found.\r
+  Status = gBS->LocateProtocol (&gHardwareInterruptProtocolGuid, NULL, (VOID **)&gInterrupt);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  // Set up the timer registers\r
+  TimerBaseAddress = TimerBase (FixedPcdGet32(PcdOmap35xxArchTimer));\r
+  TISR = TimerBaseAddress + GPTIMER_TISR;\r
+  TCLR = TimerBaseAddress + GPTIMER_TCLR;\r
+  TLDR = TimerBaseAddress + GPTIMER_TLDR;\r
+  TCRR = TimerBaseAddress + GPTIMER_TCRR;\r
+  TIER = TimerBaseAddress + GPTIMER_TIER;\r
+\r
+  // Disable the timer\r
+  Status = TimerDriverSetTimerPeriod (&gTimer, 0);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  // Install interrupt handler\r
+  gVector = InterruptVectorForTimer (FixedPcdGet32(PcdOmap35xxArchTimer));\r
+  Status = gInterrupt->RegisterInterruptSource (gInterrupt, gVector, TimerInterruptHandler);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  // Turn on the functional clock for Timer\r
+  MmioOr32 (CM_FCLKEN_PER, CM_FCLKEN_PER_EN_GPT3_ENABLE);\r
+\r
+  // Set up default timer\r
+  Status = TimerDriverSetTimerPeriod (&gTimer, FixedPcdGet32(PcdTimerPeriod));\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  // Install the Timer Architectural Protocol onto a new handle\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Handle,\r
+                  &gEfiTimerArchProtocolGuid,      &gTimer,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  return Status;\r
+}\r
+\r
index 6cfab775709c9a968316b0418e39d4519090c765..2c5a2f7a4a8ad611f89c31eca374eb87d4f1821e 100644 (file)
@@ -1,57 +1,57 @@
-#/** @file
-#  
-#    Component description file for Timer module
-#  
-#  Copyright (c) 2009, Apple Inc. All rights reserved.<BR>
-#  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                      = BeagleBoardTimerDxe
-  FILE_GUID                      = 6ddbf08b-cfc9-43cc-9e81-0784ba312ca0
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-
-  ENTRY_POINT                    = TimerInitialize
-
-[Sources.common]
-  Timer.c
-
-[Packages]
-  Omap35xxPkg/Omap35xxPkg.dec
-  MdePkg/MdePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  ArmPkg/ArmPkg.dec
-
-[LibraryClasses]
-  BaseLib
-  UefiRuntimeServicesTableLib
-  UefiLib
-  UefiBootServicesTableLib
-  BaseMemoryLib
-  DebugLib
-  UefiDriverEntryPoint
-  IoLib
-  OmapLib
-
-[Guids]
-
-[Protocols]
-  gEfiTimerArchProtocolGuid  
-  gHardwareInterruptProtocolGuid
-
-[Pcd.common]
-  gEmbeddedTokenSpaceGuid.PcdTimerPeriod
-  gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterPeriodInNanoseconds
-  gOmap35xxTokenSpaceGuid.PcdOmap35xxArchTimer
-
-[Depex]
-  gHardwareInterruptProtocolGuid
\ No newline at end of file
+#/** @file\r
+#  \r
+#    Component description file for Timer module\r
+#  \r
+#  Copyright (c) 2009, Apple Inc. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  \r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  \r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = BeagleBoardTimerDxe\r
+  FILE_GUID                      = 6ddbf08b-cfc9-43cc-9e81-0784ba312ca0\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = TimerInitialize\r
+\r
+[Sources.common]\r
+  Timer.c\r
+\r
+[Packages]\r
+  Omap35xxPkg/Omap35xxPkg.dec\r
+  MdePkg/MdePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  UefiRuntimeServicesTableLib\r
+  UefiLib\r
+  UefiBootServicesTableLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  UefiDriverEntryPoint\r
+  IoLib\r
+  OmapLib\r
+\r
+[Guids]\r
+\r
+[Protocols]\r
+  gEfiTimerArchProtocolGuid  \r
+  gHardwareInterruptProtocolGuid\r
+\r
+[Pcd.common]\r
+  gEmbeddedTokenSpaceGuid.PcdTimerPeriod\r
+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterPeriodInNanoseconds\r
+  gOmap35xxTokenSpaceGuid.PcdOmap35xxArchTimer\r
+\r
+[Depex]\r
+  gHardwareInterruptProtocolGuid\r
\ No newline at end of file