InOsEmuPkg: Rename package to EmulatorPkg & Sec to Host
authorjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 28 Jun 2011 16:47:23 +0000 (16:47 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 28 Jun 2011 16:47:23 +0000 (16:47 +0000)
* Rename InOsEmuPkg to EmulatorPkg
* Rename Unix/Sec to Unix/Host

Signed-off-by: jljusten
Reviewed-by: andrewfish
Reviewed-by: geekboy15a
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11918 6f19259b-4bc3-4df7-8a09-765794883524

382 files changed:
EmulatorPkg/AutoScanPei/AutoScanPei.c [new file with mode: 0644]
EmulatorPkg/AutoScanPei/AutoScanPei.inf [new file with mode: 0644]
EmulatorPkg/BootModePei/BootModePei.c [new file with mode: 0644]
EmulatorPkg/BootModePei/BootModePei.inf [new file with mode: 0644]
EmulatorPkg/CpuRuntimeDxe/Cpu.c [new file with mode: 0644]
EmulatorPkg/CpuRuntimeDxe/Cpu.inf [new file with mode: 0644]
EmulatorPkg/CpuRuntimeDxe/CpuDriver.h [new file with mode: 0644]
EmulatorPkg/CpuRuntimeDxe/CpuIo.c [new file with mode: 0644]
EmulatorPkg/CpuRuntimeDxe/MpService.c [new file with mode: 0644]
EmulatorPkg/CpuRuntimeDxe/Strings.uni [new file with mode: 0644]
EmulatorPkg/EmuBlockIoDxe/ComponentName.c [new file with mode: 0644]
EmulatorPkg/EmuBlockIoDxe/DriverConfiguration.c [new file with mode: 0644]
EmulatorPkg/EmuBlockIoDxe/DriverDiagnostics.c [new file with mode: 0644]
EmulatorPkg/EmuBlockIoDxe/EmuBlockIo.c [new file with mode: 0644]
EmulatorPkg/EmuBlockIoDxe/EmuBlockIo.h [new file with mode: 0644]
EmulatorPkg/EmuBlockIoDxe/EmuBlockIoDxe.inf [new file with mode: 0644]
EmulatorPkg/EmuBusDriverDxe/ComponentName.c [new file with mode: 0644]
EmulatorPkg/EmuBusDriverDxe/EmuBusDriverDxe.c [new file with mode: 0644]
EmulatorPkg/EmuBusDriverDxe/EmuBusDriverDxe.h [new file with mode: 0644]
EmulatorPkg/EmuBusDriverDxe/EmuBusDriverDxe.inf [new file with mode: 0644]
EmulatorPkg/EmuGopDxe/ComponentName.c [new file with mode: 0644]
EmulatorPkg/EmuGopDxe/EmuGopDxe.inf [new file with mode: 0644]
EmulatorPkg/EmuGopDxe/Gop.h [new file with mode: 0644]
EmulatorPkg/EmuGopDxe/GopDriver.c [new file with mode: 0644]
EmulatorPkg/EmuGopDxe/GopInput.c [new file with mode: 0644]
EmulatorPkg/EmuGopDxe/GopScreen.c [new file with mode: 0644]
EmulatorPkg/EmuSimpleFileSystemDxe/ComponentName.c [new file with mode: 0644]
EmulatorPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystem.c [new file with mode: 0644]
EmulatorPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystem.h [new file with mode: 0644]
EmulatorPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystemDxe.inf [new file with mode: 0644]
EmulatorPkg/EmuSnpDxe/ComponentName.c [new file with mode: 0644]
EmulatorPkg/EmuSnpDxe/EmuSnpDxe.c [new file with mode: 0644]
EmulatorPkg/EmuSnpDxe/EmuSnpDxe.h [new file with mode: 0644]
EmulatorPkg/EmuSnpDxe/EmuSnpDxe.inf [new file with mode: 0644]
EmulatorPkg/EmuThunkDxe/EmuThunk.c [new file with mode: 0644]
EmulatorPkg/EmuThunkDxe/EmuThunk.inf [new file with mode: 0644]
EmulatorPkg/EmulatorPkg.dec [new file with mode: 0644]
EmulatorPkg/FirmwareVolumePei/FirmwareVolumePei.c [new file with mode: 0644]
EmulatorPkg/FirmwareVolumePei/FirmwareVolumePei.inf [new file with mode: 0644]
EmulatorPkg/FlashMapPei/FlashMapPei.c [new file with mode: 0644]
EmulatorPkg/FlashMapPei/FlashMapPei.inf [new file with mode: 0644]
EmulatorPkg/FvbServicesRuntimeDxe/FWBlockService.c [new file with mode: 0644]
EmulatorPkg/FvbServicesRuntimeDxe/FvbInfo.c [new file with mode: 0644]
EmulatorPkg/FvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf [new file with mode: 0644]
EmulatorPkg/FvbServicesRuntimeDxe/FwBlockService.h [new file with mode: 0644]
EmulatorPkg/Include/Guid/EmuPhysicalDisk.h [new file with mode: 0644]
EmulatorPkg/Include/Guid/EmuSystemConfig.h [new file with mode: 0644]
EmulatorPkg/Include/Guid/EmuVirtualDisk.h [new file with mode: 0644]
EmulatorPkg/Include/Library/EmuMagicPageLib.h [new file with mode: 0644]
EmulatorPkg/Include/Library/EmuThunkLib.h [new file with mode: 0644]
EmulatorPkg/Include/Library/KeyMapLib.h [new file with mode: 0644]
EmulatorPkg/Include/Library/PpiListLib.h [new file with mode: 0644]
EmulatorPkg/Include/Library/ThunkPpiList.h [new file with mode: 0644]
EmulatorPkg/Include/Library/ThunkProtocolList.h [new file with mode: 0644]
EmulatorPkg/Include/Ppi/EmuThunk.h [new file with mode: 0644]
EmulatorPkg/Include/Protocol/EmuBlockIo.h [new file with mode: 0644]
EmulatorPkg/Include/Protocol/EmuFileSystem.h [new file with mode: 0644]
EmulatorPkg/Include/Protocol/EmuGraphicsWindow.h [new file with mode: 0644]
EmulatorPkg/Include/Protocol/EmuIoThunk.h [new file with mode: 0644]
EmulatorPkg/Include/Protocol/EmuSnp.h [new file with mode: 0644]
EmulatorPkg/Include/Protocol/EmuThread.h [new file with mode: 0644]
EmulatorPkg/Include/Protocol/EmuThunk.h [new file with mode: 0644]
EmulatorPkg/Library/DevicePathTextLib/DevicePathTextLib.c [new file with mode: 0644]
EmulatorPkg/Library/DevicePathTextLib/DevicePathTextLib.inf [new file with mode: 0644]
EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c [new file with mode: 0644]
EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.inf [new file with mode: 0644]
EmulatorPkg/Library/DxeEmuLib/DxeEmuLib.c [new file with mode: 0644]
EmulatorPkg/Library/DxeEmuLib/DxeEmuLib.inf [new file with mode: 0644]
EmulatorPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.c [new file with mode: 0644]
EmulatorPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.inf [new file with mode: 0644]
EmulatorPkg/Library/DxeEmuSerialPortLib/DxeEmuSerialPortLib.c [new file with mode: 0644]
EmulatorPkg/Library/DxeEmuSerialPortLib/DxeEmuSerialPortLib.inf [new file with mode: 0644]
EmulatorPkg/Library/DxeEmuStdErrSerialPortLib/DxeEmuStdErrSerialPortLib.c [new file with mode: 0644]
EmulatorPkg/Library/DxeEmuStdErrSerialPortLib/DxeEmuStdErrSerialPortLib.inf [new file with mode: 0644]
EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c [new file with mode: 0644]
EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.inf [new file with mode: 0644]
EmulatorPkg/Library/EmuBdsLib/BdsPlatform.c [new file with mode: 0644]
EmulatorPkg/Library/EmuBdsLib/BdsPlatform.h [new file with mode: 0644]
EmulatorPkg/Library/EmuBdsLib/EmuBdsLib.inf [new file with mode: 0644]
EmulatorPkg/Library/EmuBdsLib/PlatformData.c [new file with mode: 0644]
EmulatorPkg/Library/GuardUefiMemoryAllocationLib/GuardUefiMemoryAllocationLib.inf [new file with mode: 0644]
EmulatorPkg/Library/GuardUefiMemoryAllocationLib/MemoryAllocationLib.c [new file with mode: 0644]
EmulatorPkg/Library/KeyMapLibNull/KeyMapLibNull.c [new file with mode: 0644]
EmulatorPkg/Library/KeyMapLibNull/KeyMapLibNull.inf [new file with mode: 0644]
EmulatorPkg/Library/PeiCoreServicesTablePointerLib/PeiCoreServicesTablePointerLib.inf [new file with mode: 0644]
EmulatorPkg/Library/PeiCoreServicesTablePointerLib/PeiServicesTablePointer.c [new file with mode: 0644]
EmulatorPkg/Library/PeiEmuPeCoffExtraActionLib/PeiEmuPeCoffExtraActionLib.c [new file with mode: 0644]
EmulatorPkg/Library/PeiEmuPeCoffExtraActionLib/PeiEmuPeCoffExtraActionLib.inf [new file with mode: 0644]
EmulatorPkg/Library/PeiEmuPeCoffGetEntryPointLib/PeiEmuPeCoffGetEntryPointLib.c [new file with mode: 0644]
EmulatorPkg/Library/PeiEmuPeCoffGetEntryPointLib/PeiEmuPeCoffGetEntryPointLib.inf [new file with mode: 0644]
EmulatorPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.c [new file with mode: 0644]
EmulatorPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf [new file with mode: 0644]
EmulatorPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.c [new file with mode: 0644]
EmulatorPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf [new file with mode: 0644]
EmulatorPkg/Library/PeiServicesTablePointerLibMagicPage/PeiServicesTablePointer.c [new file with mode: 0644]
EmulatorPkg/Library/PeiServicesTablePointerLibMagicPage/PeiServicesTablePointerLibMagicPage.inf [new file with mode: 0644]
EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c [new file with mode: 0644]
EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.inf [new file with mode: 0644]
EmulatorPkg/Library/SecPeiServicesLib/FwVol.c [new file with mode: 0644]
EmulatorPkg/Library/SecPeiServicesLib/PeiServicesLib.c [new file with mode: 0644]
EmulatorPkg/Library/SecPeiServicesLib/SecPeiServicesLib.inf [new file with mode: 0644]
EmulatorPkg/Library/SecPpiListLib/PpiListLib.c [new file with mode: 0644]
EmulatorPkg/Library/SecPpiListLib/SecPpiListLib.inf [new file with mode: 0644]
EmulatorPkg/Library/ThunkPpiList/ThunkPpiList.c [new file with mode: 0644]
EmulatorPkg/Library/ThunkPpiList/ThunkPpiList.inf [new file with mode: 0644]
EmulatorPkg/Library/ThunkProtocolList/ThunkProtocolList.c [new file with mode: 0644]
EmulatorPkg/Library/ThunkProtocolList/ThunkProtocolList.inf [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturer.uni [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerData.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerFunction.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscBiosVendor.uni [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscBiosVendorData.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscBiosVendorFunction.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscBootInformationData.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscBootInformationFunction.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscChassisManufacturer.uni [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerData.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerFunction.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscDevicePath.h [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesData.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesFunction.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscOemString.uni [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscOemStringData.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscOemStringFunction.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignator.uni [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorData.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorFunction.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesData.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesFunction.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.h [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.uni [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscSubclassDriverDataTable.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscSystemLanguageString.uni [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringData.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringFunction.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscSystemManufacturer.uni [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerData.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerFunction.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscSystemOptionString.uni [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringData.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringFunction.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignation.uni [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationData.c [new file with mode: 0644]
EmulatorPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationFunction.c [new file with mode: 0644]
EmulatorPkg/RealTimeClockRuntimeDxe/RealTimeClock.c [new file with mode: 0644]
EmulatorPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf [new file with mode: 0644]
EmulatorPkg/ResetRuntimeDxe/Reset.c [new file with mode: 0644]
EmulatorPkg/ResetRuntimeDxe/Reset.inf [new file with mode: 0644]
EmulatorPkg/Sec/Ia32/SwitchRam.S [new file with mode: 0644]
EmulatorPkg/Sec/Ia32/TempRam.c [new file with mode: 0644]
EmulatorPkg/Sec/Sec.c [new file with mode: 0644]
EmulatorPkg/Sec/Sec.h [new file with mode: 0644]
EmulatorPkg/Sec/Sec.inf [new file with mode: 0644]
EmulatorPkg/Sec/X64/SwitchRam.S [new file with mode: 0644]
EmulatorPkg/ThunkPpiToProtocolPei/ThunkPpiToProtocolPei.c [new file with mode: 0644]
EmulatorPkg/ThunkPpiToProtocolPei/ThunkPpiToProtocolPei.inf [new file with mode: 0644]
EmulatorPkg/TimerDxe/Timer.c [new file with mode: 0644]
EmulatorPkg/TimerDxe/Timer.h [new file with mode: 0644]
EmulatorPkg/TimerDxe/Timer.inf [new file with mode: 0644]
EmulatorPkg/Unix/.gdbinit [new file with mode: 0644]
EmulatorPkg/Unix/GdbRun [new file with mode: 0644]
EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c [new file with mode: 0644]
EmulatorPkg/Unix/Host/BlockIo.c [new file with mode: 0644]
EmulatorPkg/Unix/Host/EmuThunk.c [new file with mode: 0644]
EmulatorPkg/Unix/Host/Gasket.h [new file with mode: 0644]
EmulatorPkg/Unix/Host/Ia32/Gasket.S [new file with mode: 0644]
EmulatorPkg/Unix/Host/Ia32/SwitchStack.c [new file with mode: 0644]
EmulatorPkg/Unix/Host/LinuxPacketFilter.c [new file with mode: 0644]
EmulatorPkg/Unix/Host/MemoryAllocationLib.c [new file with mode: 0644]
EmulatorPkg/Unix/Host/PosixFileSystem.c [new file with mode: 0644]
EmulatorPkg/Unix/Host/Pthreads.c [new file with mode: 0644]
EmulatorPkg/Unix/Host/SecMain.c [new file with mode: 0644]
EmulatorPkg/Unix/Host/SecMain.h [new file with mode: 0644]
EmulatorPkg/Unix/Host/SecMain.inf [new file with mode: 0644]
EmulatorPkg/Unix/Host/X11GraphicsWindow.c [new file with mode: 0644]
EmulatorPkg/Unix/Host/X64/Gasket.S [new file with mode: 0644]
EmulatorPkg/Unix/Host/X64/SwitchStack.S [new file with mode: 0644]
EmulatorPkg/Unix/UnixX64.dsc [new file with mode: 0644]
EmulatorPkg/Unix/UnixX64.fdf [new file with mode: 0644]
EmulatorPkg/Unix/Xcode/xcode_project32/XcodeBuild.sh [new file with mode: 0755]
EmulatorPkg/Unix/Xcode/xcode_project32/xcode_project.xcodeproj/default.pbxuser [new file with mode: 0644]
EmulatorPkg/Unix/Xcode/xcode_project32/xcode_project.xcodeproj/project.pbxproj [new file with mode: 0644]
EmulatorPkg/Unix/Xcode/xcode_project64/XcodeBuild.sh [new file with mode: 0755]
EmulatorPkg/Unix/Xcode/xcode_project64/xcode_project.xcodeproj/default.pbxuser [new file with mode: 0644]
EmulatorPkg/Unix/Xcode/xcode_project64/xcode_project.xcodeproj/project.pbxproj [new file with mode: 0644]
EmulatorPkg/Unix/build.sh [new file with mode: 0755]
EmulatorPkg/Unix/build64.sh [new file with mode: 0755]
EmulatorPkg/build.sh [new file with mode: 0755]
EmulatorPkg/build64.sh [new file with mode: 0755]
InOsEmuPkg/AutoScanPei/AutoScanPei.c [deleted file]
InOsEmuPkg/AutoScanPei/AutoScanPei.inf [deleted file]
InOsEmuPkg/BootModePei/BootModePei.c [deleted file]
InOsEmuPkg/BootModePei/BootModePei.inf [deleted file]
InOsEmuPkg/CpuRuntimeDxe/Cpu.c [deleted file]
InOsEmuPkg/CpuRuntimeDxe/Cpu.inf [deleted file]
InOsEmuPkg/CpuRuntimeDxe/CpuDriver.h [deleted file]
InOsEmuPkg/CpuRuntimeDxe/CpuIo.c [deleted file]
InOsEmuPkg/CpuRuntimeDxe/MpService.c [deleted file]
InOsEmuPkg/CpuRuntimeDxe/Strings.uni [deleted file]
InOsEmuPkg/EmuBlockIoDxe/ComponentName.c [deleted file]
InOsEmuPkg/EmuBlockIoDxe/DriverConfiguration.c [deleted file]
InOsEmuPkg/EmuBlockIoDxe/DriverDiagnostics.c [deleted file]
InOsEmuPkg/EmuBlockIoDxe/EmuBlockIo.c [deleted file]
InOsEmuPkg/EmuBlockIoDxe/EmuBlockIo.h [deleted file]
InOsEmuPkg/EmuBlockIoDxe/EmuBlockIoDxe.inf [deleted file]
InOsEmuPkg/EmuBusDriverDxe/ComponentName.c [deleted file]
InOsEmuPkg/EmuBusDriverDxe/EmuBusDriverDxe.c [deleted file]
InOsEmuPkg/EmuBusDriverDxe/EmuBusDriverDxe.h [deleted file]
InOsEmuPkg/EmuBusDriverDxe/EmuBusDriverDxe.inf [deleted file]
InOsEmuPkg/EmuGopDxe/ComponentName.c [deleted file]
InOsEmuPkg/EmuGopDxe/EmuGopDxe.inf [deleted file]
InOsEmuPkg/EmuGopDxe/Gop.h [deleted file]
InOsEmuPkg/EmuGopDxe/GopDriver.c [deleted file]
InOsEmuPkg/EmuGopDxe/GopInput.c [deleted file]
InOsEmuPkg/EmuGopDxe/GopScreen.c [deleted file]
InOsEmuPkg/EmuSimpleFileSystemDxe/ComponentName.c [deleted file]
InOsEmuPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystem.c [deleted file]
InOsEmuPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystem.h [deleted file]
InOsEmuPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystemDxe.inf [deleted file]
InOsEmuPkg/EmuSnpDxe/ComponentName.c [deleted file]
InOsEmuPkg/EmuSnpDxe/EmuSnpDxe.c [deleted file]
InOsEmuPkg/EmuSnpDxe/EmuSnpDxe.h [deleted file]
InOsEmuPkg/EmuSnpDxe/EmuSnpDxe.inf [deleted file]
InOsEmuPkg/EmuThunkDxe/EmuThunk.c [deleted file]
InOsEmuPkg/EmuThunkDxe/EmuThunk.inf [deleted file]
InOsEmuPkg/FirmwareVolumePei/FirmwareVolumePei.c [deleted file]
InOsEmuPkg/FirmwareVolumePei/FirmwareVolumePei.inf [deleted file]
InOsEmuPkg/FlashMapPei/FlashMapPei.c [deleted file]
InOsEmuPkg/FlashMapPei/FlashMapPei.inf [deleted file]
InOsEmuPkg/FvbServicesRuntimeDxe/FWBlockService.c [deleted file]
InOsEmuPkg/FvbServicesRuntimeDxe/FvbInfo.c [deleted file]
InOsEmuPkg/FvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf [deleted file]
InOsEmuPkg/FvbServicesRuntimeDxe/FwBlockService.h [deleted file]
InOsEmuPkg/InOsEmuPkg.dec [deleted file]
InOsEmuPkg/Include/Guid/EmuPhysicalDisk.h [deleted file]
InOsEmuPkg/Include/Guid/EmuSystemConfig.h [deleted file]
InOsEmuPkg/Include/Guid/EmuVirtualDisk.h [deleted file]
InOsEmuPkg/Include/Library/EmuMagicPageLib.h [deleted file]
InOsEmuPkg/Include/Library/EmuThunkLib.h [deleted file]
InOsEmuPkg/Include/Library/KeyMapLib.h [deleted file]
InOsEmuPkg/Include/Library/PpiListLib.h [deleted file]
InOsEmuPkg/Include/Library/ThunkPpiList.h [deleted file]
InOsEmuPkg/Include/Library/ThunkProtocolList.h [deleted file]
InOsEmuPkg/Include/Ppi/EmuThunk.h [deleted file]
InOsEmuPkg/Include/Protocol/EmuBlockIo.h [deleted file]
InOsEmuPkg/Include/Protocol/EmuFileSystem.h [deleted file]
InOsEmuPkg/Include/Protocol/EmuGraphicsWindow.h [deleted file]
InOsEmuPkg/Include/Protocol/EmuIoThunk.h [deleted file]
InOsEmuPkg/Include/Protocol/EmuSnp.h [deleted file]
InOsEmuPkg/Include/Protocol/EmuThread.h [deleted file]
InOsEmuPkg/Include/Protocol/EmuThunk.h [deleted file]
InOsEmuPkg/Library/DevicePathTextLib/DevicePathTextLib.c [deleted file]
InOsEmuPkg/Library/DevicePathTextLib/DevicePathTextLib.inf [deleted file]
InOsEmuPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c [deleted file]
InOsEmuPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.inf [deleted file]
InOsEmuPkg/Library/DxeEmuLib/DxeEmuLib.c [deleted file]
InOsEmuPkg/Library/DxeEmuLib/DxeEmuLib.inf [deleted file]
InOsEmuPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.c [deleted file]
InOsEmuPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.inf [deleted file]
InOsEmuPkg/Library/DxeEmuSerialPortLib/DxeEmuSerialPortLib.c [deleted file]
InOsEmuPkg/Library/DxeEmuSerialPortLib/DxeEmuSerialPortLib.inf [deleted file]
InOsEmuPkg/Library/DxeEmuStdErrSerialPortLib/DxeEmuStdErrSerialPortLib.c [deleted file]
InOsEmuPkg/Library/DxeEmuStdErrSerialPortLib/DxeEmuStdErrSerialPortLib.inf [deleted file]
InOsEmuPkg/Library/DxeTimerLib/DxeTimerLib.c [deleted file]
InOsEmuPkg/Library/DxeTimerLib/DxeTimerLib.inf [deleted file]
InOsEmuPkg/Library/EmuBdsLib/BdsPlatform.c [deleted file]
InOsEmuPkg/Library/EmuBdsLib/BdsPlatform.h [deleted file]
InOsEmuPkg/Library/EmuBdsLib/EmuBdsLib.inf [deleted file]
InOsEmuPkg/Library/EmuBdsLib/PlatformData.c [deleted file]
InOsEmuPkg/Library/GuardUefiMemoryAllocationLib/GuardUefiMemoryAllocationLib.inf [deleted file]
InOsEmuPkg/Library/GuardUefiMemoryAllocationLib/MemoryAllocationLib.c [deleted file]
InOsEmuPkg/Library/KeyMapLibNull/KeyMapLibNull.c [deleted file]
InOsEmuPkg/Library/KeyMapLibNull/KeyMapLibNull.inf [deleted file]
InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiCoreServicesTablePointerLib.inf [deleted file]
InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiServicesTablePointer.c [deleted file]
InOsEmuPkg/Library/PeiEmuPeCoffExtraActionLib/PeiEmuPeCoffExtraActionLib.c [deleted file]
InOsEmuPkg/Library/PeiEmuPeCoffExtraActionLib/PeiEmuPeCoffExtraActionLib.inf [deleted file]
InOsEmuPkg/Library/PeiEmuPeCoffGetEntryPointLib/PeiEmuPeCoffGetEntryPointLib.c [deleted file]
InOsEmuPkg/Library/PeiEmuPeCoffGetEntryPointLib/PeiEmuPeCoffGetEntryPointLib.inf [deleted file]
InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.c [deleted file]
InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf [deleted file]
InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.c [deleted file]
InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf [deleted file]
InOsEmuPkg/Library/PeiServicesTablePointerLibMagicPage/PeiServicesTablePointer.c [deleted file]
InOsEmuPkg/Library/PeiServicesTablePointerLibMagicPage/PeiServicesTablePointerLibMagicPage.inf [deleted file]
InOsEmuPkg/Library/PeiTimerLib/PeiTimerLib.c [deleted file]
InOsEmuPkg/Library/PeiTimerLib/PeiTimerLib.inf [deleted file]
InOsEmuPkg/Library/SecPeiServicesLib/FwVol.c [deleted file]
InOsEmuPkg/Library/SecPeiServicesLib/PeiServicesLib.c [deleted file]
InOsEmuPkg/Library/SecPeiServicesLib/SecPeiServicesLib.inf [deleted file]
InOsEmuPkg/Library/SecPpiListLib/PpiListLib.c [deleted file]
InOsEmuPkg/Library/SecPpiListLib/SecPpiListLib.inf [deleted file]
InOsEmuPkg/Library/ThunkPpiList/ThunkPpiList.c [deleted file]
InOsEmuPkg/Library/ThunkPpiList/ThunkPpiList.inf [deleted file]
InOsEmuPkg/Library/ThunkProtocolList/ThunkProtocolList.c [deleted file]
InOsEmuPkg/Library/ThunkProtocolList/ThunkProtocolList.inf [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturer.uni [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerData.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerFunction.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscBiosVendor.uni [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscBiosVendorData.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscBiosVendorFunction.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscBootInformationData.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscBootInformationFunction.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscChassisManufacturer.uni [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerData.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerFunction.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscDevicePath.h [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesData.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesFunction.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscOemString.uni [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscOemStringData.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscOemStringFunction.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignator.uni [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorData.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorFunction.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesData.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesFunction.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.h [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.uni [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubclassDriverDataTable.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemLanguageString.uni [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringData.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringFunction.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemManufacturer.uni [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerData.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerFunction.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemOptionString.uni [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringData.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringFunction.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignation.uni [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationData.c [deleted file]
InOsEmuPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationFunction.c [deleted file]
InOsEmuPkg/RealTimeClockRuntimeDxe/RealTimeClock.c [deleted file]
InOsEmuPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf [deleted file]
InOsEmuPkg/ResetRuntimeDxe/Reset.c [deleted file]
InOsEmuPkg/ResetRuntimeDxe/Reset.inf [deleted file]
InOsEmuPkg/Sec/Ia32/SwitchRam.S [deleted file]
InOsEmuPkg/Sec/Ia32/TempRam.c [deleted file]
InOsEmuPkg/Sec/Sec.c [deleted file]
InOsEmuPkg/Sec/Sec.h [deleted file]
InOsEmuPkg/Sec/Sec.inf [deleted file]
InOsEmuPkg/Sec/X64/SwitchRam.S [deleted file]
InOsEmuPkg/ThunkPpiToProtocolPei/ThunkPpiToProtocolPei.c [deleted file]
InOsEmuPkg/ThunkPpiToProtocolPei/ThunkPpiToProtocolPei.inf [deleted file]
InOsEmuPkg/TimerDxe/Timer.c [deleted file]
InOsEmuPkg/TimerDxe/Timer.h [deleted file]
InOsEmuPkg/TimerDxe/Timer.inf [deleted file]
InOsEmuPkg/Unix/.gdbinit [deleted file]
InOsEmuPkg/Unix/GdbRun [deleted file]
InOsEmuPkg/Unix/Sec/BerkeleyPacketFilter.c [deleted file]
InOsEmuPkg/Unix/Sec/BlockIo.c [deleted file]
InOsEmuPkg/Unix/Sec/EmuThunk.c [deleted file]
InOsEmuPkg/Unix/Sec/Gasket.h [deleted file]
InOsEmuPkg/Unix/Sec/Ia32/Gasket.S [deleted file]
InOsEmuPkg/Unix/Sec/Ia32/SwitchStack.c [deleted file]
InOsEmuPkg/Unix/Sec/LinuxPacketFilter.c [deleted file]
InOsEmuPkg/Unix/Sec/MemoryAllocationLib.c [deleted file]
InOsEmuPkg/Unix/Sec/PosixFileSystem.c [deleted file]
InOsEmuPkg/Unix/Sec/Pthreads.c [deleted file]
InOsEmuPkg/Unix/Sec/SecMain.c [deleted file]
InOsEmuPkg/Unix/Sec/SecMain.h [deleted file]
InOsEmuPkg/Unix/Sec/SecMain.inf [deleted file]
InOsEmuPkg/Unix/Sec/X11GraphicsWindow.c [deleted file]
InOsEmuPkg/Unix/Sec/X64/Gasket.S [deleted file]
InOsEmuPkg/Unix/Sec/X64/SwitchStack.S [deleted file]
InOsEmuPkg/Unix/UnixX64.dsc [deleted file]
InOsEmuPkg/Unix/UnixX64.fdf [deleted file]
InOsEmuPkg/Unix/Xcode/xcode_project32/XcodeBuild.sh [deleted file]
InOsEmuPkg/Unix/Xcode/xcode_project32/xcode_project.xcodeproj/default.pbxuser [deleted file]
InOsEmuPkg/Unix/Xcode/xcode_project32/xcode_project.xcodeproj/project.pbxproj [deleted file]
InOsEmuPkg/Unix/Xcode/xcode_project64/XcodeBuild.sh [deleted file]
InOsEmuPkg/Unix/Xcode/xcode_project64/xcode_project.xcodeproj/default.pbxuser [deleted file]
InOsEmuPkg/Unix/Xcode/xcode_project64/xcode_project.xcodeproj/project.pbxproj [deleted file]
InOsEmuPkg/Unix/build.sh [deleted file]
InOsEmuPkg/Unix/build64.sh [deleted file]
InOsEmuPkg/build.sh [deleted file]
InOsEmuPkg/build64.sh [deleted file]

diff --git a/EmulatorPkg/AutoScanPei/AutoScanPei.c b/EmulatorPkg/AutoScanPei/AutoScanPei.c
new file mode 100644 (file)
index 0000000..78cdd34
--- /dev/null
@@ -0,0 +1,109 @@
+/*++ @file\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\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
+#include <Ppi/EmuThunk.h>\r
+#include <Ppi/MemoryDiscovered.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeimEntryPoint.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PeimInitializeAutoScanPei (\r
+  IN       EFI_PEI_FILE_HANDLE       FileHandle,\r
+  IN CONST EFI_PEI_SERVICES          **PeiServices\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Perform a call-back into the SEC simulator to get a memory value\r
+\r
+Arguments:\r
+  FfsHeader   - General purpose data available to every PEIM\r
+  PeiServices - General purpose services available to every PEIM.\r
+    \r
+Returns:\r
+  None\r
+\r
+**/\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_PEI_PPI_DESCRIPTOR      *PpiDescriptor;\r
+  EMU_THUNK_PPI               *Thunk;\r
+  UINT64                      MemorySize;\r
+  EFI_PHYSICAL_ADDRESS        MemoryBase;\r
+  UINTN                       Index;\r
+  EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;\r
+\r
+\r
+  DEBUG ((EFI_D_ERROR, "Emu Autoscan PEIM Loaded\n"));\r
+\r
+  //\r
+  // Get the PEI UNIX Autoscan PPI\r
+  //\r
+  Status = PeiServicesLocatePpi (\r
+             &gEmuThunkPpiGuid,      // GUID\r
+             0,                      // INSTANCE\r
+             &PpiDescriptor,         // EFI_PEI_PPI_DESCRIPTOR\r
+             (VOID **)&Thunk         // PPI\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Index = 0;\r
+  do {\r
+    Status = Thunk->MemoryAutoScan (Index, &MemoryBase, &MemorySize);\r
+    if (!EFI_ERROR (Status)) {\r
+      Attributes =\r
+        (\r
+          EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
+          EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
+          EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r
+          EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r
+          EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r
+          EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE\r
+        );\r
+\r
+      if (Index == 0) {\r
+        //\r
+        // Register the memory with the PEI Core\r
+        //\r
+        Status = PeiServicesInstallPeiMemory (MemoryBase, MemorySize);\r
+        ASSERT_EFI_ERROR (Status);\r
+\r
+        Attributes |= EFI_RESOURCE_ATTRIBUTE_TESTED;\r
+      }\r
+      \r
+      BuildResourceDescriptorHob (\r
+        EFI_RESOURCE_SYSTEM_MEMORY,\r
+        Attributes,\r
+        MemoryBase,\r
+        MemorySize\r
+        );\r
+    }\r
+    Index++;\r
+  } while (!EFI_ERROR (Status));\r
+\r
+  //\r
+  // Build the CPU hob with 36-bit addressing and 16-bits of IO space.\r
+  //\r
+  BuildCpuHob (36, 16);\r
+  \r
+  return Status;\r
+}\r
diff --git a/EmulatorPkg/AutoScanPei/AutoScanPei.inf b/EmulatorPkg/AutoScanPei/AutoScanPei.inf
new file mode 100644 (file)
index 0000000..9fd4a7d
--- /dev/null
@@ -0,0 +1,58 @@
+## @file\r
+# Component description file for EmuAutoScan module\r
+#\r
+# This module abstracts memory auto-scan in a Emu environment.\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. 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                      = AutoScanPei\r
+  FILE_GUID                      = 2D6F6BCC-9681-8E42-8579-B57DCD0060F0\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = PeimInitializeAutoScanPei\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources]\r
+  AutoScanPei.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+#  MdeModulePkg/MdeModulePkg.dec\r
+  EmulatorPkg/EmulatorPkg.dec\r
+\r
+[LibraryClasses]\r
+  PeiServicesTablePointerLib\r
+  PeiServicesLib\r
+  HobLib\r
+  BaseMemoryLib\r
+  BaseLib\r
+  PeimEntryPoint\r
+  DebugLib\r
+\r
+\r
+[Ppis]\r
+  gEfiPeiMemoryDiscoveredPpiGuid                # PPI ALWAYS_PRODUCED\r
+  gEmuThunkPpiGuid                              # PPI ALWAYS_CONSUMED\r
+\r
+\r
+[Depex]\r
+  gEmuThunkPpiGuid AND gEfiPeiMasterBootModePpiGuid\r
+\r
diff --git a/EmulatorPkg/BootModePei/BootModePei.c b/EmulatorPkg/BootModePei/BootModePei.c
new file mode 100644 (file)
index 0000000..e26e929
--- /dev/null
@@ -0,0 +1,94 @@
+/** @file\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\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
+// The package level header files this module uses\r
+//\r
+#include <PiPei.h>\r
+\r
+#include <Library/PcdLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+\r
+\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Ppi/MasterBootMode.h>\r
+#include <Ppi/BootInRecoveryMode.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeimEntryPoint.h>\r
+\r
+\r
+//\r
+// Module globals\r
+//\r
+EFI_PEI_PPI_DESCRIPTOR  mPpiListBootMode = {\r
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+  &gEfiPeiMasterBootModePpiGuid,\r
+  NULL\r
+};\r
+\r
+EFI_PEI_PPI_DESCRIPTOR  mPpiListRecoveryBootMode = {\r
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+  &gEfiPeiBootInRecoveryModePpiGuid,\r
+  NULL\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeBootMode (\r
+  IN       EFI_PEI_FILE_HANDLE       FileHandle,\r
+  IN CONST EFI_PEI_SERVICES          **PeiServices\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Peform the boot mode determination logic\r
+\r
+Arguments:\r
+\r
+  PeiServices - General purpose services available to every PEIM.\r
+    \r
+Returns:\r
+\r
+  Status -  EFI_SUCCESS if the boot mode could be set\r
+\r
+**/\r
+{\r
+  EFI_STATUS    Status;\r
+  EFI_BOOT_MODE BootMode;\r
+\r
+  DEBUG ((EFI_D_ERROR, "Emu Boot Mode PEIM Loaded\n"));\r
+\r
+  BootMode  = FixedPcdGet32 (PcdEmuBootMode);\r
+\r
+  Status    = PeiServicesSetBootMode (BootMode);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = PeiServicesInstallPpi (&mPpiListBootMode);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  if (BootMode == BOOT_IN_RECOVERY_MODE) {\r
+    Status = PeiServicesInstallPpi (&mPpiListRecoveryBootMode);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
+  return Status;\r
+}\r
diff --git a/EmulatorPkg/BootModePei/BootModePei.inf b/EmulatorPkg/BootModePei/BootModePei.inf
new file mode 100644 (file)
index 0000000..34172bb
--- /dev/null
@@ -0,0 +1,59 @@
+## @file\r
+# Component description file for BootMode module\r
+#\r
+# This module provides platform specific function to detect boot mode.\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. 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                      = BootModePei\r
+  FILE_GUID                      = 64196C76-58E3-0B4D-9484-B54F7C4349CA\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = InitializeBootMode\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources]\r
+  BootModePei.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  EmulatorPkg/EmulatorPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  PeiServicesTablePointerLib\r
+  PeiServicesLib\r
+  BaseLib\r
+  PeimEntryPoint\r
+  DebugLib\r
+\r
+\r
+[Ppis]\r
+  gEfiPeiMasterBootModePpiGuid                  # PPI ALWAYS_PRODUCED\r
+  gEfiPeiBootInRecoveryModePpiGuid              # PPI SOMETIMES_PRODUCED\r
+\r
+[FixedPcd]\r
+  gEmulatorPkgTokenSpaceGuid.PcdEmuBootMode\r
+\r
+[Depex]\r
+  TRUE\r
+\r
diff --git a/EmulatorPkg/CpuRuntimeDxe/Cpu.c b/EmulatorPkg/CpuRuntimeDxe/Cpu.c
new file mode 100644 (file)
index 0000000..5ec315b
--- /dev/null
@@ -0,0 +1,374 @@
+/*++ @file\r
+  Emu driver to produce CPU Architectural Protocol.\r
+  \r
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\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 "CpuDriver.h"\r
+\r
+UINT64  mTimerPeriod;\r
+\r
+CPU_ARCH_PROTOCOL_PRIVATE mCpuTemplate = {\r
+  CPU_ARCH_PROT_PRIVATE_SIGNATURE,\r
+  NULL,\r
+  {\r
+    EmuFlushCpuDataCache,\r
+    EmuEnableInterrupt,\r
+    EmuDisableInterrupt,\r
+    EmuGetInterruptState,\r
+    EmuInit,\r
+    EmuRegisterInterruptHandler,\r
+    EmuGetTimerValue,\r
+    EmuSetMemoryAttributes,\r
+    0,\r
+    4\r
+  },\r
+  {\r
+    {\r
+      CpuMemoryServiceRead,\r
+      CpuMemoryServiceWrite\r
+    },\r
+    {\r
+      CpuIoServiceRead,\r
+      CpuIoServiceWrite\r
+    }\r
+  },\r
+  TRUE\r
+};\r
+\r
+#define EFI_CPU_DATA_MAXIMUM_LENGTH 0x100\r
+\r
+\r
+\r
+//\r
+// Service routines for the driver\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+EmuFlushCpuDataCache (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_PHYSICAL_ADDRESS   Start,\r
+  IN UINT64                 Length,\r
+  IN EFI_CPU_FLUSH_TYPE     FlushType\r
+  )\r
+{\r
+  if (FlushType == EfiCpuFlushTypeWriteBackInvalidate) {\r
+    //\r
+    // Only WB flush is supported. We actually need do nothing on Emu emulator\r
+    // environment. Classify this to follow EFI spec\r
+    //\r
+    return EFI_SUCCESS;\r
+  }\r
+  //\r
+  // Other flush types are not supported by Emu emulator\r
+  //\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuEnableInterrupt (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
+  )\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  Private                 = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  Private->InterruptState = TRUE;\r
+  gEmuThunk->EnableInterrupt ();\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuDisableInterrupt (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
+  )\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  Private                 = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  Private->InterruptState = FALSE;\r
+  gEmuThunk->DisableInterrupt ();\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuGetInterruptState (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  OUT BOOLEAN               *State\r
+  )\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  if (State == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  *State  = Private->InterruptState;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuInit (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_CPU_INIT_TYPE      InitType\r
+  )\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuRegisterInterruptHandler (\r
+  IN EFI_CPU_ARCH_PROTOCOL      *This,\r
+  IN EFI_EXCEPTION_TYPE         InterruptType,\r
+  IN EFI_CPU_INTERRUPT_HANDLER  InterruptHandler\r
+  )\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  //\r
+  // Do parameter checking for EFI spec conformance\r
+  //\r
+  if (InterruptType < 0 || InterruptType > 0xff) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Do nothing for Emu emulation\r
+  //\r
+  Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuGetTimerValue (\r
+  IN  EFI_CPU_ARCH_PROTOCOL *This,\r
+  IN  UINT32                TimerIndex,\r
+  OUT UINT64                *TimerValue,\r
+  OUT UINT64                *TimerPeriod OPTIONAL\r
+  )\r
+{\r
+  if (TimerValue == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (TimerIndex != 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  *TimerValue = gEmuThunk->QueryPerformanceCounter ();\r
+  \r
+  if (TimerPeriod != NULL) {\r
+    *TimerPeriod = mTimerPeriod;\r
+  } \r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSetMemoryAttributes (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_PHYSICAL_ADDRESS   BaseAddress,\r
+  IN UINT64                 Length,\r
+  IN UINT64                 Attributes\r
+  )\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  //\r
+  // Check for invalid parameter for Spec conformance\r
+  //\r
+  if (Length == 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Do nothing for Nt32 emulation\r
+  //\r
+  Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Logs SMBIOS record.\r
+\r
+  @param  Smbios   Pointer to SMBIOS protocol instance.\r
+  @param  Buffer   Pointer to the data buffer.\r
+\r
+**/\r
+VOID\r
+LogSmbiosData (\r
+  IN  EFI_SMBIOS_PROTOCOL        *Smbios,\r
+  IN  UINT8                      *Buffer\r
+  )\r
+{\r
+  EFI_STATUS         Status;\r
+  EFI_SMBIOS_HANDLE  SmbiosHandle;\r
+  \r
+  SmbiosHandle = 0;\r
+  Status = Smbios->Add (\r
+                     Smbios,\r
+                     NULL,\r
+                     &SmbiosHandle,\r
+                     (EFI_SMBIOS_TABLE_HEADER*)Buffer\r
+                     );\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+VOID\r
+CpuUpdateSmbios (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  UINT32                      TotalSize;\r
+  EFI_SMBIOS_PROTOCOL         *Smbios;\r
+  EFI_HII_HANDLE              HiiHandle;\r
+  STRING_REF                  Token;\r
+  UINTN                       CpuVerStrLen;\r
+  EFI_STRING                  CpuVerStr;\r
+  SMBIOS_TABLE_TYPE4          *SmbiosRecord;\r
+  CHAR8                       *OptionalStrStart;\r
+\r
+  //\r
+  // Locate Smbios protocol.\r
+  //\r
+  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&Smbios);\r
+  \r
+  if (EFI_ERROR (Status)) {\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Initialize strings to HII database\r
+  //\r
+  HiiHandle = HiiAddPackages (\r
+                &gEfiCallerIdGuid,\r
+                NULL,\r
+                CpuStrings,\r
+                NULL\r
+                );\r
+  ASSERT (HiiHandle != NULL);\r
+\r
+  Token  = STRING_TOKEN (STR_PROCESSOR_VERSION);\r
+  CpuVerStr = HiiGetPackageString(&gEfiCallerIdGuid, Token, NULL);\r
+  CpuVerStrLen = StrLen(CpuVerStr);\r
+  ASSERT (CpuVerStrLen <= SMBIOS_STRING_MAX_LENGTH);\r
+\r
+  TotalSize = sizeof(SMBIOS_TABLE_TYPE4) + CpuVerStrLen + 1 + 1;\r
+  SmbiosRecord = AllocatePool(TotalSize);\r
+  ZeroMem(SmbiosRecord, TotalSize);\r
+\r
+  SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION;\r
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE4);\r
+  //\r
+  // Make handle chosen by smbios protocol.add automatically.\r
+  //\r
+  SmbiosRecord->Hdr.Handle = 0;  \r
+  //\r
+  // Processor version is the 1st string.\r
+  //\r
+  SmbiosRecord->ProcessorVersion = 1;\r
+  //\r
+  // Store CPU frequency data record to data hub - It's an emulator so make up a value\r
+  //\r
+  SmbiosRecord->CurrentSpeed  = 1234;\r
+\r
+  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);\r
+  UnicodeStrToAsciiStr(CpuVerStr, OptionalStrStart);\r
+\r
+  //\r
+  // Now we have got the full smbios record, call smbios protocol to add this record.\r
+  //\r
+  LogSmbiosData(Smbios, (UINT8 *) SmbiosRecord);\r
+  FreePool (SmbiosRecord);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Callback function for idle events.\r
\r
+  @param  Event                 Event whose notification function is being invoked.\r
+  @param  Context               The pointer to the notification function's context,\r
+                                which is implementation-dependent.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+IdleLoopEventCallback (\r
+  IN EFI_EVENT                Event,\r
+  IN VOID                     *Context\r
+  )\r
+{\r
+  gEmuThunk->CpuSleep ();\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeCpu (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  UINT64        Frequency;\r
+  EFI_EVENT     IdleLoopEvent;\r
+\r
+  //\r
+  // Retrieve the frequency of the performance counter in Hz.\r
+  //  \r
+  Frequency = gEmuThunk->QueryPerformanceFrequency ();\r
+  \r
+  //\r
+  // Convert frequency in Hz to a clock period in femtoseconds.\r
+  //\r
+  mTimerPeriod = DivU64x64Remainder (1000000000000000ULL, Frequency, NULL);\r
+\r
+  CpuUpdateSmbios ();\r
+  \r
+  CpuMpServicesInit ();\r
+  \r
+  Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  IdleLoopEventCallback,\r
+                  NULL,\r
+                  &gIdleLoopEventGuid,\r
+                  &IdleLoopEvent\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &mCpuTemplate.Handle,\r
+                  &gEfiCpuArchProtocolGuid,   &mCpuTemplate.Cpu,\r
+                  &gEfiCpuIo2ProtocolGuid,    &mCpuTemplate.CpuIo,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
diff --git a/EmulatorPkg/CpuRuntimeDxe/Cpu.inf b/EmulatorPkg/CpuRuntimeDxe/Cpu.inf
new file mode 100644 (file)
index 0000000..ed8237f
--- /dev/null
@@ -0,0 +1,76 @@
+## @file\r
+# Component description file for Cpu module.\r
+#\r
+# This CPU module abstracts the interrupt subsystem of a platform and the CPU-specific setjump-long pair.\r
+#\r
+# Copyright (c) 2006 - 2011, 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
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = Cpu\r
+  FILE_GUID                      = f3794b60-8985-11db-8e53-0040d02b1835\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = InitializeCpu\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources]\r
+  CpuIo.c\r
+  Cpu.c\r
+  CpuDriver.h\r
+  Strings.uni\r
+  MpService.c\r
+  \r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  EmulatorPkg/EmulatorPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  HiiLib\r
+  DebugLib\r
+  BaseLib\r
+  EmuThunkLib\r
+  PcdLib\r
+\r
+[Protocols]\r
+  gEmuIoThunkProtocolGuid                       # PROTOCOL_NOTIFY SOMETIMES_CONSUMED\r
+  gEfiSmbiosProtocolGuid                        # PROTOCOL SOMETIMES_CONSUMED\r
+  gEfiHiiProtocolGuid                           # PROTOCOL SOMETIMES_CONSUMED\r
+  gEfiCpuIo2ProtocolGuid                        # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiCpuArchProtocolGuid                       # PROTOCOL ALWAYS_PRODUCED\r
+  gEmuThreadThunkProtocolGuid\r
+  gEfiMpServiceProtocolGuid\r
+\r
+[Guids]\r
+  gIdleLoopEventGuid                            ## CONSUMES ## GUID\r
+\r
+[Pcd]\r
+  gEmulatorPkgTokenSpaceGuid.PcdEmuMpServicesPollingInterval\r
+\r
+[Depex]\r
+  gEfiSmbiosProtocolGuid\r
diff --git a/EmulatorPkg/CpuRuntimeDxe/CpuDriver.h b/EmulatorPkg/CpuRuntimeDxe/CpuDriver.h
new file mode 100644 (file)
index 0000000..69505ff
--- /dev/null
@@ -0,0 +1,246 @@
+/*++ @file\r
+\r
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. 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 _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_\r
+#define _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_\r
+\r
+\r
+#include <FrameworkDxe.h>\r
+#include <IndustryStandard/SmBios.h>\r
+\r
+#include <Protocol/Cpu.h>\r
+#include <Protocol/Smbios.h>\r
+#include <Protocol/FrameworkHii.h>\r
+#include <Protocol/MpService.h>\r
+#include <Protocol/EmuThread.h>\r
+#include <Protocol/CpuIo2.h>\r
+\r
+#include <Guid/DataHubRecords.h>\r
+#include <Guid/IdleLoopEvent.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HiiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/EmuThunkLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+\r
+extern UINT8  CpuStrings[];\r
+\r
+//\r
+// Internal Data Structures\r
+//\r
+#define CPU_ARCH_PROT_PRIVATE_SIGNATURE SIGNATURE_32 ('c', 'a', 'p', 'd')\r
+\r
+typedef struct {\r
+  UINTN                 Signature;\r
+  EFI_HANDLE            Handle;\r
+\r
+  EFI_CPU_ARCH_PROTOCOL Cpu;\r
+  EFI_CPU_IO2_PROTOCOL  CpuIo;\r
+\r
+  //\r
+  // Local Data for CPU interface goes here\r
+  //\r
+  BOOLEAN               InterruptState;\r
+\r
+} CPU_ARCH_PROTOCOL_PRIVATE;\r
+\r
+#define CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS(a) \\r
+  CR (a, \\r
+      CPU_ARCH_PROTOCOL_PRIVATE, \\r
+      Cpu, \\r
+      CPU_ARCH_PROT_PRIVATE_SIGNATURE \\r
+      )\r
+\r
+\r
+\r
+typedef enum {\r
+  CPU_STATE_IDLE,\r
+  CPU_STATE_BLOCKED,\r
+  CPU_STATE_READY,\r
+  CPU_STATE_BUSY,\r
+  CPU_STATE_FINISHED\r
+} PROCESSOR_STATE;\r
+\r
+\r
+//\r
+// Define Individual Processor Data block.\r
+//\r
+typedef struct {\r
+  EFI_PROCESSOR_INFORMATION   Info;\r
+  EFI_AP_PROCEDURE            Procedure;\r
+  VOID                        *Parameter;\r
+  VOID                        *StateLock;\r
+  VOID                        *ProcedureLock;\r
+  PROCESSOR_STATE             State;\r
+  EFI_EVENT                   CheckThisAPEvent;   \r
+} PROCESSOR_DATA_BLOCK;\r
+\r
+\r
+//\r
+// Define MP data block which consumes individual processor block.\r
+//\r
+typedef struct {\r
+  UINTN                       NumberOfProcessors;\r
+  UINTN                       NumberOfEnabledProcessors;\r
+  EFI_EVENT                   CheckAllAPsEvent;\r
+  EFI_EVENT                   WaitEvent;\r
+  UINTN                       FinishCount;\r
+  UINTN                       StartCount;\r
+  EFI_AP_PROCEDURE            Procedure;\r
+  VOID                        *ProcedureArgument;\r
+  BOOLEAN                     SingleThread;\r
+  UINTN                       StartedNumber;\r
+  PROCESSOR_DATA_BLOCK        *ProcessorData;\r
+  UINTN                       Timeout;\r
+  UINTN                       *FailedList;\r
+  UINTN                       FailedListIndex;\r
+  BOOLEAN                     TimeoutActive;\r
+} MP_SYSTEM_DATA;\r
+\r
+\r
+\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceRead (\r
+  IN  EFI_CPU_IO2_PROTOCOL              *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceWrite (\r
+  IN EFI_CPU_IO2_PROTOCOL               *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceRead (\r
+  IN EFI_CPU_IO2_PROTOCOL               *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            UserAddress,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *UserBuffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceWrite (\r
+  IN EFI_CPU_IO2_PROTOCOL               *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            UserAddress,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *UserBuffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeCpu (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuFlushCpuDataCache (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_PHYSICAL_ADDRESS   Start,\r
+  IN UINT64                 Length,\r
+  IN EFI_CPU_FLUSH_TYPE     FlushType\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuEnableInterrupt (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuDisableInterrupt (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuGetInterruptState (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  OUT BOOLEAN               *State\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuInit (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_CPU_INIT_TYPE      InitType\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuRegisterInterruptHandler (\r
+  IN EFI_CPU_ARCH_PROTOCOL      *This,\r
+  IN EFI_EXCEPTION_TYPE         InterruptType,\r
+  IN EFI_CPU_INTERRUPT_HANDLER  InterruptHandler\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuGetTimerValue (\r
+  IN  EFI_CPU_ARCH_PROTOCOL *This,\r
+  IN  UINT32                TimerIndex,\r
+  OUT UINT64                *TimerValue,\r
+  OUT UINT64                *TimerPeriod OPTIONAL\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuSetMemoryAttributes (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_PHYSICAL_ADDRESS   BaseAddress,\r
+  IN UINT64                 Length,\r
+  IN UINT64                 Attributes\r
+  );\r
+\r
+EFI_STATUS\r
+CpuMpServicesInit (\r
+  VOID\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMpServicesWhoAmI (\r
+  IN EFI_MP_SERVICES_PROTOCOL  *This,\r
+  OUT UINTN                    *ProcessorNumber\r
+  );\r
+\r
+extern EFI_MP_SERVICES_PROTOCOL  mMpSercicesTemplate;\r
+\r
+\r
+#endif\r
diff --git a/EmulatorPkg/CpuRuntimeDxe/CpuIo.c b/EmulatorPkg/CpuRuntimeDxe/CpuIo.c
new file mode 100644 (file)
index 0000000..6f63375
--- /dev/null
@@ -0,0 +1,333 @@
+/*++ @file\r
+  This is the code that publishes the CPU I/O Protocol.\r
+  The intent herein is to have a single I/O service that can load\r
+  as early as possible, extend into runtime, and be layered upon by \r
+  the implementations of architectural protocols and the PCI Root\r
+  Bridge I/O Protocol.\r
+\r
+\r
+Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\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 <FrameworkDxe.h>\r
+#include <Protocol/Cpu.h>\r
+#include <Protocol/DataHub.h>\r
+#include <Guid/DataHubRecords.h>\r
+#include <Protocol/CpuIo2.h>\r
+#include <Protocol/FrameworkHii.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HiiLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <CpuDriver.h>\r
+\r
+#define IA32_MAX_IO_ADDRESS   0xFFFF\r
+#define IA32_MAX_MEM_ADDRESS  0xFFFFFFFF\r
+\r
+EFI_STATUS\r
+CpuIoCheckAddressRange (\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  VOID                              *Buffer,\r
+  IN  UINT64                            Limit\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceRead (\r
+  IN  EFI_CPU_IO2_PROTOCOL              *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Perform the Memory Access Read service for the CPU I/O Protocol\r
+\r
+Arguments:\r
+\r
+  Pointer to an instance of the CPU I/O Protocol\r
+  Width of the Memory Access\r
+  Address of the Memory access\r
+  Count of the number of accesses to perform\r
+  Pointer to the buffer to read or write from memory\r
+\r
+Returns:\r
+\r
+  Status\r
+\r
+  EFI_SUCCESS             - The data was read from or written to the EFI \r
+                            System.\r
+  EFI_INVALID_PARAMETER   - Width is invalid for this EFI System.\r
+  EFI_INVALID_PARAMETER   - Buffer is NULL.\r
+  EFI_UNSUPPORTED         - The Buffer is not aligned for the given Width.\r
+  EFI_UNSUPPORTED         - The address range specified by Address, Width, \r
+                            and Count is not valid for this EFI System.\r
+\r
+**/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  if (!Buffer) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Do nothing for Nt32 version\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceWrite (\r
+  IN EFI_CPU_IO2_PROTOCOL               *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Perform the Memory Access Read service for the CPU I/O Protocol\r
+\r
+Arguments:\r
+\r
+  Pointer to an instance of the CPU I/O Protocol\r
+  Width of the Memory Access\r
+  Address of the Memory access\r
+  Count of the number of accesses to perform\r
+  Pointer to the buffer to read or write from memory\r
+\r
+Returns:\r
+\r
+  Status\r
+\r
+  EFI_SUCCESS             - The data was read from or written to the EFI System.\r
+  EFI_INVALID_PARAMETER   - Width is invalid for this EFI System.\r
+  EFI_INVALID_PARAMETER   - Buffer is NULL.\r
+  EFI_UNSUPPORTED         - The Buffer is not aligned for the given Width.\r
+  EFI_UNSUPPORTED         - The address range specified by Address, Width, and \r
+                            Count is not valid for this EFI System.\r
+\r
+**/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  if (!Buffer) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Do nothing for Nt32 version\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceRead (\r
+  IN EFI_CPU_IO2_PROTOCOL               *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            UserAddress,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *UserBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+  This is the service that implements the I/O read\r
+\r
+Arguments:\r
+\r
+  Pointer to an instance of the CPU I/O Protocol\r
+  Width of the Memory Access\r
+  Address of the I/O access\r
+  Count of the number of accesses to perform\r
+  Pointer to the buffer to read or write from I/O space\r
+\r
+Returns:\r
+\r
+  Status\r
+  EFI_SUCCESS             - The data was read from or written to the EFI System.\r
+  EFI_INVALID_PARAMETER   - Width is invalid for this EFI System.\r
+  EFI_INVALID_PARAMETER   - Buffer is NULL.\r
+  EFI_UNSUPPORTED         - The Buffer is not aligned for the given Width.\r
+  EFI_UNSUPPORTED         - The address range specified by Address, Width, and \r
+                            Count is not valid for this EFI System.\r
+**/\r
+{\r
+  UINTN       Address;\r
+  EFI_STATUS  Status;\r
+\r
+  if (!UserBuffer) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Address = (UINTN) UserAddress;\r
+\r
+  if (Width >= EfiCpuIoWidthMaximum) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Do nothing for Nt32 version\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceWrite (\r
+  IN EFI_CPU_IO2_PROTOCOL               *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            UserAddress,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *UserBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  \r
+  This is the service that implements the I/O Write\r
+\r
+Arguments:\r
+\r
+  Pointer to an instance of the CPU I/O Protocol\r
+  Width of the Memory Access\r
+  Address of the I/O access\r
+  Count of the number of accesses to perform\r
+  Pointer to the buffer to read or write from I/O space\r
+\r
+Returns:\r
+\r
+  Status\r
+\r
+  Status\r
+  EFI_SUCCESS             - The data was read from or written to the EFI System.\r
+  EFI_INVALID_PARAMETER   - Width is invalid for this EFI System.\r
+  EFI_INVALID_PARAMETER   - Buffer is NULL.\r
+  EFI_UNSUPPORTED         - The Buffer is not aligned for the given Width.\r
+  EFI_UNSUPPORTED         - The address range specified by Address, Width, and \r
+                            Count is not valid for this EFI System.\r
+\r
+**/\r
+{\r
+  UINTN       Address;\r
+  EFI_STATUS  Status;\r
+\r
+  if (!UserBuffer) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Address = (UINTN) UserAddress;\r
+\r
+  if (Width >= EfiCpuIoWidthMaximum) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Do nothing for Nt32 version\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+  Width   - TODO: add argument description\r
+  Address - TODO: add argument description\r
+  Count   - TODO: add argument description\r
+  Buffer  - TODO: add argument description\r
+  Limit   - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_UNSUPPORTED - TODO: Add description for return value\r
+  EFI_UNSUPPORTED - TODO: Add description for return value\r
+  EFI_UNSUPPORTED - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+**/\r
+EFI_STATUS\r
+CpuIoCheckAddressRange (\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  VOID                              *Buffer,\r
+  IN  UINT64                            Limit\r
+  )\r
+{\r
+  UINTN AlignMask;\r
+\r
+  if (Address > Limit) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // For FiFo type, the target address won't increase during the access, so treat count as 1\r
+  //\r
+  if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {\r
+    Count = 1;\r
+  }\r
+\r
+  Width = Width & 0x03;\r
+  if (Address - 1 + (1 << Width) * Count > Limit) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  AlignMask = (1 << Width) - 1;\r
+  if ((UINTN) Buffer & AlignMask) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
diff --git a/EmulatorPkg/CpuRuntimeDxe/MpService.c b/EmulatorPkg/CpuRuntimeDxe/MpService.c
new file mode 100644 (file)
index 0000000..7f3b199
--- /dev/null
@@ -0,0 +1,1366 @@
+/** @file\r
+  Construct MP Services Protocol on top of the EMU Thread protocol.\r
+  This code makes APs show up in the emulator. PcdEmuApCount is the\r
+  number of APs the emulator should produce.\r
+\r
+  The MP Services Protocol provides a generalized way of performing following tasks:\r
+    - Retrieving information of multi-processor environment and MP-related status of\r
+      specific processors.\r
+    - Dispatching user-provided function to APs.\r
+    - Maintain MP-related processor status.\r
+\r
+  The MP Services Protocol must be produced on any system with more than one logical\r
+  processor.\r
+\r
+  The Protocol is available only during boot time.\r
+\r
+  MP Services Protocol is hardware-independent. Most of the logic of this protocol\r
+  is architecturally neutral. It abstracts the multi-processor environment and \r
+  status of processors, and provides interfaces to retrieve information, maintain, \r
+  and dispatch.\r
+\r
+  MP Services Protocol may be consumed by ACPI module. The ACPI module may use this \r
+  protocol to retrieve data that are needed for an MP platform and report them to OS.\r
+  MP Services Protocol may also be used to program and configure processors, such \r
+  as MTRR synchronization for memory space attributes setting in DXE Services.\r
+  MP Services Protocol may be used by non-CPU DXE drivers to speed up platform boot \r
+  by taking advantage of the processing capabilities of the APs, for example, using \r
+  APs to help test system memory in parallel with other device initialization.\r
+  Diagnostics applications may also use this protocol for multi-processor.\r
+\r
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Portitions Copyright (c) 2011, Apple Inc. All rights reserved.\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that 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
+\r
+#include "CpuDriver.h"\r
+\r
+\r
+MP_SYSTEM_DATA                gMPSystem;\r
+EMU_THREAD_THUNK_PROTOCOL     *gThread = NULL; \r
+EFI_EVENT                     gReadToBootEvent;\r
+BOOLEAN                       gReadToBoot = FALSE;\r
+UINTN                         gPollInterval;\r
+\r
+\r
+BOOLEAN\r
+IsBSP (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       ProcessorNumber;\r
+  \r
+  Status = CpuMpServicesWhoAmI (&mMpSercicesTemplate, &ProcessorNumber);\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+  \r
+  return (gMPSystem.ProcessorData[ProcessorNumber].Info.StatusFlag & PROCESSOR_AS_BSP_BIT) != 0;\r
+}\r
+\r
+\r
+VOID\r
+SetApProcedure (\r
+  IN   PROCESSOR_DATA_BLOCK  *Processor,\r
+  IN   EFI_AP_PROCEDURE      Procedure,\r
+  IN   VOID                  *ProcedureArgument\r
+  )\r
+{\r
+  gThread->MutexLock (Processor->ProcedureLock);\r
+  Processor->Parameter  = ProcedureArgument;\r
+  Processor->Procedure  = Procedure;\r
+  gThread->MutexUnlock (Processor->ProcedureLock);\r
+}\r
+\r
+\r
+EFI_STATUS\r
+GetNextBlockedNumber (\r
+  OUT UINTN                               *NextNumber\r
+  )\r
+{\r
+  UINTN                 Number;\r
+  PROCESSOR_STATE       ProcessorState;\r
+  PROCESSOR_DATA_BLOCK  *Data;\r
+\r
+  for (Number = 0; Number < gMPSystem.NumberOfProcessors; Number++) {\r
+    Data = &gMPSystem.ProcessorData[Number];\r
+    if ((Data->Info.StatusFlag & PROCESSOR_AS_BSP_BIT) != 0) {\r
+      // Skip BSP\r
+      continue;\r
+    }\r
+\r
+    gThread->MutexLock (Data->StateLock);\r
+    ProcessorState = Data->State;\r
+    gThread->MutexUnlock (Data->StateLock);\r
+\r
+    if (ProcessorState == CPU_STATE_BLOCKED) {\r
+      *NextNumber = Number;\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+\r
+\r
+\r
+/**\r
+  This service retrieves the number of logical processor in the platform\r
+  and the number of those logical processors that are enabled on this boot.\r
+  This service may only be called from the BSP.\r
+\r
+  This function is used to retrieve the following information:\r
+    - The number of logical processors that are present in the system.\r
+    - The number of enabled logical processors in the system at the instant \r
+      this call is made.\r
+\r
+  Because MP Service Protocol provides services to enable and disable processors \r
+  dynamically, the number of enabled logical processors may vary during the \r
+  course of a boot session.\r
+  \r
+  If this service is called from an AP, then EFI_DEVICE_ERROR is returned. \r
+  If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then \r
+  EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors \r
+  is returned in NumberOfProcessors, the number of currently enabled processor \r
+  is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.\r
+\r
+  @param[in]  This                        A pointer to the EFI_MP_SERVICES_PROTOCOL\r
+                                          instance.\r
+  @param[out] NumberOfProcessors          Pointer to the total number of logical\r
+                                          processors in the system, including the BSP\r
+                                          and disabled APs.\r
+  @param[out] NumberOfEnabledProcessors   Pointer to the number of enabled logical\r
+                                          processors that exist in system, including\r
+                                          the BSP.\r
+\r
+  @retval EFI_SUCCESS             The number of logical processors and enabled \r
+                                  logical processors was retrieved.\r
+  @retval EFI_DEVICE_ERROR        The calling processor is an AP.\r
+  @retval EFI_INVALID_PARAMETER   NumberOfProcessors is NULL.\r
+  @retval EFI_INVALID_PARAMETER   NumberOfEnabledProcessors is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMpServicesGetNumberOfProcessors (\r
+  IN  EFI_MP_SERVICES_PROTOCOL  *This,\r
+  OUT UINTN                     *NumberOfProcessors,\r
+  OUT UINTN                     *NumberOfEnabledProcessors\r
+  )\r
+{\r
+  if ((NumberOfProcessors == NULL) || (NumberOfEnabledProcessors == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  if (!IsBSP ()) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  \r
+  *NumberOfProcessors        = gMPSystem.NumberOfProcessors;\r
+  *NumberOfEnabledProcessors = gMPSystem.NumberOfEnabledProcessors;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Gets detailed MP-related information on the requested processor at the\r
+  instant this call is made. This service may only be called from the BSP.\r
+\r
+  This service retrieves detailed MP-related information about any processor \r
+  on the platform. Note the following:\r
+    - The processor information may change during the course of a boot session.\r
+    - The information presented here is entirely MP related.\r
+  \r
+  Information regarding the number of caches and their sizes, frequency of operation,\r
+  slot numbers is all considered platform-related information and is not provided \r
+  by this service.\r
+\r
+  @param[in]  This                  A pointer to the EFI_MP_SERVICES_PROTOCOL\r
+                                    instance.\r
+  @param[in]  ProcessorNumber       The handle number of processor.\r
+  @param[out] ProcessorInfoBuffer   A pointer to the buffer where information for\r
+                                    the requested processor is deposited.\r
+\r
+  @retval EFI_SUCCESS             Processor information was returned.\r
+  @retval EFI_DEVICE_ERROR        The calling processor is an AP.\r
+  @retval EFI_INVALID_PARAMETER   ProcessorInfoBuffer is NULL.\r
+  @retval EFI_NOT_FOUND           The processor with the handle specified by\r
+                                  ProcessorNumber does not exist in the platform.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMpServicesGetProcessorInfo (\r
+  IN  EFI_MP_SERVICES_PROTOCOL   *This,\r
+  IN  UINTN                      ProcessorNumber,\r
+  OUT EFI_PROCESSOR_INFORMATION  *ProcessorInfoBuffer\r
+  )\r
+{\r
+  if (ProcessorInfoBuffer == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  if (!IsBSP ()) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  \r
+  if (ProcessorNumber >= gMPSystem.NumberOfProcessors) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  \r
+  CopyMem (ProcessorInfoBuffer, &gMPSystem.ProcessorData[ProcessorNumber], sizeof (EFI_PROCESSOR_INFORMATION));\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  This service executes a caller provided function on all enabled APs. APs can \r
+  run either simultaneously or one at a time in sequence. This service supports \r
+  both blocking and non-blocking requests. The non-blocking requests use EFI \r
+  events so the BSP can detect when the APs have finished. This service may only \r
+  be called from the BSP.\r
+\r
+  This function is used to dispatch all the enabled APs to the function specified \r
+  by Procedure.  If any enabled AP is busy, then EFI_NOT_READY is returned \r
+  immediately and Procedure is not started on any AP.\r
+\r
+  If SingleThread is TRUE, all the enabled APs execute the function specified by \r
+  Procedure one by one, in ascending order of processor handle number. Otherwise, \r
+  all the enabled APs execute the function specified by Procedure simultaneously.\r
+\r
+  If WaitEvent is NULL, execution is in blocking mode. The BSP waits until all \r
+  APs finish or TimeoutInMicroseconds expires. Otherwise, execution is in non-blocking \r
+  mode, and the BSP returns from this service without waiting for APs. If a \r
+  non-blocking mode is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT \r
+  is signaled, then EFI_UNSUPPORTED must be returned.\r
+\r
+  If the timeout specified by TimeoutInMicroseconds expires before all APs return \r
+  from Procedure, then Procedure on the failed APs is terminated. All enabled APs \r
+  are always available for further calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()\r
+  and EFI_MP_SERVICES_PROTOCOL.StartupThisAP(). If FailedCpuList is not NULL, its \r
+  content points to the list of processor handle numbers in which Procedure was \r
+  terminated.\r
+\r
+  Note: It is the responsibility of the consumer of the EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() \r
+  to make sure that the nature of the code that is executed on the BSP and the \r
+  dispatched APs is well controlled. The MP Services Protocol does not guarantee \r
+  that the Procedure function is MP-safe. Hence, the tasks that can be run in \r
+  parallel are limited to certain independent tasks and well-controlled exclusive \r
+  code. EFI services and protocols may not be called by APs unless otherwise \r
+  specified.\r
+\r
+  In blocking execution mode, BSP waits until all APs finish or \r
+  TimeoutInMicroseconds expires.\r
+\r
+  In non-blocking execution mode, BSP is freed to return to the caller and then \r
+  proceed to the next task without having to wait for APs. The following \r
+  sequence needs to occur in a non-blocking execution mode:\r
+\r
+    -# The caller that intends to use this MP Services Protocol in non-blocking \r
+       mode creates WaitEvent by calling the EFI CreateEvent() service.  The caller \r
+       invokes EFI_MP_SERVICES_PROTOCOL.StartupAllAPs(). If the parameter WaitEvent \r
+       is not NULL, then StartupAllAPs() executes in non-blocking mode. It requests \r
+       the function specified by Procedure to be started on all the enabled APs, \r
+       and releases the BSP to continue with other tasks.\r
+    -# The caller can use the CheckEvent() and WaitForEvent() services to check \r
+       the state of the WaitEvent created in step 1.\r
+    -# When the APs complete their task or TimeoutInMicroSecondss expires, the MP \r
+       Service signals WaitEvent by calling the EFI SignalEvent() function. If \r
+       FailedCpuList is not NULL, its content is available when WaitEvent is \r
+       signaled. If all APs returned from Procedure prior to the timeout, then \r
+       FailedCpuList is set to NULL. If not all APs return from Procedure before \r
+       the timeout, then FailedCpuList is filled in with the list of the failed \r
+       APs. The buffer is allocated by MP Service Protocol using AllocatePool(). \r
+       It is the caller's responsibility to free the buffer with FreePool() service.\r
+    -# This invocation of SignalEvent() function informs the caller that invoked\r
+       EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() that either all the APs completed\r
+       the specified task or a timeout occurred. The contents of FailedCpuList \r
+       can be examined to determine which APs did not complete the specified task \r
+       prior to the timeout.\r
+\r
+  @param[in]  This                    A pointer to the EFI_MP_SERVICES_PROTOCOL\r
+                                      instance.\r
+  @param[in]  Procedure               A pointer to the function to be run on \r
+                                      enabled APs of the system. See type\r
+                                      EFI_AP_PROCEDURE.\r
+  @param[in]  SingleThread            If TRUE, then all the enabled APs execute \r
+                                      the function specified by Procedure one by \r
+                                      one, in ascending order of processor handle \r
+                                      number.  If FALSE, then all the enabled APs \r
+                                      execute the function specified by Procedure\r
+                                      simultaneously.\r
+  @param[in]  WaitEvent               The event created by the caller with CreateEvent()\r
+                                      service.  If it is NULL, then execute in \r
+                                      blocking mode. BSP waits until all APs finish \r
+                                      or TimeoutInMicroseconds expires.  If it's \r
+                                      not NULL, then execute in non-blocking mode. \r
+                                      BSP requests the function specified by \r
+                                      Procedure to be started on all the enabled \r
+                                      APs, and go on executing immediately. If \r
+                                      all return from Procedure, or TimeoutInMicroseconds\r
+                                      expires, this event is signaled. The BSP \r
+                                      can use the CheckEvent() or WaitForEvent() \r
+                                      services to check the state of event.  Type \r
+                                      EFI_EVENT is defined in CreateEvent() in \r
+                                      the Unified Extensible Firmware Interface \r
+                                      Specification.  \r
+  @param[in]  TimeoutInMicrosecsond   Indicates the time limit in microseconds for \r
+                                      APs to return from Procedure, either for \r
+                                      blocking or non-blocking mode. Zero means \r
+                                      infinity.  If the timeout expires before \r
+                                      all APs return from Procedure, then Procedure\r
+                                      on the failed APs is terminated. All enabled \r
+                                      APs are available for next function assigned \r
+                                      by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() \r
+                                      or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().\r
+                                      If the timeout expires in blocking mode, \r
+                                      BSP returns EFI_TIMEOUT.  If the timeout \r
+                                      expires in non-blocking mode, WaitEvent \r
+                                      is signaled with SignalEvent().\r
+  @param[in]  ProcedureArgument       The parameter passed into Procedure for \r
+                                      all APs.\r
+  @param[out] FailedCpuList           If NULL, this parameter is ignored. Otherwise, \r
+                                      if all APs finish successfully, then its \r
+                                      content is set to NULL. If not all APs \r
+                                      finish before timeout expires, then its \r
+                                      content is set to address of the buffer \r
+                                      holding handle numbers of the failed APs. \r
+                                      The buffer is allocated by MP Service Protocol, \r
+                                      and it's the caller's responsibility to \r
+                                      free the buffer with FreePool() service.\r
+                                      In blocking mode, it is ready for consumption \r
+                                      when the call returns. In non-blocking mode, \r
+                                      it is ready when WaitEvent is signaled.  The \r
+                                      list of failed CPU is terminated by \r
+                                      END_OF_CPU_LIST.\r
+\r
+  @retval EFI_SUCCESS             In blocking mode, all APs have finished before \r
+                                  the timeout expired.\r
+  @retval EFI_SUCCESS             In non-blocking mode, function has been dispatched \r
+                                  to all enabled APs.\r
+  @retval EFI_UNSUPPORTED         A non-blocking mode request was made after the \r
+                                  UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was \r
+                                  signaled.\r
+  @retval EFI_DEVICE_ERROR        Caller processor is AP.\r
+  @retval EFI_NOT_STARTED         No enabled APs exist in the system.\r
+  @retval EFI_NOT_READY           Any enabled APs are busy.\r
+  @retval EFI_TIMEOUT             In blocking mode, the timeout expired before \r
+                                  all enabled APs have finished.\r
+  @retval EFI_INVALID_PARAMETER   Procedure is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMpServicesStartupAllAps (\r
+  IN  EFI_MP_SERVICES_PROTOCOL  *This,\r
+  IN  EFI_AP_PROCEDURE          Procedure,\r
+  IN  BOOLEAN                   SingleThread,\r
+  IN  EFI_EVENT                 WaitEvent               OPTIONAL,\r
+  IN  UINTN                     TimeoutInMicroseconds,\r
+  IN  VOID                      *ProcedureArgument      OPTIONAL,\r
+  OUT UINTN                     **FailedCpuList         OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  PROCESSOR_DATA_BLOCK  *ProcessorData;\r
+  UINTN                 ListIndex;\r
+  UINTN                 Number;\r
+  UINTN                 NextNumber;\r
+  PROCESSOR_STATE       APInitialState;\r
+  PROCESSOR_STATE       ProcessorState;\r
+  INTN                  Timeout;\r
+\r
+\r
+  if (!IsBSP ()) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  \r
+  if (gMPSystem.NumberOfProcessors == 1) {\r
+    return EFI_NOT_STARTED;\r
+  }\r
+\r
+  if (Procedure == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  if ((WaitEvent != NULL)  && gReadToBoot) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  \r
+  \r
+  if (FailedCpuList != NULL) {\r
+    gMPSystem.FailedList = AllocatePool ((gMPSystem.NumberOfProcessors + 1) * sizeof (UINTN));\r
+    if (gMPSystem.FailedList == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    SetMemN (gMPSystem.FailedList, (gMPSystem.NumberOfProcessors + 1) * sizeof (UINTN), END_OF_CPU_LIST);\r
+    gMPSystem.FailedListIndex = 0;\r
+    *FailedCpuList = gMPSystem.FailedList;\r
+  }\r
+\r
+  Timeout = TimeoutInMicroseconds;\r
+\r
+  ListIndex                   = 0;\r
+  ProcessorData               = NULL;\r
+\r
+  gMPSystem.FinishCount   = 0;\r
+  gMPSystem.StartCount    = 0;\r
+  gMPSystem.SingleThread  = SingleThread;\r
+  APInitialState          = CPU_STATE_READY;\r
+\r
+  for (Number = 0; Number < gMPSystem.NumberOfProcessors; Number++) {\r
+    ProcessorData = &gMPSystem.ProcessorData[Number];\r
+\r
+    if ((ProcessorData->Info.StatusFlag & PROCESSOR_AS_BSP_BIT) == PROCESSOR_AS_BSP_BIT) {\r
+      // Skip BSP\r
+      continue;\r
+    }\r
+\r
+    if ((ProcessorData->Info.StatusFlag & PROCESSOR_ENABLED_BIT) == 0) {\r
+      // Skip Disabled processors\r
+      gMPSystem.FailedList[gMPSystem.FailedListIndex++] = Number;\r
+      continue;\r
+    }\r
+\r
+    //\r
+    // Get APs prepared, and put failing APs into FailedCpuList\r
+    // if "SingleThread", only 1 AP will put to ready state, other AP will be put to ready\r
+    // state 1 by 1, until the previous 1 finished its task\r
+    // if not "SingleThread", all APs are put to ready state from the beginning\r
+    //\r
+    if (ProcessorData->State == CPU_STATE_IDLE) {\r
+      gMPSystem.StartCount++;\r
+\r
+      gThread->MutexLock (&ProcessorData->StateLock);\r
+      ProcessorData->State = APInitialState;\r
+      gThread->MutexUnlock (&ProcessorData->StateLock);\r
+\r
+      if (SingleThread) {\r
+        APInitialState = CPU_STATE_BLOCKED;\r
+      }\r
+    } else {\r
+      return EFI_NOT_READY;\r
+    }\r
+  }\r
+  \r
+  if (WaitEvent != NULL) {\r
+    for (Number = 0; Number < gMPSystem.NumberOfProcessors; Number++) {\r
+      ProcessorData = &gMPSystem.ProcessorData[Number];  \r
+      if ((ProcessorData->Info.StatusFlag & PROCESSOR_AS_BSP_BIT) == PROCESSOR_AS_BSP_BIT) {\r
+       // Skip BSP\r
+        continue;\r
+      }\r
+\r
+      if ((ProcessorData->Info.StatusFlag & PROCESSOR_ENABLED_BIT) == 0) {\r
+        // Skip Disabled processors\r
+        continue;\r
+      }\r
+    \r
+      SetApProcedure (ProcessorData, Procedure, ProcedureArgument);\r
+    }\r
+\r
+    //\r
+    // Save data into private data structure, and create timer to poll AP state before exiting\r
+    //\r
+    gMPSystem.Procedure         = Procedure;\r
+    gMPSystem.ProcedureArgument = ProcedureArgument;\r
+    gMPSystem.WaitEvent         = WaitEvent;\r
+    gMPSystem.Timeout           = TimeoutInMicroseconds;\r
+    gMPSystem.TimeoutActive     = (BOOLEAN)(TimeoutInMicroseconds != 0);\r
+    Status = gBS->SetTimer (\r
+                    gMPSystem.CheckAllAPsEvent,\r
+                    TimerPeriodic,\r
+                    gPollInterval\r
+                    );\r
+    return Status;\r
+\r
+  }\r
+\r
+  while (TRUE) {\r
+    for (Number = 0; Number < gMPSystem.NumberOfProcessors; Number++) {\r
+      ProcessorData = &gMPSystem.ProcessorData[Number];  \r
+      if ((ProcessorData->Info.StatusFlag & PROCESSOR_AS_BSP_BIT) == PROCESSOR_AS_BSP_BIT) {\r
+       // Skip BSP\r
+        continue;\r
+      }\r
+\r
+      if ((ProcessorData->Info.StatusFlag & PROCESSOR_ENABLED_BIT) == 0) {\r
+        // Skip Disabled processors\r
+        continue;\r
+      }\r
+\r
+      gThread->MutexLock (ProcessorData->StateLock);\r
+      ProcessorState = ProcessorData->State;\r
+      gThread->MutexUnlock (ProcessorData->StateLock);\r
+\r
+      switch (ProcessorState) {\r
+      case CPU_STATE_READY:\r
+        SetApProcedure (ProcessorData, Procedure, ProcedureArgument);\r
+        break;\r
+\r
+      case CPU_STATE_FINISHED:\r
+        gMPSystem.FinishCount++;\r
+        if (SingleThread) {\r
+          Status = GetNextBlockedNumber (&NextNumber);\r
+          if (!EFI_ERROR (Status)) {\r
+            gMPSystem.ProcessorData[NextNumber].State = CPU_STATE_READY;\r
+          }\r
+        }\r
+\r
+        ProcessorData->State = CPU_STATE_IDLE;\r
+        break;\r
+\r
+      default:\r
+        break;\r
+      }\r
+    }\r
+\r
+    if (gMPSystem.FinishCount == gMPSystem.StartCount) {\r
+      Status = EFI_SUCCESS;\r
+      goto Done;\r
+    }\r
+\r
+    if ((TimeoutInMicroseconds != 0) && (Timeout < 0)) {\r
+      Status = EFI_TIMEOUT;\r
+      goto Done;\r
+    }\r
+\r
+    gBS->Stall (gPollInterval);\r
+    Timeout -= gPollInterval;\r
+  }\r
+\r
+Done:\r
+  if (FailedCpuList != NULL) {\r
+    if (gMPSystem.FailedListIndex == 0) {\r
+      FreePool (*FailedCpuList);\r
+      *FailedCpuList = NULL;\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  This service lets the caller get one enabled AP to execute a caller-provided \r
+  function. The caller can request the BSP to either wait for the completion \r
+  of the AP or just proceed with the next task by using the EFI event mechanism. \r
+  See EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() for more details on non-blocking \r
+  execution support.  This service may only be called from the BSP.\r
+\r
+  This function is used to dispatch one enabled AP to the function specified by \r
+  Procedure passing in the argument specified by ProcedureArgument.  If WaitEvent \r
+  is NULL, execution is in blocking mode. The BSP waits until the AP finishes or \r
+  TimeoutInMicroSecondss expires. Otherwise, execution is in non-blocking mode. \r
+  BSP proceeds to the next task without waiting for the AP. If a non-blocking mode \r
+  is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled, \r
+  then EFI_UNSUPPORTED must be returned.\r
+  \r
+  If the timeout specified by TimeoutInMicroseconds expires before the AP returns \r
+  from Procedure, then execution of Procedure by the AP is terminated. The AP is \r
+  available for subsequent calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() and \r
+  EFI_MP_SERVICES_PROTOCOL.StartupThisAP().\r
+\r
+  @param[in]  This                    A pointer to the EFI_MP_SERVICES_PROTOCOL\r
+                                      instance.\r
+  @param[in]  Procedure               A pointer to the function to be run on \r
+                                      enabled APs of the system. See type\r
+                                      EFI_AP_PROCEDURE.\r
+  @param[in]  ProcessorNumber         The handle number of the AP. The range is \r
+                                      from 0 to the total number of logical\r
+                                      processors minus 1. The total number of \r
+                                      logical processors can be retrieved by\r
+                                      EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().\r
+  @param[in]  WaitEvent               The event created by the caller with CreateEvent()\r
+                                      service.  If it is NULL, then execute in \r
+                                      blocking mode. BSP waits until all APs finish \r
+                                      or TimeoutInMicroseconds expires.  If it's \r
+                                      not NULL, then execute in non-blocking mode. \r
+                                      BSP requests the function specified by \r
+                                      Procedure to be started on all the enabled \r
+                                      APs, and go on executing immediately. If \r
+                                      all return from Procedure or TimeoutInMicroseconds\r
+                                      expires, this event is signaled. The BSP \r
+                                      can use the CheckEvent() or WaitForEvent() \r
+                                      services to check the state of event.  Type \r
+                                      EFI_EVENT is defined in CreateEvent() in \r
+                                      the Unified Extensible Firmware Interface \r
+                                      Specification.  \r
+  @param[in]  TimeoutInMicrosecsond   Indicates the time limit in microseconds for \r
+                                      APs to return from Procedure, either for \r
+                                      blocking or non-blocking mode. Zero means \r
+                                      infinity.  If the timeout expires before \r
+                                      all APs return from Procedure, then Procedure\r
+                                      on the failed APs is terminated. All enabled \r
+                                      APs are available for next function assigned \r
+                                      by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() \r
+                                      or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().\r
+                                      If the timeout expires in blocking mode, \r
+                                      BSP returns EFI_TIMEOUT.  If the timeout \r
+                                      expires in non-blocking mode, WaitEvent \r
+                                      is signaled with SignalEvent().\r
+  @param[in]  ProcedureArgument       The parameter passed into Procedure for \r
+                                      all APs.\r
+  @param[out] Finished                If NULL, this parameter is ignored.  In \r
+                                      blocking mode, this parameter is ignored.\r
+                                      In non-blocking mode, if AP returns from \r
+                                      Procedure before the timeout expires, its\r
+                                      content is set to TRUE. Otherwise, the \r
+                                      value is set to FALSE. The caller can\r
+                                      determine if the AP returned from Procedure \r
+                                      by evaluating this value.\r
+\r
+  @retval EFI_SUCCESS             In blocking mode, specified AP finished before \r
+                                  the timeout expires.\r
+  @retval EFI_SUCCESS             In non-blocking mode, the function has been \r
+                                  dispatched to specified AP.\r
+  @retval EFI_UNSUPPORTED         A non-blocking mode request was made after the \r
+                                  UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was \r
+                                  signaled.\r
+  @retval EFI_DEVICE_ERROR        The calling processor is an AP.\r
+  @retval EFI_TIMEOUT             In blocking mode, the timeout expired before \r
+                                  the specified AP has finished.\r
+  @retval EFI_NOT_READY           The specified AP is busy.\r
+  @retval EFI_NOT_FOUND           The processor with the handle specified by \r
+                                  ProcessorNumber does not exist.\r
+  @retval EFI_INVALID_PARAMETER   ProcessorNumber specifies the BSP or disabled AP.\r
+  @retval EFI_INVALID_PARAMETER   Procedure is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMpServicesStartupThisAP (\r
+  IN  EFI_MP_SERVICES_PROTOCOL  *This,\r
+  IN  EFI_AP_PROCEDURE          Procedure,\r
+  IN  UINTN                     ProcessorNumber,\r
+  IN  EFI_EVENT                 WaitEvent               OPTIONAL,\r
+  IN  UINTN                     TimeoutInMicroseconds,\r
+  IN  VOID                      *ProcedureArgument      OPTIONAL,\r
+  OUT BOOLEAN                   *Finished               OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+  INTN            Timeout;\r
+  \r
+  if (!IsBSP ()) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  \r
+  if (Procedure == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+    \r
+  if (ProcessorNumber >= gMPSystem.NumberOfProcessors) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  \r
+  if ((gMPSystem.ProcessorData[ProcessorNumber].Info.StatusFlag & PROCESSOR_AS_BSP_BIT) != 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (gMPSystem.ProcessorData[ProcessorNumber].State != CPU_STATE_IDLE) {\r
+    return EFI_NOT_READY;\r
+  }\r
+\r
+  if ((WaitEvent != NULL)  && gReadToBoot) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Timeout = TimeoutInMicroseconds;\r
+\r
+  gMPSystem.StartCount   = 1;\r
+  gMPSystem.FinishCount  = 0;\r
+\r
+  SetApProcedure (&gMPSystem.ProcessorData[ProcessorNumber], Procedure, ProcedureArgument);\r
+\r
+  if (WaitEvent != NULL) {\r
+      // Non Blocking\r
+      gMPSystem.WaitEvent = WaitEvent;\r
+      Status = gBS->SetTimer (\r
+                      gMPSystem.ProcessorData[ProcessorNumber].CheckThisAPEvent,\r
+                      TimerPeriodic,\r
+                      gPollInterval\r
+                      );\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  // Blocking\r
+  while (TRUE) {\r
+    gThread->MutexLock (&gMPSystem.ProcessorData[ProcessorNumber].StateLock);\r
+    if (gMPSystem.ProcessorData[ProcessorNumber].State == CPU_STATE_FINISHED) {\r
+      gMPSystem.ProcessorData[ProcessorNumber].State = CPU_STATE_IDLE;\r
+      gThread->MutexUnlock (&gMPSystem.ProcessorData[ProcessorNumber].StateLock);\r
+      break;\r
+    }\r
+\r
+    gThread->MutexUnlock (&gMPSystem.ProcessorData[ProcessorNumber].StateLock);\r
+\r
+    if ((TimeoutInMicroseconds != 0) && (Timeout < 0)) {\r
+      return EFI_TIMEOUT;\r
+    }\r
+\r
+    gBS->Stall (gPollInterval);\r
+    Timeout -= gPollInterval;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+\r
+}\r
+\r
+\r
+/**\r
+  This service switches the requested AP to be the BSP from that point onward. \r
+  This service changes the BSP for all purposes.   This call can only be performed \r
+  by the current BSP.\r
+\r
+  This service switches the requested AP to be the BSP from that point onward. \r
+  This service changes the BSP for all purposes. The new BSP can take over the \r
+  execution of the old BSP and continue seamlessly from where the old one left \r
+  off. This service may not be supported after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT \r
+  is signaled.\r
+\r
+  If the BSP cannot be switched prior to the return from this service, then \r
+  EFI_UNSUPPORTED must be returned.\r
+\r
+  @param[in] This              A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r
+  @param[in] ProcessorNumber   The handle number of AP that is to become the new \r
+                               BSP. The range is from 0 to the total number of \r
+                               logical processors minus 1. The total number of \r
+                               logical processors can be retrieved by\r
+                               EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().\r
+  @param[in] EnableOldBSP      If TRUE, then the old BSP will be listed as an \r
+                               enabled AP. Otherwise, it will be disabled.\r
+\r
+  @retval EFI_SUCCESS             BSP successfully switched.\r
+  @retval EFI_UNSUPPORTED         Switching the BSP cannot be completed prior to \r
+                                  this service returning.\r
+  @retval EFI_UNSUPPORTED         Switching the BSP is not supported.\r
+  @retval EFI_SUCCESS             The calling processor is an AP.\r
+  @retval EFI_NOT_FOUND           The processor with the handle specified by\r
+                                  ProcessorNumber does not exist.\r
+  @retval EFI_INVALID_PARAMETER   ProcessorNumber specifies the current BSP or \r
+                                  a disabled AP.\r
+  @retval EFI_NOT_READY           The specified AP is busy.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMpServicesSwitchBSP (\r
+  IN EFI_MP_SERVICES_PROTOCOL  *This,\r
+  IN  UINTN                    ProcessorNumber,\r
+  IN  BOOLEAN                  EnableOldBSP\r
+  )\r
+{\r
+  UINTN   Index;\r
+  \r
+  if (!IsBSP ()) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  \r
+  if (ProcessorNumber >= gMPSystem.NumberOfProcessors) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  \r
+  if ((gMPSystem.ProcessorData[ProcessorNumber].Info.StatusFlag & PROCESSOR_ENABLED_BIT) == 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if ((gMPSystem.ProcessorData[ProcessorNumber].Info.StatusFlag & PROCESSOR_AS_BSP_BIT) != 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  for (Index = 0; Index < gMPSystem.NumberOfProcessors; Index++) {\r
+    if ((gMPSystem.ProcessorData[Index].Info.StatusFlag & PROCESSOR_AS_BSP_BIT) != 0) {\r
+      break;\r
+    }\r
+  }\r
+  ASSERT (Index != gMPSystem.NumberOfProcessors);\r
+  \r
+  if (gMPSystem.ProcessorData[ProcessorNumber].State != CPU_STATE_IDLE) {\r
+    return EFI_NOT_READY;\r
+  }\r
+  \r
+  // Skip for now as we need switch a bunch of stack stuff around and it's complex\r
+  // May not be worth it?\r
+  return EFI_NOT_READY;\r
+}\r
+\r
+\r
+/**\r
+  This service lets the caller enable or disable an AP from this point onward.  \r
+  This service may only be called from the BSP.\r
+\r
+  This service allows the caller enable or disable an AP from this point onward. \r
+  The caller can optionally specify the health status of the AP by Health. If \r
+  an AP is being disabled, then the state of the disabled AP is implementation \r
+  dependent. If an AP is enabled, then the implementation must guarantee that a \r
+  complete initialization sequence is performed on the AP, so the AP is in a state \r
+  that is compatible with an MP operating system. This service may not be supported \r
+  after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled.\r
+\r
+  If the enable or disable AP operation cannot be completed prior to the return \r
+  from this service, then EFI_UNSUPPORTED must be returned.\r
+\r
+  @param[in] This              A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r
+  @param[in] ProcessorNumber   The handle number of AP that is to become the new \r
+                               BSP. The range is from 0 to the total number of \r
+                               logical processors minus 1. The total number of \r
+                               logical processors can be retrieved by\r
+                               EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().\r
+  @param[in] EnableAP          Specifies the new state for the processor for \r
+                               enabled, FALSE for disabled.\r
+  @param[in] HealthFlag        If not NULL, a pointer to a value that specifies \r
+                               the new health status of the AP. This flag \r
+                               corresponds to StatusFlag defined in \r
+                               EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only \r
+                               the PROCESSOR_HEALTH_STATUS_BIT is used. All other \r
+                               bits are ignored.  If it is NULL, this parameter \r
+                               is ignored.\r
+\r
+  @retval EFI_SUCCESS             The specified AP was enabled or disabled successfully.\r
+  @retval EFI_UNSUPPORTED         Enabling or disabling an AP cannot be completed \r
+                                  prior to this service returning.\r
+  @retval EFI_UNSUPPORTED         Enabling or disabling an AP is not supported.\r
+  @retval EFI_DEVICE_ERROR        The calling processor is an AP.\r
+  @retval EFI_NOT_FOUND           Processor with the handle specified by ProcessorNumber\r
+                                  does not exist.\r
+  @retval EFI_INVALID_PARAMETER   ProcessorNumber specifies the BSP.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMpServicesEnableDisableAP (\r
+  IN  EFI_MP_SERVICES_PROTOCOL  *This,\r
+  IN  UINTN                     ProcessorNumber,\r
+  IN  BOOLEAN                   EnableAP,\r
+  IN  UINT32                    *HealthFlag OPTIONAL\r
+  )\r
+{\r
+  if (!IsBSP ()) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  \r
+  if (ProcessorNumber >= gMPSystem.NumberOfProcessors) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  \r
+  if ((gMPSystem.ProcessorData[ProcessorNumber].Info.StatusFlag & PROCESSOR_AS_BSP_BIT) != 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }  \r
+\r
+  if (gMPSystem.ProcessorData[ProcessorNumber].State != CPU_STATE_IDLE) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  gThread->MutexLock (&gMPSystem.ProcessorData[ProcessorNumber].StateLock);\r
+  \r
+  if (EnableAP) {\r
+    if ((gMPSystem.ProcessorData[ProcessorNumber].Info.StatusFlag & PROCESSOR_ENABLED_BIT) == 0 ) {\r
+      gMPSystem.NumberOfEnabledProcessors++;\r
+    }\r
+    gMPSystem.ProcessorData[ProcessorNumber].Info.StatusFlag |= PROCESSOR_ENABLED_BIT;\r
+  } else {\r
+    if ((gMPSystem.ProcessorData[ProcessorNumber].Info.StatusFlag & PROCESSOR_ENABLED_BIT) == PROCESSOR_ENABLED_BIT ) {\r
+      gMPSystem.NumberOfEnabledProcessors--;\r
+    }\r
+    gMPSystem.ProcessorData[ProcessorNumber].Info.StatusFlag &= ~PROCESSOR_ENABLED_BIT;\r
+  }\r
+  \r
+  if (HealthFlag != NULL) {\r
+    gMPSystem.ProcessorData[ProcessorNumber].Info.StatusFlag &= ~PROCESSOR_HEALTH_STATUS_BIT;\r
+    gMPSystem.ProcessorData[ProcessorNumber].Info.StatusFlag |= (*HealthFlag & PROCESSOR_HEALTH_STATUS_BIT);\r
+  }\r
+  \r
+  gThread->MutexUnlock (&gMPSystem.ProcessorData[ProcessorNumber].StateLock);\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  This return the handle number for the calling processor.  This service may be \r
+  called from the BSP and APs.\r
+\r
+  This service returns the processor handle number for the calling processor. \r
+  The returned value is in the range from 0 to the total number of logical \r
+  processors minus 1. The total number of logical processors can be retrieved \r
+  with EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors(). This service may be \r
+  called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER \r
+  is returned. Otherwise, the current processors handle number is returned in \r
+  ProcessorNumber, and EFI_SUCCESS is returned.\r
+\r
+  @param[in] This              A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r
+  @param[in] ProcessorNumber   The handle number of AP that is to become the new \r
+                               BSP. The range is from 0 to the total number of \r
+                               logical processors minus 1. The total number of \r
+                               logical processors can be retrieved by\r
+                               EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().\r
+\r
+  @retval EFI_SUCCESS             The current processor handle number was returned \r
+                                  in ProcessorNumber.\r
+  @retval EFI_INVALID_PARAMETER   ProcessorNumber is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMpServicesWhoAmI (\r
+  IN EFI_MP_SERVICES_PROTOCOL  *This,\r
+  OUT UINTN                    *ProcessorNumber\r
+  )\r
+{\r
+  UINTN   Index;\r
+  UINT64  ProcessorId;\r
+  \r
+  if (ProcessorNumber == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  ProcessorId = gThread->Self ();\r
+  for (Index = 0; Index < gMPSystem.NumberOfProcessors; Index++) {\r
+    if (gMPSystem.ProcessorData[Index].Info.ProcessorId == ProcessorId) {\r
+      break;\r
+    }\r
+  }\r
+\r
+  *ProcessorNumber = Index;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+\r
+EFI_MP_SERVICES_PROTOCOL  mMpSercicesTemplate = {\r
+  CpuMpServicesGetNumberOfProcessors,\r
+  CpuMpServicesGetProcessorInfo,\r
+  CpuMpServicesStartupAllAps,\r
+  CpuMpServicesStartupThisAP,\r
+  CpuMpServicesSwitchBSP,\r
+  CpuMpServicesEnableDisableAP,\r
+  CpuMpServicesWhoAmI\r
+};\r
+\r
+\r
+\r
+/*++\r
+  If timeout occurs in StartupAllAps(), a timer is set, which invokes this\r
+  procedure periodically to check whether all APs have finished.\r
+\r
+\r
+--*/\r
+VOID\r
+EFIAPI\r
+CpuCheckAllAPsStatus (\r
+  IN  EFI_EVENT   Event,\r
+  IN  VOID        *Context\r
+  )\r
+{\r
+  UINTN                 ProcessorNumber;\r
+  UINTN                 NextNumber;\r
+  PROCESSOR_DATA_BLOCK  *ProcessorData;\r
+  PROCESSOR_DATA_BLOCK  *NextData;\r
+  EFI_STATUS            Status;\r
+  PROCESSOR_STATE       ProcessorState;\r
+  UINTN                 Cpu;\r
+  BOOLEAN               Found;\r
+\r
+  if (gMPSystem.TimeoutActive) {\r
+    gMPSystem.Timeout -= gPollInterval;\r
+  }\r
+  \r
+  ProcessorData = (PROCESSOR_DATA_BLOCK *) Context;\r
+\r
+  for (ProcessorNumber = 0; ProcessorNumber < gMPSystem.NumberOfProcessors; ProcessorNumber++) {\r
+    if ((ProcessorData[ProcessorNumber].Info.StatusFlag & PROCESSOR_AS_BSP_BIT) == PROCESSOR_AS_BSP_BIT) {\r
+     // Skip BSP\r
+      continue;\r
+    }\r
+\r
+    if ((ProcessorData->Info.StatusFlag & PROCESSOR_ENABLED_BIT) == 0) {\r
+      // Skip Disabled processors\r
+      continue;\r
+    }\r
+\r
+    // This is an Interrupt Service routine.\r
+    // This can grab a lock that is held in a non-interrupt\r
+    // context. Meaning deadlock. Which is a bad thing.\r
+    // So, try lock it. If we can get it, cool, do our thing.\r
+    // otherwise, just dump out & try again on the next iteration.\r
+    Status = gThread->MutexTryLock (gMPSystem.ProcessorData[ProcessorNumber].StateLock);\r
+    if (EFI_ERROR(Status)) {\r
+      return;\r
+    }\r
+    ProcessorState = gMPSystem.ProcessorData[ProcessorNumber].State;\r
+    gThread->MutexUnlock (gMPSystem.ProcessorData[ProcessorNumber].StateLock);\r
+\r
+    switch (ProcessorState) {\r
+    case CPU_STATE_READY:\r
+      SetApProcedure (ProcessorData, gMPSystem.Procedure, gMPSystem.ProcedureArgument);\r
+      break;\r
+\r
+    case CPU_STATE_FINISHED:\r
+      if (gMPSystem.SingleThread) {\r
+        Status = GetNextBlockedNumber (&NextNumber);\r
+        if (!EFI_ERROR (Status)) {\r
+          NextData = &gMPSystem.ProcessorData[NextNumber];\r
+\r
+          gThread->MutexLock (&NextData->ProcedureLock);\r
+          NextData->State = CPU_STATE_READY;\r
+          gThread->MutexUnlock (&NextData->ProcedureLock);\r
+\r
+          SetApProcedure (NextData, gMPSystem.Procedure, gMPSystem.ProcedureArgument);\r
+        }\r
+      }\r
+\r
+      gMPSystem.ProcessorData[ProcessorNumber].State = CPU_STATE_IDLE;\r
+      gMPSystem.FinishCount++;\r
+      break;\r
+\r
+    default:\r
+      break;\r
+    }\r
+  }\r
+  \r
+  if (gMPSystem.TimeoutActive && gMPSystem.Timeout < 0) {\r
+    //\r
+    // Timeout\r
+    //\r
+    if (gMPSystem.FailedList != NULL) {\r
+      for (ProcessorNumber = 0; ProcessorNumber < gMPSystem.NumberOfProcessors; ProcessorNumber++) {\r
+        if ((ProcessorData[ProcessorNumber].Info.StatusFlag & PROCESSOR_AS_BSP_BIT) == PROCESSOR_AS_BSP_BIT) {\r
+         // Skip BSP\r
+          continue;\r
+        }\r
+\r
+        if ((ProcessorData->Info.StatusFlag & PROCESSOR_ENABLED_BIT) == 0) {\r
+          // Skip Disabled processors\r
+          continue;\r
+        }\r
+    \r
+        // Mark the \r
+        Status = gThread->MutexTryLock (gMPSystem.ProcessorData[ProcessorNumber].StateLock);\r
+        if (EFI_ERROR(Status)) {\r
+          return;\r
+        }\r
+        ProcessorState = gMPSystem.ProcessorData[ProcessorNumber].State;\r
+        gThread->MutexUnlock (gMPSystem.ProcessorData[ProcessorNumber].StateLock);\r
+    \r
+        if (ProcessorState != CPU_STATE_IDLE) {\r
+          // If we are retrying make sure we don't double count\r
+          for (Cpu = 0, Found = FALSE; Cpu < gMPSystem.NumberOfProcessors; Cpu++) {\r
+            if (gMPSystem.FailedList[Cpu] == END_OF_CPU_LIST) {\r
+              break;\r
+            }\r
+            if (gMPSystem.FailedList[ProcessorNumber] == Cpu) {\r
+              Found = TRUE;\r
+              break;\r
+            }\r
+          }\r
+          if (!Found) {\r
+            gMPSystem.FailedList[gMPSystem.FailedListIndex++] = Cpu;\r
+          }\r
+        }\r
+      }\r
+    }\r
+    // Force terminal exit\r
+    gMPSystem.FinishCount = gMPSystem.StartCount;\r
+  }\r
+\r
+  if (gMPSystem.FinishCount != gMPSystem.StartCount) {\r
+    return;\r
+  }\r
+  \r
+  gBS->SetTimer (\r
+         gMPSystem.CheckAllAPsEvent,\r
+         TimerCancel,\r
+         0\r
+         );\r
+\r
+  if (gMPSystem.FailedListIndex == 0) {\r
+    if (gMPSystem.FailedList != NULL) {\r
+      FreePool (gMPSystem.FailedList);\r
+      gMPSystem.FailedList = NULL;\r
+    }\r
+  }\r
+\r
+  Status = gBS->SignalEvent (gMPSystem.WaitEvent);\r
+\r
+  return ;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+CpuCheckThisAPStatus (\r
+  IN  EFI_EVENT                           Event,\r
+  IN  VOID                                *Context\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  PROCESSOR_DATA_BLOCK  *ProcessorData;\r
+  PROCESSOR_STATE       ProcessorState;\r
+\r
+  ProcessorData = (PROCESSOR_DATA_BLOCK *) Context;\r
+\r
+  //\r
+  // This is an Interrupt Service routine.\r
+  // that can grab a lock that is held in a non-interrupt\r
+  // context. Meaning deadlock. Which is a badddd thing.\r
+  // So, try lock it. If we can get it, cool, do our thing.\r
+  // otherwise, just dump out & try again on the next iteration.\r
+  //\r
+  Status = gThread->MutexTryLock (ProcessorData->StateLock);\r
+  if (EFI_ERROR(Status)) {\r
+    return;\r
+  }\r
+  ProcessorState = ProcessorData->State;\r
+  gThread->MutexUnlock (ProcessorData->StateLock);\r
+\r
+  if (ProcessorState == CPU_STATE_FINISHED) {\r
+    Status = gBS->SetTimer (ProcessorData->CheckThisAPEvent, TimerCancel, 0);\r
+    ASSERT_EFI_ERROR (Status);\r
+    \r
+    Status = gBS->SignalEvent (gMPSystem.WaitEvent);\r
+    ASSERT_EFI_ERROR (Status);\r
+    \r
+    gThread->MutexLock (ProcessorData->StateLock);\r
+    ProcessorData->State = CPU_STATE_IDLE;\r
+    gThread->MutexUnlock (ProcessorData->StateLock);\r
+  }\r
+\r
+  return ;\r
+}\r
+\r
+\r
+/*++\r
+  This function is called by all processors (both BSP and AP) once and collects MP related data\r
+\r
+  MPSystemData  - Pointer to the data structure containing MP related data\r
+  BSP           - TRUE if the CPU is BSP\r
+\r
+  EFI_SUCCESS   - Data for the processor collected and filled in\r
+\r
+--*/\r
+EFI_STATUS\r
+FillInProcessorInformation (\r
+  IN     BOOLEAN              BSP,\r
+  IN     UINTN                ProcessorNumber\r
+  )\r
+{\r
+  PROCESSOR_DATA_BLOCK            *ProcessorData;\r
+\r
+  ProcessorData = &gMPSystem.ProcessorData[ProcessorNumber];\r
+  \r
+  gMPSystem.ProcessorData[ProcessorNumber].Info.ProcessorId  = gThread->Self ();\r
+  gMPSystem.ProcessorData[ProcessorNumber].Info.StatusFlag   = PROCESSOR_ENABLED_BIT | PROCESSOR_HEALTH_STATUS_BIT;\r
+  if (BSP) {\r
+    gMPSystem.ProcessorData[ProcessorNumber].Info.StatusFlag |= PROCESSOR_AS_BSP_BIT;\r
+  }\r
+  \r
+  gMPSystem.ProcessorData[ProcessorNumber].Info.Location.Package = ProcessorNumber;\r
+  gMPSystem.ProcessorData[ProcessorNumber].Info.Location.Core    = 0;\r
+  gMPSystem.ProcessorData[ProcessorNumber].Info.Location.Thread  = 0;\r
+  gMPSystem.ProcessorData[ProcessorNumber].State = BSP ? CPU_STATE_BUSY : CPU_STATE_IDLE;\r
+  \r
+  gMPSystem.ProcessorData[ProcessorNumber].Procedure        = NULL;\r
+  gMPSystem.ProcessorData[ProcessorNumber].Parameter        = NULL;\r
+  gMPSystem.ProcessorData[ProcessorNumber].StateLock        = gThread->MutexInit ();\r
+  gMPSystem.ProcessorData[ProcessorNumber].ProcedureLock    = gThread->MutexInit ();\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+VOID *\r
+EFIAPI\r
+CpuDriverApIdolLoop (\r
+  VOID  *Context\r
+  )\r
+{\r
+  EFI_AP_PROCEDURE      Procedure;\r
+  VOID                  *Parameter;\r
+  UINTN                 ProcessorNumber;\r
+  PROCESSOR_DATA_BLOCK  *ProcessorData;\r
+  \r
+  ProcessorNumber = (UINTN)Context;\r
+  ProcessorData = &gMPSystem.ProcessorData[ProcessorNumber];\r
+    \r
+  ProcessorData->Info.ProcessorId = gThread->Self ();\r
\r
+  while (TRUE) {\r
+    //\r
+    // Make a local copy on the stack to be extra safe\r
+    //\r
+    gThread->MutexLock (ProcessorData->ProcedureLock);\r
+    Procedure = ProcessorData->Procedure;\r
+    Parameter = ProcessorData->Parameter;\r
+    gThread->MutexUnlock (ProcessorData->ProcedureLock);\r
+  \r
+    if (Procedure != NULL) {\r
+      gThread->MutexLock (ProcessorData->StateLock);\r
+      ProcessorData->State = CPU_STATE_BUSY;\r
+      gThread->MutexUnlock (ProcessorData->StateLock);\r
+  \r
+      Procedure (Parameter);\r
+    \r
+      gThread->MutexLock (ProcessorData->ProcedureLock);\r
+      ProcessorData->Procedure = NULL;\r
+      gThread->MutexUnlock (ProcessorData->ProcedureLock);\r
+  \r
+      gThread->MutexLock (ProcessorData->StateLock);\r
+      ProcessorData->State = CPU_STATE_FINISHED;\r
+      gThread->MutexUnlock (ProcessorData->StateLock);  \r
+    }\r
+    \r
+    // Poll 5 times a seconds, 200ms\r
+    // Don't want to burn too many system resources doing nothing.\r
+    gEmuThunk->Sleep (200 * 1000);\r
+  }\r
+  \r
+  return 0;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+InitializeMpSystemData (\r
+  IN   UINTN     NumberOfProcessors\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  UINTN                   Index;\r
+\r
+  \r
+  //\r
+  // Clear the data structure area first.\r
+  //\r
+  ZeroMem (&gMPSystem, sizeof (MP_SYSTEM_DATA));\r
+\r
+  //\r
+  // First BSP fills and inits all known values, including it's own records.\r
+  //\r
+  gMPSystem.NumberOfProcessors         = NumberOfProcessors;\r
+  gMPSystem.NumberOfEnabledProcessors  = NumberOfProcessors;\r
+  \r
+  gMPSystem.ProcessorData = AllocateZeroPool (gMPSystem.NumberOfProcessors * sizeof (PROCESSOR_DATA_BLOCK));\r
+  ASSERT (gMPSystem.ProcessorData != NULL);\r
+\r
+  FillInProcessorInformation (TRUE, 0);\r
+  \r
+  Status = gBS->CreateEvent (\r
+                  EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  CpuCheckAllAPsStatus,\r
+                  NULL,\r
+                  &gMPSystem.CheckAllAPsEvent\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+\r
+  for (Index = 0; Index < gMPSystem.NumberOfProcessors; Index++) {\r
+    if ((gMPSystem.ProcessorData[Index].Info.StatusFlag & PROCESSOR_AS_BSP_BIT) == PROCESSOR_AS_BSP_BIT) {\r
+     // Skip BSP\r
+      continue;\r
+    }\r
+    \r
+    FillInProcessorInformation (FALSE, Index);\r
+    \r
+    Status = gThread->CreateThread (\r
+                        (VOID *)&gMPSystem.ProcessorData[Index].Info.ProcessorId, \r
+                        NULL,\r
+                        CpuDriverApIdolLoop,\r
+                        (VOID *)Index\r
+                        );\r
+                      \r
+              \r
+    Status = gBS->CreateEvent (\r
+                         EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
+                         TPL_CALLBACK,\r
+                         CpuCheckThisAPStatus,\r
+                         (VOID *)  &gMPSystem.ProcessorData[Index],\r
+                         &gMPSystem.ProcessorData[Index].CheckThisAPEvent\r
+                         );\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Invoke a notification event\r
+\r
+  @param  Event                 Event whose notification function is being invoked.\r
+  @param  Context               The pointer to the notification function's context,\r
+                                which is implementation-dependent.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+CpuReadToBootFunction (\r
+  IN  EFI_EVENT                Event,\r
+  IN  VOID                     *Context\r
+  )\r
+{\r
+  gReadToBoot = TRUE;\r
+}\r
+\r
+\r
+\r
+EFI_STATUS\r
+CpuMpServicesInit (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_HANDLE              Handle;\r
+  EMU_IO_THUNK_PROTOCOL   *IoThunk;\r
+  UINTN                   MaxCpus;\r
+\r
+  MaxCpus = 1; // BSP\r
+  \r
+  IoThunk = GetIoThunkInstance (&gEmuThreadThunkProtocolGuid, 0);\r
+  if (IoThunk != NULL) {\r
+    Status = IoThunk->Open (IoThunk);\r
+    if (!EFI_ERROR (Status)) {\r
+      if (IoThunk->ConfigString != NULL) {\r
+        MaxCpus += StrDecimalToUintn (IoThunk->ConfigString);\r
+        gThread = IoThunk->Interface;\r
+      }\r
+    }\r
+  }\r
+\r
+  if (MaxCpus == 1) {\r
+    // We are not MP so nothing to do\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  gPollInterval = PcdGet64 (PcdEmuMpServicesPollingInterval);\r
+\r
+  Status  = InitializeMpSystemData (MaxCpus);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = EfiCreateEventReadyToBootEx (TPL_CALLBACK, CpuReadToBootFunction, NULL, &gReadToBootEvent);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Now install the MP services protocol.\r
+  //\r
+  Handle = NULL;\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Handle,\r
+                  &gEfiMpServiceProtocolGuid,   &mMpSercicesTemplate,\r
+                  NULL\r
+                  );\r
+  return Status;\r
+}\r
+\r
+\r
diff --git a/EmulatorPkg/CpuRuntimeDxe/Strings.uni b/EmulatorPkg/CpuRuntimeDxe/Strings.uni
new file mode 100644 (file)
index 0000000..c8a226e
Binary files /dev/null and b/EmulatorPkg/CpuRuntimeDxe/Strings.uni differ
diff --git a/EmulatorPkg/EmuBlockIoDxe/ComponentName.c b/EmulatorPkg/EmuBlockIoDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..2cad6ca
--- /dev/null
@@ -0,0 +1,354 @@
+/**@file\r
+\r
+Copyright (c) 2006, 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
+Module Name:\r
+\r
+  ComponentName.c\r
+\r
+Abstract:\r
+\r
+**/\r
+\r
+#include "EmuBlockIo.h"\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+  This function retrieves the user readable name of a driver in the form of a\r
+  Unicode string. If the driver specified by This has a user readable name in\r
+  the language specified by Language, then a pointer to the driver name is\r
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+  by This does not support the language specified by Language,\r
+  then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language. This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  DriverName[out]       A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                driver specified by This in the language\r
+                                specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by a driver.\r
+\r
+  This function retrieves the user readable name of the controller specified by\r
+  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+  driver specified by This has a user readable name in the language specified by\r
+  Language, then a pointer to the controller name is returned in ControllerName,\r
+  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
+  managing the controller specified by ControllerHandle and ChildHandle,\r
+  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
+  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  ControllerHandle[in]  The handle of a controller that the driver\r
+                                specified by This is managing.  This handle\r
+                                specifies the controller whose name is to be\r
+                                returned.\r
+\r
+  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
+                                the name of.  This is an optional parameter that\r
+                                may be NULL.  It will be NULL for device\r
+                                drivers.  It will also be NULL for a bus drivers\r
+                                that wish to retrieve the name of the bus\r
+                                controller.  It will not be NULL for a bus\r
+                                driver that wishes to retrieve the name of a\r
+                                child controller.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language.  This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified in\r
+                                RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                controller specified by ControllerHandle and\r
+                                ChildHandle in the language specified by\r
+                                Language from the point of view of the driver\r
+                                specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
+                                the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED  EFI_COMPONENT_NAME_PROTOCOL     gEmuBlockIoComponentName = {\r
+  EmuBlockIoComponentNameGetDriverName,\r
+  EmuBlockIoComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+//\r
+// EFI Component Name 2 Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuBlockIoComponentName2 = {\r
+  (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) EmuBlockIoComponentNameGetDriverName,\r
+  (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) EmuBlockIoComponentNameGetControllerName,\r
+  "en"\r
+};\r
+\r
+\r
+EFI_UNICODE_STRING_TABLE mEmuBlockIoDriverNameTable[] = {\r
+  { "eng;en", L"Emu Block I/O Driver" },\r
+  { NULL , NULL }\r
+};\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+  This function retrieves the user readable name of a driver in the form of a\r
+  Unicode string. If the driver specified by This has a user readable name in\r
+  the language specified by Language, then a pointer to the driver name is\r
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+  by This does not support the language specified by Language,\r
+  then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language. This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  DriverName[out]       A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                driver specified by This in the language\r
+                                specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+{\r
+  return LookupUnicodeString2 (\r
+          Language,\r
+          This->SupportedLanguages,\r
+          mEmuBlockIoDriverNameTable,\r
+          DriverName,\r
+           (BOOLEAN)(This == &gEmuBlockIoComponentName)\r
+          );\r
+}\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by a driver.\r
+\r
+  This function retrieves the user readable name of the controller specified by\r
+  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+  driver specified by This has a user readable name in the language specified by\r
+  Language, then a pointer to the controller name is returned in ControllerName,\r
+  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
+  managing the controller specified by ControllerHandle and ChildHandle,\r
+  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
+  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  ControllerHandle[in]  The handle of a controller that the driver\r
+                                specified by This is managing.  This handle\r
+                                specifies the controller whose name is to be\r
+                                returned.\r
+\r
+  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
+                                the name of.  This is an optional parameter that\r
+                                may be NULL.  It will be NULL for device\r
+                                drivers.  It will also be NULL for a bus drivers\r
+                                that wish to retrieve the name of the bus\r
+                                controller.  It will not be NULL for a bus\r
+                                driver that wishes to retrieve the name of a\r
+                                child controller.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language.  This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified in\r
+                                RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                controller specified by ControllerHandle and\r
+                                ChildHandle in the language specified by\r
+                                Language from the point of view of the driver\r
+                                specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
+                                the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_BLOCK_IO_PROTOCOL   *BlockIo;\r
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+\r
+  //\r
+  // This is a device driver, so ChildHandle must be NULL.\r
+  //\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Make sure this driver is currently managing ControllerHandle\r
+  //\r
+  Status = EfiTestManagedDevice (\r
+             ControllerHandle,\r
+             gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+             &gEmuIoThunkProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  (VOID  **)&BlockIo,\r
+                  gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);\r
+\r
+  return LookupUnicodeString2 (\r
+          Language,\r
+           This->SupportedLanguages,\r
+           Private->ControllerNameTable,\r
+           ControllerName,\r
+           (BOOLEAN)(This == &gEmuBlockIoComponentName)\r
+          );\r
+}\r
diff --git a/EmulatorPkg/EmuBlockIoDxe/DriverConfiguration.c b/EmulatorPkg/EmuBlockIoDxe/DriverConfiguration.c
new file mode 100644 (file)
index 0000000..44a3cc3
--- /dev/null
@@ -0,0 +1,338 @@
+/**@file\r
+\r
+Copyright (c) 2006, 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
+Module Name:\r
+\r
+  DriverConfiguration.c\r
+\r
+Abstract:\r
+\r
+**/\r
+\r
+#include "EmuBlockIo.h"\r
+\r
+//\r
+// EFI Driver Configuration Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverConfigurationSetOptions (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL                      *This,\r
+  IN  EFI_HANDLE                                             ControllerHandle,\r
+  IN  EFI_HANDLE                                             ChildHandle  OPTIONAL,\r
+  IN  CHAR8                                                  *Language,\r
+  OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED               *ActionRequired\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverConfigurationOptionsValid (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL               *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle  OPTIONAL\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverConfigurationForceDefaults (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL                      *This,\r
+  IN  EFI_HANDLE                                             ControllerHandle,\r
+  IN  EFI_HANDLE                                             ChildHandle  OPTIONAL,\r
+  IN  UINT32                                                 DefaultType,\r
+  OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED               *ActionRequired\r
+  );\r
+\r
+//\r
+// EFI Driver Configuration Protocol\r
+//\r
+EFI_DRIVER_CONFIGURATION_PROTOCOL gEmuBlockIoDriverConfiguration = {\r
+  EmuBlockIoDriverConfigurationSetOptions,\r
+  EmuBlockIoDriverConfigurationOptionsValid,\r
+  EmuBlockIoDriverConfigurationForceDefaults,\r
+  "eng"\r
+};\r
+\r
+/*++\r
+\r
+  Routine Description:\r
+    Allows the user to set controller specific options for a controller that a \r
+    driver is currently managing.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.\r
+    ControllerHandle - The handle of the controller to set options on.\r
+    ChildHandle      - The handle of the child controller to set options on.  This\r
+                       is an optional parameter that may be NULL.  It will be NULL \r
+                       for device drivers, and for a bus drivers that wish to set \r
+                       options for the bus controller.  It will not be NULL for a \r
+                       bus driver that wishes to set options for one of its child \r
+                       controllers.\r
+    Language         - A pointer to a three character ISO 639-2 language identifier.\r
+                       This is the language of the user interface that should be \r
+                       presented to the user, and it must match one of the languages \r
+                       specified in SupportedLanguages.  The number of languages \r
+                       supported by a driver is up to the driver writer.\r
+    ActionRequired   - A pointer to the action that the calling agent is required \r
+                       to perform when this function returns.  See "Related \r
+                       Definitions" for a list of the actions that the calling \r
+                       agent is required to perform prior to accessing \r
+                       ControllerHandle again.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The driver specified by This successfully set the \r
+                            configuration options for the controller specified \r
+                            by ControllerHandle..\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ActionRequired is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support setting \r
+                            configuration options for the controller specified by \r
+                            ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+    EFI_DEVICE_ERROR      - A device error occurred while attempt to set the \r
+                            configuration options for the controller specified \r
+                            by ControllerHandle and ChildHandle.\r
+    EFI_OUT_RESOURCES     - There are not enough resources available to set the \r
+                            configuration options for the controller specified \r
+                            by ControllerHandle and ChildHandle.\r
+\r
+--*/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverConfigurationSetOptions (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL                      *This,\r
+  IN  EFI_HANDLE                                             ControllerHandle,\r
+  IN  EFI_HANDLE                                             ChildHandle  OPTIONAL,\r
+  IN  CHAR8                                                  *Language,\r
+  OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED               *ActionRequired\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+  CHAR8                 *SupportedLanguage;\r
+\r
+  SupportedLanguage = This->SupportedLanguages;\r
+\r
+  Status            = EFI_UNSUPPORTED;\r
+  while (*SupportedLanguage != 0) {\r
+    if (AsciiStrnCmp (Language, SupportedLanguage, 3) == 0) {\r
+      Status = EFI_SUCCESS;\r
+    }\r
+\r
+    SupportedLanguage += 3;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (ActionRequired == NULL || ControllerHandle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Validate controller handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (VOID **)&BlockIo,\r
+                  gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEmuIoThunkProtocolGuid,\r
+          gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status == EFI_UNSUPPORTED) {\r
+    return Status;\r
+  } else if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *ActionRequired = EfiDriverConfigurationActionNone;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/*++\r
+\r
+  Routine Description:\r
+    Tests to see if a controller's current configuration options are valid.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_DRIVER_CONFIGURATION_PROTOCOL instance.\r
+    ControllerHandle - The handle of the controller to test if it's current \r
+                       configuration options are valid.\r
+    ChildHandle      - The handle of the child controller to test if it's current\r
+                       configuration options are valid.  This is an optional \r
+                       parameter that may be NULL.  It will be NULL for device \r
+                       drivers.  It will also be NULL for a bus drivers that wish\r
+                       to test the configuration options for the bus controller.\r
+                       It will not be NULL for a bus driver that wishes to test \r
+                       configuration options for one of its child controllers.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The controller specified by ControllerHandle and \r
+                            ChildHandle that is being managed by the driver \r
+                            specified by This has a valid set of  configuration\r
+                            options.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently \r
+                            managing the controller specified by ControllerHandle \r
+                            and ChildHandle.\r
+    EFI_DEVICE_ERROR      - The controller specified by ControllerHandle and \r
+                            ChildHandle that is being managed by the driver \r
+                            specified by This has an invalid set of configuration \r
+                            options.\r
+\r
+--*/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverConfigurationOptionsValid (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL               *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle  OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (ControllerHandle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Validate controller handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (VOID **)&BlockIo,\r
+                  gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEmuIoThunkProtocolGuid,\r
+          gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status == EFI_UNSUPPORTED) {\r
+    return Status;\r
+  } else if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/*++\r
+\r
+  Routine Description:\r
+    Forces a driver to set the default configuration options for a controller.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.\r
+    ControllerHandle - The handle of the controller to force default configuration options on.\r
+    ChildHandle      - The handle of the child controller to force default configuration options on  This is an optional parameter that may be NULL.  It will be NULL for device drivers.  It will also be NULL for a bus drivers that wish to force default configuration options for the bus controller.  It will not be NULL for a bus driver that wishes to force default configuration options for one of its child controllers.\r
+    DefaultType      - The type of default configuration options to force on the controller specified by ControllerHandle and ChildHandle.  See Table 9-1 for legal values.  A DefaultType of 0x00000000 must be supported by this protocol.\r
+    ActionRequired   - A pointer to the action that the calling agent is required to perform when this function returns.  See "Related Definitions" in Section 9.1for a list of the actions that the calling agent is required to perform prior to accessing ControllerHandle again.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The driver specified by This successfully forced the default configuration options on the controller specified by ControllerHandle and ChildHandle.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ActionRequired is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support forcing the default configuration options on the controller specified by ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the configuration type specified by DefaultType.\r
+    EFI_DEVICE_ERROR      - A device error occurred while attempt to force the default configuration options on the controller specified by  ControllerHandle and ChildHandle.\r
+    EFI_OUT_RESOURCES     - There are not enough resources available to force the default configuration options on the controller specified by ControllerHandle and ChildHandle.\r
+\r
+--*/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverConfigurationForceDefaults (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL                      *This,\r
+  IN  EFI_HANDLE                                             ControllerHandle,\r
+  IN  EFI_HANDLE                                             ChildHandle  OPTIONAL,\r
+  IN  UINT32                                                 DefaultType,\r
+  OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED               *ActionRequired\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (ActionRequired == NULL || ControllerHandle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Validate controller handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (VOID **)&BlockIo,\r
+                  gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEmuIoThunkProtocolGuid,\r
+          gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status == EFI_UNSUPPORTED) {\r
+    return Status;\r
+  } else if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *ActionRequired = EfiDriverConfigurationActionNone;\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/EmulatorPkg/EmuBlockIoDxe/DriverDiagnostics.c b/EmulatorPkg/EmuBlockIoDxe/DriverDiagnostics.c
new file mode 100644 (file)
index 0000000..ebb730b
--- /dev/null
@@ -0,0 +1,219 @@
+/**@file\r
+\r
+Copyright (c) 2006 - 2007, 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
+Module Name:\r
+\r
+  DriverDiagnostics.c\r
+\r
+Abstract:\r
+\r
+**/\r
+\r
+#include "EmuBlockIo.h"\r
+\r
+//\r
+// EFI Driver Diagnostics Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverDiagnosticsRunDiagnostics (\r
+  IN  EFI_DRIVER_DIAGNOSTICS_PROTOCOL               *This,\r
+  IN  EFI_HANDLE                                    ControllerHandle,\r
+  IN  EFI_HANDLE                                    ChildHandle  OPTIONAL,\r
+  IN  EFI_DRIVER_DIAGNOSTIC_TYPE                    DiagnosticType,\r
+  IN  CHAR8                                         *Language,\r
+  OUT EFI_GUID                                      **ErrorType,\r
+  OUT UINTN                                         *BufferSize,\r
+  OUT CHAR16                                        **Buffer\r
+  );\r
+\r
+//\r
+// EFI Driver Diagnostics Protocol\r
+//\r
+EFI_DRIVER_DIAGNOSTICS_PROTOCOL gEmuBlockIoDriverDiagnostics = {\r
+  EmuBlockIoDriverDiagnosticsRunDiagnostics,\r
+  "eng"\r
+};\r
+\r
+//\r
+// EFI Driver Diagnostics 2 Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gEmuBlockIoDriverDiagnostics2 = {\r
+  (EFI_DRIVER_DIAGNOSTICS2_RUN_DIAGNOSTICS) EmuBlockIoDriverDiagnosticsRunDiagnostics,\r
+  "en"\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverDiagnosticsRunDiagnostics (\r
+  IN  EFI_DRIVER_DIAGNOSTICS_PROTOCOL               *This,\r
+  IN  EFI_HANDLE                                    ControllerHandle,\r
+  IN  EFI_HANDLE                                    ChildHandle  OPTIONAL,\r
+  IN  EFI_DRIVER_DIAGNOSTIC_TYPE                    DiagnosticType,\r
+  IN  CHAR8                                         *Language,\r
+  OUT EFI_GUID                                      **ErrorType,\r
+  OUT UINTN                                         *BufferSize,\r
+  OUT CHAR16                                        **Buffer\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Runs diagnostics on a controller.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL instance.\r
+    ControllerHandle - The handle of the controller to run diagnostics on.\r
+    ChildHandle      - The handle of the child controller to run diagnostics on  \r
+                       This is an optional parameter that may be NULL.  It will \r
+                       be NULL for device drivers.  It will also be NULL for a \r
+                       bus drivers that wish to run diagnostics on the bus \r
+                       controller.  It will not be NULL for a bus driver that \r
+                       wishes to run diagnostics on one of its child controllers.\r
+    DiagnosticType   - Indicates type of diagnostics to perform on the controller \r
+                       specified by ControllerHandle and ChildHandle.   See \r
+                       "Related Definitions" for the list of supported types.\r
+    Language         - A pointer to a three character ISO 639-2 language \r
+                       identifier or a Null-terminated ASCII string array indicating\r
+                       the language.  This is the language in which the optional\r
+                       error message should be returned in Buffer, and it must \r
+                       match one of the languages specified in SupportedLanguages.\r
+                       The number of languages supported by a driver is up to \r
+                       the driver writer.  \r
+    ErrorType        - A GUID that defines the format of the data returned in \r
+                       Buffer.  \r
+    BufferSize       - The size, in bytes, of the data returned in Buffer.  \r
+    Buffer           - A buffer that contains a Null-terminated Unicode string \r
+                       plus some additional data whose format is defined by \r
+                       ErrorType.  Buffer is allocated by this function with \r
+                       AllocatePool(), and it is the caller's responsibility \r
+                       to free it with a call to FreePool().  \r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The controller specified by ControllerHandle and \r
+                            ChildHandle passed the diagnostic.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid \r
+                            EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ErrorType is NULL.\r
+    EFI_INVALID_PARAMETER - BufferType is NULL.\r
+    EFI_INVALID_PARAMETER - Buffer is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support \r
+                            running diagnostics for the controller specified \r
+                            by ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            type of diagnostic specified by DiagnosticType.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+    EFI_OUT_OF_RESOURCES  - There are not enough resources available to complete\r
+                            the diagnostics.\r
+    EFI_OUT_OF_RESOURCES  - There are not enough resources available to return\r
+                            the status information in ErrorType, BufferSize, \r
+                            and Buffer.\r
+    EFI_DEVICE_ERROR      - The controller specified by ControllerHandle and \r
+                            ChildHandle did not pass the diagnostic.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+  CHAR8                 *SupportedLanguages;\r
+  BOOLEAN               Iso639Language;\r
+  BOOLEAN               Found;\r
+  UINTN                 Index;\r
+\r
+  if (Language         == NULL ||\r
+      ErrorType        == NULL ||\r
+      Buffer           == NULL ||\r
+      ControllerHandle == NULL ||\r
+      BufferSize       == NULL) {\r
+\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  SupportedLanguages = This->SupportedLanguages;\r
+  Iso639Language = (BOOLEAN)(This == &gEmuBlockIoDriverDiagnostics);\r
+  //\r
+  // Make sure Language is in the set of Supported Languages\r
+  //\r
+  Found = FALSE;\r
+  while (*SupportedLanguages != 0) {\r
+    if (Iso639Language) {\r
+      if (CompareMem (Language, SupportedLanguages, 3) == 0) {\r
+        Found = TRUE;\r
+      break;\r
+    }\r
+      SupportedLanguages += 3;\r
+    } else {\r
+      for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r
+      if ((AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) && (Language[Index] == 0)) {\r
+        Found = TRUE;\r
+        break;\r
+  }\r
+      SupportedLanguages += Index;\r
+      for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r
+    }\r
+  }\r
+  //\r
+  // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r
+  //\r
+  if (!Found) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  *ErrorType  = NULL;\r
+  *BufferSize = 0;\r
+  if (DiagnosticType != EfiDriverDiagnosticTypeStandard) {\r
+    *ErrorType  = &gEfiBlockIoProtocolGuid;\r
+    *BufferSize = 0x60;\r
+    Buffer = AllocatePool ((UINTN) (*BufferSize));\r
+    CopyMem (*Buffer, L"Windows Block I/O Driver Diagnostics Failed\n", *BufferSize);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  //\r
+  // This is a device driver, so ChildHandle must be NULL.\r
+  //\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Validate controller handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (VOID **)&BlockIo,\r
+                  gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEmuIoThunkProtocolGuid,\r
+          gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status == EFI_UNSUPPORTED) {\r
+    return Status;\r
+  } else if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/EmulatorPkg/EmuBlockIoDxe/EmuBlockIo.c b/EmulatorPkg/EmuBlockIoDxe/EmuBlockIo.c
new file mode 100644 (file)
index 0000000..b679d8f
--- /dev/null
@@ -0,0 +1,747 @@
+/**@file\r
+\r
+Copyright (c) 2004 - 2009, 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
+bbe\r
+**/\r
+\r
+#include "EmuBlockIo.h"\r
+\r
+\r
+/**\r
+  Reset the block device hardware.\r
+\r
+  @param[in]  This                 Indicates a pointer to the calling context.\r
+  @param[in]  ExtendedVerification Indicates that the driver may perform a more\r
+                                   exhausive verfication operation of the device\r
+                                   during reset.\r
+\r
+  @retval EFI_SUCCESS          The device was reset.\r
+  @retval EFI_DEVICE_ERROR     The device is not functioning properly and could\r
+                               not be reset.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIo2Reset (\r
+  IN EFI_BLOCK_IO2_PROTOCOL  *This,\r
+  IN BOOLEAN                 ExtendedVerification\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Status = Private->Io->Reset (Private->Io, ExtendedVerification);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Read BufferSize bytes from Lba into Buffer.\r
+  \r
+  This function reads the requested number of blocks from the device. All the\r
+  blocks are read, or an error is returned.\r
+  If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_or EFI_MEDIA_CHANGED is returned and\r
+  non-blocking I/O is being used, the Event associated with this request will\r
+  not be signaled.\r
+\r
+  @param[in]       This       Indicates a pointer to the calling context.\r
+  @param[in]       MediaId    Id of the media, changes every time the media is \r
+                              replaced.\r
+  @param[in]       Lba        The starting Logical Block Address to read from.\r
+  @param[in, out]  Token           A pointer to the token associated with the transaction.\r
+  @param[in]       BufferSize Size of Buffer, must be a multiple of device block size.  \r
+  @param[out]      Buffer     A pointer to the destination buffer for the data. The \r
+                              caller is responsible for either having implicit or \r
+                              explicit ownership of the buffer.\r
+\r
+  @retval EFI_SUCCESS           The read request was queued if Token->Event is\r
+                                not NULL.The data was read correctly from the\r
+                                device if the Token->Event is NULL.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing\r
+                                the read.\r
+  @retval EFI_NO_MEDIA          There is no media in the device.\r
+  @retval EFI_MEDIA_CHANGED     The MediaId is not for the current media.\r
+  @retval EFI_BAD_BUFFER_SIZE   The BufferSize parameter is not a multiple of the\r
+                                intrinsic block size of the device.\r
+  @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid, \r
+                                or the buffer is not on proper alignment.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack\r
+                                of resources.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIo2ReadBlocksEx (\r
+  IN     EFI_BLOCK_IO2_PROTOCOL *This,\r
+  IN     UINT32                 MediaId,\r
+  IN     EFI_LBA                LBA,\r
+  IN OUT EFI_BLOCK_IO2_TOKEN    *Token,\r
+  IN     UINTN                  BufferSize,\r
+     OUT VOID                  *Buffer\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Status = Private->Io->ReadBlocks (Private->Io, MediaId, LBA, Token, BufferSize, Buffer);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Write BufferSize bytes from Lba into Buffer.\r
+\r
+  This function writes the requested number of blocks to the device. All blocks\r
+  are written, or an error is returned.If EFI_DEVICE_ERROR, EFI_NO_MEDIA,\r
+  EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED is returned and non-blocking I/O is\r
+  being used, the Event associated with this request will not be signaled.\r
+\r
+  @param[in]       This       Indicates a pointer to the calling context.\r
+  @param[in]       MediaId    The media ID that the write request is for.\r
+  @param[in]       Lba        The starting logical block address to be written. The\r
+                              caller is responsible for writing to only legitimate\r
+                              locations.\r
+  @param[in, out]  Token      A pointer to the token associated with the transaction.\r
+  @param[in]       BufferSize Size of Buffer, must be a multiple of device block size.\r
+  @param[in]       Buffer     A pointer to the source buffer for the data.\r
+\r
+  @retval EFI_SUCCESS           The write request was queued if Event is not NULL.\r
+                                The data was written correctly to the device if\r
+                                the Event is NULL.\r
+  @retval EFI_WRITE_PROTECTED   The device can not be written to.\r
+  @retval EFI_NO_MEDIA          There is no media in the device.\r
+  @retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.\r
+  @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
+  @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid, \r
+                                or the buffer is not on proper alignment.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack\r
+                                of resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI \r
+EmuBlockIo2WriteBlocksEx (\r
+  IN     EFI_BLOCK_IO2_PROTOCOL  *This,\r
+  IN     UINT32                 MediaId,\r
+  IN     EFI_LBA                LBA,\r
+  IN OUT EFI_BLOCK_IO2_TOKEN    *Token,\r
+  IN     UINTN                  BufferSize,\r
+  IN     VOID                   *Buffer\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Status = Private->Io->WriteBlocks (Private->Io, MediaId, LBA, Token, BufferSize, Buffer);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Flush the Block Device.\r
\r
+  If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED\r
+  is returned and non-blocking I/O is being used, the Event associated with\r
+  this request will not be signaled.  \r
+\r
+  @param[in]      This     Indicates a pointer to the calling context.\r
+  @param[in,out]  Token    A pointer to the token associated with the transaction\r
+\r
+  @retval EFI_SUCCESS          The flush request was queued if Event is not NULL.\r
+                               All outstanding data was written correctly to the\r
+                               device if the Event is NULL.\r
+  @retval EFI_DEVICE_ERROR     The device reported an error while writting back\r
+                               the data.\r
+  @retval EFI_WRITE_PROTECTED  The device cannot be written to.\r
+  @retval EFI_NO_MEDIA         There is no media in the device.\r
+  @retval EFI_MEDIA_CHANGED    The MediaId is not for the current media.\r
+  @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack\r
+                               of resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIo2Flush (\r
+  IN     EFI_BLOCK_IO2_PROTOCOL   *This,\r
+  IN OUT EFI_BLOCK_IO2_TOKEN      *Token\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Status = Private->Io->FlushBlocks (Private->Io, Token);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Reset the Block Device.\r
+\r
+  @param  This                 Indicates a pointer to the calling context.\r
+  @param  ExtendedVerification Driver may perform diagnostics on reset.\r
+\r
+  @retval EFI_SUCCESS          The device was reset.\r
+  @retval EFI_DEVICE_ERROR     The device is not functioning properly and could\r
+                               not be reset.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoReset (\r
+  IN EFI_BLOCK_IO_PROTOCOL          *This,\r
+  IN BOOLEAN                        ExtendedVerification\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Status = Private->Io->Reset (Private->Io, ExtendedVerification);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Read BufferSize bytes from Lba into Buffer.\r
+\r
+  @param  This       Indicates a pointer to the calling context.\r
+  @param  MediaId    Id of the media, changes every time the media is replaced.\r
+  @param  Lba        The starting Logical Block Address to read from\r
+  @param  BufferSize Size of Buffer, must be a multiple of device block size.\r
+  @param  Buffer     A pointer to the destination buffer for the data. The caller is\r
+                     responsible for either having implicit or explicit ownership of the buffer.\r
+\r
+  @retval EFI_SUCCESS           The data was read correctly from the device.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the read.\r
+  @retval EFI_NO_MEDIA          There is no media in the device.\r
+  @retval EFI_MEDIA_CHANGED     The MediaId does not matched the current device.\r
+  @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
+  @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid, \r
+                                or the buffer is not on proper alignment.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoReadBlocks (\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
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+  EFI_TPL                 OldTpl;\r
+  EFI_BLOCK_IO2_TOKEN     Token;\r
+\r
+  Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Token.Event = NULL;\r
+  Status = Private->Io->ReadBlocks (Private->Io, MediaId, Lba, &Token, BufferSize, Buffer);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Write BufferSize bytes from Lba into Buffer.\r
+\r
+  @param  This       Indicates a pointer to the calling context.\r
+  @param  MediaId    The media ID that the write request is for.\r
+  @param  Lba        The starting logical block address to be written. The caller is\r
+                     responsible for writing to only legitimate locations.\r
+  @param  BufferSize Size of Buffer, must be a multiple of device block size.\r
+  @param  Buffer     A pointer to the source buffer for the data.\r
+\r
+  @retval EFI_SUCCESS           The data was written correctly to the device.\r
+  @retval EFI_WRITE_PROTECTED   The device can not be written to.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.\r
+  @retval EFI_NO_MEDIA          There is no media in the device.\r
+  @retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.\r
+  @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
+  @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid, \r
+                                or the buffer is not on proper alignment.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoWriteBlocks (\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
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+  EFI_TPL                 OldTpl;\r
+  EFI_BLOCK_IO2_TOKEN     Token;\r
+\r
+  Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Token.Event = NULL;\r
+  Status = Private->Io->WriteBlocks (Private->Io, MediaId, Lba, &Token, BufferSize, Buffer);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Flush the Block Device.\r
+\r
+  @param  This              Indicates a pointer to the calling context.\r
+\r
+  @retval EFI_SUCCESS       All outstanding data was written to the device\r
+  @retval EFI_DEVICE_ERROR  The device reported an error while writting back the data\r
+  @retval EFI_NO_MEDIA      There is no media in the device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoFlushBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+  EFI_TPL                 OldTpl;\r
+  EFI_BLOCK_IO2_TOKEN     Token;\r
+\r
+  Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Token.Event = NULL;\r
+  Status = Private->Io->FlushBlocks (Private->Io, &Token);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Tests to see if this driver supports a given controller. If a child device is provided, \r
+  it further tests to see if this driver supports creating a handle for the specified child device.\r
+\r
+  This function checks to see if the driver specified by This supports the device specified by \r
+  ControllerHandle. Drivers will typically use the device path attached to \r
+  ControllerHandle and/or the services from the bus I/O abstraction attached to \r
+  ControllerHandle to determine if the driver supports ControllerHandle. This function \r
+  may be called many times during platform initialization. In order to reduce boot times, the tests \r
+  performed by this function must be very small, and take as little time as possible to execute. This \r
+  function must not change the state of any hardware devices, and this function must be aware that the \r
+  device specified by ControllerHandle may already be managed by the same driver or a \r
+  different driver. This function must match its calls to AllocatePages() with FreePages(), \r
+  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().  \r
+  Because ControllerHandle may have been previously started by the same driver, if a protocol is \r
+  already in the opened state, then it must not be closed with CloseProtocol(). This is required \r
+  to guarantee the state of ControllerHandle is not modified by this function.\r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to test. This handle \r
+                                   must support a protocol interface that supplies \r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This \r
+                                   parameter is ignored by device drivers, and is optional for bus \r
+                                   drivers. For bus drivers, if this parameter is not NULL, then \r
+                                   the bus driver must determine if the bus controller specified \r
+                                   by ControllerHandle and the child controller specified \r
+                                   by RemainingDevicePath are both supported by this \r
+                                   bus driver.\r
+\r
+  @retval EFI_SUCCESS              The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is supported by the driver specified by This.\r
+  @retval EFI_ALREADY_STARTED      The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by the driver\r
+                                   specified by This.\r
+  @retval EFI_ACCESS_DENIED        The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by a different\r
+                                   driver or an application that requires exclusive access.\r
+                                   Currently not implemented.\r
+  @retval EFI_UNSUPPORTED          The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is not supported by the driver specified by This.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_IO_THUNK_PROTOCOL   *EmuIoThunk;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (VOID **)&EmuIoThunk,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Make sure GUID is for a File System handle.\r
+  //\r
+  Status = EFI_UNSUPPORTED;\r
+  if (CompareGuid (EmuIoThunk->Protocol, &gEmuBlockIoProtocolGuid)) {\r
+    Status = EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+        Handle,\r
+        &gEmuIoThunkProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Handle\r
+        );\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Starts a device controller or a bus controller.\r
+\r
+  The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
+  As a result, much of the error checking on the parameters to Start() has been moved into this \r
+  common boot service. It is legal to call Start() from other locations, \r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE.\r
+  2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
+     EFI_DEVICE_PATH_PROTOCOL.\r
+  3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
+     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.  \r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to start. This handle \r
+                                   must support a protocol interface that supplies \r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This \r
+                                   parameter is ignored by device drivers, and is optional for bus \r
+                                   drivers. For a bus driver, if this parameter is NULL, then handles \r
+                                   for all the children of Controller are created by this driver.  \r
+                                   If this parameter is not NULL and the first Device Path Node is \r
+                                   not the End of Device Path Node, then only the handle for the \r
+                                   child device specified by the first Device Path Node of \r
+                                   RemainingDevicePath is created by this driver.\r
+                                   If the first Device Path Node of RemainingDevicePath is \r
+                                   the End of Device Path Node, no child handle is created by this\r
+                                   driver.\r
+\r
+  @retval EFI_SUCCESS              The device was started.\r
+  @retval EFI_DEVICE_ERROR         The device could not be started due to a device error.Currently not implemented.\r
+  @retval EFI_OUT_OF_RESOURCES     The request could not be completed due to a lack of resources.\r
+  @retval Others                   The driver failded to start the device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EMU_IO_THUNK_PROTOCOL       *EmuIoThunk;\r
+  EMU_BLOCK_IO_PRIVATE        *Private = NULL;\r
+\r
+  //\r
+  // Grab the protocols we need\r
+  //\r
+  \r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (void *)&EmuIoThunk,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  \r
+  if (!CompareGuid (EmuIoThunk->Protocol, &gEmuBlockIoProtocolGuid)) {\r
+    Status = EFI_UNSUPPORTED;\r
+    goto Done;\r
+  }\r
+\r
+  Status = EmuIoThunk->Open (EmuIoThunk);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  Private = AllocatePool (sizeof (EMU_BLOCK_IO_PRIVATE));\r
+  if (Private == NULL) {\r
+    goto Done;\r
+  }\r
+\r
+  Private->Signature = EMU_BLOCK_IO_PRIVATE_SIGNATURE;\r
+  Private->IoThunk   = EmuIoThunk;\r
+  Private->Io        = EmuIoThunk->Interface;\r
+  Private->EfiHandle = Handle;\r
+  \r
+  Private->BlockIo.Revision    = EFI_BLOCK_IO_PROTOCOL_REVISION2;\r
+  Private->BlockIo.Media       = &Private->Media;\r
+  Private->BlockIo.Reset       = EmuBlockIoReset;\r
+  Private->BlockIo.ReadBlocks  = EmuBlockIoReadBlocks;\r
+  Private->BlockIo.WriteBlocks = EmuBlockIoWriteBlocks;\r
+  Private->BlockIo.FlushBlocks = EmuBlockIoFlushBlocks;\r
+\r
+  Private->BlockIo2.Media         = &Private->Media;\r
+  Private->BlockIo2.Reset         = EmuBlockIo2Reset;\r
+  Private->BlockIo2.ReadBlocksEx  = EmuBlockIo2ReadBlocksEx;\r
+  Private->BlockIo2.WriteBlocksEx = EmuBlockIo2WriteBlocksEx;\r
+  Private->BlockIo2.FlushBlocksEx = EmuBlockIo2Flush;\r
+\r
+  Private->ControllerNameTable = NULL;\r
+\r
+  Status = Private->Io->CreateMapping (Private->Io, &Private->Media);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  AddUnicodeString2 (\r
+    "eng",\r
+    gEmuBlockIoComponentName.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    EmuIoThunk->ConfigString,\r
+    TRUE\r
+    );\r
+    \r
+  AddUnicodeString2 (\r
+    "en",\r
+    gEmuBlockIoComponentName2.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    EmuIoThunk->ConfigString,\r
+    FALSE\r
+    );\r
+\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Handle,\r
+                  &gEfiBlockIoProtocolGuid,    &Private->BlockIo,\r
+                  &gEfiBlockIo2ProtocolGuid,   &Private->BlockIo2,\r
+                  NULL\r
+                  );\r
+\r
+Done:\r
+  if (EFI_ERROR (Status)) {\r
+    if (Private != NULL) {\r
+      if (Private->ControllerNameTable != NULL) {\r
+        FreeUnicodeStringTable (Private->ControllerNameTable);\r
+      }\r
+      \r
+      gBS->FreePool (Private);\r
+    \r
+    }\r
+    \r
+    gBS->CloseProtocol (\r
+          Handle,\r
+          &gEmuIoThunkProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Handle\r
+          );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Stops a device controller or a bus controller.\r
+  \r
+  The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). \r
+  As a result, much of the error checking on the parameters to Stop() has been moved \r
+  into this common boot service. It is legal to call Stop() from other locations, \r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
+     same driver's Start() function.\r
+  2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
+     EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
+     Start() function, and the Start() function must have called OpenProtocol() on\r
+     ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
+  \r
+  @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must \r
+                                support a bus specific I/O protocol for the driver \r
+                                to use to stop the device.\r
+  @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.\r
+  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL \r
+                                if NumberOfChildren is 0.\r
+\r
+  @retval EFI_SUCCESS           The device was stopped.\r
+  @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+{\r
+  EFI_BLOCK_IO_PROTOCOL   *BlockIo;\r
+  EFI_STATUS              Status;\r
+  EMU_BLOCK_IO_PRIVATE *Private;\r
+\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  (void *)&BlockIo,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);\r
+  Status = Private->IoThunk->Close (Private->IoThunk);\r
+\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  Private->EfiHandle,\r
+                  &gEfiBlockIoProtocolGuid,   &Private->BlockIo,\r
+                  &gEfiBlockIo2ProtocolGuid,  &Private->BlockIo2,\r
+                  NULL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = gBS->CloseProtocol (\r
+                    Handle,\r
+                    &gEmuIoThunkProtocolGuid,\r
+                    This->DriverBindingHandle,\r
+                    Handle\r
+                    );\r
+  }\r
+  \r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Free our instance data\r
+    //\r
+    FreeUnicodeStringTable (Private->ControllerNameTable);\r
+    gBS->FreePool (Private);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+\r
+\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gEmuBlockIoDriverBinding = {\r
+  EmuBlockIoDriverBindingSupported,\r
+  EmuBlockIoDriverBindingStart,\r
+  EmuBlockIoDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+\r
+\r
+\r
+/**\r
+  The user Entry Point for module EmuBlockIo . The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeEmuBlockIo (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  Status = EfiLibInstallAllDriverProtocols2 (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gEmuBlockIoDriverBinding,\r
+             ImageHandle,\r
+             &gEmuBlockIoComponentName,\r
+             &gEmuBlockIoComponentName2,\r
+             NULL,\r
+             NULL,\r
+             &gEmuBlockIoDriverDiagnostics,\r
+             &gEmuBlockIoDriverDiagnostics2\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+\r
diff --git a/EmulatorPkg/EmuBlockIoDxe/EmuBlockIo.h b/EmulatorPkg/EmuBlockIoDxe/EmuBlockIo.h
new file mode 100644 (file)
index 0000000..b11f305
--- /dev/null
@@ -0,0 +1,84 @@
+/*++\r
+\r
+Copyright (c) 2004 - 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
+Module Name:\r
+\r
+  EmuBlockIo.h\r
+\r
+Abstract:\r
+\r
+  Produce block IO abstractions for real devices on your PC using Posix APIs.\r
+  The configuration of what devices to mount or emulate comes from UNIX \r
+  environment variables. The variables must be visible to the Microsoft* \r
+  Developer Studio for them to work.\r
+\r
+  * Other names and brands may be claimed as the property of others.\r
+\r
+**/\r
+\r
+#ifndef _EMU_BLOCK_IO_H_\r
+#define _EMU_BLOCK_IO_H_\r
+\r
+#include <PiDxe.h>\r
+#include <Protocol/EmuIoThunk.h>\r
+#include <Protocol/BlockIo.h>\r
+#include <Protocol/BlockIo2.h>\r
+#include <Protocol/EmuBlockIo.h>\r
+\r
+#include <Guid/EmuPhysicalDisk.h>\r
+#include <Guid/EmuVirtualDisk.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+\r
+//\r
+// Language supported for driverconfiguration protocol\r
+//\r
+\r
+#define EMU_BLOCK_IO_PRIVATE_SIGNATURE SIGNATURE_32 ('E', 'M', 'b', 'k')\r
+typedef struct {\r
+  UINTN                       Signature;\r
+  EMU_IO_THUNK_PROTOCOL       *IoThunk;\r
+  EMU_BLOCK_IO_PROTOCOL       *Io;\r
+\r
+  EFI_HANDLE                  EfiHandle;\r
+  EFI_BLOCK_IO_PROTOCOL       BlockIo;\r
+  EFI_BLOCK_IO2_PROTOCOL      BlockIo2;\r
+  EFI_BLOCK_IO_MEDIA          Media;\r
+\r
+  EFI_UNICODE_STRING_TABLE    *ControllerNameTable;\r
+\r
+} EMU_BLOCK_IO_PRIVATE;\r
+\r
+#define EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS(a) \\r
+         CR(a, EMU_BLOCK_IO_PRIVATE, BlockIo, EMU_BLOCK_IO_PRIVATE_SIGNATURE)\r
+\r
+#define EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS(a) \\r
+         CR(a, EMU_BLOCK_IO_PRIVATE, BlockIo2, EMU_BLOCK_IO_PRIVATE_SIGNATURE)\r
+\r
+\r
+//\r
+// Block I/O Global Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL        gEmuBlockIoDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL        gEmuBlockIoComponentName;\r
+extern EFI_COMPONENT_NAME2_PROTOCOL       gEmuBlockIoComponentName2;\r
+extern EFI_DRIVER_CONFIGURATION_PROTOCOL  gEmuBlockIoDriverConfiguration;\r
+extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL    gEmuBlockIoDriverDiagnostics;\r
+extern EFI_DRIVER_DIAGNOSTICS2_PROTOCOL   gEmuBlockIoDriverDiagnostics2;\r
+\r
+#endif\r
diff --git a/EmulatorPkg/EmuBlockIoDxe/EmuBlockIoDxe.inf b/EmulatorPkg/EmuBlockIoDxe/EmuBlockIoDxe.inf
new file mode 100644 (file)
index 0000000..0e07822
--- /dev/null
@@ -0,0 +1,69 @@
+## @file\r
+# Block Io driver\r
+#\r
+# Produce block IO abstractions for real devices on your PC using Unix APIs.\r
+#  The configuration of what devices to mount or emulate comes from\r
+#  environment variables.\r
+# Copyright (c) 2006 - 2010, 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
+#  THE PROGRAM IS DISTRIBUTED UNDER 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                      = EmuBlockIo\r
+  FILE_GUID                      = C6760651-A38D-5F4F-AEAF-F6661549DF75\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = InitializeEmuBlockIo\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+#  DRIVER_BINDING                =  gUnixBlockIoDriverBinding                    \r
+#  COMPONENT_NAME                =  gUnixBlockIoComponentName                    \r
+#  DRIVER_DIAG                   =  gUnixBlockIoDriverDiagnostics                \r
+#\r
+\r
+[Sources]\r
+  DriverDiagnostics.c\r
+  DriverConfiguration.c\r
+  ComponentName.c\r
+  EmuBlockIo.c\r
+  EmuBlockIo.h\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  EmulatorPkg/EmulatorPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  BaseLib\r
+  DebugLib\r
+\r
+\r
+[Guids]\r
+  gEmuPhysicalDisksGuid                    # SOMETIMES_CONSUMED\r
+  gEmuVirtualDisksGuid                     # ALWAYS_CONSUMED\r
+\r
+\r
+[Protocols]\r
+  gEfiBlockIoProtocolGuid                     # PROTOCOL BY_START\r
+  gEfiBlockIo2ProtocolGuid                    # PROTOCOL BY_START\r
+  gEmuIoThunkProtocolGuid                     # PROTOCOL TO_START\r
+  gEmuBlockIoProtocolGuid                     # PROTOCOL BY_START\r
diff --git a/EmulatorPkg/EmuBusDriverDxe/ComponentName.c b/EmulatorPkg/EmuBusDriverDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..e8be214
--- /dev/null
@@ -0,0 +1,247 @@
+/** @file\r
+\r
+Copyright (c) 2006, 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
+**/\r
+\r
+#include "EmuBusDriverDxe.h"\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBusDriverComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBusDriverComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL     gEmuBusDriverComponentName = {\r
+  EmuBusDriverComponentNameGetDriverName,\r
+  EmuBusDriverComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+//\r
+// EFI Component Name 2 Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuBusDriverComponentName2 = {\r
+  (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) EmuBusDriverComponentNameGetDriverName,\r
+  (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) EmuBusDriverComponentNameGetControllerName,\r
+  "en"\r
+};\r
+\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mEmuBusDriverNameTable[] = {\r
+  { "eng", L"Emu Bus Driver" },\r
+  { NULL , NULL }\r
+};\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+  This function retrieves the user readable name of a driver in the form of a\r
+  Unicode string. If the driver specified by This has a user readable name in\r
+  the language specified by Language, then a pointer to the driver name is\r
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+  by This does not support the language specified by Language,\r
+  then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language. This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  DriverName[out]       A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                driver specified by This in the language\r
+                                specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBusDriverComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+{\r
+  return LookupUnicodeString2 (\r
+          Language,\r
+          This->SupportedLanguages,\r
+          mEmuBusDriverNameTable,\r
+          DriverName,\r
+          (BOOLEAN)(This == &gEmuBusDriverComponentName)\r
+          );\r
+}\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by a driver.\r
+\r
+  This function retrieves the user readable name of the controller specified by\r
+  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+  driver specified by This has a user readable name in the language specified by\r
+  Language, then a pointer to the controller name is returned in ControllerName,\r
+  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
+  managing the controller specified by ControllerHandle and ChildHandle,\r
+  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
+  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  ControllerHandle[in]  The handle of a controller that the driver\r
+                                specified by This is managing.  This handle\r
+                                specifies the controller whose name is to be\r
+                                returned.\r
+\r
+  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
+                                the name of.  This is an optional parameter that\r
+                                may be NULL.  It will be NULL for device\r
+                                drivers.  It will also be NULL for a bus drivers\r
+                                that wish to retrieve the name of the bus\r
+                                controller.  It will not be NULL for a bus\r
+                                driver that wishes to retrieve the name of a\r
+                                child controller.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language.  This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified in\r
+                                RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                controller specified by ControllerHandle and\r
+                                ChildHandle in the language specified by\r
+                                Language from the point of view of the driver\r
+                                specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
+                                the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBusDriverComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_IO_THUNK_PROTOCOL   *EmuIo;\r
+  EMU_IO_DEVICE           *Private;\r
+\r
+  //\r
+  // Make sure this driver is currently managing ControllHandle\r
+  //\r
+  Status = EfiTestManagedDevice (\r
+             ControllerHandle,\r
+             gEmuBusDriverBinding.DriverBindingHandle,\r
+             &gEmuThunkProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // This is a bus driver, so ChildHandle can not be NULL.\r
+  //\r
+  if (ChildHandle == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = EfiTestChildHandle (\r
+             ControllerHandle,\r
+             ChildHandle,\r
+             &gEmuThunkProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ChildHandle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (VOID**)&EmuIo,\r
+                  gEmuBusDriverBinding.DriverBindingHandle,\r
+                  ChildHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = EMU_IO_DEVICE_FROM_THIS (EmuIo);\r
+\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           Private->ControllerNameTable,\r
+           ControllerName,\r
+           (BOOLEAN)(This == &gEmuBusDriverComponentName)\r
+          );\r
+}\r
diff --git a/EmulatorPkg/EmuBusDriverDxe/EmuBusDriverDxe.c b/EmulatorPkg/EmuBusDriverDxe/EmuBusDriverDxe.c
new file mode 100644 (file)
index 0000000..0430ec3
--- /dev/null
@@ -0,0 +1,529 @@
+/** @file\r
+ Emu Bus driver\r
+\r
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2011, Apple Inc. All rights reserved.\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 "EmuBusDriverDxe.h"\r
+\r
+\r
+\r
+//\r
+// DriverBinding protocol global\r
+//\r
+EFI_DRIVER_BINDING_PROTOCOL           gEmuBusDriverBinding = {\r
+  EmuBusDriverBindingSupported,\r
+  EmuBusDriverBindingStart,\r
+  EmuBusDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBusDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
+  EMU_THUNK_PROTOCOL        *EmuThunk;\r
+\r
+  //\r
+  // Check the contents of the first Device Path Node of RemainingDevicePath to make sure\r
+  // it is a legal Device Path Node for this bus driver's children.\r
+  //\r
+  if (RemainingDevicePath != NULL) {\r
+    //\r
+    // Check if RemainingDevicePath is the End of Device Path Node, \r
+    // if yes, go on checking other conditions\r
+    //\r
+    if (!IsDevicePathEnd (RemainingDevicePath)) {\r
+      //\r
+      // If RemainingDevicePath isn't the End of Device Path Node,\r
+      // check its validation\r
+      //\r
+      if (RemainingDevicePath->Type != HARDWARE_DEVICE_PATH ||\r
+          RemainingDevicePath->SubType != HW_VENDOR_DP ||\r
+          DevicePathNodeLength(RemainingDevicePath) != sizeof(EMU_VENDOR_DEVICE_PATH_NODE)) {\r
+        return EFI_UNSUPPORTED;\r
+      }\r
+    }\r
+  }\r
+  \r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEmuThunkProtocolGuid,\r
+                  (VOID **)&EmuThunk   ,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        &gEmuThunkProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+\r
+  //\r
+  // Open the EFI Device Path protocol needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **)&ParentDevicePath,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+\r
+  //\r
+  // Close protocol, don't use device path protocol in the Support() function\r
+  //\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        &gEfiDevicePathProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBusDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  EFI_STATUS                      InstallStatus;\r
+  EMU_THUNK_PROTOCOL              *EmuThunk;\r
+  EFI_DEVICE_PATH_PROTOCOL        *ParentDevicePath;\r
+  EMU_IO_DEVICE                   *EmuDevice;\r
+  EMU_BUS_DEVICE                  *EmuBusDevice;\r
+  EMU_IO_THUNK_PROTOCOL           *EmuIoThunk;\r
+  UINT16                          ComponentName[512];\r
+  EMU_VENDOR_DEVICE_PATH_NODE     *Node;\r
+  BOOLEAN                         CreateDevice;\r
+\r
+  InstallStatus = EFI_UNSUPPORTED;\r
+  Status = EFI_UNSUPPORTED;\r
+\r
+  //\r
+  // Grab the protocols we need\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **)&ParentDevicePath,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
+    return Status;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEmuThunkProtocolGuid,\r
+                  (VOID **)&EmuThunk,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
+    return Status;\r
+  }\r
+\r
+  if (Status != EFI_ALREADY_STARTED) {\r
+    EmuBusDevice = AllocatePool (sizeof (EMU_BUS_DEVICE));\r
+    if (EmuBusDevice == NULL) {\r
+      return EFI_OUT_OF_RE