InOsEmuPkg: Rename package to EmulatorPkg & Sec to Host

* 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
This commit is contained in:
jljusten
2011-06-28 16:47:23 +00:00
parent d3e0289ccf
commit bb89ec1a7e
191 changed files with 220 additions and 220 deletions

View File

@@ -0,0 +1,109 @@
/*++ @file
Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "PiPei.h"
#include <Ppi/EmuThunk.h>
#include <Ppi/MemoryDiscovered.h>
#include <Library/DebugLib.h>
#include <Library/PeimEntryPoint.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/HobLib.h>
#include <Library/PeiServicesLib.h>
#include <Library/PeiServicesTablePointerLib.h>
EFI_STATUS
EFIAPI
PeimInitializeAutoScanPei (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
/*++
Routine Description:
Perform a call-back into the SEC simulator to get a memory value
Arguments:
FfsHeader - General purpose data available to every PEIM
PeiServices - General purpose services available to every PEIM.
Returns:
None
**/
{
EFI_STATUS Status;
EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
EMU_THUNK_PPI *Thunk;
UINT64 MemorySize;
EFI_PHYSICAL_ADDRESS MemoryBase;
UINTN Index;
EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;
DEBUG ((EFI_D_ERROR, "Emu Autoscan PEIM Loaded\n"));
//
// Get the PEI UNIX Autoscan PPI
//
Status = PeiServicesLocatePpi (
&gEmuThunkPpiGuid, // GUID
0, // INSTANCE
&PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
(VOID **)&Thunk // PPI
);
ASSERT_EFI_ERROR (Status);
Index = 0;
do {
Status = Thunk->MemoryAutoScan (Index, &MemoryBase, &MemorySize);
if (!EFI_ERROR (Status)) {
Attributes =
(
EFI_RESOURCE_ATTRIBUTE_PRESENT |
EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
);
if (Index == 0) {
//
// Register the memory with the PEI Core
//
Status = PeiServicesInstallPeiMemory (MemoryBase, MemorySize);
ASSERT_EFI_ERROR (Status);
Attributes |= EFI_RESOURCE_ATTRIBUTE_TESTED;
}
BuildResourceDescriptorHob (
EFI_RESOURCE_SYSTEM_MEMORY,
Attributes,
MemoryBase,
MemorySize
);
}
Index++;
} while (!EFI_ERROR (Status));
//
// Build the CPU hob with 36-bit addressing and 16-bits of IO space.
//
BuildCpuHob (36, 16);
return Status;
}

View File

@@ -0,0 +1,58 @@
## @file
# Component description file for EmuAutoScan module
#
# This module abstracts memory auto-scan in a Emu environment.
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = AutoScanPei
FILE_GUID = 2D6F6BCC-9681-8E42-8579-B57DCD0060F0
MODULE_TYPE = PEIM
VERSION_STRING = 1.0
ENTRY_POINT = PeimInitializeAutoScanPei
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
AutoScanPei.c
[Packages]
MdePkg/MdePkg.dec
# MdeModulePkg/MdeModulePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
PeiServicesTablePointerLib
PeiServicesLib
HobLib
BaseMemoryLib
BaseLib
PeimEntryPoint
DebugLib
[Ppis]
gEfiPeiMemoryDiscoveredPpiGuid # PPI ALWAYS_PRODUCED
gEmuThunkPpiGuid # PPI ALWAYS_CONSUMED
[Depex]
gEmuThunkPpiGuid AND gEfiPeiMasterBootModePpiGuid

View File

@@ -0,0 +1,94 @@
/** @file
Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
//
// The package level header files this module uses
//
#include <PiPei.h>
#include <Library/PcdLib.h>
#include <Library/PeiServicesLib.h>
//
// The protocols, PPI and GUID defintions for this module
//
#include <Ppi/MasterBootMode.h>
#include <Ppi/BootInRecoveryMode.h>
//
// The Library classes this module consumes
//
#include <Library/DebugLib.h>
#include <Library/PeimEntryPoint.h>
//
// Module globals
//
EFI_PEI_PPI_DESCRIPTOR mPpiListBootMode = {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiPeiMasterBootModePpiGuid,
NULL
};
EFI_PEI_PPI_DESCRIPTOR mPpiListRecoveryBootMode = {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiPeiBootInRecoveryModePpiGuid,
NULL
};
EFI_STATUS
EFIAPI
InitializeBootMode (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
/*++
Routine Description:
Peform the boot mode determination logic
Arguments:
PeiServices - General purpose services available to every PEIM.
Returns:
Status - EFI_SUCCESS if the boot mode could be set
**/
{
EFI_STATUS Status;
EFI_BOOT_MODE BootMode;
DEBUG ((EFI_D_ERROR, "Emu Boot Mode PEIM Loaded\n"));
BootMode = FixedPcdGet32 (PcdEmuBootMode);
Status = PeiServicesSetBootMode (BootMode);
ASSERT_EFI_ERROR (Status);
Status = PeiServicesInstallPpi (&mPpiListBootMode);
ASSERT_EFI_ERROR (Status);
if (BootMode == BOOT_IN_RECOVERY_MODE) {
Status = PeiServicesInstallPpi (&mPpiListRecoveryBootMode);
ASSERT_EFI_ERROR (Status);
}
return Status;
}

View File

@@ -0,0 +1,59 @@
## @file
# Component description file for BootMode module
#
# This module provides platform specific function to detect boot mode.
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = BootModePei
FILE_GUID = 64196C76-58E3-0B4D-9484-B54F7C4349CA
MODULE_TYPE = PEIM
VERSION_STRING = 1.0
ENTRY_POINT = InitializeBootMode
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
BootModePei.c
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
PeiServicesTablePointerLib
PeiServicesLib
BaseLib
PeimEntryPoint
DebugLib
[Ppis]
gEfiPeiMasterBootModePpiGuid # PPI ALWAYS_PRODUCED
gEfiPeiBootInRecoveryModePpiGuid # PPI SOMETIMES_PRODUCED
[FixedPcd]
gEmulatorPkgTokenSpaceGuid.PcdEmuBootMode
[Depex]
TRUE

View File

@@ -0,0 +1,374 @@
/*++ @file
Emu driver to produce CPU Architectural Protocol.
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "CpuDriver.h"
UINT64 mTimerPeriod;
CPU_ARCH_PROTOCOL_PRIVATE mCpuTemplate = {
CPU_ARCH_PROT_PRIVATE_SIGNATURE,
NULL,
{
EmuFlushCpuDataCache,
EmuEnableInterrupt,
EmuDisableInterrupt,
EmuGetInterruptState,
EmuInit,
EmuRegisterInterruptHandler,
EmuGetTimerValue,
EmuSetMemoryAttributes,
0,
4
},
{
{
CpuMemoryServiceRead,
CpuMemoryServiceWrite
},
{
CpuIoServiceRead,
CpuIoServiceWrite
}
},
TRUE
};
#define EFI_CPU_DATA_MAXIMUM_LENGTH 0x100
//
// Service routines for the driver
//
EFI_STATUS
EFIAPI
EmuFlushCpuDataCache (
IN EFI_CPU_ARCH_PROTOCOL *This,
IN EFI_PHYSICAL_ADDRESS Start,
IN UINT64 Length,
IN EFI_CPU_FLUSH_TYPE FlushType
)
{
if (FlushType == EfiCpuFlushTypeWriteBackInvalidate) {
//
// Only WB flush is supported. We actually need do nothing on Emu emulator
// environment. Classify this to follow EFI spec
//
return EFI_SUCCESS;
}
//
// Other flush types are not supported by Emu emulator
//
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
EmuEnableInterrupt (
IN EFI_CPU_ARCH_PROTOCOL *This
)
{
CPU_ARCH_PROTOCOL_PRIVATE *Private;
Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);
Private->InterruptState = TRUE;
gEmuThunk->EnableInterrupt ();
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
EmuDisableInterrupt (
IN EFI_CPU_ARCH_PROTOCOL *This
)
{
CPU_ARCH_PROTOCOL_PRIVATE *Private;
Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);
Private->InterruptState = FALSE;
gEmuThunk->DisableInterrupt ();
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
EmuGetInterruptState (
IN EFI_CPU_ARCH_PROTOCOL *This,
OUT BOOLEAN *State
)
{
CPU_ARCH_PROTOCOL_PRIVATE *Private;
if (State == NULL) {
return EFI_INVALID_PARAMETER;
}
Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);
*State = Private->InterruptState;
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
EmuInit (
IN EFI_CPU_ARCH_PROTOCOL *This,
IN EFI_CPU_INIT_TYPE InitType
)
{
CPU_ARCH_PROTOCOL_PRIVATE *Private;
Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
EmuRegisterInterruptHandler (
IN EFI_CPU_ARCH_PROTOCOL *This,
IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
)
{
CPU_ARCH_PROTOCOL_PRIVATE *Private;
//
// Do parameter checking for EFI spec conformance
//
if (InterruptType < 0 || InterruptType > 0xff) {
return EFI_UNSUPPORTED;
}
//
// Do nothing for Emu emulation
//
Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
EmuGetTimerValue (
IN EFI_CPU_ARCH_PROTOCOL *This,
IN UINT32 TimerIndex,
OUT UINT64 *TimerValue,
OUT UINT64 *TimerPeriod OPTIONAL
)
{
if (TimerValue == NULL) {
return EFI_INVALID_PARAMETER;
}
if (TimerIndex != 0) {
return EFI_INVALID_PARAMETER;
}
*TimerValue = gEmuThunk->QueryPerformanceCounter ();
if (TimerPeriod != NULL) {
*TimerPeriod = mTimerPeriod;
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
EmuSetMemoryAttributes (
IN EFI_CPU_ARCH_PROTOCOL *This,
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN UINT64 Attributes
)
{
CPU_ARCH_PROTOCOL_PRIVATE *Private;
//
// Check for invalid parameter for Spec conformance
//
if (Length == 0) {
return EFI_INVALID_PARAMETER;
}
//
// Do nothing for Nt32 emulation
//
Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);
return EFI_UNSUPPORTED;
}
/**
Logs SMBIOS record.
@param Smbios Pointer to SMBIOS protocol instance.
@param Buffer Pointer to the data buffer.
**/
VOID
LogSmbiosData (
IN EFI_SMBIOS_PROTOCOL *Smbios,
IN UINT8 *Buffer
)
{
EFI_STATUS Status;
EFI_SMBIOS_HANDLE SmbiosHandle;
SmbiosHandle = 0;
Status = Smbios->Add (
Smbios,
NULL,
&SmbiosHandle,
(EFI_SMBIOS_TABLE_HEADER*)Buffer
);
ASSERT_EFI_ERROR (Status);
}
VOID
CpuUpdateSmbios (
VOID
)
{
EFI_STATUS Status;
UINT32 TotalSize;
EFI_SMBIOS_PROTOCOL *Smbios;
EFI_HII_HANDLE HiiHandle;
STRING_REF Token;
UINTN CpuVerStrLen;
EFI_STRING CpuVerStr;
SMBIOS_TABLE_TYPE4 *SmbiosRecord;
CHAR8 *OptionalStrStart;
//
// Locate Smbios protocol.
//
Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&Smbios);
if (EFI_ERROR (Status)) {
return;
}
//
// Initialize strings to HII database
//
HiiHandle = HiiAddPackages (
&gEfiCallerIdGuid,
NULL,
CpuStrings,
NULL
);
ASSERT (HiiHandle != NULL);
Token = STRING_TOKEN (STR_PROCESSOR_VERSION);
CpuVerStr = HiiGetPackageString(&gEfiCallerIdGuid, Token, NULL);
CpuVerStrLen = StrLen(CpuVerStr);
ASSERT (CpuVerStrLen <= SMBIOS_STRING_MAX_LENGTH);
TotalSize = sizeof(SMBIOS_TABLE_TYPE4) + CpuVerStrLen + 1 + 1;
SmbiosRecord = AllocatePool(TotalSize);
ZeroMem(SmbiosRecord, TotalSize);
SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION;
SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE4);
//
// Make handle chosen by smbios protocol.add automatically.
//
SmbiosRecord->Hdr.Handle = 0;
//
// Processor version is the 1st string.
//
SmbiosRecord->ProcessorVersion = 1;
//
// Store CPU frequency data record to data hub - It's an emulator so make up a value
//
SmbiosRecord->CurrentSpeed = 1234;
OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
UnicodeStrToAsciiStr(CpuVerStr, OptionalStrStart);
//
// Now we have got the full smbios record, call smbios protocol to add this record.
//
LogSmbiosData(Smbios, (UINT8 *) SmbiosRecord);
FreePool (SmbiosRecord);
}
/**
Callback function for idle events.
@param Event Event whose notification function is being invoked.
@param Context The pointer to the notification function's context,
which is implementation-dependent.
**/
VOID
EFIAPI
IdleLoopEventCallback (
IN EFI_EVENT Event,
IN VOID *Context
)
{
gEmuThunk->CpuSleep ();
}
EFI_STATUS
EFIAPI
InitializeCpu (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
UINT64 Frequency;
EFI_EVENT IdleLoopEvent;
//
// Retrieve the frequency of the performance counter in Hz.
//
Frequency = gEmuThunk->QueryPerformanceFrequency ();
//
// Convert frequency in Hz to a clock period in femtoseconds.
//
mTimerPeriod = DivU64x64Remainder (1000000000000000ULL, Frequency, NULL);
CpuUpdateSmbios ();
CpuMpServicesInit ();
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
IdleLoopEventCallback,
NULL,
&gIdleLoopEventGuid,
&IdleLoopEvent
);
ASSERT_EFI_ERROR (Status);
Status = gBS->InstallMultipleProtocolInterfaces (
&mCpuTemplate.Handle,
&gEfiCpuArchProtocolGuid, &mCpuTemplate.Cpu,
&gEfiCpuIo2ProtocolGuid, &mCpuTemplate.CpuIo,
NULL
);
ASSERT_EFI_ERROR (Status);
return Status;
}

View File

@@ -0,0 +1,76 @@
## @file
# Component description file for Cpu module.
#
# This CPU module abstracts the interrupt subsystem of a platform and the CPU-specific setjump-long pair.
#
# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = Cpu
FILE_GUID = f3794b60-8985-11db-8e53-0040d02b1835
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = InitializeCpu
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
CpuIo.c
Cpu.c
CpuDriver.h
Strings.uni
MpService.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
IntelFrameworkPkg/IntelFrameworkPkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
UefiBootServicesTableLib
MemoryAllocationLib
BaseMemoryLib
UefiDriverEntryPoint
UefiLib
HiiLib
DebugLib
BaseLib
EmuThunkLib
PcdLib
[Protocols]
gEmuIoThunkProtocolGuid # PROTOCOL_NOTIFY SOMETIMES_CONSUMED
gEfiSmbiosProtocolGuid # PROTOCOL SOMETIMES_CONSUMED
gEfiHiiProtocolGuid # PROTOCOL SOMETIMES_CONSUMED
gEfiCpuIo2ProtocolGuid # PROTOCOL ALWAYS_PRODUCED
gEfiCpuArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED
gEmuThreadThunkProtocolGuid
gEfiMpServiceProtocolGuid
[Guids]
gIdleLoopEventGuid ## CONSUMES ## GUID
[Pcd]
gEmulatorPkgTokenSpaceGuid.PcdEmuMpServicesPollingInterval
[Depex]
gEfiSmbiosProtocolGuid

View File

@@ -0,0 +1,246 @@
/*++ @file
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_
#define _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_
#include <FrameworkDxe.h>
#include <IndustryStandard/SmBios.h>
#include <Protocol/Cpu.h>
#include <Protocol/Smbios.h>
#include <Protocol/FrameworkHii.h>
#include <Protocol/MpService.h>
#include <Protocol/EmuThread.h>
#include <Protocol/CpuIo2.h>
#include <Guid/DataHubRecords.h>
#include <Guid/IdleLoopEvent.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/HiiLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/EmuThunkLib.h>
#include <Library/UefiLib.h>
#include <Library/PcdLib.h>
extern UINT8 CpuStrings[];
//
// Internal Data Structures
//
#define CPU_ARCH_PROT_PRIVATE_SIGNATURE SIGNATURE_32 ('c', 'a', 'p', 'd')
typedef struct {
UINTN Signature;
EFI_HANDLE Handle;
EFI_CPU_ARCH_PROTOCOL Cpu;
EFI_CPU_IO2_PROTOCOL CpuIo;
//
// Local Data for CPU interface goes here
//
BOOLEAN InterruptState;
} CPU_ARCH_PROTOCOL_PRIVATE;
#define CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS(a) \
CR (a, \
CPU_ARCH_PROTOCOL_PRIVATE, \
Cpu, \
CPU_ARCH_PROT_PRIVATE_SIGNATURE \
)
typedef enum {
CPU_STATE_IDLE,
CPU_STATE_BLOCKED,
CPU_STATE_READY,
CPU_STATE_BUSY,
CPU_STATE_FINISHED
} PROCESSOR_STATE;
//
// Define Individual Processor Data block.
//
typedef struct {
EFI_PROCESSOR_INFORMATION Info;
EFI_AP_PROCEDURE Procedure;
VOID *Parameter;
VOID *StateLock;
VOID *ProcedureLock;
PROCESSOR_STATE State;
EFI_EVENT CheckThisAPEvent;
} PROCESSOR_DATA_BLOCK;
//
// Define MP data block which consumes individual processor block.
//
typedef struct {
UINTN NumberOfProcessors;
UINTN NumberOfEnabledProcessors;
EFI_EVENT CheckAllAPsEvent;
EFI_EVENT WaitEvent;
UINTN FinishCount;
UINTN StartCount;
EFI_AP_PROCEDURE Procedure;
VOID *ProcedureArgument;
BOOLEAN SingleThread;
UINTN StartedNumber;
PROCESSOR_DATA_BLOCK *ProcessorData;
UINTN Timeout;
UINTN *FailedList;
UINTN FailedListIndex;
BOOLEAN TimeoutActive;
} MP_SYSTEM_DATA;
EFI_STATUS
EFIAPI
CpuMemoryServiceRead (
IN EFI_CPU_IO2_PROTOCOL *This,
IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
);
EFI_STATUS
EFIAPI
CpuMemoryServiceWrite (
IN EFI_CPU_IO2_PROTOCOL *This,
IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
);
EFI_STATUS
EFIAPI
CpuIoServiceRead (
IN EFI_CPU_IO2_PROTOCOL *This,
IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
IN UINT64 UserAddress,
IN UINTN Count,
IN OUT VOID *UserBuffer
);
EFI_STATUS
EFIAPI
CpuIoServiceWrite (
IN EFI_CPU_IO2_PROTOCOL *This,
IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
IN UINT64 UserAddress,
IN UINTN Count,
IN OUT VOID *UserBuffer
);
EFI_STATUS
EFIAPI
InitializeCpu (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
EFI_STATUS
EFIAPI
EmuFlushCpuDataCache (
IN EFI_CPU_ARCH_PROTOCOL *This,
IN EFI_PHYSICAL_ADDRESS Start,
IN UINT64 Length,
IN EFI_CPU_FLUSH_TYPE FlushType
);
EFI_STATUS
EFIAPI
EmuEnableInterrupt (
IN EFI_CPU_ARCH_PROTOCOL *This
);
EFI_STATUS
EFIAPI
EmuDisableInterrupt (
IN EFI_CPU_ARCH_PROTOCOL *This
);
EFI_STATUS
EFIAPI
EmuGetInterruptState (
IN EFI_CPU_ARCH_PROTOCOL *This,
OUT BOOLEAN *State
);
EFI_STATUS
EFIAPI
EmuInit (
IN EFI_CPU_ARCH_PROTOCOL *This,
IN EFI_CPU_INIT_TYPE InitType
);
EFI_STATUS
EFIAPI
EmuRegisterInterruptHandler (
IN EFI_CPU_ARCH_PROTOCOL *This,
IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
);
EFI_STATUS
EFIAPI
EmuGetTimerValue (
IN EFI_CPU_ARCH_PROTOCOL *This,
IN UINT32 TimerIndex,
OUT UINT64 *TimerValue,
OUT UINT64 *TimerPeriod OPTIONAL
);
EFI_STATUS
EFIAPI
EmuSetMemoryAttributes (
IN EFI_CPU_ARCH_PROTOCOL *This,
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN UINT64 Attributes
);
EFI_STATUS
CpuMpServicesInit (
VOID
);
EFI_STATUS
EFIAPI
CpuMpServicesWhoAmI (
IN EFI_MP_SERVICES_PROTOCOL *This,
OUT UINTN *ProcessorNumber
);
extern EFI_MP_SERVICES_PROTOCOL mMpSercicesTemplate;
#endif

View File

@@ -0,0 +1,333 @@
/*++ @file
This is the code that publishes the CPU I/O Protocol.
The intent herein is to have a single I/O service that can load
as early as possible, extend into runtime, and be layered upon by
the implementations of architectural protocols and the PCI Root
Bridge I/O Protocol.
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <FrameworkDxe.h>
#include <Protocol/Cpu.h>
#include <Protocol/DataHub.h>
#include <Guid/DataHubRecords.h>
#include <Protocol/CpuIo2.h>
#include <Protocol/FrameworkHii.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/HiiLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <CpuDriver.h>
#define IA32_MAX_IO_ADDRESS 0xFFFF
#define IA32_MAX_MEM_ADDRESS 0xFFFFFFFF
EFI_STATUS
CpuIoCheckAddressRange (
IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN VOID *Buffer,
IN UINT64 Limit
);
EFI_STATUS
EFIAPI
CpuMemoryServiceRead (
IN EFI_CPU_IO2_PROTOCOL *This,
IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
)
/*++
Routine Description:
Perform the Memory Access Read service for the CPU I/O Protocol
Arguments:
Pointer to an instance of the CPU I/O Protocol
Width of the Memory Access
Address of the Memory access
Count of the number of accesses to perform
Pointer to the buffer to read or write from memory
Returns:
Status
EFI_SUCCESS - The data was read from or written to the EFI
System.
EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
EFI_INVALID_PARAMETER - Buffer is NULL.
EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
EFI_UNSUPPORTED - The address range specified by Address, Width,
and Count is not valid for this EFI System.
**/
{
EFI_STATUS Status;
if (!Buffer) {
return EFI_INVALID_PARAMETER;
}
Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Do nothing for Nt32 version
//
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
CpuMemoryServiceWrite (
IN EFI_CPU_IO2_PROTOCOL *This,
IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
)
/*++
Routine Description:
Perform the Memory Access Read service for the CPU I/O Protocol
Arguments:
Pointer to an instance of the CPU I/O Protocol
Width of the Memory Access
Address of the Memory access
Count of the number of accesses to perform
Pointer to the buffer to read or write from memory
Returns:
Status
EFI_SUCCESS - The data was read from or written to the EFI System.
EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
EFI_INVALID_PARAMETER - Buffer is NULL.
EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
EFI_UNSUPPORTED - The address range specified by Address, Width, and
Count is not valid for this EFI System.
**/
{
EFI_STATUS Status;
if (!Buffer) {
return EFI_INVALID_PARAMETER;
}
Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Do nothing for Nt32 version
//
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
CpuIoServiceRead (
IN EFI_CPU_IO2_PROTOCOL *This,
IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
IN UINT64 UserAddress,
IN UINTN Count,
IN OUT VOID *UserBuffer
)
/*++
Routine Description:
This is the service that implements the I/O read
Arguments:
Pointer to an instance of the CPU I/O Protocol
Width of the Memory Access
Address of the I/O access
Count of the number of accesses to perform
Pointer to the buffer to read or write from I/O space
Returns:
Status
EFI_SUCCESS - The data was read from or written to the EFI System.
EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
EFI_INVALID_PARAMETER - Buffer is NULL.
EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
EFI_UNSUPPORTED - The address range specified by Address, Width, and
Count is not valid for this EFI System.
**/
{
UINTN Address;
EFI_STATUS Status;
if (!UserBuffer) {
return EFI_INVALID_PARAMETER;
}
Address = (UINTN) UserAddress;
if (Width >= EfiCpuIoWidthMaximum) {
return EFI_INVALID_PARAMETER;
}
Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Do nothing for Nt32 version
//
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
CpuIoServiceWrite (
IN EFI_CPU_IO2_PROTOCOL *This,
IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
IN UINT64 UserAddress,
IN UINTN Count,
IN OUT VOID *UserBuffer
)
/*++
Routine Description:
This is the service that implements the I/O Write
Arguments:
Pointer to an instance of the CPU I/O Protocol
Width of the Memory Access
Address of the I/O access
Count of the number of accesses to perform
Pointer to the buffer to read or write from I/O space
Returns:
Status
Status
EFI_SUCCESS - The data was read from or written to the EFI System.
EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
EFI_INVALID_PARAMETER - Buffer is NULL.
EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
EFI_UNSUPPORTED - The address range specified by Address, Width, and
Count is not valid for this EFI System.
**/
{
UINTN Address;
EFI_STATUS Status;
if (!UserBuffer) {
return EFI_INVALID_PARAMETER;
}
Address = (UINTN) UserAddress;
if (Width >= EfiCpuIoWidthMaximum) {
return EFI_INVALID_PARAMETER;
}
Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Do nothing for Nt32 version
//
return EFI_SUCCESS;
}
/*++
Routine Description:
Arguments:
Width - TODO: add argument description
Address - TODO: add argument description
Count - TODO: add argument description
Buffer - TODO: add argument description
Limit - TODO: add argument description
Returns:
EFI_UNSUPPORTED - TODO: Add description for return value
EFI_UNSUPPORTED - TODO: Add description for return value
EFI_UNSUPPORTED - TODO: Add description for return value
EFI_SUCCESS - TODO: Add description for return value
**/
EFI_STATUS
CpuIoCheckAddressRange (
IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN VOID *Buffer,
IN UINT64 Limit
)
{
UINTN AlignMask;
if (Address > Limit) {
return EFI_UNSUPPORTED;
}
//
// For FiFo type, the target address won't increase during the access, so treat count as 1
//
if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {
Count = 1;
}
Width = Width & 0x03;
if (Address - 1 + (1 << Width) * Count > Limit) {
return EFI_UNSUPPORTED;
}
AlignMask = (1 << Width) - 1;
if ((UINTN) Buffer & AlignMask) {
return EFI_UNSUPPORTED;
}
return EFI_SUCCESS;
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -0,0 +1,354 @@
/**@file
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
ComponentName.c
Abstract:
**/
#include "EmuBlockIo.h"
//
// EFI Component Name Functions
//
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified
in RFC 4646 or ISO 639-2 language code format.
@param DriverName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
driver specified by This in the language
specified by Language.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
EmuBlockIoComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param ControllerHandle[in] The handle of a controller that the driver
specified by This is managing. This handle
specifies the controller whose name is to be
returned.
@param ChildHandle[in] The handle of the child controller to retrieve
the name of. This is an optional parameter that
may be NULL. It will be NULL for device
drivers. It will also be NULL for a bus drivers
that wish to retrieve the name of the bus
controller. It will not be NULL for a bus
driver that wishes to retrieve the name of a
child controller.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified in
RFC 4646 or ISO 639-2 language code format.
@param ControllerName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
controller specified by ControllerHandle and
ChildHandle in the language specified by
Language from the point of view of the driver
specified by This.
@retval EFI_SUCCESS The Unicode string for the user readable name in
the language specified by Language for the
driver specified by This was returned in
DriverName.
@retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
EmuBlockIoComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
);
//
// EFI Component Name Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gEmuBlockIoComponentName = {
EmuBlockIoComponentNameGetDriverName,
EmuBlockIoComponentNameGetControllerName,
"eng"
};
//
// EFI Component Name 2 Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuBlockIoComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) EmuBlockIoComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) EmuBlockIoComponentNameGetControllerName,
"en"
};
EFI_UNICODE_STRING_TABLE mEmuBlockIoDriverNameTable[] = {
{ "eng;en", L"Emu Block I/O Driver" },
{ NULL , NULL }
};
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified
in RFC 4646 or ISO 639-2 language code format.
@param DriverName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
driver specified by This in the language
specified by Language.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
EmuBlockIoComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
)
{
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mEmuBlockIoDriverNameTable,
DriverName,
(BOOLEAN)(This == &gEmuBlockIoComponentName)
);
}
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param ControllerHandle[in] The handle of a controller that the driver
specified by This is managing. This handle
specifies the controller whose name is to be
returned.
@param ChildHandle[in] The handle of the child controller to retrieve
the name of. This is an optional parameter that
may be NULL. It will be NULL for device
drivers. It will also be NULL for a bus drivers
that wish to retrieve the name of the bus
controller. It will not be NULL for a bus
driver that wishes to retrieve the name of a
child controller.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified in
RFC 4646 or ISO 639-2 language code format.
@param ControllerName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
controller specified by ControllerHandle and
ChildHandle in the language specified by
Language from the point of view of the driver
specified by This.
@retval EFI_SUCCESS The Unicode string for the user readable name in
the language specified by Language for the
driver specified by This was returned in
DriverName.
@retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
EmuBlockIoComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
{
EFI_STATUS Status;
EFI_BLOCK_IO_PROTOCOL *BlockIo;
EMU_BLOCK_IO_PRIVATE *Private;
//
// This is a device driver, so ChildHandle must be NULL.
//
if (ChildHandle != NULL) {
return EFI_UNSUPPORTED;
}
//
// Make sure this driver is currently managing ControllerHandle
//
Status = EfiTestManagedDevice (
ControllerHandle,
gEmuBlockIoDriverBinding.DriverBindingHandle,
&gEmuIoThunkProtocolGuid
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
//
// Get our context back
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiBlockIoProtocolGuid,
(VOID **)&BlockIo,
gEmuBlockIoDriverBinding.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
Private->ControllerNameTable,
ControllerName,
(BOOLEAN)(This == &gEmuBlockIoComponentName)
);
}

View File

@@ -0,0 +1,338 @@
/**@file
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
DriverConfiguration.c
Abstract:
**/
#include "EmuBlockIo.h"
//
// EFI Driver Configuration Functions
//
EFI_STATUS
EFIAPI
EmuBlockIoDriverConfigurationSetOptions (
IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
);
EFI_STATUS
EFIAPI
EmuBlockIoDriverConfigurationOptionsValid (
IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL
);
EFI_STATUS
EFIAPI
EmuBlockIoDriverConfigurationForceDefaults (
IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN UINT32 DefaultType,
OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
);
//
// EFI Driver Configuration Protocol
//
EFI_DRIVER_CONFIGURATION_PROTOCOL gEmuBlockIoDriverConfiguration = {
EmuBlockIoDriverConfigurationSetOptions,
EmuBlockIoDriverConfigurationOptionsValid,
EmuBlockIoDriverConfigurationForceDefaults,
"eng"
};
/*++
Routine Description:
Allows the user to set controller specific options for a controller that a
driver is currently managing.
Arguments:
This - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.
ControllerHandle - The handle of the controller to set options on.
ChildHandle - The handle of the child controller to set options on. This
is an optional parameter that may be NULL. It will be NULL
for device drivers, and for a bus drivers that wish to set
options for the bus controller. It will not be NULL for a
bus driver that wishes to set options for one of its child
controllers.
Language - A pointer to a three character ISO 639-2 language identifier.
This is the language of the user interface that should be
presented to the user, and it must match one of the languages
specified in SupportedLanguages. The number of languages
supported by a driver is up to the driver writer.
ActionRequired - A pointer to the action that the calling agent is required
to perform when this function returns. See "Related
Definitions" for a list of the actions that the calling
agent is required to perform prior to accessing
ControllerHandle again.
Returns:
EFI_SUCCESS - The driver specified by This successfully set the
configuration options for the controller specified
by ControllerHandle..
EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
EFI_INVALID_PARAMETER - ActionRequired is NULL.
EFI_UNSUPPORTED - The driver specified by This does not support setting
configuration options for the controller specified by
ControllerHandle and ChildHandle.
EFI_UNSUPPORTED - The driver specified by This does not support the
language specified by Language.
EFI_DEVICE_ERROR - A device error occurred while attempt to set the
configuration options for the controller specified
by ControllerHandle and ChildHandle.
EFI_OUT_RESOURCES - There are not enough resources available to set the
configuration options for the controller specified
by ControllerHandle and ChildHandle.
--*/
EFI_STATUS
EFIAPI
EmuBlockIoDriverConfigurationSetOptions (
IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
)
{
EFI_STATUS Status;
EFI_BLOCK_IO_PROTOCOL *BlockIo;
CHAR8 *SupportedLanguage;
SupportedLanguage = This->SupportedLanguages;
Status = EFI_UNSUPPORTED;
while (*SupportedLanguage != 0) {
if (AsciiStrnCmp (Language, SupportedLanguage, 3) == 0) {
Status = EFI_SUCCESS;
}
SupportedLanguage += 3;
}
if (EFI_ERROR (Status)) {
return Status;
}
if (ActionRequired == NULL || ControllerHandle == NULL) {
return EFI_INVALID_PARAMETER;
}
if (ChildHandle != NULL) {
return EFI_UNSUPPORTED;
}
//
// Validate controller handle
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
(VOID **)&BlockIo,
gEmuBlockIoDriverBinding.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (!EFI_ERROR (Status)) {
gBS->CloseProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
gEmuBlockIoDriverBinding.DriverBindingHandle,
ControllerHandle
);
return EFI_UNSUPPORTED;
}
if (Status == EFI_UNSUPPORTED) {
return Status;
} else if (Status != EFI_ALREADY_STARTED) {
return EFI_INVALID_PARAMETER;
}
*ActionRequired = EfiDriverConfigurationActionNone;
return EFI_SUCCESS;
}
/*++
Routine Description:
Tests to see if a controller's current configuration options are valid.
Arguments:
This - A pointer to the EFI_DRIVER_CONFIGURATION_PROTOCOL instance.
ControllerHandle - The handle of the controller to test if it's current
configuration options are valid.
ChildHandle - The handle of the child controller to test if it's current
configuration options are valid. This is an optional
parameter that may be NULL. It will be NULL for device
drivers. It will also be NULL for a bus drivers that wish
to test the configuration options for the bus controller.
It will not be NULL for a bus driver that wishes to test
configuration options for one of its child controllers.
Returns:
EFI_SUCCESS - The controller specified by ControllerHandle and
ChildHandle that is being managed by the driver
specified by This has a valid set of configuration
options.
EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
EFI_UNSUPPORTED - The driver specified by This is not currently
managing the controller specified by ControllerHandle
and ChildHandle.
EFI_DEVICE_ERROR - The controller specified by ControllerHandle and
ChildHandle that is being managed by the driver
specified by This has an invalid set of configuration
options.
--*/
EFI_STATUS
EFIAPI
EmuBlockIoDriverConfigurationOptionsValid (
IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL
)
{
EFI_STATUS Status;
EFI_BLOCK_IO_PROTOCOL *BlockIo;
if (ChildHandle != NULL) {
return EFI_UNSUPPORTED;
}
if (ControllerHandle == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Validate controller handle
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
(VOID **)&BlockIo,
gEmuBlockIoDriverBinding.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (!EFI_ERROR (Status)) {
gBS->CloseProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
gEmuBlockIoDriverBinding.DriverBindingHandle,
ControllerHandle
);
return EFI_UNSUPPORTED;
}
if (Status == EFI_UNSUPPORTED) {
return Status;
} else if (Status != EFI_ALREADY_STARTED) {
return EFI_INVALID_PARAMETER;
}
return EFI_SUCCESS;
}
/*++
Routine Description:
Forces a driver to set the default configuration options for a controller.
Arguments:
This - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.
ControllerHandle - The handle of the controller to force default configuration options on.
ChildHandle - The handle of the child controller to force default configuration options on This is an optional parameter that may be NULL. It will be NULL for device drivers. It will also be NULL for a bus drivers that wish to force default configuration options for the bus controller. It will not be NULL for a bus driver that wishes to force default configuration options for one of its child controllers.
DefaultType - The type of default configuration options to force on the controller specified by ControllerHandle and ChildHandle. See Table 9-1 for legal values. A DefaultType of 0x00000000 must be supported by this protocol.
ActionRequired - A pointer to the action that the calling agent is required to perform when this function returns. See "Related Definitions" in Section 9.1for a list of the actions that the calling agent is required to perform prior to accessing ControllerHandle again.
Returns:
EFI_SUCCESS - The driver specified by This successfully forced the default configuration options on the controller specified by ControllerHandle and ChildHandle.
EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
EFI_INVALID_PARAMETER - ActionRequired is NULL.
EFI_UNSUPPORTED - The driver specified by This does not support forcing the default configuration options on the controller specified by ControllerHandle and ChildHandle.
EFI_UNSUPPORTED - The driver specified by This does not support the configuration type specified by DefaultType.
EFI_DEVICE_ERROR - A device error occurred while attempt to force the default configuration options on the controller specified by ControllerHandle and ChildHandle.
EFI_OUT_RESOURCES - There are not enough resources available to force the default configuration options on the controller specified by ControllerHandle and ChildHandle.
--*/
EFI_STATUS
EFIAPI
EmuBlockIoDriverConfigurationForceDefaults (
IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN UINT32 DefaultType,
OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
)
{
EFI_STATUS Status;
EFI_BLOCK_IO_PROTOCOL *BlockIo;
if (ChildHandle != NULL) {
return EFI_UNSUPPORTED;
}
if (ActionRequired == NULL || ControllerHandle == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Validate controller handle
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
(VOID **)&BlockIo,
gEmuBlockIoDriverBinding.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (!EFI_ERROR (Status)) {
gBS->CloseProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
gEmuBlockIoDriverBinding.DriverBindingHandle,
ControllerHandle
);
return EFI_UNSUPPORTED;
}
if (Status == EFI_UNSUPPORTED) {
return Status;
} else if (Status != EFI_ALREADY_STARTED) {
return EFI_INVALID_PARAMETER;
}
*ActionRequired = EfiDriverConfigurationActionNone;
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,219 @@
/**@file
Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
DriverDiagnostics.c
Abstract:
**/
#include "EmuBlockIo.h"
//
// EFI Driver Diagnostics Functions
//
EFI_STATUS
EFIAPI
EmuBlockIoDriverDiagnosticsRunDiagnostics (
IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,
IN CHAR8 *Language,
OUT EFI_GUID **ErrorType,
OUT UINTN *BufferSize,
OUT CHAR16 **Buffer
);
//
// EFI Driver Diagnostics Protocol
//
EFI_DRIVER_DIAGNOSTICS_PROTOCOL gEmuBlockIoDriverDiagnostics = {
EmuBlockIoDriverDiagnosticsRunDiagnostics,
"eng"
};
//
// EFI Driver Diagnostics 2 Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gEmuBlockIoDriverDiagnostics2 = {
(EFI_DRIVER_DIAGNOSTICS2_RUN_DIAGNOSTICS) EmuBlockIoDriverDiagnosticsRunDiagnostics,
"en"
};
EFI_STATUS
EFIAPI
EmuBlockIoDriverDiagnosticsRunDiagnostics (
IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,
IN CHAR8 *Language,
OUT EFI_GUID **ErrorType,
OUT UINTN *BufferSize,
OUT CHAR16 **Buffer
)
/*++
Routine Description:
Runs diagnostics on a controller.
Arguments:
This - A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL instance.
ControllerHandle - The handle of the controller to run diagnostics on.
ChildHandle - The handle of the child controller to run diagnostics on
This is an optional parameter that may be NULL. It will
be NULL for device drivers. It will also be NULL for a
bus drivers that wish to run diagnostics on the bus
controller. It will not be NULL for a bus driver that
wishes to run diagnostics on one of its child controllers.
DiagnosticType - Indicates type of diagnostics to perform on the controller
specified by ControllerHandle and ChildHandle. See
"Related Definitions" for the list of supported types.
Language - A pointer to a three character ISO 639-2 language
identifier or a Null-terminated ASCII string array indicating
the language. This is the language in which the optional
error message should be returned in Buffer, and it must
match one of the languages specified in SupportedLanguages.
The number of languages supported by a driver is up to
the driver writer.
ErrorType - A GUID that defines the format of the data returned in
Buffer.
BufferSize - The size, in bytes, of the data returned in Buffer.
Buffer - A buffer that contains a Null-terminated Unicode string
plus some additional data whose format is defined by
ErrorType. Buffer is allocated by this function with
AllocatePool(), and it is the caller's responsibility
to free it with a call to FreePool().
Returns:
EFI_SUCCESS - The controller specified by ControllerHandle and
ChildHandle passed the diagnostic.
EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
EFI_INVALID_PARAMETER - Language is NULL.
EFI_INVALID_PARAMETER - ErrorType is NULL.
EFI_INVALID_PARAMETER - BufferType is NULL.
EFI_INVALID_PARAMETER - Buffer is NULL.
EFI_UNSUPPORTED - The driver specified by This does not support
running diagnostics for the controller specified
by ControllerHandle and ChildHandle.
EFI_UNSUPPORTED - The driver specified by This does not support the
type of diagnostic specified by DiagnosticType.
EFI_UNSUPPORTED - The driver specified by This does not support the
language specified by Language.
EFI_OUT_OF_RESOURCES - There are not enough resources available to complete
the diagnostics.
EFI_OUT_OF_RESOURCES - There are not enough resources available to return
the status information in ErrorType, BufferSize,
and Buffer.
EFI_DEVICE_ERROR - The controller specified by ControllerHandle and
ChildHandle did not pass the diagnostic.
--*/
{
EFI_STATUS Status;
EFI_BLOCK_IO_PROTOCOL *BlockIo;
CHAR8 *SupportedLanguages;
BOOLEAN Iso639Language;
BOOLEAN Found;
UINTN Index;
if (Language == NULL ||
ErrorType == NULL ||
Buffer == NULL ||
ControllerHandle == NULL ||
BufferSize == NULL) {
return EFI_INVALID_PARAMETER;
}
SupportedLanguages = This->SupportedLanguages;
Iso639Language = (BOOLEAN)(This == &gEmuBlockIoDriverDiagnostics);
//
// Make sure Language is in the set of Supported Languages
//
Found = FALSE;
while (*SupportedLanguages != 0) {
if (Iso639Language) {
if (CompareMem (Language, SupportedLanguages, 3) == 0) {
Found = TRUE;
break;
}
SupportedLanguages += 3;
} else {
for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);
if ((AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) && (Language[Index] == 0)) {
Found = TRUE;
break;
}
SupportedLanguages += Index;
for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);
}
}
//
// If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED
//
if (!Found) {
return EFI_UNSUPPORTED;
}
*ErrorType = NULL;
*BufferSize = 0;
if (DiagnosticType != EfiDriverDiagnosticTypeStandard) {
*ErrorType = &gEfiBlockIoProtocolGuid;
*BufferSize = 0x60;
Buffer = AllocatePool ((UINTN) (*BufferSize));
CopyMem (*Buffer, L"Windows Block I/O Driver Diagnostics Failed\n", *BufferSize);
return EFI_DEVICE_ERROR;
}
//
// This is a device driver, so ChildHandle must be NULL.
//
if (ChildHandle != NULL) {
return EFI_UNSUPPORTED;
}
//
// Validate controller handle
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
(VOID **)&BlockIo,
gEmuBlockIoDriverBinding.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (!EFI_ERROR (Status)) {
gBS->CloseProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
gEmuBlockIoDriverBinding.DriverBindingHandle,
ControllerHandle
);
return EFI_UNSUPPORTED;
}
if (Status == EFI_UNSUPPORTED) {
return Status;
} else if (Status != EFI_ALREADY_STARTED) {
return EFI_INVALID_PARAMETER;
}
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,747 @@
/**@file
Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
bbe
**/
#include "EmuBlockIo.h"
/**
Reset the block device hardware.
@param[in] This Indicates a pointer to the calling context.
@param[in] ExtendedVerification Indicates that the driver may perform a more
exhausive verfication operation of the device
during reset.
@retval EFI_SUCCESS The device was reset.
@retval EFI_DEVICE_ERROR The device is not functioning properly and could
not be reset.
**/
EFI_STATUS
EFIAPI
EmuBlockIo2Reset (
IN EFI_BLOCK_IO2_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
{
EFI_STATUS Status;
EMU_BLOCK_IO_PRIVATE *Private;
EFI_TPL OldTpl;
Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
Status = Private->Io->Reset (Private->Io, ExtendedVerification);
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Read BufferSize bytes from Lba into Buffer.
This function reads the requested number of blocks from the device. All the
blocks are read, or an error is returned.
If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_or EFI_MEDIA_CHANGED is returned and
non-blocking I/O is being used, the Event associated with this request will
not be signaled.
@param[in] This Indicates a pointer to the calling context.
@param[in] MediaId Id of the media, changes every time the media is
replaced.
@param[in] Lba The starting Logical Block Address to read from.
@param[in, out] Token A pointer to the token associated with the transaction.
@param[in] BufferSize Size of Buffer, must be a multiple of device block size.
@param[out] Buffer A pointer to the destination buffer for the data. The
caller is responsible for either having implicit or
explicit ownership of the buffer.
@retval EFI_SUCCESS The read request was queued if Token->Event is
not NULL.The data was read correctly from the
device if the Token->Event is NULL.
@retval EFI_DEVICE_ERROR The device reported an error while performing
the read.
@retval EFI_NO_MEDIA There is no media in the device.
@retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
@retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the
intrinsic block size of the device.
@retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
or the buffer is not on proper alignment.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
of resources.
**/
EFI_STATUS
EFIAPI
EmuBlockIo2ReadBlocksEx (
IN EFI_BLOCK_IO2_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA LBA,
IN OUT EFI_BLOCK_IO2_TOKEN *Token,
IN UINTN BufferSize,
OUT VOID *Buffer
)
{
EFI_STATUS Status;
EMU_BLOCK_IO_PRIVATE *Private;
EFI_TPL OldTpl;
Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
Status = Private->Io->ReadBlocks (Private->Io, MediaId, LBA, Token, BufferSize, Buffer);
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Write BufferSize bytes from Lba into Buffer.
This function writes the requested number of blocks to the device. All blocks
are written, or an error is returned.If EFI_DEVICE_ERROR, EFI_NO_MEDIA,
EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED is returned and non-blocking I/O is
being used, the Event associated with this request will not be signaled.
@param[in] This Indicates a pointer to the calling context.
@param[in] MediaId The media ID that the write request is for.
@param[in] Lba The starting logical block address to be written. The
caller is responsible for writing to only legitimate
locations.
@param[in, out] Token A pointer to the token associated with the transaction.
@param[in] BufferSize Size of Buffer, must be a multiple of device block size.
@param[in] Buffer A pointer to the source buffer for the data.
@retval EFI_SUCCESS The write request was queued if Event is not NULL.
The data was written correctly to the device if
the Event is NULL.
@retval EFI_WRITE_PROTECTED The device can not be written to.
@retval EFI_NO_MEDIA There is no media in the device.
@retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
@retval EFI_DEVICE_ERROR The device reported an error while performing the write.
@retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
@retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
or the buffer is not on proper alignment.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
of resources.
**/
EFI_STATUS
EFIAPI
EmuBlockIo2WriteBlocksEx (
IN EFI_BLOCK_IO2_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA LBA,
IN OUT EFI_BLOCK_IO2_TOKEN *Token,
IN UINTN BufferSize,
IN VOID *Buffer
)
{
EFI_STATUS Status;
EMU_BLOCK_IO_PRIVATE *Private;
EFI_TPL OldTpl;
Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
Status = Private->Io->WriteBlocks (Private->Io, MediaId, LBA, Token, BufferSize, Buffer);
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Flush the Block Device.
If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED
is returned and non-blocking I/O is being used, the Event associated with
this request will not be signaled.
@param[in] This Indicates a pointer to the calling context.
@param[in,out] Token A pointer to the token associated with the transaction
@retval EFI_SUCCESS The flush request was queued if Event is not NULL.
All outstanding data was written correctly to the
device if the Event is NULL.
@retval EFI_DEVICE_ERROR The device reported an error while writting back
the data.
@retval EFI_WRITE_PROTECTED The device cannot be written to.
@retval EFI_NO_MEDIA There is no media in the device.
@retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
of resources.
**/
EFI_STATUS
EFIAPI
EmuBlockIo2Flush (
IN EFI_BLOCK_IO2_PROTOCOL *This,
IN OUT EFI_BLOCK_IO2_TOKEN *Token
)
{
EFI_STATUS Status;
EMU_BLOCK_IO_PRIVATE *Private;
EFI_TPL OldTpl;
Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
Status = Private->Io->FlushBlocks (Private->Io, Token);
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Reset the Block Device.
@param This Indicates a pointer to the calling context.
@param ExtendedVerification Driver may perform diagnostics on reset.
@retval EFI_SUCCESS The device was reset.
@retval EFI_DEVICE_ERROR The device is not functioning properly and could
not be reset.
**/
EFI_STATUS
EFIAPI
EmuBlockIoReset (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
{
EFI_STATUS Status;
EMU_BLOCK_IO_PRIVATE *Private;
EFI_TPL OldTpl;
Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
Status = Private->Io->Reset (Private->Io, ExtendedVerification);
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Read BufferSize bytes from Lba into Buffer.
@param This Indicates a pointer to the calling context.
@param MediaId Id of the media, changes every time the media is replaced.
@param Lba The starting Logical Block Address to read from
@param BufferSize Size of Buffer, must be a multiple of device block size.
@param Buffer A pointer to the destination buffer for the data. The caller is
responsible for either having implicit or explicit ownership of the buffer.
@retval EFI_SUCCESS The data was read correctly from the device.
@retval EFI_DEVICE_ERROR The device reported an error while performing the read.
@retval EFI_NO_MEDIA There is no media in the device.
@retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.
@retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
@retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
or the buffer is not on proper alignment.
**/
EFI_STATUS
EFIAPI
EmuBlockIoReadBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
OUT VOID *Buffer
)
{
EFI_STATUS Status;
EMU_BLOCK_IO_PRIVATE *Private;
EFI_TPL OldTpl;
EFI_BLOCK_IO2_TOKEN Token;
Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
Token.Event = NULL;
Status = Private->Io->ReadBlocks (Private->Io, MediaId, Lba, &Token, BufferSize, Buffer);
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Write BufferSize bytes from Lba into Buffer.
@param This Indicates a pointer to the calling context.
@param MediaId The media ID that the write request is for.
@param Lba The starting logical block address to be written. The caller is
responsible for writing to only legitimate locations.
@param BufferSize Size of Buffer, must be a multiple of device block size.
@param Buffer A pointer to the source buffer for the data.
@retval EFI_SUCCESS The data was written correctly to the device.
@retval EFI_WRITE_PROTECTED The device can not be written to.
@retval EFI_DEVICE_ERROR The device reported an error while performing the write.
@retval EFI_NO_MEDIA There is no media in the device.
@retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
@retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
@retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
or the buffer is not on proper alignment.
**/
EFI_STATUS
EFIAPI
EmuBlockIoWriteBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
IN VOID *Buffer
)
{
EFI_STATUS Status;
EMU_BLOCK_IO_PRIVATE *Private;
EFI_TPL OldTpl;
EFI_BLOCK_IO2_TOKEN Token;
Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
Token.Event = NULL;
Status = Private->Io->WriteBlocks (Private->Io, MediaId, Lba, &Token, BufferSize, Buffer);
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Flush the Block Device.
@param This Indicates a pointer to the calling context.
@retval EFI_SUCCESS All outstanding data was written to the device
@retval EFI_DEVICE_ERROR The device reported an error while writting back the data
@retval EFI_NO_MEDIA There is no media in the device.
**/
EFI_STATUS
EFIAPI
EmuBlockIoFlushBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This
)
{
EFI_STATUS Status;
EMU_BLOCK_IO_PRIVATE *Private;
EFI_TPL OldTpl;
EFI_BLOCK_IO2_TOKEN Token;
Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
Token.Event = NULL;
Status = Private->Io->FlushBlocks (Private->Io, &Token);
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Tests to see if this driver supports a given controller. If a child device is provided,
it further tests to see if this driver supports creating a handle for the specified child device.
This function checks to see if the driver specified by This supports the device specified by
ControllerHandle. Drivers will typically use the device path attached to
ControllerHandle and/or the services from the bus I/O abstraction attached to
ControllerHandle to determine if the driver supports ControllerHandle. This function
may be called many times during platform initialization. In order to reduce boot times, the tests
performed by this function must be very small, and take as little time as possible to execute. This
function must not change the state of any hardware devices, and this function must be aware that the
device specified by ControllerHandle may already be managed by the same driver or a
different driver. This function must match its calls to AllocatePages() with FreePages(),
AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
Because ControllerHandle may have been previously started by the same driver, if a protocol is
already in the opened state, then it must not be closed with CloseProtocol(). This is required
to guarantee the state of ControllerHandle is not modified by this function.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle The handle of the controller to test. This handle
must support a protocol interface that supplies
an I/O abstraction to the driver.
@param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
parameter is ignored by device drivers, and is optional for bus
drivers. For bus drivers, if this parameter is not NULL, then
the bus driver must determine if the bus controller specified
by ControllerHandle and the child controller specified
by RemainingDevicePath are both supported by this
bus driver.
@retval EFI_SUCCESS The device specified by ControllerHandle and
RemainingDevicePath is supported by the driver specified by This.
@retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
RemainingDevicePath is already being managed by the driver
specified by This.
@retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
RemainingDevicePath is already being managed by a different
driver or an application that requires exclusive access.
Currently not implemented.
@retval EFI_UNSUPPORTED The device specified by ControllerHandle and
RemainingDevicePath is not supported by the driver specified by This.
**/
EFI_STATUS
EFIAPI
EmuBlockIoDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Handle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
EMU_IO_THUNK_PROTOCOL *EmuIoThunk;
//
// Open the IO Abstraction(s) needed to perform the supported test
//
Status = gBS->OpenProtocol (
Handle,
&gEmuIoThunkProtocolGuid,
(VOID **)&EmuIoThunk,
This->DriverBindingHandle,
Handle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Make sure GUID is for a File System handle.
//
Status = EFI_UNSUPPORTED;
if (CompareGuid (EmuIoThunk->Protocol, &gEmuBlockIoProtocolGuid)) {
Status = EFI_SUCCESS;
}
//
// Close the I/O Abstraction(s) used to perform the supported test
//
gBS->CloseProtocol (
Handle,
&gEmuIoThunkProtocolGuid,
This->DriverBindingHandle,
Handle
);
return Status;
}
/**
Starts a device controller or a bus controller.
The Start() function is designed to be invoked from the EFI boot service ConnectController().
As a result, much of the error checking on the parameters to Start() has been moved into this
common boot service. It is legal to call Start() from other locations,
but the following calling restrictions must be followed, or the system behavior will not be deterministic.
1. ControllerHandle must be a valid EFI_HANDLE.
2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
EFI_DEVICE_PATH_PROTOCOL.
3. Prior to calling Start(), the Supported() function for the driver specified by This must
have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle The handle of the controller to start. This handle
must support a protocol interface that supplies
an I/O abstraction to the driver.
@param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
parameter is ignored by device drivers, and is optional for bus
drivers. For a bus driver, if this parameter is NULL, then handles
for all the children of Controller are created by this driver.
If this parameter is not NULL and the first Device Path Node is
not the End of Device Path Node, then only the handle for the
child device specified by the first Device Path Node of
RemainingDevicePath is created by this driver.
If the first Device Path Node of RemainingDevicePath is
the End of Device Path Node, no child handle is created by this
driver.
@retval EFI_SUCCESS The device was started.
@retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
@retval Others The driver failded to start the device.
**/
EFI_STATUS
EFIAPI
EmuBlockIoDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Handle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
EMU_IO_THUNK_PROTOCOL *EmuIoThunk;
EMU_BLOCK_IO_PRIVATE *Private = NULL;
//
// Grab the protocols we need
//
Status = gBS->OpenProtocol (
Handle,
&gEmuIoThunkProtocolGuid,
(void *)&EmuIoThunk,
This->DriverBindingHandle,
Handle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
if (!CompareGuid (EmuIoThunk->Protocol, &gEmuBlockIoProtocolGuid)) {
Status = EFI_UNSUPPORTED;
goto Done;
}
Status = EmuIoThunk->Open (EmuIoThunk);
if (EFI_ERROR (Status)) {
goto Done;
}
Private = AllocatePool (sizeof (EMU_BLOCK_IO_PRIVATE));
if (Private == NULL) {
goto Done;
}
Private->Signature = EMU_BLOCK_IO_PRIVATE_SIGNATURE;
Private->IoThunk = EmuIoThunk;
Private->Io = EmuIoThunk->Interface;
Private->EfiHandle = Handle;
Private->BlockIo.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION2;
Private->BlockIo.Media = &Private->Media;
Private->BlockIo.Reset = EmuBlockIoReset;
Private->BlockIo.ReadBlocks = EmuBlockIoReadBlocks;
Private->BlockIo.WriteBlocks = EmuBlockIoWriteBlocks;
Private->BlockIo.FlushBlocks = EmuBlockIoFlushBlocks;
Private->BlockIo2.Media = &Private->Media;
Private->BlockIo2.Reset = EmuBlockIo2Reset;
Private->BlockIo2.ReadBlocksEx = EmuBlockIo2ReadBlocksEx;
Private->BlockIo2.WriteBlocksEx = EmuBlockIo2WriteBlocksEx;
Private->BlockIo2.FlushBlocksEx = EmuBlockIo2Flush;
Private->ControllerNameTable = NULL;
Status = Private->Io->CreateMapping (Private->Io, &Private->Media);
if (EFI_ERROR (Status)) {
goto Done;
}
AddUnicodeString2 (
"eng",
gEmuBlockIoComponentName.SupportedLanguages,
&Private->ControllerNameTable,
EmuIoThunk->ConfigString,
TRUE
);
AddUnicodeString2 (
"en",
gEmuBlockIoComponentName2.SupportedLanguages,
&Private->ControllerNameTable,
EmuIoThunk->ConfigString,
FALSE
);
Status = gBS->InstallMultipleProtocolInterfaces (
&Handle,
&gEfiBlockIoProtocolGuid, &Private->BlockIo,
&gEfiBlockIo2ProtocolGuid, &Private->BlockIo2,
NULL
);
Done:
if (EFI_ERROR (Status)) {
if (Private != NULL) {
if (Private->ControllerNameTable != NULL) {
FreeUnicodeStringTable (Private->ControllerNameTable);
}
gBS->FreePool (Private);
}
gBS->CloseProtocol (
Handle,
&gEmuIoThunkProtocolGuid,
This->DriverBindingHandle,
Handle
);
}
return Status;
}
/**
Stops a device controller or a bus controller.
The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
As a result, much of the error checking on the parameters to Stop() has been moved
into this common boot service. It is legal to call Stop() from other locations,
but the following calling restrictions must be followed, or the system behavior will not be deterministic.
1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
same driver's Start() function.
2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
EFI_HANDLE. In addition, all of these handles must have been created in this driver's
Start() function, and the Start() function must have called OpenProtocol() on
ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle A handle to the device being stopped. The handle must
support a bus specific I/O protocol for the driver
to use to stop the device.
@param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
@param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
if NumberOfChildren is 0.
@retval EFI_SUCCESS The device was stopped.
@retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
**/
EFI_STATUS
EFIAPI
EmuBlockIoDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Handle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_BLOCK_IO_PROTOCOL *BlockIo;
EFI_STATUS Status;
EMU_BLOCK_IO_PRIVATE *Private;
//
// Get our context back
//
Status = gBS->OpenProtocol (
Handle,
&gEfiBlockIoProtocolGuid,
(void *)&BlockIo,
This->DriverBindingHandle,
Handle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);
Status = Private->IoThunk->Close (Private->IoThunk);
Status = gBS->UninstallMultipleProtocolInterfaces (
Private->EfiHandle,
&gEfiBlockIoProtocolGuid, &Private->BlockIo,
&gEfiBlockIo2ProtocolGuid, &Private->BlockIo2,
NULL
);
if (!EFI_ERROR (Status)) {
Status = gBS->CloseProtocol (
Handle,
&gEmuIoThunkProtocolGuid,
This->DriverBindingHandle,
Handle
);
}
if (!EFI_ERROR (Status)) {
//
// Free our instance data
//
FreeUnicodeStringTable (Private->ControllerNameTable);
gBS->FreePool (Private);
}
return Status;
}
EFI_DRIVER_BINDING_PROTOCOL gEmuBlockIoDriverBinding = {
EmuBlockIoDriverBindingSupported,
EmuBlockIoDriverBindingStart,
EmuBlockIoDriverBindingStop,
0xa,
NULL,
NULL
};
/**
The user Entry Point for module EmuBlockIo . The user code starts with this function.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The entry point is executed successfully.
@retval other Some error occurs when executing this entry point.
**/
EFI_STATUS
EFIAPI
InitializeEmuBlockIo (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
Status = EfiLibInstallAllDriverProtocols2 (
ImageHandle,
SystemTable,
&gEmuBlockIoDriverBinding,
ImageHandle,
&gEmuBlockIoComponentName,
&gEmuBlockIoComponentName2,
NULL,
NULL,
&gEmuBlockIoDriverDiagnostics,
&gEmuBlockIoDriverDiagnostics2
);
ASSERT_EFI_ERROR (Status);
return Status;
}

View File

@@ -0,0 +1,84 @@
/*++
Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EmuBlockIo.h
Abstract:
Produce block IO abstractions for real devices on your PC using Posix APIs.
The configuration of what devices to mount or emulate comes from UNIX
environment variables. The variables must be visible to the Microsoft*
Developer Studio for them to work.
* Other names and brands may be claimed as the property of others.
**/
#ifndef _EMU_BLOCK_IO_H_
#define _EMU_BLOCK_IO_H_
#include <PiDxe.h>
#include <Protocol/EmuIoThunk.h>
#include <Protocol/BlockIo.h>
#include <Protocol/BlockIo2.h>
#include <Protocol/EmuBlockIo.h>
#include <Guid/EmuPhysicalDisk.h>
#include <Guid/EmuVirtualDisk.h>
#include <Library/DebugLib.h>
#include <Library/BaseLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
//
// Language supported for driverconfiguration protocol
//
#define EMU_BLOCK_IO_PRIVATE_SIGNATURE SIGNATURE_32 ('E', 'M', 'b', 'k')
typedef struct {
UINTN Signature;
EMU_IO_THUNK_PROTOCOL *IoThunk;
EMU_BLOCK_IO_PROTOCOL *Io;
EFI_HANDLE EfiHandle;
EFI_BLOCK_IO_PROTOCOL BlockIo;
EFI_BLOCK_IO2_PROTOCOL BlockIo2;
EFI_BLOCK_IO_MEDIA Media;
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
} EMU_BLOCK_IO_PRIVATE;
#define EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS(a) \
CR(a, EMU_BLOCK_IO_PRIVATE, BlockIo, EMU_BLOCK_IO_PRIVATE_SIGNATURE)
#define EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS(a) \
CR(a, EMU_BLOCK_IO_PRIVATE, BlockIo2, EMU_BLOCK_IO_PRIVATE_SIGNATURE)
//
// Block I/O Global Variables
//
extern EFI_DRIVER_BINDING_PROTOCOL gEmuBlockIoDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gEmuBlockIoComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gEmuBlockIoComponentName2;
extern EFI_DRIVER_CONFIGURATION_PROTOCOL gEmuBlockIoDriverConfiguration;
extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL gEmuBlockIoDriverDiagnostics;
extern EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gEmuBlockIoDriverDiagnostics2;
#endif

View File

@@ -0,0 +1,69 @@
## @file
# Block Io driver
#
# Produce block IO abstractions for real devices on your PC using Unix APIs.
# The configuration of what devices to mount or emulate comes from
# environment variables.
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = EmuBlockIo
FILE_GUID = C6760651-A38D-5F4F-AEAF-F6661549DF75
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = InitializeEmuBlockIo
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
# DRIVER_BINDING = gUnixBlockIoDriverBinding
# COMPONENT_NAME = gUnixBlockIoComponentName
# DRIVER_DIAG = gUnixBlockIoDriverDiagnostics
#
[Sources]
DriverDiagnostics.c
DriverConfiguration.c
ComponentName.c
EmuBlockIo.c
EmuBlockIo.h
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
UefiBootServicesTableLib
MemoryAllocationLib
BaseMemoryLib
UefiLib
UefiDriverEntryPoint
BaseLib
DebugLib
[Guids]
gEmuPhysicalDisksGuid # SOMETIMES_CONSUMED
gEmuVirtualDisksGuid # ALWAYS_CONSUMED
[Protocols]
gEfiBlockIoProtocolGuid # PROTOCOL BY_START
gEfiBlockIo2ProtocolGuid # PROTOCOL BY_START
gEmuIoThunkProtocolGuid # PROTOCOL TO_START
gEmuBlockIoProtocolGuid # PROTOCOL BY_START

View File

@@ -0,0 +1,247 @@
/** @file
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
**/
#include "EmuBusDriverDxe.h"
//
// EFI Component Name Functions
//
EFI_STATUS
EFIAPI
EmuBusDriverComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
EFI_STATUS
EFIAPI
EmuBusDriverComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
);
//
// EFI Component Name Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gEmuBusDriverComponentName = {
EmuBusDriverComponentNameGetDriverName,
EmuBusDriverComponentNameGetControllerName,
"eng"
};
//
// EFI Component Name 2 Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuBusDriverComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) EmuBusDriverComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) EmuBusDriverComponentNameGetControllerName,
"en"
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mEmuBusDriverNameTable[] = {
{ "eng", L"Emu Bus Driver" },
{ NULL , NULL }
};
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified
in RFC 4646 or ISO 639-2 language code format.
@param DriverName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
driver specified by This in the language
specified by Language.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
EmuBusDriverComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
)
{
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mEmuBusDriverNameTable,
DriverName,
(BOOLEAN)(This == &gEmuBusDriverComponentName)
);
}
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param ControllerHandle[in] The handle of a controller that the driver
specified by This is managing. This handle
specifies the controller whose name is to be
returned.
@param ChildHandle[in] The handle of the child controller to retrieve
the name of. This is an optional parameter that
may be NULL. It will be NULL for device
drivers. It will also be NULL for a bus drivers
that wish to retrieve the name of the bus
controller. It will not be NULL for a bus
driver that wishes to retrieve the name of a
child controller.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified in
RFC 4646 or ISO 639-2 language code format.
@param ControllerName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
controller specified by ControllerHandle and
ChildHandle in the language specified by
Language from the point of view of the driver
specified by This.
@retval EFI_SUCCESS The Unicode string for the user readable name in
the language specified by Language for the
driver specified by This was returned in
DriverName.
@retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
EmuBusDriverComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
{
EFI_STATUS Status;
EMU_IO_THUNK_PROTOCOL *EmuIo;
EMU_IO_DEVICE *Private;
//
// Make sure this driver is currently managing ControllHandle
//
Status = EfiTestManagedDevice (
ControllerHandle,
gEmuBusDriverBinding.DriverBindingHandle,
&gEmuThunkProtocolGuid
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// This is a bus driver, so ChildHandle can not be NULL.
//
if (ChildHandle == NULL) {
return EFI_UNSUPPORTED;
}
Status = EfiTestChildHandle (
ControllerHandle,
ChildHandle,
&gEmuThunkProtocolGuid
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Get our context back
//
Status = gBS->OpenProtocol (
ChildHandle,
&gEmuIoThunkProtocolGuid,
(VOID**)&EmuIo,
gEmuBusDriverBinding.DriverBindingHandle,
ChildHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
Private = EMU_IO_DEVICE_FROM_THIS (EmuIo);
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
Private->ControllerNameTable,
ControllerName,
(BOOLEAN)(This == &gEmuBusDriverComponentName)
);
}

View File

@@ -0,0 +1,529 @@
/** @file
Emu Bus driver
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "EmuBusDriverDxe.h"
//
// DriverBinding protocol global
//
EFI_DRIVER_BINDING_PROTOCOL gEmuBusDriverBinding = {
EmuBusDriverBindingSupported,
EmuBusDriverBindingStart,
EmuBusDriverBindingStop,
0xa,
NULL,
NULL
};
EFI_STATUS
EFIAPI
EmuBusDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
EMU_THUNK_PROTOCOL *EmuThunk;
//
// Check the contents of the first Device Path Node of RemainingDevicePath to make sure
// it is a legal Device Path Node for this bus driver's children.
//
if (RemainingDevicePath != NULL) {
//
// Check if RemainingDevicePath is the End of Device Path Node,
// if yes, go on checking other conditions
//
if (!IsDevicePathEnd (RemainingDevicePath)) {
//
// If RemainingDevicePath isn't the End of Device Path Node,
// check its validation
//
if (RemainingDevicePath->Type != HARDWARE_DEVICE_PATH ||
RemainingDevicePath->SubType != HW_VENDOR_DP ||
DevicePathNodeLength(RemainingDevicePath) != sizeof(EMU_VENDOR_DEVICE_PATH_NODE)) {
return EFI_UNSUPPORTED;
}
}
}
//
// Open the IO Abstraction(s) needed to perform the supported test
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEmuThunkProtocolGuid,
(VOID **)&EmuThunk ,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (Status == EFI_ALREADY_STARTED) {
return EFI_SUCCESS;
}
if (EFI_ERROR (Status)) {
return Status;
}
//
// Close the I/O Abstraction(s) used to perform the supported test
//
gBS->CloseProtocol (
ControllerHandle,
&gEmuThunkProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
//
// Open the EFI Device Path protocol needed to perform the supported test
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDevicePathProtocolGuid,
(VOID **)&ParentDevicePath,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (Status == EFI_ALREADY_STARTED) {
return EFI_SUCCESS;
}
if (EFI_ERROR (Status)) {
return Status;
}
//
// Close protocol, don't use device path protocol in the Support() function
//
gBS->CloseProtocol (
ControllerHandle,
&gEfiDevicePathProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
return Status;
}
EFI_STATUS
EFIAPI
EmuBusDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
EFI_STATUS InstallStatus;
EMU_THUNK_PROTOCOL *EmuThunk;
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
EMU_IO_DEVICE *EmuDevice;
EMU_BUS_DEVICE *EmuBusDevice;
EMU_IO_THUNK_PROTOCOL *EmuIoThunk;
UINT16 ComponentName[512];
EMU_VENDOR_DEVICE_PATH_NODE *Node;
BOOLEAN CreateDevice;
InstallStatus = EFI_UNSUPPORTED;
Status = EFI_UNSUPPORTED;
//
// Grab the protocols we need
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDevicePathProtocolGuid,
(VOID **)&ParentDevicePath,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {
return Status;
}
Status = gBS->OpenProtocol (
ControllerHandle,
&gEmuThunkProtocolGuid,
(VOID **)&EmuThunk,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {
return Status;
}
if (Status != EFI_ALREADY_STARTED) {
EmuBusDevice = AllocatePool (sizeof (EMU_BUS_DEVICE));
if (EmuBusDevice == NULL) {
return EFI_OUT_OF_RESOURCES;
}
EmuBusDevice->Signature = EMU_BUS_DEVICE_SIGNATURE;
EmuBusDevice->ControllerNameTable = NULL;
AddUnicodeString2 (
"eng",
gEmuBusDriverComponentName.SupportedLanguages,
&EmuBusDevice->ControllerNameTable,
L"Emulator Bus Controller",
TRUE
);
AddUnicodeString2 (
"en",
gEmuBusDriverComponentName2.SupportedLanguages,
&EmuBusDevice->ControllerNameTable,
L"Emulator Bus Controller",
FALSE
);
Status = gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiCallerIdGuid, EmuBusDevice,
NULL
);
if (EFI_ERROR (Status)) {
FreeUnicodeStringTable (EmuBusDevice->ControllerNameTable);
gBS->FreePool (EmuBusDevice);
return Status;
}
}
for (Status = EFI_SUCCESS, EmuIoThunk = NULL; !EFI_ERROR (Status); ) {
Status = EmuThunk->GetNextProtocol (TRUE, &EmuIoThunk);
if (EFI_ERROR (Status)) {
break;
}
CreateDevice = TRUE;
if (RemainingDevicePath != NULL) {
CreateDevice = FALSE;
//
// Check if RemainingDevicePath is the End of Device Path Node,
// if yes, don't create any child device
//
if (!IsDevicePathEnd (RemainingDevicePath)) {
//
// If RemainingDevicePath isn't the End of Device Path Node,
// check its validation
//
Node = (EMU_VENDOR_DEVICE_PATH_NODE *) RemainingDevicePath;
if (Node->VendorDevicePath.Header.Type == HARDWARE_DEVICE_PATH &&
Node->VendorDevicePath.Header.SubType == HW_VENDOR_DP &&
DevicePathNodeLength (&Node->VendorDevicePath.Header) == sizeof (EMU_VENDOR_DEVICE_PATH_NODE)
) {
if (CompareGuid (&Node->VendorDevicePath.Guid, EmuIoThunk->Protocol) && Node->Instance == EmuIoThunk->Instance) {
CreateDevice = TRUE;
}
}
}
}
if (CreateDevice) {
//
// Allocate instance structure, and fill in parent information.
//
EmuDevice = AllocatePool (sizeof (EMU_IO_DEVICE));
if (EmuDevice == NULL) {
return EFI_OUT_OF_RESOURCES;
}
EmuDevice->Handle = NULL;
EmuDevice->ControllerHandle = ControllerHandle;
EmuDevice->ParentDevicePath = ParentDevicePath;
CopyMem (&EmuDevice->EmuIoThunk, EmuIoThunk, sizeof (EMU_IO_THUNK_PROTOCOL));
EmuDevice->ControllerNameTable = NULL;
StrnCpy (ComponentName, EmuIoThunk->ConfigString, sizeof (ComponentName)/sizeof (CHAR16));
EmuDevice->DevicePath = EmuBusCreateDevicePath (
ParentDevicePath,
EmuIoThunk->Protocol,
EmuIoThunk->Instance
);
if (EmuDevice->DevicePath == NULL) {
gBS->FreePool (EmuDevice);
return EFI_OUT_OF_RESOURCES;
}
AddUnicodeString (
"eng",
gEmuBusDriverComponentName.SupportedLanguages,
&EmuDevice->ControllerNameTable,
ComponentName
);
EmuDevice->Signature = EMU_IO_DEVICE_SIGNATURE;
InstallStatus = gBS->InstallMultipleProtocolInterfaces (
&EmuDevice->Handle,
&gEfiDevicePathProtocolGuid, EmuDevice->DevicePath,
&gEmuIoThunkProtocolGuid, &EmuDevice->EmuIoThunk,
NULL
);
if (EFI_ERROR (InstallStatus)) {
FreeUnicodeStringTable (EmuDevice->ControllerNameTable);
gBS->FreePool (EmuDevice);
} else {
//
// Open For Child Device
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEmuThunkProtocolGuid,
(VOID **)&EmuThunk ,
This->DriverBindingHandle,
EmuDevice->Handle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
);
if (!EFI_ERROR (Status)) {
InstallStatus = EFI_SUCCESS;
}
}
}
}
return InstallStatus;
}
EFI_STATUS
EFIAPI
EmuBusDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_STATUS Status;
UINTN Index;
BOOLEAN AllChildrenStopped;
EMU_IO_THUNK_PROTOCOL *EmuIoThunk;
EMU_BUS_DEVICE *EmuBusDevice;
EMU_IO_DEVICE *EmuDevice;
EMU_THUNK_PROTOCOL *EmuThunk;
//
// Complete all outstanding transactions to Controller.
// Don't allow any new transaction to Controller to be started.
//
if (NumberOfChildren == 0) {
//
// Close the bus driver
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiCallerIdGuid,
(VOID **)&EmuBusDevice,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
gBS->UninstallMultipleProtocolInterfaces (
ControllerHandle,
&gEfiCallerIdGuid, EmuBusDevice,
NULL
);
FreeUnicodeStringTable (EmuBusDevice->ControllerNameTable);
gBS->FreePool (EmuBusDevice);
gBS->CloseProtocol (
ControllerHandle,
&gEmuThunkProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
gBS->CloseProtocol (
ControllerHandle,
&gEfiDevicePathProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
return EFI_SUCCESS;
}
AllChildrenStopped = TRUE;
for (Index = 0; Index < NumberOfChildren; Index++) {
Status = gBS->OpenProtocol (
ChildHandleBuffer[Index],
&gEmuIoThunkProtocolGuid,
(VOID **)&EmuIoThunk,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (!EFI_ERROR (Status)) {
EmuDevice = EMU_IO_DEVICE_FROM_THIS (EmuIoThunk);
Status = gBS->CloseProtocol (
ControllerHandle,
&gEmuThunkProtocolGuid,
This->DriverBindingHandle,
EmuDevice->Handle
);
Status = gBS->UninstallMultipleProtocolInterfaces (
EmuDevice->Handle,
&gEfiDevicePathProtocolGuid, EmuDevice->DevicePath,
&gEmuIoThunkProtocolGuid, EmuDevice->EmuIoThunk,
NULL
);
if (EFI_ERROR (Status)) {
gBS->OpenProtocol (
ControllerHandle,
&gEmuThunkProtocolGuid,
(VOID **) &EmuThunk ,
This->DriverBindingHandle,
EmuDevice->Handle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
);
} else {
//
// Close the child handle
//
FreeUnicodeStringTable (EmuDevice->ControllerNameTable);
FreePool (EmuDevice);
}
}
if (EFI_ERROR (Status)) {
AllChildrenStopped = FALSE;
}
}
if (!AllChildrenStopped) {
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
/*++
Routine Description:
Create a device path node using Guid and InstanceNumber and append it to
the passed in RootDevicePath
Arguments:
RootDevicePath - Root of the device path to return.
Guid - GUID to use in vendor device path node.
InstanceNumber - Instance number to use in the vendor device path. This
argument is needed to make sure each device path is unique.
Returns:
EFI_DEVICE_PATH_PROTOCOL
**/
EFI_DEVICE_PATH_PROTOCOL *
EmuBusCreateDevicePath (
IN EFI_DEVICE_PATH_PROTOCOL *RootDevicePath,
IN EFI_GUID *Guid,
IN UINT16 InstanceNumber
)
{
EMU_VENDOR_DEVICE_PATH_NODE DevicePath;
DevicePath.VendorDevicePath.Header.Type = HARDWARE_DEVICE_PATH;
DevicePath.VendorDevicePath.Header.SubType = HW_VENDOR_DP;
SetDevicePathNodeLength (&DevicePath.VendorDevicePath.Header, sizeof (EMU_VENDOR_DEVICE_PATH_NODE));
//
// The GUID defines the Class
//
CopyMem (&DevicePath.VendorDevicePath.Guid, Guid, sizeof (EFI_GUID));
//
// Add an instance number so we can make sure there are no Device Path
// duplication.
//
DevicePath.Instance = InstanceNumber;
return AppendDevicePathNode (
RootDevicePath,
(EFI_DEVICE_PATH_PROTOCOL *) &DevicePath
);
}
/**
The user Entry Point for module EmuBusDriver. The user code starts with this function.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The entry point is executed successfully.
@retval other Some error occurs when executing this entry point.
**/
EFI_STATUS
EFIAPI
InitializeEmuBusDriver (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
Status = EfiLibInstallAllDriverProtocols (
ImageHandle,
SystemTable,
&gEmuBusDriverBinding,
ImageHandle,
&gEmuBusDriverComponentName,
NULL,
NULL
);
ASSERT_EFI_ERROR (Status);
return Status;
}

View File

@@ -0,0 +1,116 @@
/*++ @file
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __EMU_BUS_DRIVER_H__
#define __EMU_BUS_DRIVER_H__
#include <PiDxe.h>
#include <Protocol/DevicePath.h>
#include <Protocol/EmuThunk.h>
#include <Protocol/EmuIoThunk.h>
#include <Library/DebugLib.h>
#include <Library/BaseLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiLib.h>
#include <Library/PcdLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DevicePathLib.h>
extern EFI_DRIVER_BINDING_PROTOCOL gEmuBusDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gEmuBusDriverComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gEmuBusDriverComponentName2;
//
// Unix Bus Controller Structure
//
#define EMU_BUS_DEVICE_SIGNATURE SIGNATURE_32 ('L', 'X', 'B', 'D')
typedef struct {
UINT64 Signature;
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
} EMU_BUS_DEVICE;
//
// Unix Child Device Controller Structure
//
#define EMU_IO_DEVICE_SIGNATURE SIGNATURE_32 ('L', 'X', 'V', 'D')
typedef struct {
UINT64 Signature;
EFI_HANDLE Handle;
EMU_IO_THUNK_PROTOCOL EmuIoThunk;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
//
// Private data about the parent
//
EFI_HANDLE ControllerHandle;
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
} EMU_IO_DEVICE;
#define EMU_IO_DEVICE_FROM_THIS(a) \
CR(a, EMU_IO_DEVICE, EmuIoThunk, EMU_IO_DEVICE_SIGNATURE)
//
// Driver Binding Protocol function prototypes
//
EFI_STATUS
EFIAPI
EmuBusDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Handle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
EFI_STATUS
EFIAPI
EmuBusDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ParentHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
EFI_STATUS
EFIAPI
EmuBusDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Handle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
//
// Unix Bus Driver private worker functions
//
EFI_DEVICE_PATH_PROTOCOL *
EmuBusCreateDevicePath (
IN EFI_DEVICE_PATH_PROTOCOL *RootDevicePath,
IN EFI_GUID *Guid,
IN UINT16 InstanceNumber
);
#endif

View File

@@ -0,0 +1,63 @@
## @file
# Emu Bus driver
#
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = EmuBusDriver
FILE_GUID = 9842073D-95D9-9F49-BD3F-2E29525125DF
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = InitializeEmuBusDriver
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
# DRIVER_BINDING = gEmuBusDriverBinding
# COMPONENT_NAME = gEmuBusDriverComponentName
#
[Sources]
ComponentName.c
EmuBusDriverDxe.c
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
DevicePathLib
UefiBootServicesTableLib
MemoryAllocationLib
BaseMemoryLib
PcdLib
UefiLib
UefiDriverEntryPoint
BaseLib
DebugLib
[Protocols]
gEfiDevicePathProtocolGuid # PROTOCOL TO_START
gEmuThunkProtocolGuid # PROTOCOL TO_START
gEmuIoThunkProtocolGuid # PROTOCOL BY_START

View File

@@ -0,0 +1,250 @@
/** @file
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2010,Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
ComponentName.c
Abstract:
**/
#include "Gop.h"
//
// EFI Component Name Functions
//
EFI_STATUS
EFIAPI
EmuGopComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
EFI_STATUS
EFIAPI
EmuGopComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
);
//
// EFI Component Name Protocol
//
EFI_COMPONENT_NAME_PROTOCOL gEmuGopComponentName = {
EmuGopComponentNameGetDriverName,
EmuGopComponentNameGetControllerName,
"eng"
};
//
// EFI Component Name 2 Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuGopComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) EmuGopComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) EmuGopComponentNameGetControllerName,
"en"
};
EFI_UNICODE_STRING_TABLE mEmuGopDriverNameTable[] = {
{ "eng", L"Emulator GOP Driver" },
{ NULL , NULL }
};
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified
in RFC 4646 or ISO 639-2 language code format.
@param DriverName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
driver specified by This in the language
specified by Language.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
EmuGopComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
)
{
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mEmuGopDriverNameTable,
DriverName,
(BOOLEAN)(This == &gEmuGopComponentName)
);
}
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param ControllerHandle[in] The handle of a controller that the driver
specified by This is managing. This handle
specifies the controller whose name is to be
returned.
@param ChildHandle[in] The handle of the child controller to retrieve
the name of. This is an optional parameter that
may be NULL. It will be NULL for device
drivers. It will also be NULL for a bus drivers
that wish to retrieve the name of the bus
controller. It will not be NULL for a bus
driver that wishes to retrieve the name of a
child controller.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified in
RFC 4646 or ISO 639-2 language code format.
@param ControllerName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
controller specified by ControllerHandle and
ChildHandle in the language specified by
Language from the point of view of the driver
specified by This.
@retval EFI_SUCCESS The Unicode string for the user readable name in
the language specified by Language for the
driver specified by This was returned in
DriverName.
@retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
EmuGopComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
{
EFI_STATUS Status;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
GOP_PRIVATE_DATA *Private;
//
// This is a device driver, so ChildHandle must be NULL.
//
if (ChildHandle != NULL) {
return EFI_UNSUPPORTED;
}
//
// Make sure this driver is currently managing ControllerHandle
//
Status = EfiTestManagedDevice (
ControllerHandle,
gEmuGopDriverBinding.DriverBindingHandle,
&gEmuIoThunkProtocolGuid
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
//
// Get our context back
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiGraphicsOutputProtocolGuid,
(VOID **)&GraphicsOutput,
gEmuGopDriverBinding.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
Private = GOP_PRIVATE_DATA_FROM_THIS (GraphicsOutput);
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
Private->ControllerNameTable,
ControllerName,
(BOOLEAN)(This == &gEmuGopComponentName)
);
}

View File

@@ -0,0 +1,69 @@
## @file
# GOP driver
#
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = EmuGopDxe
FILE_GUID = BCC87E0D-86D6-4D4D-8040-2D983D368BD1
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = InitializeEmuGop
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
# DRIVER_BINDING = gEmuGopDriverBinding
# COMPONENT_NAME = gEmuGopComponentName
#
[Sources]
ComponentName.c
GopScreen.c
GopDriver.c
GopInput.c
Gop.h
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
UefiBootServicesTableLib
MemoryAllocationLib
BaseMemoryLib
UefiLib
UefiDriverEntryPoint
BaseLib
DebugLib
KeyMapLib
[Guids]
gEfiEventExitBootServicesGuid # SOMETIMES_CONSUMED Create Event: EVENT_GROUP_GUID
[Protocols]
gEfiGraphicsOutputProtocolGuid
gEfiSimpleTextInProtocolGuid # PROTOCOL BY_START
gEfiSimpleTextInputExProtocolGuid # PROTOCOL BY_START
gEfiSimplePointerProtocolGuid # PROTOCOL BY_START
gEmuIoThunkProtocolGuid # PROTOCOL TO_START
gEmuGraphicsWindowProtocolGuid # PROTOCOL TO_START

195
EmulatorPkg/EmuGopDxe/Gop.h Normal file
View File

@@ -0,0 +1,195 @@
/*++ @file
Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2010,Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __UGA_H_
#define __UGA_H_
#include <PiDxe.h>
#include <Protocol/GraphicsOutput.h>
#include <Protocol/SimpleTextIn.h>
#include <Protocol/SimpleTextInEx.h>
#include <Protocol/SimplePointer.h>
#include <Protocol/EmuIoThunk.h>
#include <Protocol/EmuGraphicsWindow.h>
#include <Guid/EventGroup.h>
#include <Library/DebugLib.h>
#include <Library/BaseLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/KeyMapLib.h>
#define MAX_Q 256
typedef struct {
UINTN Front;
UINTN Rear;
UINTN Count;
EFI_INPUT_KEY Q[MAX_Q];
} GOP_QUEUE_FIXED;
#define EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('U', 'g', 'S', 'n')
typedef struct _EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY {
UINTN Signature;
EFI_HANDLE NotifyHandle;
EFI_KEY_DATA KeyData;
EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn;
EFI_EVENT Event;
LIST_ENTRY NotifyEntry;
} EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY;
#define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
typedef struct {
UINT32 HorizontalResolution;
UINT32 VerticalResolution;
UINT32 ColorDepth;
UINT32 RefreshRate;
} GOP_MODE_DATA;
extern EFI_DRIVER_BINDING_PROTOCOL gEmuGopDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gEmuGopComponentName;
#define EMU_UGA_CLASS_NAME L"EmuGopWindow"
#define GOP_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('G', 'o', 'p', 'N')
typedef struct {
UINT64 Signature;
EFI_HANDLE Handle;
EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleTextIn;
EFI_SIMPLE_POINTER_PROTOCOL SimplePointer;
EMU_IO_THUNK_PROTOCOL *EmuIoThunk;
EMU_GRAPHICS_WINDOW_PROTOCOL *EmuGraphicsWindow;
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
EFI_SIMPLE_POINTER_MODE PointerMode;
//
// GOP Private Data for QueryMode ()
//
GOP_MODE_DATA *ModeData;
//
// UGA Private Data knowing when to start hardware
//
BOOLEAN HardwareNeedsStarting;
CHAR16 *WindowName;
GOP_QUEUE_FIXED Queue;
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleTextInEx;
EFI_KEY_STATE KeyState;
LIST_ENTRY NotifyList;
} GOP_PRIVATE_DATA;
#define GOP_PRIVATE_DATA_FROM_THIS(a) \
CR(a, GOP_PRIVATE_DATA, GraphicsOutput, GOP_PRIVATE_DATA_SIGNATURE)
#define GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS(a) \
CR(a, GOP_PRIVATE_DATA, SimpleTextIn, GOP_PRIVATE_DATA_SIGNATURE)
#define GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS(a) \
CR(a, GOP_PRIVATE_DATA, SimpleTextInEx, GOP_PRIVATE_DATA_SIGNATURE)
#define GOP_PRIVATE_DATA_FROM_POINTER_MODE_THIS(a) \
CR(a, GOP_PRIVATE_DATA, SimplePointer, GOP_PRIVATE_DATA_SIGNATURE)
//
// Global Protocol Variables
//
extern EFI_DRIVER_BINDING_PROTOCOL gEmuGopDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gEmuGopComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gEmuGopComponentName2;
//
// Gop Hardware abstraction internal worker functions
//
EFI_STATUS
EmuGopSupported (
IN EMU_IO_THUNK_PROTOCOL *EmuIoThunk
);
EFI_STATUS
EmuGopConstructor (
IN GOP_PRIVATE_DATA *Private
);
EFI_STATUS
EmuGopDestructor (
IN GOP_PRIVATE_DATA *Private
);
EFI_STATUS
GopPrivateAddQ (
IN GOP_PRIVATE_DATA *Private,
IN EFI_INPUT_KEY Key
);
EFI_STATUS
EmuGopInitializeSimpleTextInForWindow (
IN GOP_PRIVATE_DATA *Private
);
EFI_STATUS
EmuGopInitializeSimplePointerForWindow (
IN GOP_PRIVATE_DATA *Private
);
EFI_STATUS
EmuGopStartWindow (
IN GOP_PRIVATE_DATA *Private,
IN UINT32 HorizontalResolution,
IN UINT32 VerticalResolution,
IN UINT32 ColorDepth,
IN UINT32 RefreshRate
);
VOID
EFIAPI
ShutdownGopEvent (
IN EFI_EVENT Event,
IN VOID *Context
);
VOID
EFIAPI
GopPrivateMakeCallbackFunction (
IN VOID *Context,
IN EFI_KEY_DATA *KeyData
);
VOID
EFIAPI
GopPrivateBreakCallbackFunction (
IN VOID *Context,
IN EFI_KEY_DATA *KeyData
);
#endif

View File

@@ -0,0 +1,443 @@
/*++ @file
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2010,Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "Gop.h"
EFI_STATUS
FreeNotifyList (
IN OUT LIST_ENTRY *ListHead
)
/*++
Routine Description:
Arguments:
ListHead - The list head
Returns:
EFI_SUCCESS - Free the notify list successfully
EFI_INVALID_PARAMETER - ListHead is invalid.
**/
{
EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *NotifyNode;
if (ListHead == NULL) {
return EFI_INVALID_PARAMETER;
}
while (!IsListEmpty (ListHead)) {
NotifyNode = CR (
ListHead->ForwardLink,
EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY,
NotifyEntry,
EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE
);
RemoveEntryList (ListHead->ForwardLink);
gBS->FreePool (NotifyNode);
}
return EFI_SUCCESS;
}
/**
Tests to see if this driver supports a given controller. If a child device is provided,
it further tests to see if this driver supports creating a handle for the specified child device.
This function checks to see if the driver specified by This supports the device specified by
ControllerHandle. Drivers will typically use the device path attached to
ControllerHandle and/or the services from the bus I/O abstraction attached to
ControllerHandle to determine if the driver supports ControllerHandle. This function
may be called many times during platform initialization. In order to reduce boot times, the tests
performed by this function must be very small, and take as little time as possible to execute. This
function must not change the state of any hardware devices, and this function must be aware that the
device specified by ControllerHandle may already be managed by the same driver or a
different driver. This function must match its calls to AllocatePages() with FreePages(),
AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
Because ControllerHandle may have been previously started by the same driver, if a protocol is
already in the opened state, then it must not be closed with CloseProtocol(). This is required
to guarantee the state of ControllerHandle is not modified by this function.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle The handle of the controller to test. This handle
must support a protocol interface that supplies
an I/O abstraction to the driver.
@param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
parameter is ignored by device drivers, and is optional for bus
drivers. For bus drivers, if this parameter is not NULL, then
the bus driver must determine if the bus controller specified
by ControllerHandle and the child controller specified
by RemainingDevicePath are both supported by this
bus driver.
@retval EFI_SUCCESS The device specified by ControllerHandle and
RemainingDevicePath is supported by the driver specified by This.
@retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
RemainingDevicePath is already being managed by the driver
specified by This.
@retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
RemainingDevicePath is already being managed by a different
driver or an application that requires exclusive access.
Currently not implemented.
@retval EFI_UNSUPPORTED The device specified by ControllerHandle and
RemainingDevicePath is not supported by the driver specified by This.
**/
EFI_STATUS
EFIAPI
EmuGopDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Handle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
EMU_IO_THUNK_PROTOCOL *EmuIoThunk;
//
// Open the IO Abstraction(s) needed to perform the supported test
//
Status = gBS->OpenProtocol (
Handle,
&gEmuIoThunkProtocolGuid,
(VOID **)&EmuIoThunk,
This->DriverBindingHandle,
Handle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = EmuGopSupported (EmuIoThunk);
//
// Close the I/O Abstraction(s) used to perform the supported test
//
gBS->CloseProtocol (
Handle,
&gEmuIoThunkProtocolGuid,
This->DriverBindingHandle,
Handle
);
return Status;
}
/**
Starts a device controller or a bus controller.
The Start() function is designed to be invoked from the EFI boot service ConnectController().
As a result, much of the error checking on the parameters to Start() has been moved into this
common boot service. It is legal to call Start() from other locations,
but the following calling restrictions must be followed, or the system behavior will not be deterministic.
1. ControllerHandle must be a valid EFI_HANDLE.
2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
EFI_DEVICE_PATH_PROTOCOL.
3. Prior to calling Start(), the Supported() function for the driver specified by This must
have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle The handle of the controller to start. This handle
must support a protocol interface that supplies
an I/O abstraction to the driver.
@param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
parameter is ignored by device drivers, and is optional for bus
drivers. For a bus driver, if this parameter is NULL, then handles
for all the children of Controller are created by this driver.
If this parameter is not NULL and the first Device Path Node is
not the End of Device Path Node, then only the handle for the
child device specified by the first Device Path Node of
RemainingDevicePath is created by this driver.
If the first Device Path Node of RemainingDevicePath is
the End of Device Path Node, no child handle is created by this
driver.
@retval EFI_SUCCESS The device was started.
@retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
@retval Others The driver failded to start the device.
**/
EFI_STATUS
EFIAPI
EmuGopDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Handle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EMU_IO_THUNK_PROTOCOL *EmuIoThunk;
EFI_STATUS Status;
GOP_PRIVATE_DATA *Private;
//
// Grab the protocols we need
//
Status = gBS->OpenProtocol (
Handle,
&gEmuIoThunkProtocolGuid,
(VOID **)&EmuIoThunk,
This->DriverBindingHandle,
Handle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
//
// Allocate Private context data for SGO inteface.
//
Private = NULL;
Status = gBS->AllocatePool (
EfiBootServicesData,
sizeof (GOP_PRIVATE_DATA),
(VOID **)&Private
);
if (EFI_ERROR (Status)) {
goto Done;
}
//
// Set up context record
//
Private->Signature = GOP_PRIVATE_DATA_SIGNATURE;
Private->Handle = Handle;
Private->EmuIoThunk = EmuIoThunk;
Private->WindowName = EmuIoThunk->ConfigString;
Private->ControllerNameTable = NULL;
AddUnicodeString (
"eng",
gEmuGopComponentName.SupportedLanguages,
&Private->ControllerNameTable,
EmuIoThunk->ConfigString
);
AddUnicodeString2 (
"en",
gEmuGopComponentName2.SupportedLanguages,
&Private->ControllerNameTable,
EmuIoThunk->ConfigString,
FALSE
);
Status = EmuGopConstructor (Private);
if (EFI_ERROR (Status)) {
goto Done;
}
//
// Publish the Gop interface to the world
//
Status = gBS->InstallMultipleProtocolInterfaces (
&Private->Handle,
&gEfiGraphicsOutputProtocolGuid, &Private->GraphicsOutput,
&gEfiSimpleTextInProtocolGuid, &Private->SimpleTextIn,
&gEfiSimplePointerProtocolGuid, &Private->SimplePointer,
&gEfiSimpleTextInputExProtocolGuid, &Private->SimpleTextInEx,
NULL
);
Done:
if (EFI_ERROR (Status)) {
gBS->CloseProtocol (
Handle,
&gEmuIoThunkProtocolGuid,
This->DriverBindingHandle,
Handle
);
if (Private != NULL) {
//
// On Error Free back private data
//
if (Private->ControllerNameTable != NULL) {
FreeUnicodeStringTable (Private->ControllerNameTable);
}
if (Private->SimpleTextIn.WaitForKey != NULL) {
gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);
}
if (Private->SimpleTextInEx.WaitForKeyEx != NULL) {
gBS->CloseEvent (Private->SimpleTextInEx.WaitForKeyEx);
}
FreeNotifyList (&Private->NotifyList);
gBS->FreePool (Private);
}
}
return Status;
}
/**
Stops a device controller or a bus controller.
The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
As a result, much of the error checking on the parameters to Stop() has been moved
into this common boot service. It is legal to call Stop() from other locations,
but the following calling restrictions must be followed, or the system behavior will not be deterministic.
1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
same driver's Start() function.
2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
EFI_HANDLE. In addition, all of these handles must have been created in this driver's
Start() function, and the Start() function must have called OpenProtocol() on
ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle A handle to the device being stopped. The handle must
support a bus specific I/O protocol for the driver
to use to stop the device.
@param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
@param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
if NumberOfChildren is 0.
@retval EFI_SUCCESS The device was stopped.
@retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
**/
EFI_STATUS
EFIAPI
EmuGopDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Handle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
EFI_STATUS Status;
GOP_PRIVATE_DATA *Private;
Status = gBS->OpenProtocol (
Handle,
&gEfiGraphicsOutputProtocolGuid,
(VOID **)&GraphicsOutput,
This->DriverBindingHandle,
Handle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
//
// If the GOP interface does not exist the driver is not started
//
return EFI_NOT_STARTED;
}
//
// Get our private context information
//
Private = GOP_PRIVATE_DATA_FROM_THIS (GraphicsOutput);
//
// Remove the SGO interface from the system
//
Status = gBS->UninstallMultipleProtocolInterfaces (
Private->Handle,
&gEfiGraphicsOutputProtocolGuid, &Private->GraphicsOutput,
&gEfiSimpleTextInProtocolGuid, &Private->SimpleTextIn,
&gEfiSimplePointerProtocolGuid, &Private->SimplePointer,
&gEfiSimpleTextInputExProtocolGuid, &Private->SimpleTextInEx,
NULL
);
if (!EFI_ERROR (Status)) {
//
// Shutdown the hardware
//
Status = EmuGopDestructor (Private);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
gBS->CloseProtocol (
Handle,
&gEmuIoThunkProtocolGuid,
This->DriverBindingHandle,
Handle
);
//
// Free our instance data
//
FreeUnicodeStringTable (Private->ControllerNameTable);
Status = gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);
ASSERT_EFI_ERROR (Status);
Status = gBS->CloseEvent (Private->SimpleTextInEx.WaitForKeyEx);
ASSERT_EFI_ERROR (Status);
FreeNotifyList (&Private->NotifyList);
gBS->FreePool (Private);
}
return Status;
}
///
/// This protocol provides the services required to determine if a driver supports a given controller.
/// If a controller is supported, then it also provides routines to start and stop the controller.
///
EFI_DRIVER_BINDING_PROTOCOL gEmuGopDriverBinding = {
EmuGopDriverBindingSupported,
EmuGopDriverBindingStart,
EmuGopDriverBindingStop,
0xa,
NULL,
NULL
};
/**
The user Entry Point for module EmuGop. The user code starts with this function.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The entry point is executed successfully.
@retval other Some error occurs when executing this entry point.
**/
EFI_STATUS
EFIAPI
InitializeEmuGop (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
Status = EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
&gEmuGopDriverBinding,
ImageHandle,
&gEmuGopComponentName,
&gEmuGopComponentName2
);
ASSERT_EFI_ERROR (Status);
return Status;
}

View File

@@ -0,0 +1,897 @@
/*++ @file
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2010 0 2011,Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "Gop.h"
BOOLEAN
GopPrivateIsKeyRegistered (
IN EFI_KEY_DATA *RegsiteredData,
IN EFI_KEY_DATA *InputData
)
/*++
Routine Description:
Arguments:
RegsiteredData - A pointer to a buffer that is filled in with the keystroke
state data for the key that was registered.
InputData - A pointer to a buffer that is filled in with the keystroke
state data for the key that was pressed.
Returns:
TRUE - Key be pressed matches a registered key.
FLASE - Match failed.
**/
{
ASSERT (RegsiteredData != NULL && InputData != NULL);
if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) ||
(RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) {
return FALSE;
}
//
// Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.
//
if (RegsiteredData->KeyState.KeyShiftState != 0 &&
RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {
return FALSE;
}
if (RegsiteredData->KeyState.KeyToggleState != 0 &&
RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {
return FALSE;
}
return TRUE;
}
VOID
EFIAPI
GopPrivateMakeCallbackFunction (
IN VOID *Context,
IN EFI_KEY_DATA *KeyData
)
{
LIST_ENTRY *Link;
EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *CurrentNotify;
GOP_PRIVATE_DATA *Private = (GOP_PRIVATE_DATA *)Context;
KeyMapMake (KeyData);
for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
CurrentNotify = CR (
Link,
EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY,
NotifyEntry,
EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE
);
if (GopPrivateIsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {
// We could be called at a high TPL so signal an event to call the registered function
// at a lower TPL.
gBS->SignalEvent (CurrentNotify->Event);
}
}
}
VOID
EFIAPI
GopPrivateBreakCallbackFunction (
IN VOID *Context,
IN EFI_KEY_DATA *KeyData
)
{
KeyMapBreak (KeyData);
}
//
// Simple Text In implementation.
//
/**
Reset the input device and optionally run diagnostics
@param This Protocol instance pointer.
@param ExtendedVerification Driver may perform diagnostics on reset.
@retval EFI_SUCCESS The device was reset.
@retval EFI_DEVICE_ERROR The device is not functioning properly and could not be reset.
**/
EFI_STATUS
EFIAPI
EmuGopSimpleTextInReset (
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
{
GOP_PRIVATE_DATA *Private;
EFI_KEY_DATA KeyData;
EFI_TPL OldTpl;
Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
if (Private->EmuGraphicsWindow == NULL) {
return EFI_SUCCESS;
}
//
// Enter critical section
//
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
//
// A reset is draining the Queue
//
while (Private->EmuGraphicsWindow->GetKey (Private->EmuGraphicsWindow, &KeyData) == EFI_SUCCESS)
;
//
// Leave critical section and return
//
gBS->RestoreTPL (OldTpl);
return EFI_SUCCESS;
}
/**
Reads the next keystroke from the input device. The WaitForKey Event can
be used to test for existence of a keystroke via WaitForEvent () call.
@param This Protocol instance pointer.
@param Key A pointer to a buffer that is filled in with the keystroke
information for the key that was pressed.
@retval EFI_SUCCESS The keystroke information was returned.
@retval EFI_NOT_READY There was no keystroke data available.
@retval EFI_DEVICE_ERROR The keystroke information was not returned due to
hardware errors.
**/
EFI_STATUS
EFIAPI
EmuGopSimpleTextInReadKeyStroke (
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
OUT EFI_INPUT_KEY *Key
)
{
GOP_PRIVATE_DATA *Private;
EFI_STATUS Status;
EFI_TPL OldTpl;
EFI_KEY_DATA KeyData;
Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
if (Private->EmuGraphicsWindow == NULL) {
return EFI_NOT_READY;
}
//
// Enter critical section
//
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
Status = Private->EmuGraphicsWindow->GetKey (Private->EmuGraphicsWindow, &KeyData);
CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY));
//
// Leave critical section and return
//
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
SimpleTextIn and SimpleTextInEx Notify Wait Event
@param Event Event whose notification function is being invoked.
@param Context Pointer to GOP_PRIVATE_DATA.
**/
VOID
EFIAPI
EmuGopSimpleTextInWaitForKey (
IN EFI_EVENT Event,
IN VOID *Context
)
{
GOP_PRIVATE_DATA *Private;
EFI_STATUS Status;
EFI_TPL OldTpl;
Private = (GOP_PRIVATE_DATA *) Context;
if (Private->EmuGraphicsWindow == NULL) {
return;
}
//
// Enter critical section
//
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
Status = Private->EmuGraphicsWindow->CheckKey (Private->EmuGraphicsWindow);
if (!EFI_ERROR (Status)) {
//
// If a there is a key in the queue signal our event.
//
gBS->SignalEvent (Event);
}
//
// Leave critical section and return
//
gBS->RestoreTPL (OldTpl);
}
//
// Simple Text Input Ex protocol functions
//
/**
The Reset() function resets the input device hardware. As part
of initialization process, the firmware/device will make a quick
but reasonable attempt to verify that the device is functioning.
If the ExtendedVerification flag is TRUE the firmware may take
an extended amount of time to verify the device is operating on
reset. Otherwise the reset operation is to occur as quickly as
possible. The hardware verification process is not defined by
this specification and is left up to the platform firmware or
driver to implement.
@param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
@param ExtendedVerification Indicates that the driver may
perform a more exhaustive
verification operation of the
device during reset.
@retval EFI_SUCCESS The device was reset.
@retval EFI_DEVICE_ERROR The device is not functioning
correctly and could not be reset.
**/
EFI_STATUS
EFIAPI
EmuGopSimpleTextInExResetEx (
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
/*++
Routine Description:
Reset the input device and optionaly run diagnostics
Arguments:
This - Protocol instance pointer.
ExtendedVerification - Driver may perform diagnostics on reset.
Returns:
EFI_SUCCESS - The device was reset.
**/
{
GOP_PRIVATE_DATA *Private;
Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This);
return EFI_SUCCESS;
}
/**
The function reads the next keystroke from the input device. If
there is no pending keystroke the function returns
EFI_NOT_READY. If there is a pending keystroke, then
KeyData.Key.ScanCode is the EFI scan code defined in Error!
Reference source not found. The KeyData.Key.UnicodeChar is the
actual printable character or is zero if the key does not
represent a printable character (control key, function key,
etc.). The KeyData.KeyState is shift state for the character
reflected in KeyData.Key.UnicodeChar or KeyData.Key.ScanCode .
When interpreting the data from this function, it should be
noted that if a class of printable characters that are
normally adjusted by shift modifiers (e.g. Shift Key + "f"
key) would be presented solely as a KeyData.Key.UnicodeChar
without the associated shift state. So in the previous example
of a Shift Key + "f" key being pressed, the only pertinent
data returned would be KeyData.Key.UnicodeChar with the value
of "F". This of course would not typically be the case for
non-printable characters such as the pressing of the Right
Shift Key + F10 key since the corresponding returned data
would be reflected both in the KeyData.KeyState.KeyShiftState
and KeyData.Key.ScanCode values. UEFI drivers which implement
the EFI_SIMPLE_TEXT_INPUT_EX protocol are required to return
KeyData.Key and KeyData.KeyState values. These drivers must
always return the most current state of
KeyData.KeyState.KeyShiftState and
KeyData.KeyState.KeyToggleState. It should also be noted that
certain input devices may not be able to produce shift or toggle
state information, and in those cases the high order bit in the
respective Toggle and Shift state fields should not be active.
@param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
@param KeyData A pointer to a buffer that is filled in with
the keystroke state data for the key that was
pressed.
@retval EFI_SUCCESS The keystroke information was
returned.
@retval EFI_NOT_READY There was no keystroke data available.
EFI_DEVICE_ERROR The keystroke
information was not returned due to
hardware errors.
**/
EFI_STATUS
EFIAPI
EmuGopSimpleTextInExReadKeyStrokeEx (
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
OUT EFI_KEY_DATA *KeyData
)
/*++
Routine Description:
Reads the next keystroke from the input device. The WaitForKey Event can
be used to test for existance of a keystroke via WaitForEvent () call.
Arguments:
This - Protocol instance pointer.
KeyData - A pointer to a buffer that is filled in with the keystroke
state data for the key that was pressed.
Returns:
EFI_SUCCESS - The keystroke information was returned.
EFI_NOT_READY - There was no keystroke data availiable.
EFI_DEVICE_ERROR - The keystroke information was not returned due to
hardware errors.
EFI_INVALID_PARAMETER - KeyData is NULL.
**/
{
EFI_STATUS Status;
GOP_PRIVATE_DATA *Private;
EFI_TPL OldTpl;
if (KeyData == NULL) {
return EFI_INVALID_PARAMETER;
}
Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
if (Private->EmuGraphicsWindow == NULL) {
return EFI_NOT_READY;
}
//
// Enter critical section
//
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
Status = Private->EmuGraphicsWindow->GetKey(Private->EmuGraphicsWindow, KeyData);
//
// Leave critical section and return
//
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
The SetState() function allows the input device hardware to
have state settings adjusted.
@param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
@param KeyToggleState Pointer to the EFI_KEY_TOGGLE_STATE to
set the state for the input device.
@retval EFI_SUCCESS The device state was set appropriately.
@retval EFI_DEVICE_ERROR The device is not functioning
correctly and could not have the
setting adjusted.
@retval EFI_UNSUPPORTED The device does not support the
ability to have its state set.
**/
EFI_STATUS
EFIAPI
EmuGopSimpleTextInExSetState (
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN EFI_KEY_TOGGLE_STATE *KeyToggleState
)
{
GOP_PRIVATE_DATA *Private;
EFI_STATUS Status;
EFI_TPL OldTpl;
Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
if (Private->EmuGraphicsWindow == NULL) {
return EFI_NOT_READY;
}
//
// Enter critical section
//
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
Status = Private->EmuGraphicsWindow->KeySetState (Private->EmuGraphicsWindow, KeyToggleState);
//
// Leave critical section and return
//
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
SimpleTextIn and SimpleTextInEx Notify Wait Event
@param Event Event whose notification function is being invoked.
@param Context Pointer to GOP_PRIVATE_DATA.
**/
VOID
EFIAPI
EmuGopRegisterKeyCallback (
IN EFI_EVENT Event,
IN VOID *Context
)
{
EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *ExNotify = (EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *)Context;
ExNotify->KeyNotificationFn (&ExNotify->KeyData);
}
/**
The RegisterKeystrokeNotify() function registers a function
which will be called when a specified keystroke will occur.
@param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
@param KeyData A pointer to a buffer that is filled in with
the keystroke information for the key that was
pressed.
@param KeyNotificationFunction Points to the function to be
called when the key sequence
is typed specified by KeyData.
@param NotifyHandle Points to the unique handle assigned to
the registered notification.
@retval EFI_SUCCESS The device state was set
appropriately.
@retval EFI_OUT_OF_RESOURCES Unable to allocate necessary
data structures.
**/
EFI_STATUS
EFIAPI
EmuGopSimpleTextInExRegisterKeyNotify (
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN EFI_KEY_DATA *KeyData,
IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
OUT EFI_HANDLE *NotifyHandle
)
{
EFI_STATUS Status;
GOP_PRIVATE_DATA *Private;
EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *CurrentNotify;
LIST_ENTRY *Link;
EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *NewNotify;
if (KeyData == NULL || KeyNotificationFunction == NULL || NotifyHandle == NULL) {
return EFI_INVALID_PARAMETER;
}
Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This);
//
// Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.
//
for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
CurrentNotify = CR (
Link,
EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY,
NotifyEntry,
EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE
);
if (GopPrivateIsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {
if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {
*NotifyHandle = CurrentNotify->NotifyHandle;
return EFI_SUCCESS;
}
}
}
//
// Allocate resource to save the notification function
//
NewNotify = (EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *) AllocateZeroPool (sizeof (EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY));
if (NewNotify == NULL) {
return EFI_OUT_OF_RESOURCES;
}
NewNotify->Signature = EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE;
NewNotify->KeyNotificationFn = KeyNotificationFunction;
NewNotify->NotifyHandle = (EFI_HANDLE) NewNotify;
CopyMem (&NewNotify->KeyData, KeyData, sizeof (KeyData));
InsertTailList (&Private->NotifyList, &NewNotify->NotifyEntry);
Status = gBS->CreateEvent (
EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
EmuGopRegisterKeyCallback,
NewNotify,
&NewNotify->Event
);
ASSERT_EFI_ERROR (Status);
*NotifyHandle = NewNotify->NotifyHandle;
return EFI_SUCCESS;
}
/**
The UnregisterKeystrokeNotify() function removes the
notification which was previously registered.
@param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
@param NotificationHandle The handle of the notification
function being unregistered.
@retval EFI_SUCCESS The device state was set appropriately.
@retval EFI_INVALID_PARAMETER The NotificationHandle is
invalid.
**/
EFI_STATUS
EFIAPI
EmuGopSimpleTextInExUnregisterKeyNotify (
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN EFI_HANDLE NotificationHandle
)
/*++
Routine Description:
Remove a registered notification function from a particular keystroke.
Arguments:
This - Protocol instance pointer.
NotificationHandle - The handle of the notification function being unregistered.
Returns:
EFI_SUCCESS - The notification function was unregistered successfully.
EFI_INVALID_PARAMETER - The NotificationHandle is invalid.
**/
{
GOP_PRIVATE_DATA *Private;
LIST_ENTRY *Link;
EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *CurrentNotify;
if (NotificationHandle == NULL) {
return EFI_INVALID_PARAMETER;
}
if (((EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *) NotificationHandle)->Signature != EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE) {
return EFI_INVALID_PARAMETER;
}
Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This);
for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
CurrentNotify = CR (
Link,
EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY,
NotifyEntry,
EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE
);
if (CurrentNotify->NotifyHandle == NotificationHandle) {
//
// Remove the notification function from NotifyList and free resources
//
RemoveEntryList (&CurrentNotify->NotifyEntry);
gBS->CloseEvent (CurrentNotify->Event);
gBS->FreePool (CurrentNotify);
return EFI_SUCCESS;
}
}
//
// Can not find the specified Notification Handle
//
return EFI_INVALID_PARAMETER;
}
/**
Initialize SimplelTextIn and SimpleTextInEx protocols in the Private
context structure.
@param Private Context structure to fill in.
@return EFI_SUCCESS Initialization was a success
**/
EFI_STATUS
EmuGopInitializeSimpleTextInForWindow (
IN GOP_PRIVATE_DATA *Private
)
{
EFI_STATUS Status;
//
// Initialize Simple Text In protoocol
//
Private->SimpleTextIn.Reset = EmuGopSimpleTextInReset;
Private->SimpleTextIn.ReadKeyStroke = EmuGopSimpleTextInReadKeyStroke;
Status = gBS->CreateEvent (
EVT_NOTIFY_WAIT,
TPL_NOTIFY,
EmuGopSimpleTextInWaitForKey,
Private,
&Private->SimpleTextIn.WaitForKey
);
ASSERT_EFI_ERROR (Status);
//
// Initialize Simple Text In Ex
//
Private->SimpleTextInEx.Reset = EmuGopSimpleTextInExResetEx;
Private->SimpleTextInEx.ReadKeyStrokeEx = EmuGopSimpleTextInExReadKeyStrokeEx;
Private->SimpleTextInEx.SetState = EmuGopSimpleTextInExSetState;
Private->SimpleTextInEx.RegisterKeyNotify = EmuGopSimpleTextInExRegisterKeyNotify;
Private->SimpleTextInEx.UnregisterKeyNotify = EmuGopSimpleTextInExUnregisterKeyNotify;
Private->SimpleTextInEx.Reset (&Private->SimpleTextInEx, FALSE);
InitializeListHead (&Private->NotifyList);
Status = gBS->CreateEvent (
EVT_NOTIFY_WAIT,
TPL_NOTIFY,
EmuGopSimpleTextInWaitForKey,
Private,
&Private->SimpleTextInEx.WaitForKeyEx
);
ASSERT_EFI_ERROR (Status);
return Status;
}
//
// Simple Pointer implementation.
//
/**
Resets the pointer device hardware.
@param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL
instance.
@param ExtendedVerification Indicates that the driver may perform a more exhaustive
verification operation of the device during reset.
@retval EFI_SUCCESS The device was reset.
@retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
**/
EFI_STATUS
EFIAPI
EmuGopSimplePointerReset (
IN EFI_SIMPLE_POINTER_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
{
GOP_PRIVATE_DATA *Private;
EFI_SIMPLE_POINTER_STATE State;
EFI_TPL OldTpl;
Private = GOP_PRIVATE_DATA_FROM_POINTER_MODE_THIS (This);
if (Private->EmuGraphicsWindow == NULL) {
return EFI_SUCCESS;
}
//
// Enter critical section
//
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
//
// A reset is draining the Queue
//
while (Private->EmuGraphicsWindow->GetPointerState (Private->EmuGraphicsWindow, &State) == EFI_SUCCESS)
;
//
// Leave critical section and return
//
gBS->RestoreTPL (OldTpl);
return EFI_SUCCESS;
}
/**
Retrieves the current state of a pointer device.
@param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL
instance.
@param State A pointer to the state information on the pointer device.
@retval EFI_SUCCESS The state of the pointer device was returned in State.
@retval EFI_NOT_READY The state of the pointer device has not changed since the last call to
GetState().
@retval EFI_DEVICE_ERROR A device error occurred while attempting to retrieve the pointer device's
current state.
**/
EFI_STATUS
EFIAPI
EmuGopSimplePointerGetState (
IN EFI_SIMPLE_POINTER_PROTOCOL *This,
IN OUT EFI_SIMPLE_POINTER_STATE *State
)
{
GOP_PRIVATE_DATA *Private;
EFI_STATUS Status;
EFI_TPL OldTpl;
Private = GOP_PRIVATE_DATA_FROM_POINTER_MODE_THIS (This);
if (Private->EmuGraphicsWindow == NULL) {
return EFI_NOT_READY;
}
//
// Enter critical section
//
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
Status = Private->EmuGraphicsWindow->GetPointerState (Private->EmuGraphicsWindow, State);
//
// Leave critical section and return
//
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
SimplePointer Notify Wait Event
@param Event Event whose notification function is being invoked.
@param Context Pointer to GOP_PRIVATE_DATA.
**/
VOID
EFIAPI
EmuGopSimplePointerWaitForInput (
IN EFI_EVENT Event,
IN VOID *Context
)
{
GOP_PRIVATE_DATA *Private;
EFI_STATUS Status;
EFI_TPL OldTpl;
Private = (GOP_PRIVATE_DATA *) Context;
if (Private->EmuGraphicsWindow == NULL) {
return;
}
//
// Enter critical section
//
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
Status = Private->EmuGraphicsWindow->CheckPointer (Private->EmuGraphicsWindow);
if (!EFI_ERROR (Status)) {
//
// If the pointer state has changed, signal our event.
//
gBS->SignalEvent (Event);
}
//
// Leave critical section and return
//
gBS->RestoreTPL (OldTpl);
}
/**
SimplePointer constructor
@param Private Context structure to fill in.
@retval EFI_SUCCESS Constructor had success
**/
EFI_STATUS
EmuGopInitializeSimplePointerForWindow (
IN GOP_PRIVATE_DATA *Private
)
{
EFI_STATUS Status;
//
// Initialize Simple Pointer protoocol
//
Private->PointerMode.ResolutionX = 1;
Private->PointerMode.ResolutionY = 1;
Private->PointerMode.ResolutionZ = 1;
Private->PointerMode.LeftButton = TRUE;
Private->PointerMode.RightButton = TRUE;
Private->SimplePointer.Reset = EmuGopSimplePointerReset;
Private->SimplePointer.GetState = EmuGopSimplePointerGetState;
Private->SimplePointer.Mode = &Private->PointerMode;
Status = gBS->CreateEvent (
EVT_NOTIFY_WAIT,
TPL_NOTIFY,
EmuGopSimplePointerWaitForInput,
Private,
&Private->SimplePointer.WaitForInput
);
return Status;
}

View File

@@ -0,0 +1,420 @@
/*++ @file
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2010 - 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EmuGopScreen.c
Abstract:
This file produces the graphics abstration of UGA. It is called by
EmuGopDriver.c file which deals with the EFI 1.1 driver model.
This file just does graphics.
**/
#include "Gop.h"
EFI_EVENT mGopScreenExitBootServicesEvent;
GOP_MODE_DATA mGopModeData[] = {
{ 800, 600, 0, 0 },
{ 640, 480, 0, 0 },
{ 720, 400, 0, 0 },
{1024, 768, 0, 0 },
{1280, 1024, 0, 0 }
};
/**
Returns information for an available graphics mode that the graphics device
and the set of active video output devices supports.
@param This The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.
@param ModeNumber The mode number to return information on.
@param SizeOfInfo A pointer to the size, in bytes, of the Info buffer.
@param Info A pointer to callee allocated buffer that returns information about ModeNumber.
@retval EFI_SUCCESS Mode information returned.
@retval EFI_BUFFER_TOO_SMALL The Info buffer was too small.
@retval EFI_DEVICE_ERROR A hardware error occurred trying to retrieve the video mode.
@retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
@retval EFI_INVALID_PARAMETER One of the input args was NULL.
**/
EFI_STATUS
EFIAPI
EmuGopQuerytMode (
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN UINT32 ModeNumber,
OUT UINTN *SizeOfInfo,
OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
)
{
GOP_PRIVATE_DATA *Private;
Private = GOP_PRIVATE_DATA_FROM_THIS (This);
if (Info == NULL || SizeOfInfo == NULL || (UINTN) ModeNumber >= This->Mode->MaxMode) {
return EFI_INVALID_PARAMETER;
}
*Info = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
if (*Info == NULL) {
return EFI_OUT_OF_RESOURCES;
}
*SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
(*Info)->Version = 0;
(*Info)->HorizontalResolution = Private->ModeData[ModeNumber].HorizontalResolution;
(*Info)->VerticalResolution = Private->ModeData[ModeNumber].VerticalResolution;
(*Info)->PixelFormat = PixelBltOnly;
(*Info)->PixelsPerScanLine = (*Info)->HorizontalResolution;
return EFI_SUCCESS;
}
/**
Set the video device into the specified mode and clears the visible portions of
the output display to black.
@param This The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.
@param ModeNumber Abstraction that defines the current video mode.
@retval EFI_SUCCESS The graphics mode specified by ModeNumber was selected.
@retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
@retval EFI_UNSUPPORTED ModeNumber is not supported by this device.
**/
EFI_STATUS
EFIAPI
EmuGopSetMode (
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN UINT32 ModeNumber
)
{
EFI_STATUS Status;
GOP_PRIVATE_DATA *Private;
GOP_MODE_DATA *ModeData;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Fill;
Private = GOP_PRIVATE_DATA_FROM_THIS (This);
if (ModeNumber >= This->Mode->MaxMode) {
return EFI_UNSUPPORTED;
}
ModeData = &Private->ModeData[ModeNumber];
This->Mode->Mode = ModeNumber;
Private->GraphicsOutput.Mode->Info->HorizontalResolution = ModeData->HorizontalResolution;
Private->GraphicsOutput.Mode->Info->VerticalResolution = ModeData->VerticalResolution;
Private->GraphicsOutput.Mode->Info->PixelsPerScanLine = ModeData->HorizontalResolution;
if (Private->HardwareNeedsStarting) {
Status = EmuGopStartWindow (
Private,
ModeData->HorizontalResolution,
ModeData->VerticalResolution,
ModeData->ColorDepth,
ModeData->RefreshRate
);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
Private->HardwareNeedsStarting = FALSE;
}
Status = Private->EmuGraphicsWindow->Size(
Private->EmuGraphicsWindow,
ModeData->HorizontalResolution,
ModeData->VerticalResolution
);
Fill.Red = 0x7f;
Fill.Green = 0x7F;
Fill.Blue = 0x7f;
This->Blt (
This,
&Fill,
EfiBltVideoFill,
0,
0,
0,
0,
ModeData->HorizontalResolution,
ModeData->VerticalResolution,
ModeData->HorizontalResolution * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
);
return EFI_SUCCESS;
}
/**
Blt a rectangle of pixels on the graphics screen. Blt stands for BLock Transfer.
@param This Protocol instance pointer.
@param BltBuffer Buffer containing data to blit into video buffer. This
buffer has a size of Width*Height*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
@param BltOperation Operation to perform on BlitBuffer and video memory
@param SourceX X coordinate of source for the BltBuffer.
@param SourceY Y coordinate of source for the BltBuffer.
@param DestinationX X coordinate of destination for the BltBuffer.
@param DestinationY Y coordinate of destination for the BltBuffer.
@param Width Width of rectangle in BltBuffer in pixels.
@param Height Hight of rectangle in BltBuffer in pixels.
@param Delta OPTIONAL
@retval EFI_SUCCESS The Blt operation completed.
@retval EFI_INVALID_PARAMETER BltOperation is not valid.
@retval EFI_DEVICE_ERROR A hardware error occured writting to the video buffer.
**/
EFI_STATUS
EFIAPI
EmuGopBlt (
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
IN UINTN SourceX,
IN UINTN SourceY,
IN UINTN DestinationX,
IN UINTN DestinationY,
IN UINTN Width,
IN UINTN Height,
IN UINTN Delta OPTIONAL
)
{
GOP_PRIVATE_DATA *Private;
EFI_TPL OriginalTPL;
EFI_STATUS Status;
EMU_GRAPHICS_WINDOWS__BLT_ARGS GopBltArgs;
Private = GOP_PRIVATE_DATA_FROM_THIS (This);
if ((BltOperation < 0) || (BltOperation >= EfiGraphicsOutputBltOperationMax)) {
return EFI_INVALID_PARAMETER;
}
if (Width == 0 || Height == 0) {
return EFI_INVALID_PARAMETER;
}
//
// If Delta is zero, then the entire BltBuffer is being used, so Delta
// is the number of bytes in each row of BltBuffer. Since BltBuffer is Width pixels size,
// the number of bytes in each row can be computed.
//
if (Delta == 0) {
Delta = Width * sizeof (EFI_UGA_PIXEL);
}
//
// We have to raise to TPL Notify, so we make an atomic write the frame buffer.
// We would not want a timer based event (Cursor, ...) to come in while we are
// doing this operation.
//
OriginalTPL = gBS->RaiseTPL (TPL_NOTIFY);
//
// Pack UGA Draw protocol parameters to EMU_GRAPHICS_WINDOWS__BLT_ARGS structure to adapt to
// GopBlt() API of Unix UGA IO protocol.
//
GopBltArgs.DestinationX = DestinationX;
GopBltArgs.DestinationY = DestinationY;
GopBltArgs.Height = Height;
GopBltArgs.Width = Width;
GopBltArgs.SourceX = SourceX;
GopBltArgs.SourceY = SourceY;
GopBltArgs.Delta = Delta;
Status = Private->EmuGraphicsWindow->Blt (
Private->EmuGraphicsWindow,
(EFI_UGA_PIXEL *)BltBuffer,
(EFI_UGA_BLT_OPERATION)BltOperation,
&GopBltArgs
);
gBS->RestoreTPL (OriginalTPL);
return Status;
}
//
// Construction and Destruction functions
//
EFI_STATUS
EmuGopSupported (
IN EMU_IO_THUNK_PROTOCOL *EmuIoThunk
)
{
//
// Check to see if the IO abstraction represents a device type we support.
//
// This would be replaced a check of PCI subsystem ID, etc.
//
if (!CompareGuid (EmuIoThunk->Protocol, &gEmuGraphicsWindowProtocolGuid)) {
return EFI_UNSUPPORTED;
}
return EFI_SUCCESS;
}
EFI_STATUS
EmuGopStartWindow (
IN GOP_PRIVATE_DATA *Private,
IN UINT32 HorizontalResolution,
IN UINT32 VerticalResolution,
IN UINT32 ColorDepth,
IN UINT32 RefreshRate
)
{
EFI_STATUS Status;
//
// Register to be notified on exit boot services so we can destroy the window.
//
Status = gBS->CreateEvent (
EVT_SIGNAL_EXIT_BOOT_SERVICES,
TPL_CALLBACK,
ShutdownGopEvent,
Private,
&mGopScreenExitBootServicesEvent
);
Status = Private->EmuIoThunk->Open (Private->EmuIoThunk);
if (!EFI_ERROR (Status)) {
Private->EmuGraphicsWindow = Private->EmuIoThunk->Interface;
// Register callback to support RegisterKeyNotify()
Status = Private->EmuGraphicsWindow->RegisterKeyNotify (
Private->EmuGraphicsWindow,
GopPrivateMakeCallbackFunction,
GopPrivateBreakCallbackFunction,
Private
);
ASSERT_EFI_ERROR (Status);
}
return Status;
}
EFI_STATUS
EmuGopConstructor (
GOP_PRIVATE_DATA *Private
)
{
Private->ModeData = mGopModeData;
Private->GraphicsOutput.QueryMode = EmuGopQuerytMode;
Private->GraphicsOutput.SetMode = EmuGopSetMode;
Private->GraphicsOutput.Blt = EmuGopBlt;
//
// Allocate buffer for Graphics Output Protocol mode information
//
Private->GraphicsOutput.Mode = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE));
if (Private->GraphicsOutput.Mode == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Private->GraphicsOutput.Mode->Info = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
if (Private->GraphicsOutput.Mode->Info == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Private->GraphicsOutput.Mode->MaxMode = sizeof(mGopModeData) / sizeof(GOP_MODE_DATA);
//
// Till now, we have no idea about the window size.
//
Private->GraphicsOutput.Mode->Mode = GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER;
Private->GraphicsOutput.Mode->Info->Version = 0;
Private->GraphicsOutput.Mode->Info->HorizontalResolution = 0;
Private->GraphicsOutput.Mode->Info->VerticalResolution = 0;
Private->GraphicsOutput.Mode->Info->PixelFormat = PixelBltOnly;
Private->GraphicsOutput.Mode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
Private->GraphicsOutput.Mode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) (UINTN) NULL;
Private->GraphicsOutput.Mode->FrameBufferSize = 0;
Private->HardwareNeedsStarting = TRUE;
Private->EmuGraphicsWindow = NULL;
EmuGopInitializeSimpleTextInForWindow (Private);
EmuGopInitializeSimplePointerForWindow (Private);
return EFI_SUCCESS;
}
EFI_STATUS
EmuGopDestructor (
GOP_PRIVATE_DATA *Private
)
{
EFI_STATUS Status;
Status = EFI_SUCCESS;
if (!Private->HardwareNeedsStarting) {
Status = Private->EmuIoThunk->Close (Private->EmuIoThunk);
Private->EmuGraphicsWindow = NULL;
}
//
// Free graphics output protocol occupied resource
//
if (Private->GraphicsOutput.Mode != NULL) {
if (Private->GraphicsOutput.Mode->Info != NULL) {
FreePool (Private->GraphicsOutput.Mode->Info);
}
FreePool (Private->GraphicsOutput.Mode);
}
return EFI_SUCCESS;
}
VOID
EFIAPI
ShutdownGopEvent (
IN EFI_EVENT Event,
IN VOID *Context
)
/*++
Routine Description:
This is the UGA screen's callback notification function for exit-boot-services.
All we do here is call EmuGopDestructor().
Arguments:
Event - not used
Context - pointer to the Private structure.
Returns:
None.
**/
{
EFI_STATUS Status;
Status = EmuGopDestructor (Context);
}

View File

@@ -0,0 +1,244 @@
/** @file
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "EmuSimpleFileSystem.h"
//
// EFI Component Name Functions
//
EFI_STATUS
EFIAPI
EmuSimpleFileSystemComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
EFI_STATUS
EFIAPI
EmuSimpleFileSystemComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
);
//
// EFI Component Name Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gEmuSimpleFileSystemComponentName = {
EmuSimpleFileSystemComponentNameGetDriverName,
EmuSimpleFileSystemComponentNameGetControllerName,
"eng"
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuSimpleFileSystemComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME)EmuSimpleFileSystemComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)EmuSimpleFileSystemComponentNameGetControllerName,
"en"
};
EFI_UNICODE_STRING_TABLE mEmuSimpleFileSystemDriverNameTable[] = {
{
"eng;en",
L"Emu Simple File System Driver"
},
{
NULL,
NULL
}
};
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified
in RFC 4646 or ISO 639-2 language code format.
@param DriverName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
driver specified by This in the language
specified by Language.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
EmuSimpleFileSystemComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
)
{
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mEmuSimpleFileSystemDriverNameTable,
DriverName,
(BOOLEAN)(This == &gEmuSimpleFileSystemComponentName)
);
}
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param ControllerHandle[in] The handle of a controller that the driver
specified by This is managing. This handle
specifies the controller whose name is to be
returned.
@param ChildHandle[in] The handle of the child controller to retrieve
the name of. This is an optional parameter that
may be NULL. It will be NULL for device
drivers. It will also be NULL for a bus drivers
that wish to retrieve the name of the bus
controller. It will not be NULL for a bus
driver that wishes to retrieve the name of a
child controller.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified in
RFC 4646 or ISO 639-2 language code format.
@param ControllerName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
controller specified by ControllerHandle and
ChildHandle in the language specified by
Language from the point of view of the driver
specified by This.
@retval EFI_SUCCESS The Unicode string for the user readable name in
the language specified by Language for the
driver specified by This was returned in
DriverName.
@retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
EmuSimpleFileSystemComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
{
EFI_STATUS Status;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;
EMU_SIMPLE_FILE_SYSTEM_PRIVATE *Private;
//
// This is a device driver, so ChildHandle must be NULL.
//
if (ChildHandle != NULL) {
return EFI_UNSUPPORTED;
}
//
// Make sure this driver is currently managing ControllerHandle
//
Status = EfiTestManagedDevice (
ControllerHandle,
gEmuSimpleFileSystemDriverBinding.DriverBindingHandle,
&gEmuIoThunkProtocolGuid
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
//
// Get our context back
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiSimpleFileSystemProtocolGuid,
(VOID**)&SimpleFileSystem,
gEmuSimpleFileSystemDriverBinding.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
Private = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (SimpleFileSystem);
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
Private->ControllerNameTable,
ControllerName,
(BOOLEAN)(This == &gEmuSimpleFileSystemComponentName)
);
}

View File

@@ -0,0 +1,915 @@
/*++ @file
Produce Simple File System abstractions for directories on your PC using Posix APIs.
The configuration of what devices to mount or emulate comes from UNIX
environment variables. The variables must be visible to the Microsoft*
Developer Studio for them to work.
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "EmuSimpleFileSystem.h"
/**
Opens a new file relative to the source file's location.
@param This The protocol instance pointer.
@param NewHandle Returns File Handle for FileName.
@param FileName Null terminated string. "\", ".", and ".." are supported.
@param OpenMode Open mode for file.
@param Attributes Only used for EFI_FILE_MODE_CREATE.
@retval EFI_SUCCESS The device was opened.
@retval EFI_NOT_FOUND The specified file could not be found on the device.
@retval EFI_NO_MEDIA The device has no media.
@retval EFI_MEDIA_CHANGED The media has changed.
@retval EFI_DEVICE_ERROR The device reported an error.
@retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
@retval EFI_ACCESS_DENIED The service denied access to the file.
@retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.
@retval EFI_VOLUME_FULL The volume is full.
**/
EFI_STATUS
EFIAPI
EmuSimpleFileSystemOpen (
IN EFI_FILE_PROTOCOL *This,
OUT EFI_FILE_PROTOCOL **NewHandle,
IN CHAR16 *FileName,
IN UINT64 OpenMode,
IN UINT64 Attributes
)
{
EMU_EFI_FILE_PRIVATE *PrivateFile;
//
// Check for obvious invalid parameters.
//
if (This == NULL || NewHandle == NULL || FileName == NULL) {
return EFI_INVALID_PARAMETER;
}
switch (OpenMode) {
case EFI_FILE_MODE_CREATE | EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:
if (Attributes &~EFI_FILE_VALID_ATTR) {
return EFI_INVALID_PARAMETER;
}
if (Attributes & EFI_FILE_READ_ONLY) {
return EFI_INVALID_PARAMETER;
}
//
// fall through
//
case EFI_FILE_MODE_READ:
case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:
break;
default:
return EFI_INVALID_PARAMETER;
}
PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
return PrivateFile->Io->Open (PrivateFile->Io, NewHandle, FileName, OpenMode, Attributes);
}
/**
Close the file handle
@param This Protocol instance pointer.
@retval EFI_SUCCESS The file was closed.
**/
EFI_STATUS
EFIAPI
EmuSimpleFileSystemClose (
IN EFI_FILE_PROTOCOL *This
)
{
EFI_STATUS Status;
EMU_EFI_FILE_PRIVATE *PrivateFile;
EFI_TPL OldTpl;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
Status = PrivateFile->Io->Close (PrivateFile->Io);
if (!EFI_ERROR (Status)) {
gBS->FreePool (PrivateFile);
}
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Close and delete the file handle.
@param This Protocol instance pointer.
@retval EFI_SUCCESS The file was closed and deleted.
@retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.
**/
EFI_STATUS
EFIAPI
EmuSimpleFileSystemDelete (
IN EFI_FILE_PROTOCOL *This
)
{
EFI_STATUS Status;
EMU_EFI_FILE_PRIVATE *PrivateFile;
EFI_TPL OldTpl;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
Status = PrivateFile->Io->Delete (PrivateFile->Io);
if (!EFI_ERROR (Status)) {
gBS->FreePool (PrivateFile);
}
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Read data from the file.
@param This Protocol instance pointer.
@param BufferSize On input size of buffer, on output amount of data in buffer.
@param Buffer The buffer in which data is read.
@retval EFI_SUCCESS Data was read.
@retval EFI_NO_MEDIA The device has no media.
@retval EFI_DEVICE_ERROR The device reported an error.
@retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
@retval EFI_BUFFER_TO_SMALL BufferSize is too small. BufferSize contains required size.
**/
EFI_STATUS
EFIAPI
EmuSimpleFileSystemRead (
IN EFI_FILE_PROTOCOL *This,
IN OUT UINTN *BufferSize,
OUT VOID *Buffer
)
{
EFI_STATUS Status;
EMU_EFI_FILE_PRIVATE *PrivateFile;
EFI_TPL OldTpl;
if (This == NULL || BufferSize == NULL) {
return EFI_INVALID_PARAMETER;
}
if ((*BufferSize != 0) && (Buffer == NULL)) {
// Buffer can be NULL if *BufferSize is zero
return EFI_INVALID_PARAMETER;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
Status = PrivateFile->Io->Read (PrivateFile->Io, BufferSize, Buffer);
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Write data to a file.
@param This Protocol instance pointer.
@param BufferSize On input size of buffer, on output amount of data in buffer.
@param Buffer The buffer in which data to write.
@retval EFI_SUCCESS Data was written.
@retval EFI_UNSUPPORTED Writes to Open directory are not supported.
@retval EFI_NO_MEDIA The device has no media.
@retval EFI_DEVICE_ERROR The device reported an error.
@retval EFI_DEVICE_ERROR An attempt was made to write to a deleted file.
@retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
@retval EFI_WRITE_PROTECTED The device is write protected.
@retval EFI_ACCESS_DENIED The file was open for read only.
@retval EFI_VOLUME_FULL The volume is full.
**/
EFI_STATUS
EFIAPI
EmuSimpleFileSystemWrite (
IN EFI_FILE_PROTOCOL *This,
IN OUT UINTN *BufferSize,
IN VOID *Buffer
)
{
EFI_STATUS Status;
EMU_EFI_FILE_PRIVATE *PrivateFile;
EFI_TPL OldTpl;
if (This == NULL || BufferSize == NULL || Buffer == NULL) {
return EFI_INVALID_PARAMETER;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
Status = PrivateFile->Io->Write (PrivateFile->Io, BufferSize, Buffer);
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Set a files current position
@param This Protocol instance pointer.
@param Position Byte position from the start of the file.
@retval EFI_SUCCESS Position was updated.
@retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open.
**/
EFI_STATUS
EFIAPI
EmuSimpleFileSystemGetPosition (
IN EFI_FILE_PROTOCOL *This,
OUT UINT64 *Position
)
{
EFI_STATUS Status;
EMU_EFI_FILE_PRIVATE *PrivateFile;
EFI_TPL OldTpl;
if (This == NULL || Position == NULL) {
return EFI_INVALID_PARAMETER;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
Status = PrivateFile->Io->GetPosition (PrivateFile->Io, Position);
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Get a file's current position
@param This Protocol instance pointer.
@param Position Byte position from the start of the file.
@retval EFI_SUCCESS Position was updated.
@retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open..
**/
EFI_STATUS
EFIAPI
EmuSimpleFileSystemSetPosition (
IN EFI_FILE_PROTOCOL *This,
IN UINT64 Position
)
{
EFI_STATUS Status;
EMU_EFI_FILE_PRIVATE *PrivateFile;
EFI_TPL OldTpl;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
Status = PrivateFile->Io->SetPosition (PrivateFile->Io, Position);
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Get information about a file.
@param This Protocol instance pointer.
@param InformationType Type of information to return in Buffer.
@param BufferSize On input size of buffer, on output amount of data in buffer.
@param Buffer The buffer to return data.
@retval EFI_SUCCESS Data was returned.
@retval EFI_UNSUPPORTED InformationType is not supported.
@retval EFI_NO_MEDIA The device has no media.
@retval EFI_DEVICE_ERROR The device reported an error.
@retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
@retval EFI_WRITE_PROTECTED The device is write protected.
@retval EFI_ACCESS_DENIED The file was open for read only.
@retval EFI_BUFFER_TOO_SMALL Buffer was too small; required size returned in BufferSize.
**/
EFI_STATUS
EFIAPI
EmuSimpleFileSystemGetInfo (
IN EFI_FILE_PROTOCOL *This,
IN EFI_GUID *InformationType,
IN OUT UINTN *BufferSize,
OUT VOID *Buffer
)
{
EFI_STATUS Status;
EMU_EFI_FILE_PRIVATE *PrivateFile;
EFI_TPL OldTpl;
if (This == NULL || InformationType == NULL || BufferSize == NULL) {
return EFI_INVALID_PARAMETER;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
Status = PrivateFile->Io->GetInfo (PrivateFile->Io, InformationType, BufferSize, Buffer);
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Set information about a file
@param File Protocol instance pointer.
@param InformationType Type of information in Buffer.
@param BufferSize Size of buffer.
@param Buffer The data to write.
@retval EFI_SUCCESS Data was set.
@retval EFI_UNSUPPORTED InformationType is not supported.
@retval EFI_NO_MEDIA The device has no media.
@retval EFI_DEVICE_ERROR The device reported an error.
@retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
@retval EFI_WRITE_PROTECTED The device is write protected.
@retval EFI_ACCESS_DENIED The file was open for read only.
**/
EFI_STATUS
EFIAPI
EmuSimpleFileSystemSetInfo (
IN EFI_FILE_PROTOCOL*This,
IN EFI_GUID *InformationType,
IN UINTN BufferSize,
IN VOID *Buffer
)
{
EFI_STATUS Status;
EMU_EFI_FILE_PRIVATE *PrivateFile;
EFI_TPL OldTpl;
//
// Check for invalid parameters.
//
if (This == NULL || InformationType == NULL || BufferSize == 0 || Buffer == NULL) {
return EFI_INVALID_PARAMETER;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
Status = PrivateFile->Io->SetInfo (PrivateFile->Io, InformationType, BufferSize, Buffer);
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Flush data back for the file handle.
@param This Protocol instance pointer.
@retval EFI_SUCCESS Data was flushed.
@retval EFI_UNSUPPORTED Writes to Open directory are not supported.
@retval EFI_NO_MEDIA The device has no media.
@retval EFI_DEVICE_ERROR The device reported an error.
@retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
@retval EFI_WRITE_PROTECTED The device is write protected.
@retval EFI_ACCESS_DENIED The file was open for read only.
@retval EFI_VOLUME_FULL The volume is full.
**/
EFI_STATUS
EFIAPI
EmuSimpleFileSystemFlush (
IN EFI_FILE_PROTOCOL *This
)
{
EFI_STATUS Status;
EMU_EFI_FILE_PRIVATE *PrivateFile;
EFI_TPL OldTpl;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
Status = PrivateFile->Io->Flush (PrivateFile->Io);
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Open the root directory on a volume.
@param This Protocol instance pointer.
@param Root Returns an Open file handle for the root directory
@retval EFI_SUCCESS The device was opened.
@retval EFI_UNSUPPORTED This volume does not support the file system.
@retval EFI_NO_MEDIA The device has no media.
@retval EFI_DEVICE_ERROR The device reported an error.
@retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
@retval EFI_ACCESS_DENIED The service denied access to the file.
@retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.
**/
EFI_STATUS
EFIAPI
EmuSimpleFileSystemOpenVolume (
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
OUT EFI_FILE_PROTOCOL **Root
)
{
EFI_STATUS Status;
EMU_SIMPLE_FILE_SYSTEM_PRIVATE *Private;
EMU_EFI_FILE_PRIVATE *PrivateFile;
EFI_TPL OldTpl;
Status = EFI_UNSUPPORTED;
if (This == NULL || Root == NULL) {
return EFI_INVALID_PARAMETER;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
Private = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (This);
PrivateFile = AllocatePool (sizeof (EMU_EFI_FILE_PRIVATE));
if (PrivateFile == NULL) {
goto Done;
}
PrivateFile->Signature = EMU_EFI_FILE_PRIVATE_SIGNATURE;
PrivateFile->IoThunk = Private->IoThunk;
PrivateFile->SimpleFileSystem = This;
PrivateFile->EfiFile.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;
PrivateFile->EfiFile.Open = EmuSimpleFileSystemOpen;
PrivateFile->EfiFile.Close = EmuSimpleFileSystemClose;
PrivateFile->EfiFile.Delete = EmuSimpleFileSystemDelete;
PrivateFile->EfiFile.Read = EmuSimpleFileSystemRead;
PrivateFile->EfiFile.Write = EmuSimpleFileSystemWrite;
PrivateFile->EfiFile.GetPosition = EmuSimpleFileSystemGetPosition;
PrivateFile->EfiFile.SetPosition = EmuSimpleFileSystemSetPosition;
PrivateFile->EfiFile.GetInfo = EmuSimpleFileSystemGetInfo;
PrivateFile->EfiFile.SetInfo = EmuSimpleFileSystemSetInfo;
PrivateFile->EfiFile.Flush = EmuSimpleFileSystemFlush;
*Root = &PrivateFile->EfiFile;
Status = Private->Io->OpenVolume (Private->Io, &PrivateFile->Io);
if (EFI_ERROR (Status)) {
goto Done;
}
AddUnicodeString2 (
"eng",
gEmuSimpleFileSystemComponentName.SupportedLanguages,
&Private->ControllerNameTable,
Private->IoThunk->ConfigString,
TRUE
);
AddUnicodeString2 (
"en",
gEmuSimpleFileSystemComponentName.SupportedLanguages,
&Private->ControllerNameTable,
Private->IoThunk->ConfigString,
FALSE
);
Done:
if (EFI_ERROR (Status)) {
if (PrivateFile) {
gBS->FreePool (PrivateFile);
}
*Root = NULL;
}
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Tests to see if this driver supports a given controller. If a child device is provided,
it further tests to see if this driver supports creating a handle for the specified child device.
This function checks to see if the driver specified by This supports the device specified by
ControllerHandle. Drivers will typically use the device path attached to
ControllerHandle and/or the services from the bus I/O abstraction attached to
ControllerHandle to determine if the driver supports ControllerHandle. This function
may be called many times during platform initialization. In order to reduce boot times, the tests
performed by this function must be very small, and take as little time as possible to execute. This
function must not change the state of any hardware devices, and this function must be aware that the
device specified by ControllerHandle may already be managed by the same driver or a
different driver. This function must match its calls to AllocatePages() with FreePages(),
AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
Because ControllerHandle may have been previously started by the same driver, if a protocol is
already in the opened state, then it must not be closed with CloseProtocol(). This is required
to guarantee the state of ControllerHandle is not modified by this function.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle The handle of the controller to test. This handle
must support a protocol interface that supplies
an I/O abstraction to the driver.
@param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
parameter is ignored by device drivers, and is optional for bus
drivers. For bus drivers, if this parameter is not NULL, then
the bus driver must determine if the bus controller specified
by ControllerHandle and the child controller specified
by RemainingDevicePath are both supported by this
bus driver.
@retval EFI_SUCCESS The device specified by ControllerHandle and
RemainingDevicePath is supported by the driver specified by This.
@retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
RemainingDevicePath is already being managed by the driver
specified by This.
@retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
RemainingDevicePath is already being managed by a different
driver or an application that requires exclusive access.
Currently not implemented.
@retval EFI_UNSUPPORTED The device specified by ControllerHandle and
RemainingDevicePath is not supported by the driver specified by This.
**/
EFI_STATUS
EFIAPI
EmuSimpleFileSystemDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
EMU_IO_THUNK_PROTOCOL *EmuIoThunk;
//
// Open the IO Abstraction(s) needed to perform the supported test
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
(VOID **)&EmuIoThunk,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Make sure GUID is for a File System handle.
//
Status = EFI_UNSUPPORTED;
if (CompareGuid (EmuIoThunk->Protocol, &gEfiSimpleFileSystemProtocolGuid)) {
Status = EFI_SUCCESS;
}
//
// Close the I/O Abstraction(s) used to perform the supported test
//
gBS->CloseProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
return Status;
}
/**
Starts a device controller or a bus controller.
The Start() function is designed to be invoked from the EFI boot service ConnectController().
As a result, much of the error checking on the parameters to Start() has been moved into this
common boot service. It is legal to call Start() from other locations,
but the following calling restrictions must be followed, or the system behavior will not be deterministic.
1. ControllerHandle must be a valid EFI_HANDLE.
2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
EFI_DEVICE_PATH_PROTOCOL.
3. Prior to calling Start(), the Supported() function for the driver specified by This must
have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle The handle of the controller to start. This handle
must support a protocol interface that supplies
an I/O abstraction to the driver.
@param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
parameter is ignored by device drivers, and is optional for bus
drivers. For a bus driver, if this parameter is NULL, then handles
for all the children of Controller are created by this driver.
If this parameter is not NULL and the first Device Path Node is
not the End of Device Path Node, then only the handle for the
child device specified by the first Device Path Node of
RemainingDevicePath is created by this driver.
If the first Device Path Node of RemainingDevicePath is
the End of Device Path Node, no child handle is created by this
driver.
@retval EFI_SUCCESS The device was started.
@retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
@retval Others The driver failded to start the device.
**/
EFI_STATUS
EFIAPI
EmuSimpleFileSystemDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
EMU_IO_THUNK_PROTOCOL *EmuIoThunk;
EMU_SIMPLE_FILE_SYSTEM_PRIVATE *Private;
Private = NULL;
//
// Open the IO Abstraction(s) needed
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
(VOID **)&EmuIoThunk,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Validate GUID
//
if (!CompareGuid (EmuIoThunk->Protocol, &gEfiSimpleFileSystemProtocolGuid)) {
Status = EFI_UNSUPPORTED;
goto Done;
}
Private = AllocateZeroPool (sizeof (EMU_SIMPLE_FILE_SYSTEM_PRIVATE));
if (Private == NULL) {
goto Done;
}
Status = EmuIoThunk->Open (EmuIoThunk);
if (EFI_ERROR (Status)) {
goto Done;
}
Private->Signature = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE;
Private->IoThunk = EmuIoThunk;
Private->Io = EmuIoThunk->Interface;
Private->SimpleFileSystem.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;
Private->SimpleFileSystem.OpenVolume = EmuSimpleFileSystemOpenVolume;
Private->ControllerNameTable = NULL;
AddUnicodeString2 (
"eng",
gEmuSimpleFileSystemComponentName.SupportedLanguages,
&Private->ControllerNameTable,
EmuIoThunk->ConfigString,
TRUE
);
AddUnicodeString2 (
"en",
gEmuSimpleFileSystemComponentName2.SupportedLanguages,
&Private->ControllerNameTable,
EmuIoThunk->ConfigString,
FALSE
);
Status = gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiSimpleFileSystemProtocolGuid, &Private->SimpleFileSystem,
NULL
);
Done:
if (EFI_ERROR (Status)) {
if (Private != NULL) {
if (Private->ControllerNameTable != NULL) {
FreeUnicodeStringTable (Private->ControllerNameTable);
}
gBS->FreePool (Private);
}
gBS->CloseProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
}
return Status;
}
/**
Stops a device controller or a bus controller.
The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
As a result, much of the error checking on the parameters to Stop() has been moved
into this common boot service. It is legal to call Stop() from other locations,
but the following calling restrictions must be followed, or the system behavior will not be deterministic.
1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
same driver's Start() function.
2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
EFI_HANDLE. In addition, all of these handles must have been created in this driver's
Start() function, and the Start() function must have called OpenProtocol() on
ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle A handle to the device being stopped. The handle must
support a bus specific I/O protocol for the driver
to use to stop the device.
@param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
@param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
if NumberOfChildren is 0.
@retval EFI_SUCCESS The device was stopped.
@retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
**/
EFI_STATUS
EFIAPI
EmuSimpleFileSystemDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_STATUS Status;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;
EMU_SIMPLE_FILE_SYSTEM_PRIVATE *Private;
//
// Get our context back
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiSimpleFileSystemProtocolGuid,
(VOID **)&SimpleFileSystem,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
Private = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (SimpleFileSystem);
Status = Private->IoThunk->Close (Private->IoThunk);
//
// Uninstall the Simple File System Protocol from ControllerHandle
//
Status = gBS->UninstallMultipleProtocolInterfaces (
ControllerHandle,
&gEfiSimpleFileSystemProtocolGuid, &Private->SimpleFileSystem,
NULL
);
if (!EFI_ERROR (Status)) {
Status = gBS->CloseProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
}
if (!EFI_ERROR (Status)) {
//
// Free our instance data
//
FreeUnicodeStringTable (Private->ControllerNameTable);
gBS->FreePool (Private);
}
return Status;
}
EFI_DRIVER_BINDING_PROTOCOL gEmuSimpleFileSystemDriverBinding = {
EmuSimpleFileSystemDriverBindingSupported,
EmuSimpleFileSystemDriverBindingStart,
EmuSimpleFileSystemDriverBindingStop,
0xa,
NULL,
NULL
};
/**
The user Entry Point for module EmuSimpleFileSystem. The user code starts with this function.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The entry point is executed successfully.
@retval other Some error occurs when executing this entry point.
**/
EFI_STATUS
EFIAPI
InitializeEmuSimpleFileSystem(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
Status = EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
&gEmuSimpleFileSystemDriverBinding,
ImageHandle,
&gEmuSimpleFileSystemComponentName,
&gEmuSimpleFileSystemComponentName2
);
ASSERT_EFI_ERROR (Status);
return Status;
}

View File

@@ -0,0 +1,80 @@
/*++ @file
Produce Simple File System abstractions for a directory on your PC using Unix APIs.
The configuration of what devices to mount or emulate comes from
environment variables.
Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _EMU_SIMPLE_FILE_SYSTEM_H_
#define _EMU_SIMPLE_FILE_SYSTEM_H_
#include "PiDxe.h"
#include <Guid/FileSystemInfo.h>
#include <Guid/FileInfo.h>
#include <Guid/FileSystemVolumeLabelInfo.h>
#include <Protocol/EmuIoThunk.h>
#include <Protocol/SimpleFileSystem.h>
#include <Library/DebugLib.h>
#include <Library/BaseLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
extern EFI_DRIVER_BINDING_PROTOCOL gEmuSimpleFileSystemDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gEmuSimpleFileSystemComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gEmuSimpleFileSystemComponentName2;
#define EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE SIGNATURE_32 ('E', 'M', 'f', 's')
typedef struct {
UINTN Signature;
EMU_IO_THUNK_PROTOCOL *IoThunk;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFileSystem;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Io;
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
} EMU_SIMPLE_FILE_SYSTEM_PRIVATE;
#define EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS(a) \
CR (a, \
EMU_SIMPLE_FILE_SYSTEM_PRIVATE, \
SimpleFileSystem, \
EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE \
)
#define EMU_EFI_FILE_PRIVATE_SIGNATURE SIGNATURE_32 ('e', 'm', 'f', 's')
typedef struct {
UINTN Signature;
EMU_IO_THUNK_PROTOCOL *IoThunk;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;
EFI_FILE_PROTOCOL EfiFile;
EFI_FILE_PROTOCOL *Io;
} EMU_EFI_FILE_PRIVATE;
#define EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS(a) \
CR (a, \
EMU_EFI_FILE_PRIVATE, \
EfiFile, \
EMU_EFI_FILE_PRIVATE_SIGNATURE \
)
#endif

View File

@@ -0,0 +1,55 @@
## @file
# Simple filesystem driver
#
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = EmuSimpleFileSystem
FILE_GUID = 35B72237-3926-CF4A-A7F3-1449F9E0E4BD
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = InitializeEmuSimpleFileSystem
[Sources]
ComponentName.c
EmuSimpleFileSystem.c
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
UefiBootServicesTableLib
MemoryAllocationLib
BaseMemoryLib
UefiLib
UefiDriverEntryPoint
BaseLib
DebugLib
[Guids]
gEfiFileSystemVolumeLabelInfoIdGuid # SOMETIMES_CONSUMED
gEfiFileInfoGuid # SOMETIMES_CONSUMED
gEfiFileSystemInfoGuid # SOMETIMES_CONSUMED
[Protocols]
gEfiSimpleFileSystemProtocolGuid # PROTOCOL BY_START
gEmuIoThunkProtocolGuid # PROTOCOL TO_START

View File

@@ -0,0 +1,318 @@
/** @file
Copyright (c) 2010, Apple, Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
ComponentName.c
Abstract:
-**/
#include "EmuSnpDxe.h"
//
// EFI Component Name Functions
//
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified
in RFC 4646 or ISO 639-2 language code format.
@param DriverName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
driver specified by This in the language
specified by Language.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
EmuSnpDriverComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param ControllerHandle[in] The handle of a controller that the driver
specified by This is managing. This handle
specifies the controller whose name is to be
returned.
@param ChildHandle[in] The handle of the child controller to retrieve
the name of. This is an optional parameter that
may be NULL. It will be NULL for device
drivers. It will also be NULL for a bus drivers
that wish to retrieve the name of the bus
controller. It will not be NULL for a bus
driver that wishes to retrieve the name of a
child controller.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified in
RFC 4646 or ISO 639-2 language code format.
@param ControllerName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
controller specified by ControllerHandle and
ChildHandle in the language specified by
Language from the point of view of the driver
specified by This.
@retval EFI_SUCCESS The Unicode string for the user readable name in
the language specified by Language for the
driver specified by This was returned in
DriverName.
@retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
EmuSnpDriverComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
);
//
// EFI Component Name Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gEmuSnpDriverComponentName = {
EmuSnpDriverComponentNameGetDriverName,
EmuSnpDriverComponentNameGetControllerName,
"eng"
};
//
// EFI Component Name 2 Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuSnpDriverComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) EmuSnpDriverComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) EmuSnpDriverComponentNameGetControllerName,
"en"
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mEmuSnpDriverNameTable[] = {
{
"eng;en",
L"Emu SNP Driver"
},
{
NULL,
NULL
}
};
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified
in RFC 4646 or ISO 639-2 language code format.
@param DriverName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
driver specified by This in the language
specified by Language.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
EmuSnpDriverComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
)
{
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mEmuSnpDriverNameTable,
DriverName,
(BOOLEAN)(This == &gEmuSnpDriverComponentName)
);
}
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param ControllerHandle[in] The handle of a controller that the driver
specified by This is managing. This handle
specifies the controller whose name is to be
returned.
@param ChildHandle[in] The handle of the child controller to retrieve
the name of. This is an optional parameter that
may be NULL. It will be NULL for device
drivers. It will also be NULL for a bus drivers
that wish to retrieve the name of the bus
controller. It will not be NULL for a bus
driver that wishes to retrieve the name of a
child controller.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified in
RFC 4646 or ISO 639-2 language code format.
@param ControllerName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
controller specified by ControllerHandle and
ChildHandle in the language specified by
Language from the point of view of the driver
specified by This.
@retval EFI_SUCCESS The Unicode string for the user readable name in
the language specified by Language for the
driver specified by This was returned in
DriverName.
@retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
EmuSnpDriverComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
{
return EFI_UNSUPPORTED;
}

View File

@@ -0,0 +1,958 @@
/** @file
Copyright (c) 2010, Apple, Inc. All rights reserved.<BR>
Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EmuSnp.c
Abstract:
-**/
#include "EmuSnpDxe.h"
EFI_SIMPLE_NETWORK_PROTOCOL gEmuSnpTemplate = {
EFI_SIMPLE_NETWORK_PROTOCOL_REVISION,
EmuSnpStart,
EmuSnpStop,
EmuSnpInitialize,
EmuSnpReset,
EmuSnpShutdown,
EmuSnpReceiveFilters,
EmuSnpStationAddress,
EmuSnpStatistics,
EmuSnpMcastIptoMac,
EmuSnpNvdata,
EmuSnpGetStatus,
EmuSnpTransmit,
EmuSnpReceive,
NULL, // WaitForPacket
NULL // Mode
};
/**
Changes the state of a network interface from "stopped" to "started".
@param This Protocol instance pointer.
@retval EFI_SUCCESS Always succeeds.
**/
EFI_STATUS
EFIAPI
EmuSnpStart(
IN EFI_SIMPLE_NETWORK_PROTOCOL *This
)
{
EFI_STATUS Status;
EMU_SNP_PRIVATE_DATA *Private;
Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);
Status = Private->Io->Start (Private->Io);
return Status;
}
/**
Changes the state of a network interface from "started" to "stopped".
@param This Protocol instance pointer.
@retval EFI_SUCCESS Always succeeds.
**/
EFI_STATUS
EFIAPI
EmuSnpStop (
IN EFI_SIMPLE_NETWORK_PROTOCOL *This
)
{
EFI_STATUS Status;
EMU_SNP_PRIVATE_DATA *Private;
Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);
Status = Private->Io->Stop (Private->Io);
return Status;
}
/**
Resets a network adapter and allocates the transmit and receive buffers
required by the network interface; optionally, also requests allocation
of additional transmit and receive buffers.
@param This Protocol instance pointer.
@param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
that the driver should allocate for the network interface.
Some network interfaces will not be able to use the extra
buffer, and the caller will not know if it is actually
being used.
@param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
that the driver should allocate for the network interface.
Some network interfaces will not be able to use the extra
buffer, and the caller will not know if it is actually
being used.
@retval EFI_SUCCESS Always succeeds.
**/
EFI_STATUS
EFIAPI
EmuSnpInitialize (
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
IN UINTN ExtraRxBufferSize OPTIONAL,
IN UINTN ExtraTxBufferSize OPTIONAL
)
{
EFI_STATUS Status;
EMU_SNP_PRIVATE_DATA *Private;
Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);
Status = Private->Io->Initialize (Private->Io, ExtraRxBufferSize, ExtraTxBufferSize);
return Status;
}
/**
Resets a network adapter and re-initializes it with the parameters that were
provided in the previous call to Initialize().
@param This Protocol instance pointer.
@param ExtendedVerification Indicates that the driver may perform a more
exhaustive verification operation of the device
during reset.
@retval EFI_SUCCESS Always succeeds.
**/
EFI_STATUS
EFIAPI
EmuSnpReset (
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
{
EFI_STATUS Status;
EMU_SNP_PRIVATE_DATA *Private;
Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);
Status = Private->Io->Reset (Private->Io, ExtendedVerification);
return Status;
}
/**
Resets a network adapter and leaves it in a state that is safe for
another driver to initialize.
@param This Protocol instance pointer.
@retval EFI_SUCCESS Always succeeds.
**/
EFI_STATUS
EFIAPI
EmuSnpShutdown (
IN EFI_SIMPLE_NETWORK_PROTOCOL *This
)
{
EFI_STATUS Status;
EMU_SNP_PRIVATE_DATA *Private;
Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);
Status = Private->Io->Shutdown (Private->Io);
return Status;
}
/**
Manages the multicast receive filters of a network interface.
@param This Protocol instance pointer.
@param EnableBits A bit mask of receive filters to enable on the network interface.
@param DisableBits A bit mask of receive filters to disable on the network interface.
@param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive
filters on the network interface to their default values.
@param McastFilterCount Number of multicast HW MAC addresses in the new
MCastFilter list. This value must be less than or equal to
the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This
field is optional if ResetMCastFilter is TRUE.
@param McastFilter A pointer to a list of new multicast receive filter HW MAC
addresses. This list will replace any existing multicast
HW MAC address list. This field is optional if
ResetMCastFilter is TRUE.
@retval EFI_SUCCESS The multicast receive filter list was updated.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
**/
EFI_STATUS
EFIAPI
EmuSnpReceiveFilters (
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
IN UINT32 EnableBits,
IN UINT32 DisableBits,
IN BOOLEAN ResetMcastFilter,
IN UINTN McastFilterCount OPTIONAL,
IN EFI_MAC_ADDRESS *McastFilter OPTIONAL
)
{
EFI_STATUS Status;
EMU_SNP_PRIVATE_DATA *Private;
Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);
Status = Private->Io->ReceiveFilters (
Private->Io,
EnableBits,
DisableBits,
ResetMcastFilter,
McastFilterCount,
McastFilter
);
return Status;
}
/**
Modifies or resets the current station address, if supported.
@param This Protocol instance pointer.
@param Reset Flag used to reset the station address to the network interfaces
permanent address.
@param NewMacAddr New station address to be used for the network interface.
@retval EFI_UNSUPPORTED Not supported yet.
**/
EFI_STATUS
EFIAPI
EmuSnpStationAddress (
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
IN BOOLEAN Reset,
IN EFI_MAC_ADDRESS *NewMacAddr OPTIONAL
)
{
EFI_STATUS Status;
EMU_SNP_PRIVATE_DATA *Private;
Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);
Status = Private->Io->StationAddress (Private->Io, Reset, NewMacAddr);
return Status;
}
/**
Resets or collects the statistics on a network interface.
@param This Protocol instance pointer.
@param Reset Set to TRUE to reset the statistics for the network interface.
@param StatisticsSize On input the size, in bytes, of StatisticsTable. On
output the size, in bytes, of the resulting table of
statistics.
@param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
contains the statistics.
@retval EFI_SUCCESS The statistics were collected from the network interface.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
size needed to hold the statistics is returned in
StatisticsSize.
@retval EFI_UNSUPPORTED Not supported yet.
**/
EFI_STATUS
EFIAPI
EmuSnpStatistics (
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
IN BOOLEAN Reset,
IN OUT UINTN *StatisticsSize OPTIONAL,
OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL
)
{
EFI_STATUS Status;
EMU_SNP_PRIVATE_DATA *Private;
Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);
Status = Private->Io->Statistics (Private->Io, Reset, StatisticsSize, StatisticsTable);
return Status;
}
/**
Converts a multicast IP address to a multicast HW MAC address.
@param This Protocol instance pointer.
@param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
to FALSE if the multicast IP address is IPv4 [RFC 791].
@param Ip The multicast IP address that is to be converted to a multicast
HW MAC address.
@param Mac The multicast HW MAC address that is to be generated from IP.
@retval EFI_SUCCESS The multicast IP address was mapped to the multicast
HW MAC address.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
size needed to hold the statistics is returned in
StatisticsSize.
@retval EFI_UNSUPPORTED Not supported yet.
**/
EFI_STATUS
EFIAPI
EmuSnpMcastIptoMac (
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
IN BOOLEAN Ipv6,
IN EFI_IP_ADDRESS *Ip,
OUT EFI_MAC_ADDRESS *Mac
)
{
EFI_STATUS Status;
EMU_SNP_PRIVATE_DATA *Private;
Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);
Status = Private->Io->MCastIpToMac (Private->Io, Ipv6, Ip, Mac);
return Status;
}
/**
Performs read and write operations on the NVRAM device attached to a
network interface.
@param This Protocol instance pointer.
@param ReadOrWrite TRUE for read operations, FALSE for write operations.
@param Offset Byte offset in the NVRAM device at which to start the read or
write operation. This must be a multiple of NvRamAccessSize and
less than NvRamSize.
@param BufferSize The number of bytes to read or write from the NVRAM device.
This must also be a multiple of NvramAccessSize.
@param Buffer A pointer to the data buffer.
@retval EFI_UNSUPPORTED Not supported yet.
**/
EFI_STATUS
EFIAPI
EmuSnpNvdata (
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
IN BOOLEAN ReadOrWrite,
IN UINTN Offset,
IN UINTN BufferSize,
IN OUT VOID *Buffer
)
{
EFI_STATUS Status;
EMU_SNP_PRIVATE_DATA *Private;
Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);
Status = Private->Io->NvData (Private->Io, ReadOrWrite, Offset, BufferSize, Buffer);
return Status;
}
/**
Reads the current interrupt status and recycled transmit buffer status from
a network interface.
@param This Protocol instance pointer.
@param InterruptStatus A pointer to the bit mask of the currently active interrupts
If this is NULL, the interrupt status will not be read from
the device. If this is not NULL, the interrupt status will
be read from the device. When the interrupt status is read,
it will also be cleared. Clearing the transmit interrupt
does not empty the recycled transmit buffer array.
@param TxBuffer Recycled transmit buffer address. The network interface will
not transmit if its internal recycled transmit buffer array
is full. Reading the transmit buffer does not clear the
transmit interrupt. If this is NULL, then the transmit buffer
status will not be read. If there are no transmit buffers to
recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
@retval EFI_SUCCESS Always succeeds.
**/
EFI_STATUS
EFIAPI
EmuSnpGetStatus (
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
OUT UINT32 *InterruptStatus,
OUT VOID **TxBuffer
)
{
EFI_STATUS Status;
EMU_SNP_PRIVATE_DATA *Private;
Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);
Status = Private->Io->GetStatus (Private->Io, InterruptStatus, TxBuffer);
return Status;
}
/**
Places a packet in the transmit queue of a network interface.
@param This Protocol instance pointer.
@param HeaderSize The size, in bytes, of the media header to be filled in by
the Transmit() function. If HeaderSize is non-zero, then it
must be equal to This->Mode->MediaHeaderSize and the DestAddr
and Protocol parameters must not be NULL.
@param BufferSize The size, in bytes, of the entire packet (media header and
data) to be transmitted through the network interface.
@param Buffer A pointer to the packet (media header followed by data) to be
transmitted. This parameter cannot be NULL. If HeaderSize is zero,
then the media header in Buffer must already be filled in by the
caller. If HeaderSize is non-zero, then the media header will be
filled in by the Transmit() function.
@param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
This->Mode->CurrentAddress is used for the source HW MAC address.
@param DestAddr The destination HW MAC address. If HeaderSize is zero, then this
parameter is ignored.
@param Protocol The type of header to build. If HeaderSize is zero, then this
parameter is ignored. See RFC 1700, section "Ether Types", for
examples.
@retval EFI_SUCCESS The packet was placed on the transmit queue.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_NOT_STARTED The network interface has not been started.
**/
EFI_STATUS
EFIAPI
EmuSnpTransmit (
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
IN UINTN HeaderSize,
IN UINTN BufferSize,
IN VOID* Buffer,
IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,
IN UINT16 *Protocol OPTIONAL
)
{
EFI_STATUS Status;
EMU_SNP_PRIVATE_DATA *Private;
Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);
Status = Private->Io->Transmit (
Private->Io,
HeaderSize,
BufferSize,
Buffer,
SrcAddr,
DestAddr,
Protocol
);
return Status;
}
/**
Receives a packet from a network interface.
@param This Protocol instance pointer.
@param HeaderSize The size, in bytes, of the media header received on the network
interface. If this parameter is NULL, then the media header size
will not be returned.
@param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in
bytes, of the packet that was received on the network interface.
@param Buffer A pointer to the data buffer to receive both the media header and
the data.
@param SourceAddr The source HW MAC address. If this parameter is NULL, the
HW MAC source address will not be extracted from the media
header.
@param DestinationAddr The destination HW MAC address. If this parameter is NULL,
the HW MAC destination address will not be extracted from the
media header.
@param Protocol The media header type. If this parameter is NULL, then the
protocol will not be extracted from the media header. See
RFC 1700 section "Ether Types" for examples.
@retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
been updated to the number of bytes received.
@retval EFI_NOT_READY The network interface is too busy to accept this transmit
request.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
**/
EFI_STATUS
EFIAPI
EmuSnpReceive (
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
OUT UINTN *HeaderSize OPTIONAL,
IN OUT UINTN *BuffSize,
OUT VOID *Buffer,
OUT EFI_MAC_ADDRESS *SourceAddr OPTIONAL,
OUT EFI_MAC_ADDRESS *DestinationAddr OPTIONAL,
OUT UINT16 *Protocol OPTIONAL
)
{
EFI_STATUS Status;
EMU_SNP_PRIVATE_DATA *Private;
Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);
Status = Private->Io->Receive (
Private->Io,
HeaderSize,
BuffSize,
Buffer,
SourceAddr,
DestinationAddr,
Protocol
);
return Status;
}
/**
Test to see if this driver supports ControllerHandle. This service
is called by the EFI boot service ConnectController(). In
order to make drivers as small as possible, there are a few calling
restrictions for this service. ConnectController() must
follow these calling restrictions. If any other agent wishes to call
Supported() it must also follow these calling restrictions.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to test
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS This driver supports this device
@retval EFI_UNSUPPORTED This driver does not support this device
**/
EFI_STATUS
EFIAPI
EmuSnpDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
EFI_STATUS Status;
EMU_IO_THUNK_PROTOCOL *EmuIoThunk;
MAC_ADDR_DEVICE_PATH *Node;
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
if (RemainingDevicePath != NULL) {
if (!IsDevicePathEnd (RemainingDevicePath)) {
Node = (MAC_ADDR_DEVICE_PATH *)RemainingDevicePath;
if (Node->Header.Type != MESSAGING_DEVICE_PATH ||
Node->Header.SubType != MSG_MAC_ADDR_DP) {
// If the remaining device path does not match we don't support the request
return EFI_UNSUPPORTED;
}
}
}
//
// Open the IO Abstraction(s) needed to perform the supported test
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
(VOID **)&EmuIoThunk,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Make sure GUID is for a File System handle.
//
Status = EFI_UNSUPPORTED;
if (CompareGuid (EmuIoThunk->Protocol, &gEmuSnpProtocolGuid)) {
Status = EFI_SUCCESS;
}
//
// Close the I/O Abstraction(s) used to perform the supported test
//
gBS->CloseProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
//
// Open the EFI Device Path protocol needed to perform the supported test
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDevicePathProtocolGuid,
(VOID **) &ParentDevicePath,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (Status == EFI_ALREADY_STARTED) {
return EFI_SUCCESS;
}
if (EFI_ERROR (Status)) {
return Status;
}
//
// Close protocol, don't use device path protocol in the Support() function
//
gBS->CloseProtocol (
ControllerHandle,
&gEfiDevicePathProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
return Status;
}
/**
Start this driver on ControllerHandle. This service is called by the
EFI boot service ConnectController(). In order to make
drivers as small as possible, there are a few calling restrictions for
this service. ConnectController() must follow these
calling restrictions. If any other agent wishes to call Start() it
must also follow these calling restrictions.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to bind driver to
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS Always succeeds.
**/
EFI_STATUS
EFIAPI
EmuSnpDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
EFI_STATUS Status;
EMU_IO_THUNK_PROTOCOL *EmuIoThunk;
EMU_SNP_PRIVATE_DATA *Private;
MAC_ADDR_DEVICE_PATH Node;
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
Private = NULL;
//
// Grab the protocols we need
//
Status = gBS->OpenProtocol(
ControllerHandle,
&gEfiDevicePathProtocolGuid,
( VOID ** ) &ParentDevicePath,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status) && Status) {
return Status;
}
Status = gBS->OpenProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
(VOID **)&EmuIoThunk,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
if (!CompareGuid (EmuIoThunk->Protocol, &gEmuSnpProtocolGuid)) {
return EFI_UNSUPPORTED;
}
Status = EmuIoThunk->Open (EmuIoThunk);
if (EFI_ERROR (Status)) {
goto Done;
}
//
// Allocate the private data.
//
Private = AllocateZeroPool (sizeof (EMU_SNP_PRIVATE_DATA));
if (Private == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
CopyMem (&Private->Snp, &gEmuSnpTemplate, sizeof (EFI_SIMPLE_NETWORK_PROTOCOL));
Private->Signature = EMU_SNP_PRIVATE_DATA_SIGNATURE;
Private->IoThunk = EmuIoThunk;
Private->Io = EmuIoThunk->Interface;
Private->EfiHandle = ControllerHandle;
Private->DeviceHandle = NULL;
Private->Snp.Mode = &Private->Mode;
Private->ControllerNameTable = NULL;
Status = Private->Io->CreateMapping (Private->Io, &Private->Mode);
if (EFI_ERROR (Status)) {
goto Done;
}
//
// Build the device path by appending the MAC node to the ParentDevicePath
// from the EmuIo handle.
//
ZeroMem (&Node, sizeof (MAC_ADDR_DEVICE_PATH));
Node.Header.Type = MESSAGING_DEVICE_PATH;
Node.Header.SubType = MSG_MAC_ADDR_DP;
Node.IfType = Private->Mode.IfType;
SetDevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL * )&Node, sizeof (MAC_ADDR_DEVICE_PATH));
CopyMem (&Node.MacAddress, &Private->Mode.CurrentAddress, sizeof (EFI_MAC_ADDRESS));
//
// Build the device path by appending the MAC node to the ParentDevicePath from the EmuIo handle.
//
Private->DevicePath = AppendDevicePathNode (ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&Node);
if ( Private->DevicePath == NULL ) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
AddUnicodeString2 (
"eng",
gEmuSnpDriverComponentName.SupportedLanguages,
&Private->ControllerNameTable,
EmuIoThunk->ConfigString,
TRUE
);
AddUnicodeString2 (
"en",
gEmuSnpDriverComponentName2.SupportedLanguages,
&Private->ControllerNameTable,
EmuIoThunk->ConfigString,
FALSE
);
//
// Create Child Handle
//
Status = gBS->InstallMultipleProtocolInterfaces(
&Private->DeviceHandle,
&gEfiSimpleNetworkProtocolGuid, &Private->Snp,
&gEfiDevicePathProtocolGuid, Private->DevicePath,
NULL
);
if (EFI_ERROR (Status)) {
goto Done;
}
//
// Open For Child Device
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
(VOID **)&EmuIoThunk,
This->DriverBindingHandle,
Private->DeviceHandle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
);
Done:
if (EFI_ERROR (Status)) {
if (Private != NULL) {
FreePool (Private);
}
if (ParentDevicePath != NULL) {
gBS->CloseProtocol(
ControllerHandle,
&gEfiDevicePathProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
}
}
return Status;
}
/**
Stop this driver on ControllerHandle. This service is called by the
EFI boot service DisconnectController(). In order to
make drivers as small as possible, there are a few calling
restrictions for this service. DisconnectController()
must follow these calling restrictions. If any other agent wishes
to call Stop() it must also follow these calling restrictions.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to stop driver on
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
children is zero stop the entire bus driver.
@param ChildHandleBuffer List of Child Handles to Stop.
@retval EFI_SUCCESS Always succeeds.
**/
EFI_STATUS
EFIAPI
EmuSnpDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_STATUS Status;
EMU_SNP_PRIVATE_DATA *Private = NULL;
EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
//
// Complete all outstanding transactions to Controller.
// Don't allow any new transaction to Controller to be started.
//
if (NumberOfChildren == 0) {
//
// Close the bus driver
//
Status = gBS->CloseProtocol (
ControllerHandle,
&gEmuIoThunkProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
Status = gBS->CloseProtocol (
ControllerHandle,
&gEfiDevicePathProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
return Status;
}
ASSERT (NumberOfChildren == 1);
//
// Get our context back.
//
Status = gBS->OpenProtocol(
ChildHandleBuffer[0],
&gEfiSimpleNetworkProtocolGuid,
( VOID ** ) &Snp,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (Snp);
Status = Private->IoThunk->Close (Private->IoThunk);
Status = gBS->CloseProtocol(
ChildHandleBuffer[0],
&gEmuIoThunkProtocolGuid,
This->DriverBindingHandle,
Private->DeviceHandle
);
Status = gBS->UninstallMultipleProtocolInterfaces(
ChildHandleBuffer[0],
&gEfiSimpleNetworkProtocolGuid, &Private->Snp,
&gEfiDevicePathProtocolGuid, Private->DevicePath,
NULL
);
FreePool (Private->DevicePath);
FreeUnicodeStringTable (Private->ControllerNameTable);
FreePool (Private);
return EFI_SUCCESS;
}
EFI_DRIVER_BINDING_PROTOCOL gEmuSnpDriverBinding = {
EmuSnpDriverBindingSupported,
EmuSnpDriverBindingStart,
EmuSnpDriverBindingStop,
0xA,
NULL,
NULL
};
/**
This is the declaration of an EFI image entry point. This entry point is
the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
both device drivers and bus drivers.
@param ImageHandle The firmware allocated handle for the UEFI image.
@param SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
**/
EFI_STATUS
EFIAPI
InitializeEmuSnpDriver (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
//
// Install the Driver Protocols
//
Status = EfiLibInstallDriverBindingComponentName2(
ImageHandle,
SystemTable,
&gEmuSnpDriverBinding,
ImageHandle,
&gEmuSnpDriverComponentName,
&gEmuSnpDriverComponentName2
);
return Status;
}

View File

@@ -0,0 +1,488 @@
/** @file
Copyright (c) 2010, Apple, Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EmuSnp.h
Abstract:
-**/
#ifndef _EMU_SNP_H_
#define _EMU_SNP_H_
#include <Uefi.h>
#include <Protocol/SimpleNetwork.h>
#include <Protocol/DevicePath.h>
#include <Protocol/EmuIoThunk.h>
#include <Protocol/EmuSnp.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/NetLib.h>
#define NET_ETHER_HEADER_SIZE 14
//
// Private data for driver.
//
#define EMU_SNP_PRIVATE_DATA_SIGNATURE SIGNATURE_32( 'U', 'S', 'N', 'P' )
typedef struct {
UINTN Signature;
EMU_IO_THUNK_PROTOCOL *IoThunk;
EMU_SNP_PROTOCOL *Io;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_HANDLE EfiHandle;
EFI_HANDLE DeviceHandle;
EFI_SIMPLE_NETWORK_PROTOCOL Snp;
EFI_SIMPLE_NETWORK_MODE Mode;
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
} EMU_SNP_PRIVATE_DATA;
#define EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS(a) \
CR( a, EMU_SNP_PRIVATE_DATA, Snp, EMU_SNP_PRIVATE_DATA_SIGNATURE )
extern EFI_DRIVER_BINDING_PROTOCOL gEmuSnpDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gEmuSnpDriverComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gEmuSnpDriverComponentName2;
/**
Test to see if this driver supports ControllerHandle. This service
is called by the EFI boot service ConnectController(). In
order to make drivers as small as possible, there are a few calling
restrictions for this service. ConnectController() must
follow these calling restrictions. If any other agent wishes to call
Supported() it must also follow these calling restrictions.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to test
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS This driver supports this device
@retval EFI_UNSUPPORTED This driver does not support this device
**/
EFI_STATUS
EFIAPI
EmuSnpDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL * This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL
);
/**
Start this driver on ControllerHandle. This service is called by the
EFI boot service ConnectController(). In order to make
drivers as small as possible, there are a few calling restrictions for
this service. ConnectController() must follow these
calling restrictions. If any other agent wishes to call Start() it
must also follow these calling restrictions.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to bind driver to
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS Always succeeds.
**/
EFI_STATUS
EFIAPI
EmuSnpDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL * This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL
);
/**
Stop this driver on ControllerHandle. This service is called by the
EFI boot service DisconnectController(). In order to
make drivers as small as possible, there are a few calling
restrictions for this service. DisconnectController()
must follow these calling restrictions. If any other agent wishes
to call Stop() it must also follow these calling restrictions.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to stop driver on
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
children is zero stop the entire bus driver.
@param ChildHandleBuffer List of Child Handles to Stop.
@retval EFI_SUCCESS Always succeeds.
**/
EFI_STATUS
EFIAPI
EmuSnpDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
/**
Changes the state of a network interface from "stopped" to "started".
@param This Protocol instance pointer.
@retval EFI_SUCCESS Always succeeds.
**/
EFI_STATUS
EFIAPI
EmuSnpStart(
IN EFI_SIMPLE_NETWORK_PROTOCOL* This
);
/**
Changes the state of a network interface from "started" to "stopped".
@param This Protocol instance pointer.
@retval EFI_SUCCESS Always succeeds.
**/
EFI_STATUS
EFIAPI
EmuSnpStop(
IN EFI_SIMPLE_NETWORK_PROTOCOL* This
);
/**
Resets a network adapter and allocates the transmit and receive buffers
required by the network interface; optionally, also requests allocation
of additional transmit and receive buffers.
@param This Protocol instance pointer.
@param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
that the driver should allocate for the network interface.
Some network interfaces will not be able to use the extra
buffer, and the caller will not know if it is actually
being used.
@param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
that the driver should allocate for the network interface.
Some network interfaces will not be able to use the extra
buffer, and the caller will not know if it is actually
being used.
@retval EFI_SUCCESS Always succeeds.
**/
EFI_STATUS
EFIAPI
EmuSnpInitialize(
IN EFI_SIMPLE_NETWORK_PROTOCOL* This,
IN UINTN ExtraRxBufferSize OPTIONAL,
IN UINTN ExtraTxBufferSize OPTIONAL
);
/**
Resets a network adapter and re-initializes it with the parameters that were
provided in the previous call to Initialize().
@param This Protocol instance pointer.
@param ExtendedVerification Indicates that the driver may perform a more
exhaustive verification operation of the device
during reset.
@retval EFI_SUCCESS Always succeeds.
**/
EFI_STATUS
EFIAPI
EmuSnpReset(
IN EFI_SIMPLE_NETWORK_PROTOCOL* This,
IN BOOLEAN ExtendedVerification
);
/**
Resets a network adapter and leaves it in a state that is safe for
another driver to initialize.
@param This Protocol instance pointer.
@retval EFI_SUCCESS Always succeeds.
**/
EFI_STATUS
EFIAPI
EmuSnpShutdown(
IN EFI_SIMPLE_NETWORK_PROTOCOL* This
);
/**
Manages the multicast receive filters of a network interface.
@param This Protocol instance pointer.
@param EnableBits A bit mask of receive filters to enable on the network interface.
@param DisableBits A bit mask of receive filters to disable on the network interface.
@param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive
filters on the network interface to their default values.
@param McastFilterCount Number of multicast HW MAC addresses in the new
MCastFilter list. This value must be less than or equal to
the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This
field is optional if ResetMCastFilter is TRUE.
@param McastFilter A pointer to a list of new multicast receive filter HW MAC
addresses. This list will replace any existing multicast
HW MAC address list. This field is optional if
ResetMCastFilter is TRUE.
@retval EFI_SUCCESS The multicast receive filter list was updated.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
**/
EFI_STATUS
EFIAPI
EmuSnpReceiveFilters(
IN EFI_SIMPLE_NETWORK_PROTOCOL* This,
IN UINT32 EnableBits,
IN UINT32 DisableBits,
IN BOOLEAN ResetMcastFilter,
IN UINTN McastFilterCount OPTIONAL,
IN EFI_MAC_ADDRESS* McastFilter OPTIONAL
);
/**
Modifies or resets the current station address, if supported.
@param This Protocol instance pointer.
@param Reset Flag used to reset the station address to the network interfaces
permanent address.
@param NewMacAddr New station address to be used for the network interface.
@retval EFI_UNSUPPORTED Not supported yet.
**/
EFI_STATUS
EFIAPI
EmuSnpStationAddress(
IN EFI_SIMPLE_NETWORK_PROTOCOL* This,
IN BOOLEAN Reset,
IN EFI_MAC_ADDRESS* NewMacAddr OPTIONAL
);
/**
Resets or collects the statistics on a network interface.
@param This Protocol instance pointer.
@param Reset Set to TRUE to reset the statistics for the network interface.
@param StatisticsSize On input the size, in bytes, of StatisticsTable. On
output the size, in bytes, of the resulting table of
statistics.
@param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
contains the statistics.
@retval EFI_SUCCESS The statistics were collected from the network interface.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
size needed to hold the statistics is returned in
StatisticsSize.
@retval EFI_UNSUPPORTED Not supported yet.
**/
EFI_STATUS
EFIAPI
EmuSnpStatistics(
IN EFI_SIMPLE_NETWORK_PROTOCOL* This,
IN BOOLEAN Reset,
IN OUT UINTN* StatisticsSize OPTIONAL,
OUT EFI_NETWORK_STATISTICS* StatisticsTable OPTIONAL
);
/**
Converts a multicast IP address to a multicast HW MAC address.
@param This Protocol instance pointer.
@param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
to FALSE if the multicast IP address is IPv4 [RFC 791].
@param Ip The multicast IP address that is to be converted to a multicast
HW MAC address.
@param Mac The multicast HW MAC address that is to be generated from IP.
@retval EFI_SUCCESS The multicast IP address was mapped to the multicast
HW MAC address.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
size needed to hold the statistics is returned in
StatisticsSize.
@retval EFI_UNSUPPORTED Not supported yet.
**/
EFI_STATUS
EFIAPI
EmuSnpMcastIptoMac(
IN EFI_SIMPLE_NETWORK_PROTOCOL* This,
IN BOOLEAN Ipv6,
IN EFI_IP_ADDRESS* Ip,
OUT EFI_MAC_ADDRESS* Mac
);
/**
Performs read and write operations on the NVRAM device attached to a
network interface.
@param This Protocol instance pointer.
@param ReadOrWrite TRUE for read operations, FALSE for write operations.
@param Offset Byte offset in the NVRAM device at which to start the read or
write operation. This must be a multiple of NvRamAccessSize and
less than NvRamSize.
@param BufferSize The number of bytes to read or write from the NVRAM device.
This must also be a multiple of NvramAccessSize.
@param Buffer A pointer to the data buffer.
@retval EFI_UNSUPPORTED Not supported yet.
**/
EFI_STATUS
EFIAPI
EmuSnpNvdata(
IN EFI_SIMPLE_NETWORK_PROTOCOL* This,
IN BOOLEAN ReadOrWrite,
IN UINTN Offset,
IN UINTN BufferSize,
IN OUT VOID* Buffer
);
/**
Reads the current interrupt status and recycled transmit buffer status from
a network interface.
@param This Protocol instance pointer.
@param InterruptStatus A pointer to the bit mask of the currently active interrupts
If this is NULL, the interrupt status will not be read from
the device. If this is not NULL, the interrupt status will
be read from the device. When the interrupt status is read,
it will also be cleared. Clearing the transmit interrupt
does not empty the recycled transmit buffer array.
@param TxBuffer Recycled transmit buffer address. The network interface will
not transmit if its internal recycled transmit buffer array
is full. Reading the transmit buffer does not clear the
transmit interrupt. If this is NULL, then the transmit buffer
status will not be read. If there are no transmit buffers to
recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
@retval EFI_SUCCESS Always succeeds.
**/
EFI_STATUS
EFIAPI
EmuSnpGetStatus(
IN EFI_SIMPLE_NETWORK_PROTOCOL* This,
OUT UINT32* InterruptStatus,
OUT VOID** TxBuffer
);
/**
Places a packet in the transmit queue of a network interface.
@param This Protocol instance pointer.
@param HeaderSize The size, in bytes, of the media header to be filled in by
the Transmit() function. If HeaderSize is non-zero, then it
must be equal to This->Mode->MediaHeaderSize and the DestAddr
and Protocol parameters must not be NULL.
@param BufferSize The size, in bytes, of the entire packet (media header and
data) to be transmitted through the network interface.
@param Buffer A pointer to the packet (media header followed by data) to be
transmitted. This parameter cannot be NULL. If HeaderSize is zero,
then the media header in Buffer must already be filled in by the
caller. If HeaderSize is non-zero, then the media header will be
filled in by the Transmit() function.
@param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
This->Mode->CurrentAddress is used for the source HW MAC address.
@param DestAddr The destination HW MAC address. If HeaderSize is zero, then this
parameter is ignored.
@param Protocol The type of header to build. If HeaderSize is zero, then this
parameter is ignored. See RFC 1700, section "Ether Types", for
examples.
@retval EFI_SUCCESS The packet was placed on the transmit queue.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_ACCESS_DENIED Error acquire global lock for operation.
**/
EFI_STATUS
EFIAPI
EmuSnpTransmit(
IN EFI_SIMPLE_NETWORK_PROTOCOL* This,
IN UINTN HeaderSize,
IN UINTN BufferSize,
IN VOID* Buffer,
IN EFI_MAC_ADDRESS* SrcAddr OPTIONAL,
IN EFI_MAC_ADDRESS* DestAddr OPTIONAL,
IN UINT16* Protocol OPTIONAL
);
/**
Receives a packet from a network interface.
@param This Protocol instance pointer.
@param HeaderSize The size, in bytes, of the media header received on the network
interface. If this parameter is NULL, then the media header size
will not be returned.
@param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in
bytes, of the packet that was received on the network interface.
@param Buffer A pointer to the data buffer to receive both the media header and
the data.
@param SourceAddr The source HW MAC address. If this parameter is NULL, the
HW MAC source address will not be extracted from the media
header.
@param DestinationAddr The destination HW MAC address. If this parameter is NULL,
the HW MAC destination address will not be extracted from the
media header.
@param Protocol The media header type. If this parameter is NULL, then the
protocol will not be extracted from the media header. See
RFC 1700 section "Ether Types" for examples.
@retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
been updated to the number of bytes received.
@retval EFI_NOT_READY The network interface is too busy to accept this transmit
request.
@retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_ACCESS_DENIED Error acquire global lock for operation.
**/
EFI_STATUS
EFIAPI
EmuSnpReceive(
IN EFI_SIMPLE_NETWORK_PROTOCOL* This,
OUT UINTN* HeaderSize OPTIONAL,
IN OUT UINTN* BuffSize,
OUT VOID* Buffer,
OUT EFI_MAC_ADDRESS* SourceAddr OPTIONAL,
OUT EFI_MAC_ADDRESS* DestinationAddr OPTIONAL,
OUT UINT16* Protocol OPTIONAL
);
VOID
EFIAPI
EmuSnpWaitForPacketNotify(
IN EFI_EVENT Event,
IN VOID* Private
);
#endif // _EMU_SNP_H_

View File

@@ -0,0 +1,57 @@
#/** @file
# Component name for module EmuSnpDxe
#
# Copyright (c) 2010, Apple, Inc. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#**/
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = EmuSnpDxe
FILE_GUID = 22597239-6107-DF44-AD3F-5F053E92222E
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
EDK_RELEASE_VERSION = 0x00020000
EFI_SPECIFICATION_VERSION = 0x00020000
ENTRY_POINT = InitializeEmuSnpDriver
# UNLOAD_IMAGE = EmuSnpUnload
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources.common]
ComponentName.c
EmuSnpDxe.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
DevicePathLib
UefiLib
UefiBootServicesTableLib
BaseMemoryLib
DebugLib
UefiDriverEntryPoint
NetLib
[Protocols]
gEfiSimpleNetworkProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiDevicePathProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEmuSnpProtocolGuid
gEmuIoThunkProtocolGuid

View File

@@ -0,0 +1,89 @@
/*++ @file
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiDxe.h>
#include <Protocol/DevicePath.h>
#include <Protocol/EmuThunk.h>
#include <Library/DebugLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/EmuThunkLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DevicePathLib.h>
//
// EmuThunk Device Path Protocol Instance
//
EMU_THUNK_DEVICE_PATH mEmuThunkDevicePath = {
{
{
{
HARDWARE_DEVICE_PATH,
HW_VENDOR_DP,
{
(UINT8) (sizeof (EMU_VENDOR_DEVICE_PATH_NODE)),
(UINT8) ((sizeof (EMU_VENDOR_DEVICE_PATH_NODE)) >> 8)
}
},
EMU_THUNK_PROTOCOL_GUID
},
0
},
{
END_DEVICE_PATH_TYPE,
END_ENTIRE_DEVICE_PATH_SUBTYPE,
{
END_DEVICE_PATH_LENGTH,
0
}
}
};
EFI_STATUS
EFIAPI
InitializeEmuThunk (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
Install UnixThunk Protocol and it's associated Device Path protocol
Arguments:
(Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
Returns:
EFI_SUCEESS - UnixThunk protocol is added or error status from
gBS->InstallMultiProtocolInterfaces().
**/
{
EFI_STATUS Status;
EFI_HANDLE Handle;
Handle = NULL;
Status = gBS->InstallMultipleProtocolInterfaces (
&Handle,
&gEmuThunkProtocolGuid, gEmuThunk,
&gEfiDevicePathProtocolGuid, &mEmuThunkDevicePath,
NULL
);
return Status;
}

View File

@@ -0,0 +1,59 @@
## @file
# A DXE driver to produce EMU_THUNK_PROTOCOL
#
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = EmuThunk
FILE_GUID = 2F62A818-4A72-CD40-90B9-FF00DAABEE7B
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = InitializeEmuThunk
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
EmuThunk.c
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
UefiBootServicesTableLib
MemoryAllocationLib
EmuThunkLib
UefiDriverEntryPoint
UefiLib
DebugLib
DevicePathLib
[Protocols]
gEfiDevicePathProtocolGuid # PROTOCOL ALWAYS_PRODUCED
gEmuThunkProtocolGuid # PROTOCOL ALWAYS_PRODUCED
[Depex]
TRUE

101
EmulatorPkg/EmulatorPkg.dec Normal file
View File

@@ -0,0 +1,101 @@
## @file
#
# This is the Emu Emulation Environment Platform
#
# Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this distribution.
# The full text of the license may be found at http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES
# OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
[Defines]
DEC_VERSION = 0x00010005
PACKAGE_NAME = EmulatorPkg
PACKAGE_GUID = 36E48BD7-7D92-5A47-A2CD-513F072E3300
PACKAGE_VERSION = 0.1
[Includes]
Include
[LibraryClasses]
ThunkPpiList|Include/Library/ThunkPpiList.h
ThunkProtocolList|Include/Library/ThunkProtocolList.h
EmuThunkLib|Include/Library/EmuThunkLib.h
KeyMap|Include/Library/KeyMapLib.h
PpiListLib|Include/Library/PpiListLib.h
[Protocols]
gEmuThunkProtocolGuid = { 0x5CF32E0B, 0x8EDF, 0x2E44, { 0x9C, 0xDA, 0x93, 0x20, 0x5E, 0x99, 0xEC, 0x1C } }
gEmuIoThunkProtocolGuid = { 0x453368F6, 0x7C85, 0x434A, { 0xA9, 0x8A, 0x72, 0xD1, 0xB7, 0xFF, 0xA9, 0x26 } }
gEmuGraphicsWindowProtocolGuid = { 0x30FD316A, 0x6728, 0x2E41, { 0xA6, 0x90, 0x0D, 0x13, 0x33, 0xD8, 0xCA, 0xC1 } }
gEmuThreadThunkProtocolGuid = { 0x3B1E4B7C, 0x09D8, 0x944F, { 0xA4, 0x08, 0x13, 0x09, 0xEB, 0x8B, 0x44, 0x27 } }
gEmuBlockIoProtocolGuid = { 0x6888A4AE, 0xAFCE, 0xE84B, { 0x91, 0x02, 0xF7, 0xB9, 0xDA, 0xE6, 0xA0, 0x30 } }
gEmuSnpProtocolGuid = { 0xFD5FBE54, 0x8C35, 0xB345, { 0x8A, 0x0F, 0x7A, 0xC8, 0xA5, 0xFD, 0x05, 0x21 } }
[Ppis]
gEmuThunkPpiGuid = { 0xE113F896, 0x75CF, 0xF640, { 0x81, 0x7F, 0xC8, 0x5A, 0x79, 0xE8, 0xAE, 0x67 } }
[Guids]
gEmulatorPkgTokenSpaceGuid = { 0x4F792E68, 0xE8C8, 0x794E, { 0xB1, 0xD8, 0x37, 0x03, 0xF3, 0xF2, 0xD5, 0xA5 } }
gEmuSystemConfigGuid = { 0xF8626165, 0x6CEB, 0x924A, { 0xBA, 0xFC, 0xF1, 0x3A, 0xB9, 0xD6, 0x57, 0x28 } }
gEmuVirtualDisksGuid = { 0xf2ba331a, 0x8985, 0x11db, { 0xa4, 0x06, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } }
gEmuPhysicalDisksGuid = { 0xf2bdcc96, 0x8985, 0x11db, { 0x87, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } }
[PcdsFixedAtBuild]
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageVariableBase|0x0|UINT64|0x00001014
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageFtwSpareBase|0x0|UINT64|0x00001015
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageFtwWorkingBase|0x0|UINT64|0x00001016
gEmulatorPkgTokenSpaceGuid.PcdEmuFdBaseAddress|0x0|UINT64|0x00001017
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageEventLogBase|0x0|UINT64|0x0000100e
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageEventLogSize|0x0|UINT32|0x0000100f
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashFvRecoveryBase|0x0|UINT64|0x00001010
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashFvRecoverySize|0x0|UINT32|0x00001011
gEmulatorPkgTokenSpaceGuid.PcdEmuFirmwareFdSize|0x0|UINT32|0x00001012
gEmulatorPkgTokenSpaceGuid.PcdEmuFirmwareBlockSize|0|UINT32|0x00001013
## Number of Application Processors (APs) in the system 0 means Uniprocessor mode
gEmulatorPkgTokenSpaceGuid.PcdEmuApCount|L"0"|VOID*|0x00001019
## Magic page to implement PEI Services Table Pointer Lib
gEmulatorPkgTokenSpaceGuid.PcdPeiServicesTablePage|0x1003000000|UINT64|0x0000101b
## Size of the packet filter
gEmulatorPkgTokenSpaceGuid.PcdNetworkPacketFilterSize|524288|UINT32|0x0000101c
[PcdsFixedAtBuild, PcdsPatchableInModule]
gEmulatorPkgTokenSpaceGuid.PcdEmuBootMode|1|UINT32|0x00001006
gEmulatorPkgTokenSpaceGuid.PcdEmuFirmwareVolume|L"..\\Fv\\Fv_Recovery.fd"|VOID*|0x00001009
gEmulatorPkgTokenSpaceGuid.PcdEmuMemorySize|L"64!64"|VOID*|0x0000100c
#
# filename[:[R|F][O|W]][:BlockSize]
# filename can be a device node, like /dev/disk1
# R - Removable Media F - Fixed Media
# O - Write protected W - Writable
# Default is Fixed Media, Writable
# For a file the default BlockSize is 512, and can be overridden via BlockSize,
# for example 2048 for an ISO CD image. The block size for a device comes from
# the device and is not configurable.
# Device Size comes from file or device.
# On Mac OS X you can use Disk Utility to create .dmg files and mount them like disks
gEmulatorPkgTokenSpaceGuid.PcdEmuVirtualDisk|L"disk.dmg:FW"|VOID*|0x00001001
gEmulatorPkgTokenSpaceGuid.PcdEmuGop|L"GOP Window"|VOID*|0x00001018
gEmulatorPkgTokenSpaceGuid.PcdEmuFileSystem|L".!../../../../../EdkShellBinPkg/bin/ia32/Apps"|VOID*|0x00001004
gEmulatorPkgTokenSpaceGuid.PcdEmuSerialPort|L"/dev/ttyS0"|VOID*|0x00001002
gEmulatorPkgTokenSpaceGuid.PcdEmuNetworkInterface|L"en0"|VOID*|0x0000100d
gEmulatorPkgTokenSpaceGuid.PcdEmuCpuModel|L"Intel(R) Processor Model"|VOID*|0x00001007
gEmulatorPkgTokenSpaceGuid.PcdEmuCpuSpeed|L"3000"|VOID*|0x00001008
gEmulatorPkgTokenSpaceGuid.PcdEmuMpServicesPollingInterval|0x100|UINT64|0x0000101a

View File

@@ -0,0 +1,130 @@
/*++ @file
Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "PiPei.h"
#include <Ppi/EmuThunk.h>
#include <Library/DebugLib.h>
#include <Library/PeimEntryPoint.h>
#include <Library/HobLib.h>
#include <Library/PeiServicesLib.h>
#include <Library/PeiServicesTablePointerLib.h>
#include <Library/PcdLib.h>
EFI_STATUS
EFIAPI
PeimInitializeFirmwareVolumePei (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
/*++
Routine Description:
Perform a call-back into the SEC simulator to get address of the Firmware Hub
Arguments:
FfsHeader - Ffs Header availible to every PEIM
PeiServices - General purpose services available to every PEIM.
Returns:
None
**/
{
EFI_STATUS Status;
EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
EMU_THUNK_PPI *Thunk;
EFI_PHYSICAL_ADDRESS FdBase;
EFI_PHYSICAL_ADDRESS FdFixUp;
EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
UINT64 FdSize;
UINTN Index;
DEBUG ((EFI_D_ERROR, "Unix Firmware Volume PEIM Loaded\n"));
//
// Get the Fwh Information PPI
//
Status = PeiServicesLocatePpi (
&gEmuThunkPpiGuid, // GUID
0, // INSTANCE
&PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
(VOID **)&Thunk // PPI
);
ASSERT_EFI_ERROR (Status);
Index = 0;
do {
//
// Get information about all the FD's in the system
//
Status = Thunk->FirmwareDevices (Index, &FdBase, &FdSize, &FdFixUp);
if (!EFI_ERROR (Status)) {
//
// Assume the FD starts with an FV header
//
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) FdBase;
//
// Make an FV Hob for the first FV in the FD
//
BuildFvHob (FdBase, FvHeader->FvLength);
if (Index == 0) {
//
// Assume the first FD was produced by the NT32.DSC
// All these strange offests are needed to keep in
// sync with the FlashMap and NT32.dsc file
//
BuildResourceDescriptorHob (
EFI_RESOURCE_FIRMWARE_DEVICE,
(EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
FdBase,
(
FvHeader->FvLength +
PcdGet32 (PcdFlashNvStorageVariableSize) +
PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
PcdGet32 (PcdFlashNvStorageFtwSpareSize) +
PcdGet32 (PcdEmuFlashNvStorageEventLogSize)
)
);
//
// Hard code the address of the spare block and variable services.
// Assume it's a hard coded offset from FV0 in FD0.
//
FdSize =
PcdGet32 (PcdFlashNvStorageVariableSize) +
PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
PcdGet32 (PcdFlashNvStorageFtwSpareSize) +
PcdGet32 (PcdEmuFlashNvStorageEventLogSize);
BuildFvHob (FdFixUp + PcdGet64 (PcdEmuFlashNvStorageVariableBase), FdSize);
} else {
//
// For other FD's just map them in.
//
BuildResourceDescriptorHob (
EFI_RESOURCE_FIRMWARE_DEVICE,
(EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
FdBase,
FdSize
);
}
}
Index++;
} while (!EFI_ERROR (Status));
return Status;
}

View File

@@ -0,0 +1,60 @@
## @file
# Component description file for EmuFwh module
#
# This PEIM will produce the HOB to describe Firmware Volume, Firmware Devices
# on the Emu emulator.
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = FirmwareVolumePei
FILE_GUID = 6DB075DE-449E-2644-96D0-CC5A1B4C3B2A
MODULE_TYPE = PEIM
VERSION_STRING = 1.0
ENTRY_POINT = PeimInitializeFirmwareVolumePei
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
FirmwareVolumePei.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
PeiServicesTablePointerLib
PeiServicesLib
HobLib
PeimEntryPoint
DebugLib
[Pcd]
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageEventLogSize
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageVariableBase
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
[Ppis]
gEmuThunkPpiGuid # PPI ALWAYS_CONSUMED
[Depex]
gEmuThunkPpiGuid AND gEfiPeiMemoryDiscoveredPpiGuid

View File

@@ -0,0 +1,83 @@
/*++ @file
PEIM to build GUIDed HOBs for platform specific flash map
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "PiPei.h"
#include <Guid/SystemNvDataGuid.h>
#include <Ppi/EmuThunk.h>
#include <Library/DebugLib.h>
#include <Library/PeimEntryPoint.h>
#include <Library/HobLib.h>
#include <Library/PeiServicesLib.h>
#include <Library/PeiServicesTablePointerLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/PcdLib.h>
EFI_STATUS
EFIAPI
PeimInitializeFlashMap (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
/*++
Routine Description:
Build GUIDed HOBs for platform specific flash map
Arguments:
FfsHeader - A pointer to the EFI_FFS_FILE_HEADER structure.
PeiServices - General purpose services available to every PEIM.
Returns:
EFI_STATUS
**/
{
EFI_STATUS Status;
EMU_THUNK_PPI *Thunk;
EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
EFI_PHYSICAL_ADDRESS FdBase;
EFI_PHYSICAL_ADDRESS FdFixUp;
UINT64 FdSize;
DEBUG ((EFI_D_ERROR, "EmulatorPkg Flash Map PEIM Loaded\n"));
//
// Get the Fwh Information PPI
//
Status = PeiServicesLocatePpi (
&gEmuThunkPpiGuid, // GUID
0, // INSTANCE
&PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
(VOID **)&Thunk // PPI
);
ASSERT_EFI_ERROR (Status);
//
// Assume that FD0 contains the Flash map.
//
Status = Thunk->FirmwareDevices (0, &FdBase, &FdSize, &FdFixUp);
if (EFI_ERROR (Status)) {
return Status;
}
PcdSet64 (PcdFlashNvStorageVariableBase64, PcdGet64 (PcdEmuFlashNvStorageVariableBase) + FdFixUp);
PcdSet64 (PcdFlashNvStorageFtwWorkingBase64, PcdGet64 (PcdEmuFlashNvStorageFtwWorkingBase) + FdFixUp);
PcdSet64 (PcdFlashNvStorageFtwSpareBase64, PcdGet64 (PcdEmuFlashNvStorageFtwSpareBase) + FdFixUp);
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,68 @@
## @file
# Component description file for FlashMap PEI module
#
# This module installs FlashMap PPI which is used to get flash layout information.
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = FlashMapPei
FILE_GUID = C9FAF091-57F8-A64C-A07A-445B124F0D93
MODULE_TYPE = PEIM
VERSION_STRING = 1.0
ENTRY_POINT = PeimInitializeFlashMap
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
FlashMapPei.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
PcdLib
BaseMemoryLib
PeiServicesTablePointerLib
PeiServicesLib
HobLib
PeimEntryPoint
DebugLib
[Ppis]
gEmuThunkPpiGuid # PPI ALWAYS_CONSUMED
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageFtwWorkingBase
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageFtwSpareBase
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageVariableBase
[Depex]
gEmuThunkPpiGuid

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,154 @@
/*++ @file
Defines data structure that is the volume header found.These data is intent
to decouple FVB driver with FV header.
Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiDxe.h>
#include <Guid/EventGroup.h>
#include <Guid/FirmwareFileSystem2.h>
#include <Guid/SystemNvDataGuid.h>
#include <Protocol/FirmwareVolumeBlock.h>
#include <Protocol/DevicePath.h>
#include <Library/UefiLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/BaseLib.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/UefiRuntimeLib.h>
#include <Library/DebugLib.h>
#include <Library/HobLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/PcdLib.h>
#include <Library/DevicePathLib.h>
typedef struct {
UINT64 FvLength;
EFI_FIRMWARE_VOLUME_HEADER FvbInfo;
//
// EFI_FV_BLOCK_MAP_ENTRY ExtraBlockMap[n];//n=0
//
EFI_FV_BLOCK_MAP_ENTRY End[1];
} EFI_FVB_MEDIA_INFO;
EFI_FVB_MEDIA_INFO mPlatformFvbMediaInfo[] = {
//
// Recovery BOIS FVB
//
{
FixedPcdGet32 (PcdEmuFlashFvRecoverySize),
{
{
0,
}, // ZeroVector[16]
EFI_FIRMWARE_FILE_SYSTEM2_GUID,
FixedPcdGet32 (PcdEmuFlashFvRecoverySize),
EFI_FVH_SIGNATURE,
EFI_FVB2_READ_ENABLED_CAP |
EFI_FVB2_READ_STATUS |
EFI_FVB2_WRITE_ENABLED_CAP |
EFI_FVB2_WRITE_STATUS |
EFI_FVB2_ERASE_POLARITY,
sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
0, // CheckSum
0, // ExtHeaderOffset
{
0,
}, // Reserved[1]
2, // Revision
{
{
FixedPcdGet32 (PcdEmuFlashFvRecoverySize)/FixedPcdGet32 (PcdEmuFirmwareBlockSize),
FixedPcdGet32 (PcdEmuFirmwareBlockSize),
}
}
},
{
{
0,
0
}
}
},
//
// Systen NvStorage FVB
//
{
FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \
FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \
FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \
FixedPcdGet32 (PcdEmuFlashNvStorageEventLogSize),
{
{
0,
}, // ZeroVector[16]
EFI_SYSTEM_NV_DATA_FV_GUID,
FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \
FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \
FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \
FixedPcdGet32 (PcdEmuFlashNvStorageEventLogSize),
EFI_FVH_SIGNATURE,
EFI_FVB2_READ_ENABLED_CAP |
EFI_FVB2_READ_STATUS |
EFI_FVB2_WRITE_ENABLED_CAP |
EFI_FVB2_WRITE_STATUS |
EFI_FVB2_ERASE_POLARITY,
sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
0, // CheckSum
0, // ExtHeaderOffset
{
0,
}, // Reserved[1]
2, // Revision
{
{
(FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \
FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \
FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \
FixedPcdGet32 (PcdEmuFlashNvStorageEventLogSize)) / FixedPcdGet32 (PcdEmuFirmwareBlockSize),
FixedPcdGet32 (PcdEmuFirmwareBlockSize),
}
}
},
{
{
0,
0
}
}
}
};
EFI_STATUS
GetFvbInfo (
IN UINT64 FvLength,
OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo
)
{
UINTN Index;
for (Index = 0; Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO); Index += 1) {
if (mPlatformFvbMediaInfo[Index].FvLength == FvLength) {
*FvbInfo = &mPlatformFvbMediaInfo[Index].FvbInfo;
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}

View File

@@ -0,0 +1,80 @@
## @file
# Component description file for Emu Fimware Volume Block DXE driver module.
#
# This DXE runtime driver implements and produces the Fimware Volue Block Protocol on
# Emu emulator.
# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = FwBlockService
FILE_GUID = A01E498C-96E8-2A4C-95F4-85248F989753
MODULE_TYPE = DXE_RUNTIME_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = FvbInitialize
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
FvbInfo.c
FWBlockService.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
UefiBootServicesTableLib
MemoryAllocationLib
BaseMemoryLib
HobLib
DebugLib
UefiRuntimeLib
DxeServicesTableLib
BaseLib
UefiDriverEntryPoint
UefiLib
DevicePathLib
[Guids]
gEfiEventVirtualAddressChangeGuid # ALWAYS_CONSUMED Create Event: EVENT_GROUP_GUID
[Protocols]
gEfiFirmwareVolumeBlockProtocolGuid # PROTOCOL ALWAYS_PRODUCED
gEfiDevicePathProtocolGuid # PROTOCOL SOMETIMES_PRODUCED
[FixedPcd]
gEmulatorPkgTokenSpaceGuid.PcdEmuFirmwareFdSize
gEmulatorPkgTokenSpaceGuid.PcdEmuFirmwareBlockSize
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashFvRecoveryBase
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashFvRecoverySize
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageEventLogBase
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageEventLogSize
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
[Depex]
TRUE

View File

@@ -0,0 +1,219 @@
/*++ @file
Firmware volume block driver for Intel Firmware Hub (FWH) device
Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _FW_BLOCK_SERVICE_H
#define _FW_BLOCK_SERVICE_H
//
// BugBug: Add documentation here for data structure!!!!
//
#define FVB_PHYSICAL 0
#define FVB_VIRTUAL 1
typedef struct {
EFI_LOCK FvbDevLock;
UINTN FvBase[2];
UINTN NumOfBlocks;
EFI_FIRMWARE_VOLUME_HEADER VolumeHeader;
} EFI_FW_VOL_INSTANCE;
typedef struct {
UINT32 NumFv;
EFI_FW_VOL_INSTANCE *FvInstance[2];
} ESAL_FWB_GLOBAL;
//
// Fvb Protocol instance data
//
#define FVB_DEVICE_FROM_THIS(a) CR (a, EFI_FW_VOL_BLOCK_DEVICE, FwVolBlockInstance, FVB_DEVICE_SIGNATURE)
#define FVB_EXTEND_DEVICE_FROM_THIS(a) CR (a, EFI_FW_VOL_BLOCK_DEVICE, FvbExtension, FVB_DEVICE_SIGNATURE)
#define FVB_DEVICE_SIGNATURE SIGNATURE_32 ('F', 'V', 'B', 'N')
typedef struct {
MEMMAP_DEVICE_PATH MemMapDevPath;
EFI_DEVICE_PATH_PROTOCOL EndDevPath;
} FV_DEVICE_PATH;
typedef struct {
UINTN Signature;
FV_DEVICE_PATH DevicePath;
UINTN Instance;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL FwVolBlockInstance;
} EFI_FW_VOL_BLOCK_DEVICE;
EFI_STATUS
GetFvbInfo (
IN UINT64 FvLength,
OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo
)
;
EFI_STATUS
FvbReadBlock (
IN UINTN Instance,
IN EFI_LBA Lba,
IN UINTN BlockOffset,
IN OUT UINTN *NumBytes,
IN UINT8 *Buffer,
IN ESAL_FWB_GLOBAL *Global,
IN BOOLEAN Virtual
)
;
EFI_STATUS
FvbWriteBlock (
IN UINTN Instance,
IN EFI_LBA Lba,
IN UINTN BlockOffset,
IN OUT UINTN *NumBytes,
IN UINT8 *Buffer,
IN ESAL_FWB_GLOBAL *Global,
IN BOOLEAN Virtual
)
;
EFI_STATUS
FvbEraseBlock (
IN UINTN Instance,
IN EFI_LBA Lba,
IN ESAL_FWB_GLOBAL *Global,
IN BOOLEAN Virtual
)
;
EFI_STATUS
FvbSetVolumeAttributes (
IN UINTN Instance,
IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes,
IN ESAL_FWB_GLOBAL *Global,
IN BOOLEAN Virtual
)
;
EFI_STATUS
FvbGetVolumeAttributes (
IN UINTN Instance,
OUT EFI_FVB_ATTRIBUTES_2 *Attributes,
IN ESAL_FWB_GLOBAL *Global,
IN BOOLEAN Virtual
)
;
EFI_STATUS
FvbGetPhysicalAddress (
IN UINTN Instance,
OUT EFI_PHYSICAL_ADDRESS *Address,
IN ESAL_FWB_GLOBAL *Global,
IN BOOLEAN Virtual
)
;
EFI_STATUS
EFIAPI
FvbInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
;
VOID
EFIAPI
FvbClassAddressChangeEvent (
IN EFI_EVENT Event,
IN VOID *Context
)
;
EFI_STATUS
FvbGetLbaAddress (
IN UINTN Instance,
IN EFI_LBA Lba,
OUT UINTN *LbaAddress,
OUT UINTN *LbaLength,
OUT UINTN *NumOfBlocks,
IN ESAL_FWB_GLOBAL *Global,
IN BOOLEAN Virtual
)
;
//
// Protocol APIs
//
EFI_STATUS
EFIAPI
FvbProtocolGetAttributes (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
OUT EFI_FVB_ATTRIBUTES_2 *Attributes
)
;
EFI_STATUS
EFIAPI
FvbProtocolSetAttributes (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
)
;
EFI_STATUS
EFIAPI
FvbProtocolGetPhysicalAddress (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
OUT EFI_PHYSICAL_ADDRESS *Address
)
;
EFI_STATUS
EFIAPI
FvbProtocolGetBlockSize (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
IN EFI_LBA Lba,
OUT UINTN *BlockSize,
OUT UINTN *NumOfBlocks
)
;
EFI_STATUS
EFIAPI
FvbProtocolRead (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
IN EFI_LBA Lba,
IN UINTN Offset,
IN OUT UINTN *NumBytes,
IN UINT8 *Buffer
)
;
EFI_STATUS
EFIAPI
FvbProtocolWrite (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
IN EFI_LBA Lba,
IN UINTN Offset,
IN OUT UINTN *NumBytes,
IN UINT8 *Buffer
)
;
EFI_STATUS
EFIAPI
FvbProtocolEraseBlocks (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
...
)
;
#endif

View File

@@ -0,0 +1,24 @@
/** @file
Setup Variable data structure for Emu platform.
Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __EMU_PHYSICAL_DISK_H__
#define __EMU_PHYSICAL_DISK_H__
#define EFI_EMU_PHYSICAL_DISK_GUID \
{ 0xf2ba331a, 0x8985, 0x11db, { 0xa4, 0x06, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } }
extern EFI_GUID gEmuPhysicalDisksGuid;
#endif

View File

@@ -0,0 +1,36 @@
/** @file
Setup Variable data structure for Emu platform.
Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __EMU_SYSTEM_CONFIG_H__
#define __EMU_SYSTEM_CONFIG_H__
#define EFI_EMU_SYSTEM_CONFIG_GUID \
{ 0x9C4FB516, 0x3A1E, 0xD847, { 0xA1, 0xA1, 0x70, 0x58, 0xB6, 0x98, 0x67, 0x32 } }
#pragma pack(1)
typedef struct {
//
// Console output mode
//
UINT32 ConOutColumn;
UINT32 ConOutRow;
} EMU_SYSTEM_CONFIGURATION;
#pragma pack()
extern EFI_GUID gEmuSystemConfigGuid;
#endif

View File

@@ -0,0 +1,24 @@
/** @file
Setup Variable data structure for Emu platform.
Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __EMU_VIRTUAL_DISK_H__
#define __EMU_VIRTUAL_DISK_H__
#define EFI_EMU_VIRTUAL_DISK_GUID \
{ 0xf2ba331a, 0x8985, 0x11db, { 0xa4, 0x06, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } }
extern EFI_GUID gEmuVirtualDisksGuid;
#endif

View File

@@ -0,0 +1,38 @@
/*++ @file
The PCD, gEmulatorPkgTokenSpaceGuid.PcdPeiServicesTablePage, points to a magic page
of memory that is like SRAM on an embedded system. This file defines what goes
where in the magic page.
Copyright (c) 2011, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __EMU_MAGIC_PAGE_LIB_H__
#define __EMU_MAGIC_PAGE_LIB_H__
#include <PiPei.h>
#include <Library/PcdLib.h>
#include <Protocol/EmuThunk.h>
typedef struct {
// Used by PEI Core and PEIMs to store the PEI Services pointer.
// Privilege issues prevent using the PI mechanism in the emulator.
CONST EFI_PEI_SERVICES **PeiServicesTablePointer;
// Used by SecPeiServicesLib
EFI_PEI_PPI_DESCRIPTOR *PpiList;
// Needed by PEI PEI PeCoffLoaderExtraActionLib
EMU_THUNK_PROTOCOL *Thunk;
} EMU_MAGIC_PAGE_LAYOUT;
#define EMU_MAGIC_PAGE() ((EMU_MAGIC_PAGE_LAYOUT *)((UINTN)PcdGet64 (PcdPeiServicesTablePage)))
#endif

View File

@@ -0,0 +1,42 @@
/*++ @file
Copyright (c) 2011, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __EMU_THUNK_LIB_H__
#define __EMU_THUNK_LIB_H__
#include <Protocol/EmuThunk.h>
extern EMU_THUNK_PROTOCOL *gEmuThunk;
/**
Serach the EMU IO Thunk database for a matching EMU IO Thunk
Protocol instance.
@param Protocol Protocol to search for.
@param Instance Instance of protocol to search for.
@retval NULL Protocol and Instance not found.
@retval other EMU IO Thunk protocol that matched.
**/
EMU_IO_THUNK_PROTOCOL *
EFIAPI
GetIoThunkInstance (
IN EFI_GUID *Protocol,
IN UINTN Instance
);
#endif

View File

@@ -0,0 +1,43 @@
/*++ @file
Copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Protocol/SimpleTextInEx.h>
/**
KeyMapMake gets called on key presses.
@param KeyData Key that was pressed.
@retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
**/
EFI_STATUS
EFIAPI
KeyMapMake (
IN EFI_KEY_DATA *KeyData
);
/**
KeyMapBreak gets called on key releases.
@param KeyData Key that was pressed.
@retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
**/
EFI_STATUS
EFIAPI
KeyMapBreak (
IN EFI_KEY_DATA *KeyData
);

View File

@@ -0,0 +1,21 @@
/*++ @file
Copyright (c) 2011, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __PPI_LIST_LIB_H__
#define __PPI_LIST_LIB_H__
extern CONST EFI_PEI_PPI_DESCRIPTOR *gPpiList;
#endif

View File

@@ -0,0 +1,33 @@
/** @file
All 3rd parties to register the PPIs passed into PEI Core
Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiPei.h>
EFI_PEI_PPI_DESCRIPTOR *
GetThunkPpiList (
VOID
);
EFI_STATUS
EFIAPI
AddThunkPpi (
IN UINTN Flags,
IN EFI_GUID *Guid,
IN VOID *Ppi
);

View File

@@ -0,0 +1,35 @@
/** @file
Emulator Thunk to abstract OS services from pure EFI code
Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Uefi.h>
#include <Protocol/EmuIoThunk.h>
EFI_STATUS
EFIAPI
AddThunkProtocol (
IN EMU_IO_THUNK_PROTOCOL *ThunkIo,
IN CHAR16 *ConfigString,
IN BOOLEAN EmuBusDriver
);
EFI_STATUS
EFIAPI
GetNextThunkProtocol (
IN BOOLEAN EmuBusDriver,
OUT EMU_IO_THUNK_PROTOCOL **Instance
);

View File

@@ -0,0 +1,127 @@
/** @file
Emulator Thunk to abstract OS services from pure EFI code
Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __EMU_THUNK_PPI_H__
#define __EMU_THUNK_PPI_H__
#define EMU_THUNK_PPI_GUID \
{ 0xB958B78C, 0x1D3E, 0xEE40, { 0x8B, 0xF4, 0xF0, 0x63, 0x2D, 0x06, 0x39, 0x16 } }
/*++
Routine Description:
This service is called from Index == 0 until it returns EFI_UNSUPPORTED.
It allows discontiguous memory regions to be supported by the emulator.
Arguments:
Index - Which memory region to use
MemoryBase - Return Base address of memory region
MemorySize - Return size in bytes of the memory region
Returns:
EFI_SUCCESS - If memory region was mapped
EFI_UNSUPPORTED - If Index is not supported
**/
typedef
EFI_STATUS
(EFIAPI *EMU_PEI_AUTOSCAN) (
IN UINTN Index,
OUT EFI_PHYSICAL_ADDRESS *MemoryBase,
OUT UINT64 *MemorySize
);
/*++
Routine Description:
Return the FD Size and base address. Since the FD is loaded from a
file into host memory only the SEC will know it's address.
Arguments:
Index - Which FD, starts at zero.
FdSize - Size of the FD in bytes
FdBase - Start address of the FD. Assume it points to an FV Header
FixUp - Difference between actual FD address and build address
Returns:
EFI_SUCCESS - Return the Base address and size of the FV
EFI_UNSUPPORTED - Index does nto map to an FD in the system
**/
typedef
EFI_STATUS
(EFIAPI *EMU_PEI_FD_INFORMATION) (
IN UINTN Index,
IN OUT EFI_PHYSICAL_ADDRESS *FdBase,
IN OUT UINT64 *FdSize,
IN OUT EFI_PHYSICAL_ADDRESS *FixUp
);
/*++
Routine Description:
Export of EMU_THUNK_PROTOCOL from the SEC.
Returns:
EFI_SUCCESS - Data returned
**/
typedef
VOID *
(EFIAPI *EMU_PEI_THUNK_INTERFACE) (
VOID
);
/*++
Routine Description:
Loads and relocates a PE/COFF image into memory.
Arguments:
Pe32Data - The base address of the PE/COFF file that is to be loaded and relocated
ImageAddress - The base address of the relocated PE/COFF image
ImageSize - The size of the relocated PE/COFF image
EntryPoint - The entry point of the relocated PE/COFF image
Returns:
EFI_SUCCESS - The file was loaded and relocated
EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file
**/
typedef
EFI_STATUS
(EFIAPI *EMU_PEI_LOAD_FILE) (
VOID *Pe32Data,
EFI_PHYSICAL_ADDRESS *ImageAddress,
UINT64 *ImageSize,
EFI_PHYSICAL_ADDRESS *EntryPoint
);
typedef struct {
EMU_PEI_AUTOSCAN MemoryAutoScan;
EMU_PEI_FD_INFORMATION FirmwareDevices;
EMU_PEI_THUNK_INTERFACE Thunk;
} EMU_THUNK_PPI;
extern EFI_GUID gEmuThunkPpiGuid;
#endif

View File

@@ -0,0 +1,192 @@
/** @file
Emu Block IO2 protocol as defined in the UEFI 2.3.1 specification.
The Block IO2 protocol defines an extension to the Block IO protocol which
enables the ability to read and write data at a block level in a non-blocking
manner.
Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __EMU_BLOCK_IO_H__
#define __EMU_BLOCK_IO_H__
#include <Protocol/BlockIo.h>
#include <Protocol/BlockIo2.h>
#define EMU_BLOCK_IO_PROTOCOL_GUID \
{ 0x6888A4AE, 0xAFCE, 0xE84B, { 0x91, 0x02, 0xF7, 0xB9, 0xDA, 0xE6, 0xA0, 0x30 } }
typedef struct _EMU_BLOCK_IO_PROTOCOL EMU_BLOCK_IO_PROTOCOL;
/**
Reset the block device hardware.
@param[in] This Indicates a pointer to the calling context.
@param[in] ExtendedVerification Indicates that the driver may perform a more
exhausive verfication operation of the device
during reset.
@retval EFI_SUCCESS The device was reset.
@retval EFI_DEVICE_ERROR The device is not functioning properly and could
not be reset.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_BLOCK_RESET) (
IN EMU_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
);
/**
Read BufferSize bytes from Lba into Buffer.
This function reads the requested number of blocks from the device. All the
blocks are read, or an error is returned.
If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_or EFI_MEDIA_CHANGED is returned and
non-blocking I/O is being used, the Event associated with this request will
not be signaled.
@param[in] This Indicates a pointer to the calling context.
@param[in] MediaId Id of the media, changes every time the media is
replaced.
@param[in] Lba The starting Logical Block Address to read from.
@param[in, out] Token A pointer to the token associated with the transaction.
@param[in] BufferSize Size of Buffer, must be a multiple of device block size.
@param[out] Buffer A pointer to the destination buffer for the data. The
caller is responsible for either having implicit or
explicit ownership of the buffer.
@retval EFI_SUCCESS The read request was queued if Token->Event is
not NULL.The data was read correctly from the
device if the Token->Event is NULL.
@retval EFI_DEVICE_ERROR The device reported an error while performing
the read.
@retval EFI_NO_MEDIA There is no media in the device.
@retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
@retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the
intrinsic block size of the device.
@retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
or the buffer is not on proper alignment.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
of resources.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_BLOCK_READ) (
IN EMU_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA LBA,
IN OUT EFI_BLOCK_IO2_TOKEN *Token,
IN UINTN BufferSize,
OUT VOID *Buffer
);
/**
Write BufferSize bytes from Lba into Buffer.
This function writes the requested number of blocks to the device. All blocks
are written, or an error is returned.If EFI_DEVICE_ERROR, EFI_NO_MEDIA,
EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED is returned and non-blocking I/O is
being used, the Event associated with this request will not be signaled.
@param[in] This Indicates a pointer to the calling context.
@param[in] MediaId The media ID that the write request is for.
@param[in] Lba The starting logical block address to be written. The
caller is responsible for writing to only legitimate
locations.
@param[in, out] Token A pointer to the token associated with the transaction.
@param[in] BufferSize Size of Buffer, must be a multiple of device block size.
@param[in] Buffer A pointer to the source buffer for the data.
@retval EFI_SUCCESS The write request was queued if Event is not NULL.
The data was written correctly to the device if
the Event is NULL.
@retval EFI_WRITE_PROTECTED The device can not be written to.
@retval EFI_NO_MEDIA There is no media in the device.
@retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
@retval EFI_DEVICE_ERROR The device reported an error while performing the write.
@retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
@retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
or the buffer is not on proper alignment.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
of resources.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_BLOCK_WRITE) (
IN EMU_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA LBA,
IN OUT EFI_BLOCK_IO2_TOKEN *Token,
IN UINTN BufferSize,
IN VOID *Buffer
);
/**
Flush the Block Device.
If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED
is returned and non-blocking I/O is being used, the Event associated with
this request will not be signaled.
@param[in] This Indicates a pointer to the calling context.
@param[in,out] Token A pointer to the token associated with the transaction
@retval EFI_SUCCESS The flush request was queued if Event is not NULL.
All outstanding data was written correctly to the
device if the Event is NULL.
@retval EFI_DEVICE_ERROR The device reported an error while writting back
the data.
@retval EFI_WRITE_PROTECTED The device cannot be written to.
@retval EFI_NO_MEDIA There is no media in the device.
@retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
of resources.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_BLOCK_FLUSH) (
IN EMU_BLOCK_IO_PROTOCOL *This,
IN OUT EFI_BLOCK_IO2_TOKEN *Token
);
typedef
EFI_STATUS
(EFIAPI *EMU_BLOCK_CREATE_MAPPING) (
IN EMU_BLOCK_IO_PROTOCOL *This,
IN EFI_BLOCK_IO_MEDIA *Media
);
///
/// The Block I/O2 protocol defines an extension to the Block I/O protocol which
/// enables the ability to read and write data at a block level in a non-blocking
// manner.
///
struct _EMU_BLOCK_IO_PROTOCOL {
EMU_BLOCK_RESET Reset;
EMU_BLOCK_READ ReadBlocks;
EMU_BLOCK_WRITE WriteBlocks;
EMU_BLOCK_FLUSH FlushBlocks;
EMU_BLOCK_CREATE_MAPPING CreateMapping;
};
extern EFI_GUID gEmuBlockIoProtocolGuid;
#endif

View File

@@ -0,0 +1,140 @@
/** @file
SimpleFileSystem protocol as defined in the UEFI 2.0 specification.
The SimpleFileSystem protocol is the programmatic access to the FAT (12,16,32)
file system specified in UEFI 2.0. It can also be used to abstract a file
system other than FAT.
UEFI 2.0 can boot from any valid EFI image contained in a SimpleFileSystem.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _EMU_UGA_IO_H_
#define _EMU_UGA_IO_H_
#include <Protocol/SimplePointer.h>
#include <Protocol/SimpleTextIn.h>
#include <Protocol/SimpleTextInEx.h>
#include <Protocol/UgaDraw.h>
#define EMU_GRAPHICS_WINDOW_PROTOCOL_GUID \
{ 0x30FD316A, 0x6728, 0x2E41, { 0xA6, 0x90, 0x0D, 0x13, 0x33, 0xD8, 0xCA, 0xC1 } }
typedef struct _EMU_GRAPHICS_WINDOW_PROTOCOL EMU_GRAPHICS_WINDOW_PROTOCOL;
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_CLOSE)(
EMU_GRAPHICS_WINDOW_PROTOCOL *Uga
);
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_SIZE)(
EMU_GRAPHICS_WINDOW_PROTOCOL *Uga,
UINT32 Width,
UINT32 Height
);
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_CHECK_KEY)(
EMU_GRAPHICS_WINDOW_PROTOCOL *Uga
);
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_GET_KEY)(
EMU_GRAPHICS_WINDOW_PROTOCOL *Uga,
EFI_KEY_DATA *key
);
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_KEY_SET_STATE) (
IN EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindows,
IN EFI_KEY_TOGGLE_STATE *KeyToggleState
);
typedef
VOID
(EFIAPI *EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK) (
IN VOID *Context,
IN EFI_KEY_DATA *KeyData
);
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_REGISTER_KEY_NOTIFY) (
IN EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindows,
IN EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK CallBack,
IN VOID *Context
);
typedef struct {
UINTN SourceX;
UINTN SourceY;
UINTN DestinationX;
UINTN DestinationY;
UINTN Width;
UINTN Height;
UINTN Delta;
} EMU_GRAPHICS_WINDOWS__BLT_ARGS;
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_BLT)(
IN EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindows,
IN EFI_UGA_PIXEL *BltBuffer OPTIONAL,
IN EFI_UGA_BLT_OPERATION BltOperation,
IN EMU_GRAPHICS_WINDOWS__BLT_ARGS *Args
);
typedef
BOOLEAN
(EFIAPI *EMU_GRAPHICS_WINDOWS_IS_KEY_PRESSED) (
IN EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindows,
IN EFI_KEY_DATA *KeyData
);
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_CHECK_POINTER)(
EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindows
);
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_GET_POINTER_STATE)(
EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindows,
EFI_SIMPLE_POINTER_STATE *state
);
struct _EMU_GRAPHICS_WINDOW_PROTOCOL {
EMU_GRAPHICS_WINDOWS_SIZE Size;
EMU_GRAPHICS_WINDOWS_CHECK_KEY CheckKey;
EMU_GRAPHICS_WINDOWS_KEY_SET_STATE KeySetState;
EMU_GRAPHICS_WINDOWS_GET_KEY GetKey;
EMU_GRAPHICS_WINDOWS_REGISTER_KEY_NOTIFY RegisterKeyNotify;
EMU_GRAPHICS_WINDOWS_BLT Blt;
EMU_GRAPHICS_WINDOWS_IS_KEY_PRESSED IsKeyPressed;
EMU_GRAPHICS_WINDOWS_CHECK_POINTER CheckPointer;
EMU_GRAPHICS_WINDOWS_GET_POINTER_STATE GetPointerState;
};
extern EFI_GUID gEmuGraphicsWindowProtocolGuid;
#endif

View File

@@ -0,0 +1,134 @@
/*++ @file
Copyright (c) 2006, Tristan Gingold. All rights reserved.<BR>
Portitions copyright (c) 2010 - 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the
BSD License which accompanies this distribution. The full text of the
license may be found at http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _EMU_UGA_IO_H_
#define _EMU_UGA_IO_H_
#include <Protocol/SimplePointer.h>
#include <Protocol/SimpleTextIn.h>
#include <Protocol/SimpleTextInEx.h>
#include <Protocol/UgaDraw.h>
#define EMU_GRAPHICS_WINDOW_PROTOCOL_GUID \
{ 0x30FD316A, 0x6728, 0x2E41, { 0xA6, 0x90, 0x0D, 0x13, 0x33, 0xD8, 0xCA, 0xC1 } }
typedef struct _EMU_GRAPHICS_WINDOW_PROTOCOL EMU_GRAPHICS_WINDOW_PROTOCOL;
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_CLOSE)(
EMU_GRAPHICS_WINDOW_PROTOCOL *Uga
);
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_SIZE)(
EMU_GRAPHICS_WINDOW_PROTOCOL *Uga,
UINT32 Width,
UINT32 Height
);
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_CHECK_KEY)(
EMU_GRAPHICS_WINDOW_PROTOCOL *Uga
);
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_GET_KEY)(
EMU_GRAPHICS_WINDOW_PROTOCOL *Uga,
EFI_KEY_DATA *key
);
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_KEY_SET_STATE) (
IN EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindows,
IN EFI_KEY_TOGGLE_STATE *KeyToggleState
);
typedef
VOID
(EFIAPI *EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK) (
IN VOID *Context,
IN EFI_KEY_DATA *KeyData
);
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_REGISTER_KEY_NOTIFY) (
IN EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindows,
IN EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK MakeCallBack,
IN EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK BreakCallBack,
IN VOID *Context
);
typedef struct {
UINTN SourceX;
UINTN SourceY;
UINTN DestinationX;
UINTN DestinationY;
UINTN Width;
UINTN Height;
UINTN Delta;
} EMU_GRAPHICS_WINDOWS__BLT_ARGS;
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_BLT)(
IN EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindows,
IN EFI_UGA_PIXEL *BltBuffer OPTIONAL,
IN EFI_UGA_BLT_OPERATION BltOperation,
IN EMU_GRAPHICS_WINDOWS__BLT_ARGS *Args
);
typedef
BOOLEAN
(EFIAPI *EMU_GRAPHICS_WINDOWS_IS_KEY_PRESSED) (
IN EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindows,
IN EFI_KEY_DATA *KeyData
);
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_CHECK_POINTER)(
EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindows
);
typedef
EFI_STATUS
(EFIAPI *EMU_GRAPHICS_WINDOWS_GET_POINTER_STATE)(
EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindows,
EFI_SIMPLE_POINTER_STATE *state
);
struct _EMU_GRAPHICS_WINDOW_PROTOCOL {
EMU_GRAPHICS_WINDOWS_SIZE Size;
EMU_GRAPHICS_WINDOWS_CHECK_KEY CheckKey;
EMU_GRAPHICS_WINDOWS_KEY_SET_STATE KeySetState;
EMU_GRAPHICS_WINDOWS_GET_KEY GetKey;
EMU_GRAPHICS_WINDOWS_REGISTER_KEY_NOTIFY RegisterKeyNotify;
EMU_GRAPHICS_WINDOWS_BLT Blt;
EMU_GRAPHICS_WINDOWS_IS_KEY_PRESSED IsKeyPressed;
EMU_GRAPHICS_WINDOWS_CHECK_POINTER CheckPointer;
EMU_GRAPHICS_WINDOWS_GET_POINTER_STATE GetPointerState;
};
extern EFI_GUID gEmuGraphicsWindowProtocolGuid;
#endif

View File

@@ -0,0 +1,51 @@
/** @file
Emulator Thunk to abstract OS services from pure EFI code
Copyright (c) 2010 - 2011, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __EMU_IO_THUNK__
#define __EMU_IO_THUNK__
#define EMU_IO_THUNK_PROTOCO_GUID \
{ 0x453368F6, 0x7C85, 0x434A, { 0xA9, 0x8A, 0x72, 0xD1, 0xB7, 0xFF, 0xA9, 0x26 } }
typedef struct _EMU_IO_THUNK_PROTOCOL EMU_IO_THUNK_PROTOCOL;
typedef
EFI_STATUS
(EFIAPI *EMU_IO_THUNK_PROTOCOL_CLOSE_OPEN) (
IN EMU_IO_THUNK_PROTOCOL *This
);
typedef
EFI_STATUS
(EFIAPI *EMU_IO_THUNK_PROTOCOL_CLOSE_CLOSE) (
IN EMU_IO_THUNK_PROTOCOL *This
);
struct _EMU_IO_THUNK_PROTOCOL {
EFI_GUID *Protocol;
VOID *Interface; /// Only be valid after Open() is called
CHAR16 *ConfigString;
UINT16 Instance;
EMU_IO_THUNK_PROTOCOL_CLOSE_OPEN Open;
EMU_IO_THUNK_PROTOCOL_CLOSE_CLOSE Close;
VOID *Private; /// Used by implementation
};
extern EFI_GUID gEmuIoThunkProtocolGuid;
#endif

View File

@@ -0,0 +1,459 @@
/** @file
The EMU_SNP_PROTOCOL provides services to initialize a network interface,
transmit packets, receive packets, and close a network interface.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Portitions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __EMU_SNP_H__
#define __EMU_SNP_H__
#include <Protocol/SimpleNetwork.h>
#define EMU_SNP_PROTOCOL_GUID \
{ 0xFD5FBE54, 0x8C35, 0xB345, { 0x8A, 0x0F, 0x7A, 0xC8, 0xA5, 0xFD, 0x05, 0x21 } }
typedef struct _EMU_SNP_PROTOCOL EMU_SNP_PROTOCOL;
/**
Register storage for SNP Mode.
@param This Protocol instance pointer.
@param Mode SimpleNetworkProtocol Mode structure passed into driver.
@retval EFI_SUCCESS The network interface was started.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_SNP_CREATE_MAPPING)(
IN EMU_SNP_PROTOCOL *This,
IN EFI_SIMPLE_NETWORK_MODE *Mode
);
/**
Changes the state of a network interface from "stopped" to "started".
@param This Protocol instance pointer.
@retval EFI_SUCCESS The network interface was started.
@retval EFI_ALREADY_STARTED The network interface is already in the started state.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_SNP_START)(
IN EMU_SNP_PROTOCOL *This
);
/**
Changes the state of a network interface from "started" to "stopped".
@param This Protocol instance pointer.
@retval EFI_SUCCESS The network interface was stopped.
@retval EFI_ALREADY_STARTED The network interface is already in the stopped state.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_SNP_STOP)(
IN EMU_SNP_PROTOCOL *This
);
/**
Resets a network adapter and allocates the transmit and receive buffers
required by the network interface; optionally, also requests allocation
of additional transmit and receive buffers.
@param This The protocol instance pointer.
@param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
that the driver should allocate for the network interface.
Some network interfaces will not be able to use the extra
buffer, and the caller will not know if it is actually
being used.
@param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
that the driver should allocate for the network interface.
Some network interfaces will not be able to use the extra
buffer, and the caller will not know if it is actually
being used.
@retval EFI_SUCCESS The network interface was initialized.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_OUT_OF_RESOURCES There was not enough memory for the transmit and
receive buffers.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_SNP_INITIALIZE)(
IN EMU_SNP_PROTOCOL *This,
IN UINTN ExtraRxBufferSize OPTIONAL,
IN UINTN ExtraTxBufferSize OPTIONAL
);
/**
Resets a network adapter and re-initializes it with the parameters that were
provided in the previous call to Initialize().
@param This The protocol instance pointer.
@param ExtendedVerification Indicates that the driver may perform a more
exhaustive verification operation of the device
during reset.
@retval EFI_SUCCESS The network interface was reset.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_SNP_RESET)(
IN EMU_SNP_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
);
/**
Resets a network adapter and leaves it in a state that is safe for
another driver to initialize.
@param This Protocol instance pointer.
@retval EFI_SUCCESS The network interface was shutdown.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_SNP_SHUTDOWN)(
IN EMU_SNP_PROTOCOL *This
);
/**
Manages the multicast receive filters of a network interface.
@param This The protocol instance pointer.
@param Enable A bit mask of receive filters to enable on the network interface.
@param Disable A bit mask of receive filters to disable on the network interface.
@param ResetMCastFilter Set to TRUE to reset the contents of the multicast receive
filters on the network interface to their default values.
@param McastFilterCnt Number of multicast HW MAC addresses in the new
MCastFilter list. This value must be less than or equal to
the MCastFilterCnt field of EMU_SNP_MODE. This
field is optional if ResetMCastFilter is TRUE.
@param MCastFilter A pointer to a list of new multicast receive filter HW MAC
addresses. This list will replace any existing multicast
HW MAC address list. This field is optional if
ResetMCastFilter is TRUE.
@retval EFI_SUCCESS The multicast receive filter list was updated.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_SNP_RECEIVE_FILTERS)(
IN EMU_SNP_PROTOCOL *This,
IN UINT32 Enable,
IN UINT32 Disable,
IN BOOLEAN ResetMCastFilter,
IN UINTN MCastFilterCnt OPTIONAL,
IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL
);
/**
Modifies or resets the current station address, if supported.
@param This The protocol instance pointer.
@param Reset Flag used to reset the station address to the network interfaces
permanent address.
@param New The new station address to be used for the network interface.
@retval EFI_SUCCESS The network interfaces station address was updated.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_SNP_STATION_ADDRESS)(
IN EMU_SNP_PROTOCOL *This,
IN BOOLEAN Reset,
IN EFI_MAC_ADDRESS *New OPTIONAL
);
/**
Resets or collects the statistics on a network interface.
@param This Protocol instance pointer.
@param Reset Set to TRUE to reset the statistics for the network interface.
@param StatisticsSize On input the size, in bytes, of StatisticsTable. On
output the size, in bytes, of the resulting table of
statistics.
@param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
contains the statistics.
@retval EFI_SUCCESS The statistics were collected from the network interface.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
size needed to hold the statistics is returned in
StatisticsSize.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_SNP_STATISTICS)(
IN EMU_SNP_PROTOCOL *This,
IN BOOLEAN Reset,
IN OUT UINTN *StatisticsSize OPTIONAL,
OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL
);
/**
Converts a multicast IP address to a multicast HW MAC address.
@param This The protocol instance pointer.
@param IPv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
to FALSE if the multicast IP address is IPv4 [RFC 791].
@param IP The multicast IP address that is to be converted to a multicast
HW MAC address.
@param MAC The multicast HW MAC address that is to be generated from IP.
@retval EFI_SUCCESS The multicast IP address was mapped to the multicast
HW MAC address.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
size needed to hold the statistics is returned in
StatisticsSize.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_SNP_MCAST_IP_TO_MAC)(
IN EMU_SNP_PROTOCOL *This,
IN BOOLEAN IPv6,
IN EFI_IP_ADDRESS *IP,
OUT EFI_MAC_ADDRESS *MAC
);
/**
Performs read and write operations on the NVRAM device attached to a
network interface.
@param This The protocol instance pointer.
@param ReadWrite TRUE for read operations, FALSE for write operations.
@param Offset Byte offset in the NVRAM device at which to start the read or
write operation. This must be a multiple of NvRamAccessSize and
less than NvRamSize.
@param BufferSize The number of bytes to read or write from the NVRAM device.
This must also be a multiple of NvramAccessSize.
@param Buffer A pointer to the data buffer.
@retval EFI_SUCCESS The NVRAM access was performed.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_SNP_NVDATA)(
IN EMU_SNP_PROTOCOL *This,
IN BOOLEAN ReadWrite,
IN UINTN Offset,
IN UINTN BufferSize,
IN OUT VOID *Buffer
);
/**
Reads the current interrupt status and recycled transmit buffer status from
a network interface.
@param This The protocol instance pointer.
@param InterruptStatus A pointer to the bit mask of the currently active interrupts
If this is NULL, the interrupt status will not be read from
the device. If this is not NULL, the interrupt status will
be read from the device. When the interrupt status is read,
it will also be cleared. Clearing the transmit interrupt
does not empty the recycled transmit buffer array.
@param TxBuf Recycled transmit buffer address. The network interface will
not transmit if its internal recycled transmit buffer array
is full. Reading the transmit buffer does not clear the
transmit interrupt. If this is NULL, then the transmit buffer
status will not be read. If there are no transmit buffers to
recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
@retval EFI_SUCCESS The status of the network interface was retrieved.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_SNP_GET_STATUS)(
IN EMU_SNP_PROTOCOL *This,
OUT UINT32 *InterruptStatus OPTIONAL,
OUT VOID **TxBuf OPTIONAL
);
/**
Places a packet in the transmit queue of a network interface.
@param This The protocol instance pointer.
@param HeaderSize The size, in bytes, of the media header to be filled in by
the Transmit() function. If HeaderSize is non-zero, then it
must be equal to This->Mode->MediaHeaderSize and the DestAddr
and Protocol parameters must not be NULL.
@param BufferSize The size, in bytes, of the entire packet (media header and
data) to be transmitted through the network interface.
@param Buffer A pointer to the packet (media header followed by data) to be
transmitted. This parameter cannot be NULL. If HeaderSize is zero,
then the media header in Buffer must already be filled in by the
caller. If HeaderSize is non-zero, then the media header will be
filled in by the Transmit() function.
@param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
This->Mode->CurrentAddress is used for the source HW MAC address.
@param DestAddr The destination HW MAC address. If HeaderSize is zero, then this
parameter is ignored.
@param Protocol The type of header to build. If HeaderSize is zero, then this
parameter is ignored. See RFC 1700, section "Ether Types", for
examples.
@retval EFI_SUCCESS The packet was placed on the transmit queue.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_NOT_READY The network interface is too busy to accept this transmit request.
@retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_SNP_TRANSMIT)(
IN EMU_SNP_PROTOCOL *This,
IN UINTN HeaderSize,
IN UINTN BufferSize,
IN VOID *Buffer,
IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,
IN UINT16 *Protocol OPTIONAL
);
/**
Receives a packet from a network interface.
@param This The protocol instance pointer.
@param HeaderSize The size, in bytes, of the media header received on the network
interface. If this parameter is NULL, then the media header size
will not be returned.
@param BufferSize On entry, the size, in bytes, of Buffer. On exit, the size, in
bytes, of the packet that was received on the network interface.
@param Buffer A pointer to the data buffer to receive both the media header and
the data.
@param SrcAddr The source HW MAC address. If this parameter is NULL, the
HW MAC source address will not be extracted from the media
header.
@param DestAddr The destination HW MAC address. If this parameter is NULL,
the HW MAC destination address will not be extracted from the
media header.
@param Protocol The media header type. If this parameter is NULL, then the
protocol will not be extracted from the media header. See
RFC 1700 section "Ether Types" for examples.
@retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
been updated to the number of bytes received.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_NOT_READY The network interface is too busy to accept this transmit
request.
@retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_SNP_RECEIVE)(
IN EMU_SNP_PROTOCOL *This,
OUT UINTN *HeaderSize OPTIONAL,
IN OUT UINTN *BufferSize,
OUT VOID *Buffer,
OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL,
OUT UINT16 *Protocol OPTIONAL
);
#define EMU_SNP_PROTOCOL_REVISION 0x00010000
//
// Revision defined in EFI1.1
//
#define EMU_SNP_INTERFACE_REVISION EMU_SNP_PROTOCOL_REVISION
///
/// The EMU_SNP_PROTOCOL protocol abstracts OS network sercices
/// from the EFI driver that produces EFI Simple Network Protocol.
///
struct _EMU_SNP_PROTOCOL {
EMU_SNP_CREATE_MAPPING CreateMapping;
EMU_SNP_START Start;
EMU_SNP_STOP Stop;
EMU_SNP_INITIALIZE Initialize;
EMU_SNP_RESET Reset;
EMU_SNP_SHUTDOWN Shutdown;
EMU_SNP_RECEIVE_FILTERS ReceiveFilters;
EMU_SNP_STATION_ADDRESS StationAddress;
EMU_SNP_STATISTICS Statistics;
EMU_SNP_MCAST_IP_TO_MAC MCastIpToMac;
EMU_SNP_NVDATA NvData;
EMU_SNP_GET_STATUS GetStatus;
EMU_SNP_TRANSMIT Transmit;
EMU_SNP_RECEIVE Receive;
};
extern EFI_GUID gEmuSnpProtocolGuid;
#endif

View File

@@ -0,0 +1,103 @@
/** @file
Emulator Thunk to abstract OS services from pure EFI code
Copyright (c) 2010 - 2011, Apple Inc. All rights reserved.<BR>
Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __EMU_THREAD_THUNK__
#define __EMU_THREAD_THUNK__
typedef struct _EMU_THREAD_THUNK_PROTOCOL EMU_THREAD_THUNK_PROTOCOL;
typedef
UINTN
(EFIAPI *THREAD_THUNK_MUTEX_LOCK) (
IN VOID *Mutex
);
typedef
UINTN
(EFIAPI *THREAD_THUNK_MUTEX_UNLOCK) (
IN VOID *Mutex
);
typedef
UINTN
(EFIAPI *THREAD_THUNK_MUTEX_TRY_LOCK) (
IN VOID *Mutex
);
typedef
VOID *
(EFIAPI *THREAD_THUNK_MUTEX_INIT) (
IN VOID
);
typedef
UINTN
(EFIAPI *THREAD_THUNK_MUTEX_DISTROY) (
IN VOID *Mutex
);
typedef
VOID *
(EFIAPI *THREAD_THUNK_THREAD_ENTRY) (
IN VOID *Context
);
typedef
UINTN
(EFIAPI *THREAD_THUNK_CREATE_THREAD) (
IN VOID *Thread,
IN VOID *Attribute,
IN THREAD_THUNK_THREAD_ENTRY Start,
IN VOID *Context
);
typedef
VOID
(EFIAPI *THREAD_THUNK_EXIT_THREAD) (
IN VOID *ValuePtr
);
typedef
UINTN
(EFIAPI *THREAD_THUNK_SELF) (
VOID
);
struct _EMU_THREAD_THUNK_PROTOCOL {
THREAD_THUNK_MUTEX_LOCK MutexLock;
THREAD_THUNK_MUTEX_UNLOCK MutexUnlock;
THREAD_THUNK_MUTEX_TRY_LOCK MutexTryLock;
THREAD_THUNK_MUTEX_INIT MutexInit;
THREAD_THUNK_MUTEX_DISTROY MutexDistroy;
THREAD_THUNK_CREATE_THREAD CreateThread;
THREAD_THUNK_EXIT_THREAD ExitThread;
THREAD_THUNK_SELF Self;
};
extern EFI_GUID gEmuThreadThunkProtocolGuid;
#endif

View File

@@ -0,0 +1,264 @@
/** @file
Emulator Thunk to abstract OS services from pure EFI code
Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __EMU_THUNK_PROTOCOL_H__
#define __EMU_THUNK_PROTOCOL_H__
#define EMU_THUNK_PROTOCOL_GUID \
{ 0x5CF32E0B, 0x8EDF, 0x2E44, { 0x9C, 0xDA, 0x93, 0x20, 0x5E, 0x99, 0xEC, 0x1C } }
// neded for things like EFI_TIME_CAPABILITIES
#include <Uefi.h>
#include <Library/PeCoffExtraActionLib.h>
#include <Protocol/EmuIoThunk.h>
#include <Protocol/DevicePath.h>
typedef struct {
VENDOR_DEVICE_PATH VendorDevicePath;
UINT32 Instance;
} EMU_VENDOR_DEVICE_PATH_NODE;
typedef struct {
EMU_VENDOR_DEVICE_PATH_NODE Vendor;
EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
} EMU_THUNK_DEVICE_PATH;
typedef struct _EMU_THUNK_PROTOCOL EMU_THUNK_PROTOCOL;
typedef
UINTN
(EFIAPI *EMU_WRITE_STD_ERROR) (
IN UINT8 *Buffer,
IN UINTN NumberOfBytes
);
typedef
EFI_STATUS
(EFIAPI *EMU_CONFIG_STD_IN) (
VOID
);
typedef
UINTN
(EFIAPI *EMU_WRITE_STD_OUT) (
IN UINT8 *Buffer,
IN UINTN NumberOfBytes
);
typedef
UINTN
(EFIAPI *EMU_READ_STD_IN) (
OUT UINT8 *Buffer,
IN UINTN NumberOfBytes
);
typedef
BOOLEAN
(EFIAPI *EMU_POLL_STD_IN) (
VOID
);
typedef
VOID *
(EFIAPI *EMU_OS_MALLOC) (
IN UINTN Size
);
typedef
VOID *
(EFIAPI *EMU_OS_VMALLOC) (
IN UINTN Size
);
typedef
BOOLEAN
(EFIAPI *EMU_OS_FREE) (
IN VOID *Ptr
);
typedef
EFI_STATUS
(EFIAPI *EMU_PE_COFF_GET_ENTRY_POINT) (
IN VOID *Pe32Data,
IN OUT VOID **EntryPoint
);
typedef
VOID
(EFIAPI *EMU_PE_COFF_RELOCATE_EXTRA_ACTION) (
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
);
typedef
VOID
(EFIAPI *EMU_PE_COFF_UNLOAD_EXTRA_ACTION) (
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
);
typedef
VOID
(EFIAPI *EMU_ENABLE_INERRUPTS) (
VOID
);
typedef
VOID
(EFIAPI *EMU_DISABLE_INERRUPTS) (
VOID
);
typedef
UINT64
(EFIAPI *EMU_QUERY_PERFORMANCE_FREQENCY) (
VOID
);
typedef
UINT64
(EFIAPI *EMU_QUERY_PERFORMANCE_COUNTER) (
VOID
);
typedef
VOID
(EFIAPI *EMU_SLEEP) (
IN UINT64 Milliseconds
);
typedef
VOID
(EFIAPI *EMU_CPU_SLEEP) (
VOID
);
typedef
VOID
(EFIAPI *EMU_EXIT) (
IN UINTN Status
);
typedef
VOID
(EFIAPI *EMU_GET_TIME) (
OUT EFI_TIME *Time,
OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL
);
typedef
VOID
(EFIAPI *EMU_SET_TIME) (
IN EFI_TIME *Time
);
typedef
VOID
(EFIAPI EMU_SET_TIMER_CALLBACK) (
IN UINT64 DeltaMs
);
typedef
VOID
(EFIAPI *EMU_SET_TIMER) (
IN UINT64 PeriodMs,
IN EMU_SET_TIMER_CALLBACK CallBack
);
/**
Enumerates the current set of protocol instances that abstract OS services from EFI.
A given protocol can have multiple instances. Usually a protocol is configured via a
single PCD string. The data associated for each instance is seperated via a ! in the string.
EMU_IO_THUNK_PROTOCOL_CLOSE.ConfigString will contain the information in the PCD string up to the next !.
Thus each instance has a unique ConfigString.
@param EmuBusDriver TRUE means only return protocol instances that need to be produced
by the EmuBusDriver. FALSE means return all possible protocols
@param Instance On input the protocol to search for, or NULL to start a search
of all the supported protocol instances.
@param NextProtocol On output it represents the next value to be passed into Protocol.
@param Interface A pointer to the EMU_IO_THUNK_PROTOCOL_CLOSE interface.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_NOT_FOUND The next protocol instance was not found.
@retval EFI_INVALID_PARAMETER Instance is NULL.
**/
typedef
EFI_STATUS
(EFIAPI *EMU_GET_NEXT_PROTOCOL) (
IN BOOLEAN EmuBusDriver,
OUT EMU_IO_THUNK_PROTOCOL **Instance OPTIONAL
);
struct _EMU_THUNK_PROTOCOL {
// Used for early debug printing
EMU_WRITE_STD_ERROR WriteStdErr;
EMU_CONFIG_STD_IN ConfigStdIn;
EMU_WRITE_STD_OUT WriteStdOut;
EMU_READ_STD_IN ReadStdIn;
EMU_POLL_STD_IN PollStdIn;
//
// Map OS malloc/free so we can use OS based guard malloc
//
EMU_OS_MALLOC Malloc;
EMU_OS_VMALLOC Valloc;
EMU_OS_FREE Free;
///
/// PE/COFF loader hooks to get symbols loaded
///
EMU_PE_COFF_GET_ENTRY_POINT PeCoffGetEntryPoint;
EMU_PE_COFF_RELOCATE_EXTRA_ACTION PeCoffRelocateImageExtraAction;
EMU_PE_COFF_UNLOAD_EXTRA_ACTION PeCoffUnloadImageExtraAction;
///
/// DXE Architecture Protocol Services
///
EMU_ENABLE_INERRUPTS EnableInterrupt;
EMU_DISABLE_INERRUPTS DisableInterrupt;
EMU_QUERY_PERFORMANCE_FREQENCY QueryPerformanceFrequency;
EMU_QUERY_PERFORMANCE_COUNTER QueryPerformanceCounter;
EMU_SLEEP Sleep;
EMU_CPU_SLEEP CpuSleep;
EMU_EXIT Exit;
EMU_GET_TIME GetTime;
EMU_SET_TIME SetTime;
EMU_SET_TIMER SetTimer;
///
/// Generic System Services
///
EMU_GET_NEXT_PROTOCOL GetNextProtocol;
};
extern EFI_GUID gEmuThunkProtocolGuid;
#endif

View File

@@ -0,0 +1,183 @@
/** @file
Null Platform Hook Library instance.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Base.h>
#include <Protocol/EmuThunk.h>
#include <Protocol/EmuGraphicsWindow.h>
#include <Protocol/EmuBlockIo.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/EmuThread.h>
#include <Library/BaseLib.h>
#include <Library/DevicePathToTextLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DevicePathLib.h>
/**
Converts a Vendor device path structure to its string representative.
@param Str The string representative of input device.
@param DevPath The input device path structure.
@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
of the display node is used, where applicable. If DisplayOnly
is FALSE, then the longer text representation of the display node
is used.
@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
representation for a device node can be used, where applicable.
@return EFI_NOT_FOUND if no string representation exists.
@return EFI_SUCCESS a string representation was created.
**/
EFI_STATUS
EFIAPI
DevPathToTextVendorLib (
IN OUT POOL_PRINT *Str,
IN VOID *DevPath,
IN BOOLEAN DisplayOnly,
IN BOOLEAN AllowShortcuts
)
{
EMU_VENDOR_DEVICE_PATH_NODE *Vendor;
CHAR16 *Type;
Vendor = (EMU_VENDOR_DEVICE_PATH_NODE *)DevPath;
if (CompareGuid (&Vendor->VendorDevicePath.Guid, &gEmuThunkProtocolGuid)) {
CatPrint (Str, L"EmuThunk()");
return EFI_SUCCESS;
}
if (CompareGuid (&Vendor->VendorDevicePath.Guid, &gEmuGraphicsWindowProtocolGuid)) {
CatPrint (Str, L"EmuGraphics(%d)", Vendor->Instance);
return EFI_SUCCESS;
}
if (CompareGuid (&Vendor->VendorDevicePath.Guid, &gEfiSimpleFileSystemProtocolGuid)) {
CatPrint (Str, L"EmuFs(%d)", Vendor->Instance);
return EFI_SUCCESS;
}
if (CompareGuid (&Vendor->VendorDevicePath.Guid, &gEmuBlockIoProtocolGuid)) {
CatPrint (Str, L"EmuBlk(%d)", Vendor->Instance);
return EFI_SUCCESS;
}
if (CompareGuid (&Vendor->VendorDevicePath.Guid, &gEmuThreadThunkProtocolGuid)) {
CatPrint (Str, L"EmuThread()");
return EFI_SUCCESS;
}
return EFI_NOT_FOUND;
}
/**
Converts a text device path node to Hardware Vendor device path structure.
@param TextDeviceNode The input Text device path node.
@return A pointer to the newly-created Hardware Vendor device path structure.
**/
EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextEmuThunk (
IN CHAR16 *TextDeviceNode
)
{
CHAR16 *Str;
VENDOR_DEVICE_PATH *Vendor;
Str = GetNextParamStr (&TextDeviceNode);
Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
HARDWARE_DEVICE_PATH,
HW_VENDOR_DP,
(UINT16) sizeof (VENDOR_DEVICE_PATH)
);
CopyGuid (&Vendor->Guid, &gEmuThunkProtocolGuid);
return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
}
/**
Converts a text device path node to Hardware Vendor device path structure.
@param TextDeviceNode The input Text device path node.
@return A pointer to the newly-created Hardware Vendor device path structure.
**/
EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextEmuThread (
IN CHAR16 *TextDeviceNode
)
{
CHAR16 *Str;
VENDOR_DEVICE_PATH *Vendor;
Str = GetNextParamStr (&TextDeviceNode);
Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
HARDWARE_DEVICE_PATH,
HW_VENDOR_DP,
(UINT16) sizeof (VENDOR_DEVICE_PATH)
);
CopyGuid (&Vendor->Guid, &gEmuThreadThunkProtocolGuid);
return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
}
/**
Converts a text device path node to Hardware Vendor device path structure.
@param TextDeviceNode The input Text device path node.
@return A pointer to the newly-created Hardware Vendor device path structure.
**/
EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextEmuFs (
IN CHAR16 *TextDeviceNode
)
{
CHAR16 *Str;
EMU_VENDOR_DEVICE_PATH_NODE *Vendor;
Str = GetNextParamStr (&TextDeviceNode);
Vendor = (EMU_VENDOR_DEVICE_PATH_NODE *) CreateDeviceNode (
HARDWARE_DEVICE_PATH,
HW_VENDOR_DP,
(UINT16) sizeof (EMU_VENDOR_DEVICE_PATH_NODE)
);
CopyGuid (&Vendor->VendorDevicePath.Guid, &gEfiSimpleFileSystemProtocolGuid);
Vendor->Instance = (UINT32) StrDecimalToUintn (Str);
return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
}
/**
Register the Filter function
@param ImageHandle The firmware allocated handle for the EFI image.
@param SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The constructor executed correctly.
**/
EFI_STATUS
EFIAPI
DevicePathToTextLibConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
DevPathToTextSetVendorDevicePathFilter (DevPathToTextVendorLib);
DevicePathFromTextAddFilter (L"EmuThunk", DevPathFromTextEmuThunk);
DevicePathFromTextAddFilter (L"EmuThread", DevPathFromTextEmuThread);
DevicePathFromTextAddFilter (L"EmuFs", DevPathFromTextEmuFs);
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,48 @@
## @file
# Null DevicePathToText library.
#
# Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = DevicePathTextLib
FILE_GUID = DCD1F939-1732-CA4D-81B7-C757AEC84DBC
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = NULL|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_CORE
CONSTRUCTOR = DevicePathToTextLibConstructor
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
DevicePathTextLib.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
BaseLib
DebugLib
DevicePathLib
[Protocols]
gEmuThunkProtocolGuid
gEmuGraphicsWindowProtocolGuid
gEfiSimpleFileSystemProtocolGuid
gEmuBlockIoProtocolGuid
gEmuThreadThunkProtocolGuid

View File

@@ -0,0 +1,128 @@
/** @file
A non-functional instance of the Timer Library.
Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiPei.h>
#include <Library/TimerLib.h>
#include <Library/DebugLib.h>
#include <Library/EmuThunkLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Protocol/Timer.h>
/**
Stalls the CPU for at least the given number of microseconds.
Stalls the CPU for the number of microseconds specified by MicroSeconds.
@param MicroSeconds The minimum number of microseconds to delay.
@return The value of MicroSeconds inputted.
**/
UINTN
EFIAPI
MicroSecondDelay (
IN UINTN MicroSeconds
)
{
return NanoSecondDelay (MicroSeconds * 1000);
}
/**
Stalls the CPU for at least the given number of nanoseconds.
Stalls the CPU for the number of nanoseconds specified by NanoSeconds.
@param NanoSeconds The minimum number of nanoseconds to delay.
@return The value of NanoSeconds inputted.
**/
UINTN
EFIAPI
NanoSecondDelay (
IN UINTN NanoSeconds
)
{
gEmuThunk->Sleep (NanoSeconds);
return NanoSeconds;
}
/**
Retrieves the current value of a 64-bit free running performance counter.
The counter can either count up by 1 or count down by 1. If the physical
performance counter counts by a larger increment, then the counter values
must be translated. The properties of the counter can be retrieved from
GetPerformanceCounterProperties().
@return The current value of the free running performance counter.
**/
UINT64
EFIAPI
GetPerformanceCounter (
VOID
)
{
return gEmuThunk->QueryPerformanceCounter ();
}
/**
Retrieves the 64-bit frequency in Hz and the range of performance counter
values.
If StartValue is not NULL, then the value that the performance counter starts
with immediately after is it rolls over is returned in StartValue. If
EndValue is not NULL, then the value that the performance counter end with
immediately before it rolls over is returned in EndValue. The 64-bit
frequency of the performance counter in Hz is always returned. If StartValue
is less than EndValue, then the performance counter counts up. If StartValue
is greater than EndValue, then the performance counter counts down. For
example, a 64-bit free running counter that counts up would have a StartValue
of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter
that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.
@param StartValue The value the performance counter starts with when it
rolls over.
@param EndValue The value that the performance counter ends with before
it rolls over.
@return The frequency in Hz.
**/
UINT64
EFIAPI
GetPerformanceCounterProperties (
OUT UINT64 *StartValue, OPTIONAL
OUT UINT64 *EndValue OPTIONAL
)
{
if (StartValue != NULL) {
*StartValue = 0ULL;
}
if (EndValue != NULL) {
*EndValue = (UINT64)-1LL;
}
return gEmuThunk->QueryPerformanceFrequency ();
}

View File

@@ -0,0 +1,44 @@
## @file
# NULL instance of Timer Library as a template.
#
# A non-functional instance of the Timer Library that can be used as a template
# for the implementation of a functional timer library instance. This library instance can
# also be used to test build DXE, Runtime, DXE SAL, and DXE SMM modules that require timer
# services as well as EBC modules that require timer services.
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = EmuDxeCodeTimerLib
FILE_GUID = FB184AF4-A2F2-EE4E-8885-E81E5D8B0135
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = TimerLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_DRIVER UEFI_APPLICATION
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
DxeCoreTimerLib.c
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
DebugLib
EmuThunkLib

View File

@@ -0,0 +1,88 @@
/*++ @file
Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiDxe.h>
#include <Library/DebugLib.h>
#include <Library/HobLib.h>
#include <Library/EmuThunkLib.h>
#include <Library/BaseMemoryLib.h>
EMU_THUNK_PROTOCOL *gEmuThunk = NULL;
/**
The constructor function caches the pointer of EMU Thunk protocol.
@param ImageHandle The firmware allocated handle for the EFI image.
@param SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
**/
EFI_STATUS
EFIAPI
DxeEmuLibConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_HOB_GUID_TYPE *GuidHob;
GuidHob = GetFirstGuidHob (&gEmuThunkProtocolGuid);
ASSERT (GuidHob != NULL);
gEmuThunk = (EMU_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
ASSERT (gEmuThunk != NULL);
return EFI_SUCCESS;
}
/**
Serach the EMU IO Thunk database for a matching EMU IO Thunk
Protocol instance.
@param Protocol Protocol to search for.
@param Instance Instance of protocol to search for.
@retval NULL Protocol and Instance not found.
@retval other EMU IO Thunk protocol that matched.
**/
EMU_IO_THUNK_PROTOCOL *
EFIAPI
GetIoThunkInstance (
IN EFI_GUID *Protocol,
IN UINTN Instance
)
{
EFI_STATUS Status;
EMU_IO_THUNK_PROTOCOL *EmuIoThunk;
for (Status = EFI_SUCCESS, EmuIoThunk = NULL; !EFI_ERROR (Status); ) {
Status = gEmuThunk->GetNextProtocol (FALSE, &EmuIoThunk);
if (EFI_ERROR (Status)) {
break;
}
if (EmuIoThunk->Instance == Instance) {
if (CompareGuid (EmuIoThunk->Protocol, Protocol)) {
return EmuIoThunk;
}
}
}
return NULL;
}

View File

@@ -0,0 +1,46 @@
## @file
# A library to produce the global variable 'gEmuThunk'
#
# This library contains a single global variable 'gEmuThunk' along with a constructor to
# initialize that global.
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = DxeEmuLib
FILE_GUID = 31479AFD-B06F-4E4A-863B-A8F7E7710778
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = EmuThunkLib
CONSTRUCTOR = DxeEmuLibConstructor
[Sources]
DxeEmuLib.c
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
HobLib
DebugLib
BaseMemoryLib
[Protocols]
gEmuThunkProtocolGuid # PROTOCOL ALWAYS_CONSUMED

View File

@@ -0,0 +1,103 @@
/** @file
Provides services to perform additional actions to relocate and unload
PE/Coff image for Emu environment specific purpose such as souce level debug.
This version only works for DXE phase
Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiDxe.h>
#include <Protocol/EmuThunk.h>
#include <Library/PeCoffLib.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/HobLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/PeCoffExtraActionLib.h>
//
// Cache of UnixThunk protocol
//
EMU_THUNK_PROTOCOL *mThunk = NULL;
/**
The constructor function gets the pointer of the WinNT thunk functions
It will ASSERT() if Unix thunk protocol is not installed.
@retval EFI_SUCCESS Unix thunk protocol is found and cached.
**/
EFI_STATUS
EFIAPI
DxeEmuPeCoffLibExtraActionConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_HOB_GUID_TYPE *GuidHob;
//
// Retrieve EmuThunkProtocol from GUID'ed HOB
//
GuidHob = GetFirstGuidHob (&gEmuThunkProtocolGuid);
ASSERT (GuidHob != NULL);
mThunk = (EMU_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
ASSERT (mThunk != NULL);
return EFI_SUCCESS;
}
/**
Performs additional actions after a PE/COFF image has been loaded and relocated.
If ImageContext is NULL, then ASSERT().
@param ImageContext Pointer to the image context structure that describes the
PE/COFF image that has already been loaded and relocated.
**/
VOID
EFIAPI
PeCoffLoaderRelocateImageExtraAction (
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
)
{
if (mThunk != NULL) {
mThunk->PeCoffRelocateImageExtraAction (ImageContext);
}
}
/**
Performs additional actions just before a PE/COFF image is unloaded. Any resources
that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
If ImageContext is NULL, then ASSERT().
@param ImageContext Pointer to the image context structure that describes the
PE/COFF image that is being unloaded.
**/
VOID
EFIAPI
PeCoffLoaderUnloadImageExtraAction (
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
)
{
if (mThunk != NULL) {
mThunk->PeCoffUnloadImageExtraAction (ImageContext);
}
}

View File

@@ -0,0 +1,48 @@
## @file
# PeCoff extra action libary for DXE phase that run Emu emulator.
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = DxeEmuPeCoffExtraActionLib
FILE_GUID = 68FCD487-D230-6846-95B1-5E1F2EF942C4
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = PeCoffExtraActionLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_DRIVER
CONSTRUCTOR = DxeEmuPeCoffLibExtraActionConstructor
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32
#
[Sources]
DxeEmuPeCoffExtraActionLib.c
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
DebugLib
HobLib
BaseMemoryLib
[Protocols]
gEmuThunkProtocolGuid # PROTOCOL ALWAYS_CONSUMED

View File

@@ -0,0 +1,119 @@
/** @file
Serial Port Lib that thunks back to Emulator services to write to StdErr.
All read functions are stubed out.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiDxe.h>
#include <Library/SerialPortLib.h>
#include <Library/EmuThunkLib.h>
/**
Initialize the serial device hardware.
If no initialization is required, then return RETURN_SUCCESS.
If the serial device was successfully initialized, then return RETURN_SUCCESS.
If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.
@retval RETURN_SUCCESS The serial device was initialized.
@retval RETURN_DEVICE_ERROR The serial device could not be initialized.
**/
RETURN_STATUS
EFIAPI
SerialPortInitialize (
VOID
)
{
return gEmuThunk->ConfigStdIn ();
}
/**
Write data from buffer to serial device.
Writes NumberOfBytes data bytes from Buffer to the serial device.
The number of bytes actually written to the serial device is returned.
If the return value is less than NumberOfBytes, then the write operation failed.
If Buffer is NULL, then ASSERT().
If NumberOfBytes is zero, then return 0.
@param Buffer The pointer to the data buffer to be written.
@param NumberOfBytes The number of bytes to written to the serial device.
@retval 0 NumberOfBytes is 0.
@retval >0 The number of bytes written to the serial device.
If this value is less than NumberOfBytes, then the read operation failed.
**/
UINTN
EFIAPI
SerialPortWrite (
IN UINT8 *Buffer,
IN UINTN NumberOfBytes
)
{
return gEmuThunk->WriteStdOut (Buffer, NumberOfBytes);
}
/**
Read data from serial device and save the datas in buffer.
Reads NumberOfBytes data bytes from a serial device into the buffer
specified by Buffer. The number of bytes actually read is returned.
If the return value is less than NumberOfBytes, then the rest operation failed.
If Buffer is NULL, then ASSERT().
If NumberOfBytes is zero, then return 0.
@param Buffer The pointer to the data buffer to store the data read from the serial device.
@param NumberOfBytes The number of bytes which will be read.
@retval 0 Read data failed; No data is to be read.
@retval >0 The actual number of bytes read from serial device.
**/
UINTN
EFIAPI
SerialPortRead (
OUT UINT8 *Buffer,
IN UINTN NumberOfBytes
)
{
return gEmuThunk->ReadStdIn (Buffer, NumberOfBytes);
}
/**
Polls a serial device to see if there is any data waiting to be read.
Polls a serial device to see if there is any data waiting to be read.
If there is data waiting to be read from the serial device, then TRUE is returned.
If there is no data waiting to be read from the serial device, then FALSE is returned.
@retval TRUE Data is waiting to be read from the serial device.
@retval FALSE There is no data waiting to be read from the serial device.
**/
BOOLEAN
EFIAPI
SerialPortPoll (
VOID
)
{
return gEmuThunk->PollStdIn ();
}

View File

@@ -0,0 +1,40 @@
## @file
# Write only instance of Serial Port Library with empty functions.
#
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = DxeEmuSerialPortLib
FILE_GUID = DF08A29A-F60B-E649-AA79-A1490E863A5D
MODULE_TYPE = PEIM
VERSION_STRING = 1.0
LIBRARY_CLASS = SerialPortLib| DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER SMM_CORE UEFI_APPLICATION UEFI_DRIVE
[Sources]
DxeEmuSerialPortLib.c
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
EmuThunkLib

View File

@@ -0,0 +1,119 @@
/** @file
Serial Port Lib that thunks back to Emulator services to write to StdErr.
All read functions are stubed out.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiDxe.h>
#include <Library/SerialPortLib.h>
#include <Library/EmuThunkLib.h>
/**
Initialize the serial device hardware.
If no initialization is required, then return RETURN_SUCCESS.
If the serial device was successfully initialized, then return RETURN_SUCCESS.
If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.
@retval RETURN_SUCCESS The serial device was initialized.
@retval RETURN_DEVICE_ERROR The serial device could not be initialized.
**/
RETURN_STATUS
EFIAPI
SerialPortInitialize (
VOID
)
{
return RETURN_SUCCESS;
}
/**
Write data from buffer to serial device.
Writes NumberOfBytes data bytes from Buffer to the serial device.
The number of bytes actually written to the serial device is returned.
If the return value is less than NumberOfBytes, then the write operation failed.
If Buffer is NULL, then ASSERT().
If NumberOfBytes is zero, then return 0.
@param Buffer The pointer to the data buffer to be written.
@param NumberOfBytes The number of bytes to written to the serial device.
@retval 0 NumberOfBytes is 0.
@retval >0 The number of bytes written to the serial device.
If this value is less than NumberOfBytes, then the read operation failed.
**/
UINTN
EFIAPI
SerialPortWrite (
IN UINT8 *Buffer,
IN UINTN NumberOfBytes
)
{
return gEmuThunk->WriteStdErr (Buffer, NumberOfBytes);
}
/**
Read data from serial device and save the datas in buffer.
Reads NumberOfBytes data bytes from a serial device into the buffer
specified by Buffer. The number of bytes actually read is returned.
If the return value is less than NumberOfBytes, then the rest operation failed.
If Buffer is NULL, then ASSERT().
If NumberOfBytes is zero, then return 0.
@param Buffer The pointer to the data buffer to store the data read from the serial device.
@param NumberOfBytes The number of bytes which will be read.
@retval 0 Read data failed; No data is to be read.
@retval >0 The actual number of bytes read from serial device.
**/
UINTN
EFIAPI
SerialPortRead (
OUT UINT8 *Buffer,
IN UINTN NumberOfBytes
)
{
return 0;
}
/**
Polls a serial device to see if there is any data waiting to be read.
Polls a serial device to see if there is any data waiting to be read.
If there is data waiting to be read from the serial device, then TRUE is returned.
If there is no data waiting to be read from the serial device, then FALSE is returned.
@retval TRUE Data is waiting to be read from the serial device.
@retval FALSE There is no data waiting to be read from the serial device.
**/
BOOLEAN
EFIAPI
SerialPortPoll (
VOID
)
{
return FALSE;
}

View File

@@ -0,0 +1,40 @@
## @file
# Write only instance of Serial Port Library with empty functions.
#
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = DxeEmuStdErrSerialPortLib
FILE_GUID = 4EED5138-C512-9E4F-AB13-149B87D40453
MODULE_TYPE = PEIM
VERSION_STRING = 1.0
LIBRARY_CLASS = SerialPortLib| DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER SMM_CORE UEFI_APPLICATION UEFI_DRIVE
[Sources]
DxeEmuStdErrSerialPortLib.c
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
EmuThunkLib

View File

@@ -0,0 +1,206 @@
/** @file
A non-functional instance of the Timer Library.
Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiPei.h>
#include <Library/BaseLib.h>
#include <Library/TimerLib.h>
#include <Library/DebugLib.h>
#include <Library/EmuThunkLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Protocol/Timer.h>
STATIC UINT64 gTimerPeriod = 0;
STATIC EFI_TIMER_ARCH_PROTOCOL *gTimerAp = NULL;
STATIC EFI_EVENT gTimerEvent = NULL;
STATIC VOID *gRegistration = NULL;
VOID
EFIAPI
RegisterTimerArchProtocol (
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_STATUS Status;
Status = gBS->LocateProtocol (&gEfiTimerArchProtocolGuid, NULL, (VOID **)&gTimerAp);
if (!EFI_ERROR (Status)) {
Status = gTimerAp->GetTimerPeriod (gTimerAp, &gTimerPeriod);
ASSERT_EFI_ERROR (Status);
// Convert to Nanoseconds.
gTimerPeriod = MultU64x32 (gTimerPeriod, 100);
if (gTimerEvent == NULL) {
Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, (VOID **)&gTimerEvent);
ASSERT_EFI_ERROR (Status);
}
}
}
/**
Stalls the CPU for at least the given number of microseconds.
Stalls the CPU for the number of microseconds specified by MicroSeconds.
@param MicroSeconds The minimum number of microseconds to delay.
@return The value of MicroSeconds inputted.
**/
UINTN
EFIAPI
MicroSecondDelay (
IN UINTN MicroSeconds
)
{
return NanoSecondDelay (MicroSeconds * 1000);
}
/**
Stalls the CPU for at least the given number of nanoseconds.
Stalls the CPU for the number of nanoseconds specified by NanoSeconds.
@param NanoSeconds The minimum number of nanoseconds to delay.
@return The value of NanoSeconds inputted.
**/
UINTN
EFIAPI
NanoSecondDelay (
IN UINTN NanoSeconds
)
{
EFI_STATUS Status;
UINT64 HundredNanoseconds;
UINTN Index;
if ((gTimerPeriod != 0) &&
((UINT64)NanoSeconds > gTimerPeriod) &&
(EfiGetCurrentTpl () == TPL_APPLICATION)) {
//
// This stall is long, so use gBS->WaitForEvent () to yield CPU to DXE Core
//
HundredNanoseconds = DivU64x32 (NanoSeconds, 100);
Status = gBS->SetTimer (gTimerEvent, TimerRelative, HundredNanoseconds);
ASSERT_EFI_ERROR (Status);
Status = gBS->WaitForEvent (sizeof (gTimerEvent)/sizeof (EFI_EVENT), &gTimerEvent, &Index);
ASSERT_EFI_ERROR (Status);
} else {
gEmuThunk->Sleep (NanoSeconds);
}
return NanoSeconds;
}
/**
Retrieves the current value of a 64-bit free running performance counter.
The counter can either count up by 1 or count down by 1. If the physical
performance counter counts by a larger increment, then the counter values
must be translated. The properties of the counter can be retrieved from
GetPerformanceCounterProperties().
@return The current value of the free running performance counter.
**/
UINT64
EFIAPI
GetPerformanceCounter (
VOID
)
{
return gEmuThunk->QueryPerformanceCounter ();
}
/**
Retrieves the 64-bit frequency in Hz and the range of performance counter
values.
If StartValue is not NULL, then the value that the performance counter starts
with immediately after is it rolls over is returned in StartValue. If
EndValue is not NULL, then the value that the performance counter end with
immediately before it rolls over is returned in EndValue. The 64-bit
frequency of the performance counter in Hz is always returned. If StartValue
is less than EndValue, then the performance counter counts up. If StartValue
is greater than EndValue, then the performance counter counts down. For
example, a 64-bit free running counter that counts up would have a StartValue
of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter
that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.
@param StartValue The value the performance counter starts with when it
rolls over.
@param EndValue The value that the performance counter ends with before
it rolls over.
@return The frequency in Hz.
**/
UINT64
EFIAPI
GetPerformanceCounterProperties (
OUT UINT64 *StartValue, OPTIONAL
OUT UINT64 *EndValue OPTIONAL
)
{
if (StartValue != NULL) {
*StartValue = 0ULL;
}
if (EndValue != NULL) {
*EndValue = (UINT64)-1LL;
}
return gEmuThunk->QueryPerformanceFrequency ();
}
/**
Register for the Timer AP protocol.
@param ImageHandle The firmware allocated handle for the EFI image.
@param SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
**/
EFI_STATUS
EFIAPI
DxeTimerLibConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EfiCreateProtocolNotifyEvent (
&gEfiTimerArchProtocolGuid,
TPL_CALLBACK,
RegisterTimerArchProtocol,
NULL,
&gRegistration
);
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,51 @@
## @file
# NULL instance of Timer Library as a template.
#
# A non-functional instance of the Timer Library that can be used as a template
# for the implementation of a functional timer library instance. This library instance can
# also be used to test build DXE, Runtime, DXE SAL, and DXE SMM modules that require timer
# services as well as EBC modules that require timer services.
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = EmuDxeTimerLib
FILE_GUID = 74B62391-AD0D-1B4D-8784-151404F9D538
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = TimerLib|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_DRIVER UEFI_APPLICATION
CONSTRUCTOR = DxeTimerLibConstructor
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
DxeTimerLib.c
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
BaseLib
DebugLib
EmuThunkLib
UefiLib
UefiBootServicesTableLib
[Protocols]
gEfiTimerArchProtocolGuid

View File

@@ -0,0 +1,557 @@
/*++ @file
Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "BdsPlatform.h"
EMU_SYSTEM_CONFIGURATION mSystemConfigData;
VOID
SetupVariableInit (
VOID
)
{
EFI_STATUS Status;
UINTN Size;
Size = sizeof (mSystemConfigData);
Status = gRT->GetVariable (
L"Setup",
&gEmuSystemConfigGuid,
NULL,
&Size,
(VOID *) &mSystemConfigData
);
if (EFI_ERROR (Status)) {
//
// SetupVariable is corrupt
//
mSystemConfigData.ConOutRow = PcdGet32 (PcdConOutColumn);
mSystemConfigData.ConOutColumn = PcdGet32 (PcdConOutRow);
Status = gRT->SetVariable (
L"Setup",
&gEmuSystemConfigGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof (mSystemConfigData),
(VOID *) &mSystemConfigData
);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "Failed to save Setup Variable to non-volatile storage, Status = %r\n", Status));
}
}
}
//
// BDS Platform Functions
//
VOID
EFIAPI
PlatformBdsInit (
VOID
)
/*++
Routine Description:
Platform Bds init. Include the platform firmware vendor, revision
and so crc check.
Arguments:
Returns:
None.
**/
{
SetupVariableInit ();
}
EFI_STATUS
PlatformBdsConnectConsole (
IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole
)
/*++
Routine Description:
Connect the predefined platform default console device. Always try to find
and enable the vga device if have.
Arguments:
PlatformConsole - Predfined platform default console device array.
Returns:
EFI_SUCCESS - Success connect at least one ConIn and ConOut
device, there must have one ConOut device is
active vga device.
EFI_STATUS - Return the status of
BdsLibConnectAllDefaultConsoles ()
**/
{
EFI_STATUS Status;
UINTN Index;
Index = 0;
Status = EFI_SUCCESS;
//
// Have chance to connect the platform default console,
// the platform default console is the minimue device group
// the platform should support
//
while (PlatformConsole[Index].DevicePath != NULL) {
//
// Update the console variable with the connect type
//
if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {
BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL);
}
if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {
BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL);
}
if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {
BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL);
}
Index++;
}
//
// Connect the all the default console with current cosole variable
//
Status = BdsLibConnectAllDefaultConsoles ();
return Status;
}
VOID
PlatformBdsConnectSequence (
VOID
)
/*++
Routine Description:
Connect with predeined platform connect sequence,
the OEM/IBV can customize with their own connect sequence.
Arguments:
None.
Returns:
None.
**/
{
UINTN Index;
Index = 0;
//
// Here we can get the customized platform connect sequence
// Notes: we can connect with new variable which record the
// last time boots connect device path sequence
//
while (gPlatformConnectSequence[Index] != NULL) {
//
// Build the platform boot option
//
BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);
Index++;
}
//
// Just use the simple policy to connect all devices
//
BdsLibConnectAll ();
}
VOID
PlatformBdsGetDriverOption (
IN OUT LIST_ENTRY *BdsDriverLists
)
/*++
Routine Description:
Load the predefined driver option, OEM/IBV can customize this
to load their own drivers
Arguments:
BdsDriverLists - The header of the driver option link list.
Returns:
None.
**/
{
UINTN Index;
Index = 0;
//
// Here we can get the customized platform driver option
//
while (gPlatformDriverOption[Index] != NULL) {
//
// Build the platform boot option
//
BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index], NULL, L"DriverOrder");
Index++;
}
}
VOID
PlatformBdsDiagnostics (
IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,
IN BOOLEAN QuietBoot,
IN BASEM_MEMORY_TEST BaseMemoryTest
)
/*++
Routine Description:
Perform the platform diagnostic, such like test memory. OEM/IBV also
can customize this fuction to support specific platform diagnostic.
Arguments:
MemoryTestLevel - The memory test intensive level
QuietBoot - Indicate if need to enable the quiet boot
BaseMemoryTest - A pointer to BdsMemoryTest()
Returns:
None.
**/
{
EFI_STATUS Status;
//
// Here we can decide if we need to show
// the diagnostics screen
// Notes: this quiet boot code should be remove
// from the graphic lib
//
if (QuietBoot) {
EnableQuietBoot (PcdGetPtr(PcdLogoFile));
//
// Perform system diagnostic
//
Status = BaseMemoryTest (MemoryTestLevel);
if (EFI_ERROR (Status)) {
DisableQuietBoot ();
}
return ;
}
//
// Perform system diagnostic
//
Status = BaseMemoryTest (MemoryTestLevel);
}
VOID
EFIAPI
PlatformBdsPolicyBehavior (
IN OUT LIST_ENTRY *DriverOptionList,
IN OUT LIST_ENTRY *BootOptionList,
IN PROCESS_CAPSULES ProcessCapsules,
IN BASEM_MEMORY_TEST BaseMemoryTest
)
/*++
Routine Description:
The function will excute with as the platform policy, current policy
is driven by boot mode. IBV/OEM can customize this code for their specific
policy action.
Arguments:
DriverOptionList - The header of the driver option link list
BootOptionList - The header of the boot option link list
ProcessCapsules - A pointer to ProcessCapsules()
BaseMemoryTest - A pointer to BaseMemoryTest()
Returns:
None.
**/
{
EFI_STATUS Status;
UINT16 Timeout;
EFI_BOOT_MODE BootMode;
//
// Init the time out value
//
Timeout = PcdGet16 (PcdPlatformBootTimeOut);
//
// Load the driver option as the driver option list
//
PlatformBdsGetDriverOption (DriverOptionList);
//
// Get current Boot Mode
//
Status = BdsLibGetBootMode (&BootMode);
//
// Go the different platform policy with different boot mode
// Notes: this part code can be change with the table policy
//
switch (BootMode) {
case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:
case BOOT_WITH_MINIMAL_CONFIGURATION:
//
// In no-configuration boot mode, we can connect the
// console directly.
//
BdsLibConnectAllDefaultConsoles ();
PlatformBdsDiagnostics (IGNORE, TRUE, BaseMemoryTest);
//
// Perform some platform specific connect sequence
//
PlatformBdsConnectSequence ();
//
// Notes: current time out = 0 can not enter the
// front page
//
PlatformBdsEnterFrontPage (Timeout, FALSE);
//
// Check the boot option with the boot option list
//
BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");
break;
case BOOT_ON_FLASH_UPDATE:
//
// Boot with the specific configuration
//
PlatformBdsConnectConsole (gPlatformConsole);
PlatformBdsDiagnostics (EXTENSIVE, FALSE, BaseMemoryTest);
BdsLibConnectAll ();
ProcessCapsules (BOOT_ON_FLASH_UPDATE);
break;
case BOOT_IN_RECOVERY_MODE:
//
// In recovery mode, just connect platform console
// and show up the front page
//
PlatformBdsConnectConsole (gPlatformConsole);
PlatformBdsDiagnostics (EXTENSIVE, FALSE, BaseMemoryTest);
//
// In recovery boot mode, we still enter to the
// frong page now
//
PlatformBdsEnterFrontPage (Timeout, FALSE);
break;
case BOOT_WITH_FULL_CONFIGURATION:
case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:
case BOOT_WITH_DEFAULT_SETTINGS:
default:
//
// Connect platform console
//
Status = PlatformBdsConnectConsole (gPlatformConsole);
if (EFI_ERROR (Status)) {
//
// Here OEM/IBV can customize with defined action
//
PlatformBdsNoConsoleAction ();
}
PlatformBdsDiagnostics (IGNORE, TRUE, BaseMemoryTest);
//
// Perform some platform specific connect sequence
//
PlatformBdsConnectSequence ();
//
// Give one chance to enter the setup if we
// have the time out
//
PlatformBdsEnterFrontPage (Timeout, FALSE);
//
// Here we have enough time to do the enumeration of boot device
//
BdsLibEnumerateAllBootOption (BootOptionList);
break;
}
return ;
}
VOID
EFIAPI
PlatformBdsBootSuccess (
IN BDS_COMMON_OPTION *Option
)
/*++
Routine Description:
Hook point after a boot attempt succeeds. We don't expect a boot option to
return, so the EFI 1.0 specification defines that you will default to an
interactive mode and stop processing the BootOrder list in this case. This
is alos a platform implementation and can be customized by IBV/OEM.
Arguments:
Option - Pointer to Boot Option that succeeded to boot.
Returns:
None.
**/
{
CHAR16 *TmpStr;
//
// If Boot returned with EFI_SUCCESS and there is not in the boot device
// select loop then we need to pop up a UI and wait for user input.
//
TmpStr = Option->StatusString;
if (TmpStr != NULL) {
BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);
FreePool (TmpStr);
}
}
VOID
EFIAPI
PlatformBdsBootFail (
IN BDS_COMMON_OPTION *Option,
IN EFI_STATUS Status,
IN CHAR16 *ExitData,
IN UINTN ExitDataSize
)
/*++
Routine Description:
Hook point after a boot attempt fails.
Arguments:
Option - Pointer to Boot Option that failed to boot.
Status - Status returned from failed boot.
ExitData - Exit data returned from failed boot.
ExitDataSize - Exit data size returned from failed boot.
Returns:
None.
**/
{
CHAR16 *TmpStr;
//
// If Boot returned with failed status then we need to pop up a UI and wait
// for user input.
//
TmpStr = Option->StatusString;
if (TmpStr != NULL) {
BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);
FreePool (TmpStr);
}
}
EFI_STATUS
PlatformBdsNoConsoleAction (
VOID
)
/*++
Routine Description:
This function is remained for IBV/OEM to do some platform action,
if there no console device can be connected.
Arguments:
None.
Returns:
EFI_SUCCESS - Direct return success now.
**/
{
return EFI_SUCCESS;
}
VOID
EFIAPI
PlatformBdsLockNonUpdatableFlash (
VOID
)
{
return;
}
/**
Lock the ConsoleIn device in system table. All key
presses will be ignored until the Password is typed in. The only way to
disable the password is to type it in to a ConIn device.
@param Password Password used to lock ConIn device.
@retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.
@retval EFI_UNSUPPORTED Password not found
**/
EFI_STATUS
EFIAPI
LockKeyboards (
IN CHAR16 *Password
)
{
return EFI_UNSUPPORTED;
}

View File

@@ -0,0 +1,97 @@
/*++ @file
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _BDS_PLATFORM_H
#define _BDS_PLATFORM_H
#include <PiDxe.h>
#include <Guid/EmuSystemConfig.h>
#include <Protocol/EmuThunk.h>
#include <Protocol/EmuIoThunk.h>
#include <Protocol/EmuGraphicsWindow.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/BaseLib.h>
#include <Library/PcdLib.h>
#include <Library/GenericBdsLib.h>
#include <Library/PlatformBdsLib.h>
#include <Library/DevicePathLib.h>
extern BDS_CONSOLE_CONNECT_ENTRY gPlatformConsole[];
extern EFI_DEVICE_PATH_PROTOCOL *gPlatformConnectSequence[];
extern EFI_DEVICE_PATH_PROTOCOL *gPlatformDriverOption[];
#define gEndEntire \
{ \
END_DEVICE_PATH_TYPE,\
END_ENTIRE_DEVICE_PATH_SUBTYPE,\
END_DEVICE_PATH_LENGTH,\
0\
}
typedef struct {
EMU_VENDOR_DEVICE_PATH_NODE EmuBus;
EMU_VENDOR_DEVICE_PATH_NODE EmuGraphicsWindow;
EFI_DEVICE_PATH_PROTOCOL End;
} EMU_PLATFORM_UGA_DEVICE_PATH;
//
// Platform BDS Functions
//
VOID
PlatformBdsGetDriverOption (
IN LIST_ENTRY *BdsDriverLists
);
EFI_STATUS
BdsMemoryTest (
EXTENDMEM_COVERAGE_LEVEL Level
);
VOID
PlatformBdsConnectSequence (
VOID
);
EFI_STATUS
ProcessCapsules (
EFI_BOOT_MODE BootMode
);
EFI_STATUS
PlatformBdsConnectConsole (
IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole
);
EFI_STATUS
PlatformBdsNoConsoleAction (
VOID
);
VOID
PlatformBdsEnterFrontPage (
IN UINT16 TimeoutDefault,
IN BOOLEAN ConnectAllHappened
);
#endif // _BDS_PLATFORM_H

View File

@@ -0,0 +1,66 @@
## @file
# Platfrom BDS driver
#
# Do platform action customized by IBV/OEM.
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = EmuBdsLib
FILE_GUID = 59569181-CBF8-2E44-9C3E-C2AB2F5608E1
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = PlatformBdsLib|DXE_DRIVER
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
BdsPlatform.c
PlatformData.c
BdsPlatform.h
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
EmulatorPkg/EmulatorPkg.dec
IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
[LibraryClasses]
BaseLib
MemoryAllocationLib
UefiBootServicesTableLib
UefiRuntimeServicesTableLib
BaseMemoryLib
DebugLib
PcdLib
GenericBdsLib
DevicePathLib
[Guids]
gEmuSystemConfigGuid
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn
gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPlatformBootTimeOut
gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile
[Depex]
gEfiVariableArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid

View File

@@ -0,0 +1,69 @@
/*++ @file
Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "BdsPlatform.h"
EMU_PLATFORM_UGA_DEVICE_PATH gGopDevicePath = {
{
{
{
HARDWARE_DEVICE_PATH,
HW_VENDOR_DP,
{
(UINT8) (sizeof (EMU_VENDOR_DEVICE_PATH_NODE)),
(UINT8) ((sizeof (EMU_VENDOR_DEVICE_PATH_NODE)) >> 8)
}
},
EMU_THUNK_PROTOCOL_GUID
},
0
},
{
HARDWARE_DEVICE_PATH,
HW_VENDOR_DP,
{
(UINT8) (sizeof (EMU_VENDOR_DEVICE_PATH_NODE)),
(UINT8) ((sizeof (EMU_VENDOR_DEVICE_PATH_NODE)) >> 8)
},
EMU_GRAPHICS_WINDOW_PROTOCOL_GUID,
0
},
gEndEntire
};
//
// Predefined platform default console device path
//
BDS_CONSOLE_CONNECT_ENTRY gPlatformConsole[] = {
{
(EFI_DEVICE_PATH_PROTOCOL *) &gGopDevicePath,
(CONSOLE_OUT | CONSOLE_IN)
},
{
NULL,
0
}
};
//
// Predefined platform specific driver option
//
EFI_DEVICE_PATH_PROTOCOL *gPlatformDriverOption[] = { NULL };
//
// Predefined platform connect sequence
//
EFI_DEVICE_PATH_PROTOCOL *gPlatformConnectSequence[] = { NULL };

View File

@@ -0,0 +1,42 @@
## @file
# Instance of Memory Allocation Library using EFI Boot Services.
#
# Memory Allocation Library that uses EFI Boot Services to allocate
# and free memory. Calls OS malloc to enable OS based debug tools
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = GuardUefiMemoryAllocationLib
FILE_GUID = DB290230-3EFA-064F-A317-E146925684FE
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = MemoryAllocationLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER DXE_CORE
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
MemoryAllocationLib.c
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
DebugLib
BaseMemoryLib
UefiBootServicesTableLib
EmuThunkLib

View File

@@ -0,0 +1,819 @@
/** @file
Support routines for memory allocation routines based
on boot services for Dxe phase drivers using OS malloc.
OS malloc is used so OS based malloc debugging tools can be used.
If a single driver links against this lib protocols from other
drivers, or EFI boot services can return a buffer that needs to
freed using the EFI scheme. This is why the gEmuThunk->Free ()
can detect if the memory rang is for EFI so the right free can be
called.
Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Uefi.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/EmuThunkLib.h>
/**
Allocates one or more 4KB pages of a certain memory type.
Allocates the number of 4KB pages of a certain memory type and returns a pointer to the allocated
buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL is returned.
If there is not enough memory remaining to satisfy the request, then NULL is returned.
@param MemoryType The type of memory to allocate.
@param Pages The number of 4 KB pages to allocate.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
InternalAllocatePages (
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN Pages
)
{
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS Memory;
if (Pages == 0) {
return NULL;
}
return gEmuThunk->Valloc (Pages * EFI_PAGE_SIZE);
}
/**
Allocates one or more 4KB pages of type EfiBootServicesData.
Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the
allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
is returned. If there is not enough memory remaining to satisfy the request, then NULL is
returned.
@param Pages The number of 4 KB pages to allocate.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
AllocatePages (
IN UINTN Pages
)
{
return InternalAllocatePages (EfiBootServicesData, Pages);
}
/**
Allocates one or more 4KB pages of type EfiRuntimeServicesData.
Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
is returned. If there is not enough memory remaining to satisfy the request, then NULL is
returned.
@param Pages The number of 4 KB pages to allocate.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
AllocateRuntimePages (
IN UINTN Pages
)
{
return InternalAllocatePages (EfiRuntimeServicesData, Pages);
}
/**
Allocates one or more 4KB pages of type EfiReservedMemoryType.
Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the
allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
is returned. If there is not enough memory remaining to satisfy the request, then NULL is
returned.
@param Pages The number of 4 KB pages to allocate.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
AllocateReservedPages (
IN UINTN Pages
)
{
return InternalAllocatePages (EfiReservedMemoryType, Pages);
}
/**
Frees one or more 4KB pages that were previously allocated with one of the page allocation
functions in the Memory Allocation Library.
Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
must have been allocated on a previous call to the page allocation services of the Memory
Allocation Library. If it is not possible to free allocated pages, then this function will
perform no actions.
If Buffer was not allocated with a page allocation function in the Memory Allocation Library,
then ASSERT().
If Pages is zero, then ASSERT().
@param Buffer The pointer to the buffer of pages to free.
@param Pages The number of 4 KB pages to free.
**/
VOID
EFIAPI
FreePages (
IN VOID *Buffer,
IN UINTN Pages
)
{
EFI_STATUS Status;
ASSERT (Pages != 0);
if (!gEmuThunk->Free (Buffer)) {
// The Free thunk will not free memory allocated in emulated EFI memory.
// The assmuption is this was allocated directly by EFI. We need this as some
// times protocols or EFI BootServices can return dynamically allocated buffers.
Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);
ASSERT_EFI_ERROR (Status);
}
}
/**
Allocates one or more 4KB pages of a certain memory type at a specified alignment.
Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment
specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned.
If there is not enough memory at the specified alignment remaining to satisfy the request, then
NULL is returned.
If Alignment is not a power of two and Alignment is not zero, then ASSERT().
@param MemoryType The type of memory to allocate.
@param Pages The number of 4 KB pages to allocate.
@param Alignment The requested alignment of the allocation. Must be a power of two.
If Alignment is zero, then byte alignment is used.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
InternalAllocateAlignedPages (
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN Pages,
IN UINTN Alignment
)
{
EFI_STATUS Status;
VOID *Memory;
UINTN AlignedMemory;
UINTN AlignmentMask;
UINTN UnalignedPages;
UINTN RealPages;
//
// Alignment must be a power of two or zero.
//
ASSERT ((Alignment & (Alignment - 1)) == 0);
if (Pages == 0) {
return NULL;
}
if (Alignment > EFI_PAGE_SIZE) {
//
// Caculate the total number of pages since alignment is larger than page size.
//
AlignmentMask = Alignment - 1;
RealPages = Pages + EFI_SIZE_TO_PAGES (Alignment);
//
// Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
//
ASSERT (RealPages > Pages);
Memory = gEmuThunk->Valloc (Pages * EFI_PAGE_SIZE);
if (Memory != NULL) {
return NULL;
}
AlignedMemory = ((UINTN) Memory + AlignmentMask) & ~AlignmentMask;
UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN) Memory);
if (UnalignedPages > 0) {
//
// Free first unaligned page(s).
//
FreePages (Memory, UnalignedPages);
}
Memory = (VOID *) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
UnalignedPages = RealPages - Pages - UnalignedPages;
if (UnalignedPages > 0) {
//
// Free last unaligned page(s).
//
FreePages (Memory, UnalignedPages);
}
} else {
//
// Do not over-allocate pages in this case.
//
Memory = gEmuThunk->Valloc (Pages * EFI_PAGE_SIZE);
if (Memory != NULL) {
return NULL;
}
AlignedMemory = (UINTN) Memory;
}
return (VOID *) AlignedMemory;
}
/**
Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
returned. If there is not enough memory at the specified alignment remaining to satisfy the
request, then NULL is returned.
If Alignment is not a power of two and Alignment is not zero, then ASSERT().
@param Pages The number of 4 KB pages to allocate.
@param Alignment The requested alignment of the allocation. Must be a power of two.
If Alignment is zero, then byte alignment is used.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
AllocateAlignedPages (
IN UINTN Pages,
IN UINTN Alignment
)
{
return InternalAllocateAlignedPages (EfiBootServicesData, Pages, Alignment);
}
/**
Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.
Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an
alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
returned. If there is not enough memory at the specified alignment remaining to satisfy the
request, then NULL is returned.
If Alignment is not a power of two and Alignment is not zero, then ASSERT().
@param Pages The number of 4 KB pages to allocate.
@param Alignment The requested alignment of the allocation. Must be a power of two.
If Alignment is zero, then byte alignment is used.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
AllocateAlignedRuntimePages (
IN UINTN Pages,
IN UINTN Alignment
)
{
return InternalAllocateAlignedPages (EfiRuntimeServicesData, Pages, Alignment);
}
/**
Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.
Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an
alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
returned. If there is not enough memory at the specified alignment remaining to satisfy the
request, then NULL is returned.
If Alignment is not a power of two and Alignment is not zero, then ASSERT().
@param Pages The number of 4 KB pages to allocate.
@param Alignment The requested alignment of the allocation. Must be a power of two.
If Alignment is zero, then byte alignment is used.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
AllocateAlignedReservedPages (
IN UINTN Pages,
IN UINTN Alignment
)
{
return InternalAllocateAlignedPages (EfiReservedMemoryType, Pages, Alignment);
}
/**
Frees one or more 4KB pages that were previously allocated with one of the aligned page
allocation functions in the Memory Allocation Library.
Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
must have been allocated on a previous call to the aligned page allocation services of the Memory
Allocation Library. If it is not possible to free allocated pages, then this function will
perform no actions.
If Buffer was not allocated with an aligned page allocation function in the Memory Allocation
Library, then ASSERT().
If Pages is zero, then ASSERT().
@param Buffer The pointer to the buffer of pages to free.
@param Pages The number of 4 KB pages to free.
**/
VOID
EFIAPI
FreeAlignedPages (
IN VOID *Buffer,
IN UINTN Pages
)
{
FreePages (Buffer, Pages);
}
/**
Allocates a buffer of a certain pool type.
Allocates the number bytes specified by AllocationSize of a certain pool type and returns a
pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
@param MemoryType The type of memory to allocate.
@param AllocationSize The number of bytes to allocate.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
InternalAllocatePool (
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN AllocationSize
)
{
return gEmuThunk->Malloc (AllocationSize);
}
/**
Allocates a buffer of type EfiBootServicesData.
Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
@param AllocationSize The number of bytes to allocate.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
AllocatePool (
IN UINTN AllocationSize
)
{
return InternalAllocatePool (EfiBootServicesData, AllocationSize);
}
/**
Allocates a buffer of type EfiRuntimeServicesData.
Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns
a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
@param AllocationSize The number of bytes to allocate.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
AllocateRuntimePool (
IN UINTN AllocationSize
)
{
return InternalAllocatePool (EfiRuntimeServicesData, AllocationSize);
}
/**
Allocates a buffer of type EfiReservedMemoryType.
Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType and returns
a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
@param AllocationSize The number of bytes to allocate.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
AllocateReservedPool (
IN UINTN AllocationSize
)
{
return InternalAllocatePool (EfiReservedMemoryType, AllocationSize);
}
/**
Allocates and zeros a buffer of a certain pool type.
Allocates the number bytes specified by AllocationSize of a certain pool type, clears the buffer
with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid
buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request,
then NULL is returned.
@param PoolType The type of memory to allocate.
@param AllocationSize The number of bytes to allocate and zero.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
InternalAllocateZeroPool (
IN EFI_MEMORY_TYPE PoolType,
IN UINTN AllocationSize
)
{
VOID *Memory;
Memory = InternalAllocatePool (PoolType, AllocationSize);
if (Memory != NULL) {
Memory = ZeroMem (Memory, AllocationSize);
}
return Memory;
}
/**
Allocates and zeros a buffer of type EfiBootServicesData.
Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
request, then NULL is returned.
@param AllocationSize The number of bytes to allocate and zero.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
AllocateZeroPool (
IN UINTN AllocationSize
)
{
return InternalAllocateZeroPool (EfiBootServicesData, AllocationSize);
}
/**
Allocates and zeros a buffer of type EfiRuntimeServicesData.
Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the
buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
request, then NULL is returned.
@param AllocationSize The number of bytes to allocate and zero.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
AllocateRuntimeZeroPool (
IN UINTN AllocationSize
)
{
return InternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);
}
/**
Allocates and zeros a buffer of type EfiReservedMemoryType.
Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the
buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
request, then NULL is returned.
@param AllocationSize The number of bytes to allocate and zero.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
AllocateReservedZeroPool (
IN UINTN AllocationSize
)
{
return InternalAllocateZeroPool (EfiReservedMemoryType, AllocationSize);
}
/**
Copies a buffer to an allocated buffer of a certain pool type.
Allocates the number bytes specified by AllocationSize of a certain pool type, copies
AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
is not enough memory remaining to satisfy the request, then NULL is returned.
If Buffer is NULL, then ASSERT().
If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
@param PoolType The type of pool to allocate.
@param AllocationSize The number of bytes to allocate and zero.
@param Buffer The buffer to copy to the allocated buffer.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
InternalAllocateCopyPool (
IN EFI_MEMORY_TYPE PoolType,
IN UINTN AllocationSize,
IN CONST VOID *Buffer
)
{
VOID *Memory;
ASSERT (Buffer != NULL);
ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));
Memory = InternalAllocatePool (PoolType, AllocationSize);
if (Memory != NULL) {
Memory = CopyMem (Memory, Buffer, AllocationSize);
}
return Memory;
}
/**
Copies a buffer to an allocated buffer of type EfiBootServicesData.
Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies
AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
is not enough memory remaining to satisfy the request, then NULL is returned.
If Buffer is NULL, then ASSERT().
If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
@param AllocationSize The number of bytes to allocate and zero.
@param Buffer The buffer to copy to the allocated buffer.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
AllocateCopyPool (
IN UINTN AllocationSize,
IN CONST VOID *Buffer
)
{
return InternalAllocateCopyPool (EfiBootServicesData, AllocationSize, Buffer);
}
/**
Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.
Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies
AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
is not enough memory remaining to satisfy the request, then NULL is returned.
If Buffer is NULL, then ASSERT().
If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
@param AllocationSize The number of bytes to allocate and zero.
@param Buffer The buffer to copy to the allocated buffer.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
AllocateRuntimeCopyPool (
IN UINTN AllocationSize,
IN CONST VOID *Buffer
)
{
return InternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer);
}
/**
Copies a buffer to an allocated buffer of type EfiReservedMemoryType.
Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies
AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
is not enough memory remaining to satisfy the request, then NULL is returned.
If Buffer is NULL, then ASSERT().
If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
@param AllocationSize The number of bytes to allocate and zero.
@param Buffer The buffer to copy to the allocated buffer.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
AllocateReservedCopyPool (
IN UINTN AllocationSize,
IN CONST VOID *Buffer
)
{
return InternalAllocateCopyPool (EfiReservedMemoryType, AllocationSize, Buffer);
}
/**
Reallocates a buffer of a specified memory type.
Allocates and zeros the number bytes specified by NewSize from memory of the type
specified by PoolType. If OldBuffer is not NULL, then the smaller of OldSize and
NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
OldBuffer is freed. A pointer to the newly allocated buffer is returned.
If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
enough memory remaining to satisfy the request, then NULL is returned.
If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
@param PoolType The type of pool to allocate.
@param OldSize The size, in bytes, of OldBuffer.
@param NewSize The size, in bytes, of the buffer to reallocate.
@param OldBuffer The buffer to copy to the allocated buffer. This is an optional
parameter that may be NULL.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
InternalReallocatePool (
IN EFI_MEMORY_TYPE PoolType,
IN UINTN OldSize,
IN UINTN NewSize,
IN VOID *OldBuffer OPTIONAL
)
{
VOID *NewBuffer;
NewBuffer = InternalAllocateZeroPool (PoolType, NewSize);
if (NewBuffer != NULL && OldBuffer != NULL) {
CopyMem (NewBuffer, OldBuffer, MIN (OldSize, NewSize));
FreePool (OldBuffer);
}
return NewBuffer;
}
/**
Reallocates a buffer of type EfiBootServicesData.
Allocates and zeros the number bytes specified by NewSize from memory of type
EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
OldBuffer is freed. A pointer to the newly allocated buffer is returned.
If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
enough memory remaining to satisfy the request, then NULL is returned.
If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
@param OldSize The size, in bytes, of OldBuffer.
@param NewSize The size, in bytes, of the buffer to reallocate.
@param OldBuffer The buffer to copy to the allocated buffer. This is an optional
parameter that may be NULL.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
ReallocatePool (
IN UINTN OldSize,
IN UINTN NewSize,
IN VOID *OldBuffer OPTIONAL
)
{
return InternalReallocatePool (EfiBootServicesData, OldSize, NewSize, OldBuffer);
}
/**
Reallocates a buffer of type EfiRuntimeServicesData.
Allocates and zeros the number bytes specified by NewSize from memory of type
EfiRuntimeServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
OldBuffer is freed. A pointer to the newly allocated buffer is returned.
If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
enough memory remaining to satisfy the request, then NULL is returned.
If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
@param OldSize The size, in bytes, of OldBuffer.
@param NewSize The size, in bytes, of the buffer to reallocate.
@param OldBuffer The buffer to copy to the allocated buffer. This is an optional
parameter that may be NULL.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
ReallocateRuntimePool (
IN UINTN OldSize,
IN UINTN NewSize,
IN VOID *OldBuffer OPTIONAL
)
{
return InternalReallocatePool (EfiRuntimeServicesData, OldSize, NewSize, OldBuffer);
}
/**
Reallocates a buffer of type EfiReservedMemoryType.
Allocates and zeros the number bytes specified by NewSize from memory of type
EfiReservedMemoryType. If OldBuffer is not NULL, then the smaller of OldSize and
NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
OldBuffer is freed. A pointer to the newly allocated buffer is returned.
If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
enough memory remaining to satisfy the request, then NULL is returned.
If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
@param OldSize The size, in bytes, of OldBuffer.
@param NewSize The size, in bytes, of the buffer to reallocate.
@param OldBuffer The buffer to copy to the allocated buffer. This is an optional
parameter that may be NULL.
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
ReallocateReservedPool (
IN UINTN OldSize,
IN UINTN NewSize,
IN VOID *OldBuffer OPTIONAL
)
{
return InternalReallocatePool (EfiReservedMemoryType, OldSize, NewSize, OldBuffer);
}
/**
Frees a buffer that was previously allocated with one of the pool allocation functions in the
Memory Allocation Library.
Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
pool allocation services of the Memory Allocation Library. If it is not possible to free pool
resources, then this function will perform no actions.
If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
then ASSERT().
@param Buffer The pointer to the buffer to free.
**/
VOID
EFIAPI
FreePool (
IN VOID *Buffer
)
{
EFI_STATUS Status;
if (!gEmuThunk->Free (Buffer)) {
// The Free thunk will not free memory allocated in emulated EFI memory.
// The assmuption is this was allocated directly by EFI. We need this as some
// times protocols or EFI BootServices can return dynamically allocated buffers.
Status = gBS->FreePool (Buffer);
ASSERT_EFI_ERROR (Status);
}
}

View File

@@ -0,0 +1,50 @@
/*++ @file
Copyright (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Uefi.h>
#include <Protocol/SimpleTextInEx.h>
/**
KeyMapMake gets called on key presses.
@param KeyData Key that was pressed.
@retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
**/
EFI_STATUS
EFIAPI
KeyMapMake (
IN EFI_KEY_DATA *KeyData
)
{
return EFI_SUCCESS;
}
/**
KeyMapBreak gets called on key releases.
@param KeyData Key that was pressed.
@retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
**/
EFI_STATUS
EFIAPI
KeyMapBreak (
IN EFI_KEY_DATA *KeyData
)
{
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,39 @@
## @file
# A library to produce the global variable 'gEmuThunk'
#
# This library contains a single global variable 'gEmuThunk' along with a constructor to
# initialize that global.
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = KeyMapLibNull
FILE_GUID = 6B7067C7-A843-A34C-9530-48446963B740
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = KeyMapLib
[Sources]
KeyMapLibNull.c
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
HobLib
DebugLib

View File

@@ -0,0 +1,41 @@
## @file
# Instance of PEI Services Table Pointer Library using global variable for the table pointer.
#
# PEI Services Table Pointer Library implementation that retrieves a pointer to the
# PEI Services Table from a global variable. Not available to modules that execute from
# read-only memory.
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = EmulatorPkgPeiCoreServicesTablePointerLib
FILE_GUID = E9A22529-44FA-3E4A-A66B-1E918E7AB26A
MODULE_TYPE = PEIM
VERSION_STRING = 1.0
LIBRARY_CLASS = PeiServicesTablePointerLib|PEI_CORE
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC (EBC is for build only)
#
[Sources]
PeiServicesTablePointer.c
[Packages]
MdePkg/MdePkg.dec
[LibraryClasses]
DebugLib

View File

@@ -0,0 +1,91 @@
/** @file
PEI Services Table Pointer Library.
This library is used for PEIM which does executed from flash device directly but
executed in memory.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiPei.h>
#include <Library/PeiServicesTablePointerLib.h>
#include <Library/DebugLib.h>
CONST EFI_PEI_SERVICES **gPeiServices;
/**
Caches a pointer PEI Services Table.
Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer
in a CPU specific manner as specified in the CPU binding section of the Platform Initialization
Pre-EFI Initialization Core Interface Specification.
If PeiServicesTablePointer is NULL, then ASSERT().
@param PeiServicesTablePointer The address of PeiServices pointer.
**/
VOID
EFIAPI
SetPeiServicesTablePointer (
IN CONST EFI_PEI_SERVICES ** PeiServicesTablePointer
)
{
ASSERT (PeiServicesTablePointer != NULL);
gPeiServices = PeiServicesTablePointer;
}
/**
Retrieves the cached value of the PEI Services Table pointer.
Returns the cached value of the PEI Services Table pointer in a CPU specific manner
as specified in the CPU binding section of the Platform Initialization Pre-EFI
Initialization Core Interface Specification.
If the cached PEI Services Table pointer is NULL, then ASSERT().
@return The pointer to PeiServices.
**/
CONST EFI_PEI_SERVICES **
EFIAPI
GetPeiServicesTablePointer (
VOID
)
{
ASSERT (gPeiServices != NULL);
return gPeiServices;
}
/**
The constructor function caches the pointer to PEI services.
The constructor function caches the pointer to PEI services.
It will always return EFI_SUCCESS.
@param FileHandle The handle of FFS header the loaded driver.
@param PeiServices The pointer to the PEI services.
@retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
**/
EFI_STATUS
EFIAPI
PeiServicesTablePointerLibConstructor (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
{
gPeiServices = PeiServices;
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,107 @@
/** @file
Provides services to perform additional actions to relocate and unload
PE/Coff image for Emu environment specific purpose such as souce level debug.
This version only works for PEI phase
Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiPei.h>
#include <Ppi/EmuThunk.h>
#include <Protocol/EmuThunk.h>
#include <Library/PeCoffLib.h>
#include <Library/PeiServicesLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseLib.h>
#include <Library/PeCoffExtraActionLib.h>
#include <Library/EmuMagicPageLib.h>
//
// Cache of UnixThunk protocol
//
EMU_THUNK_PROTOCOL *mThunk = NULL;
/**
The function caches the pointer of the Unix thunk functions
It will ASSERT() if Unix thunk ppi is not installed.
@retval EFI_SUCCESS WinNT thunk protocol is found and cached.
**/
EFI_STATUS
EFIAPI
EmuPeCoffGetThunkStucture (
)
{
EMU_THUNK_PPI *ThunkPpi;
EFI_STATUS Status;
//
// Locate Unix ThunkPpi for retrieving standard output handle
//
Status = PeiServicesLocatePpi (
&gEmuThunkPpiGuid,
0,
NULL,
(VOID **) &ThunkPpi
);
ASSERT_EFI_ERROR (Status);
EMU_MAGIC_PAGE()->Thunk = (EMU_THUNK_PROTOCOL *) ThunkPpi->Thunk ();
return EFI_SUCCESS;
}
/**
Performs additional actions after a PE/COFF image has been loaded and relocated.
If ImageContext is NULL, then ASSERT().
@param ImageContext Pointer to the image context structure that describes the
PE/COFF image that has already been loaded and relocated.
**/
VOID
EFIAPI
PeCoffLoaderRelocateImageExtraAction (
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
)
{
if (EMU_MAGIC_PAGE()->Thunk == NULL) {
EmuPeCoffGetThunkStucture ();
}
EMU_MAGIC_PAGE()->Thunk->PeCoffRelocateImageExtraAction (ImageContext);
}
/**
Performs additional actions just before a PE/COFF image is unloaded. Any resources
that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
If ImageContext is NULL, then ASSERT().
@param ImageContext Pointer to the image context structure that describes the
PE/COFF image that is being unloaded.
**/
VOID
EFIAPI
PeCoffLoaderUnloadImageExtraAction (
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
)
{
if (EMU_MAGIC_PAGE()->Thunk == NULL) {
EmuPeCoffGetThunkStucture ();
}
EMU_MAGIC_PAGE()->Thunk->PeCoffUnloadImageExtraAction (ImageContext);
}

View File

@@ -0,0 +1,49 @@
## @file
# PeCoff extra action libary for Pei phase that run Emu emulator.
#
# Lib to provide memory journal status code reporting Routines
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = PeiEmuPeCoffExtraActionLib
FILE_GUID = 79C4E72A-730B-F040-8129-95877B3A97A8
MODULE_TYPE = PEIM
VERSION_STRING = 1.0
LIBRARY_CLASS = PeCoffExtraActionLib|PEI_CORE PEIM
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32
#
[Sources]
PeiEmuPeCoffExtraActionLib.c
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
BaseLib
PeiServicesLib
DebugLib
[Ppis]
gEmuThunkPpiGuid # PPI ALWAYS_CONSUMED
[Pcd]
gEmulatorPkgTokenSpaceGuid.PcdPeiServicesTablePage

View File

@@ -0,0 +1,297 @@
/*++ @file
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "PiPei.h"
#include <Library/PeCoffGetEntryPointLib.h>
#include <Library/PeiServicesLib.h>
#include <IndustryStandard/PeImage.h>
#include <Library/DebugLib.h>
#include <Ppi/EmuThunk.h>
#include <Protocol/EmuThunk.h>
/**
Retrieves and returns a pointer to the entry point to a PE/COFF image that has been loaded
into system memory with the PE/COFF Loader Library functions.
Retrieves the entry point to the PE/COFF image specified by Pe32Data and returns this entry
point in EntryPoint. If the entry point could not be retrieved from the PE/COFF image, then
return RETURN_INVALID_PARAMETER. Otherwise return RETURN_SUCCESS.
If Pe32Data is NULL, then ASSERT().
If EntryPoint is NULL, then ASSERT().
@param Pe32Data The pointer to the PE/COFF image that is loaded in system memory.
@param EntryPoint The pointer to entry point to the PE/COFF image to return.
@retval RETURN_SUCCESS EntryPoint was returned.
@retval RETURN_INVALID_PARAMETER The entry point could not be found in the PE/COFF image.
**/
RETURN_STATUS
EFIAPI
PeCoffLoaderGetEntryPoint (
IN VOID *Pe32Data,
IN OUT VOID **EntryPoint
)
{
EMU_THUNK_PPI *ThunkPpi;
EFI_STATUS Status;
EMU_THUNK_PROTOCOL *Thunk;
//
// Locate EmuThunkPpi for retrieving standard output handle
//
Status = PeiServicesLocatePpi (
&gEmuThunkPpiGuid,
0,
NULL,
(VOID **) &ThunkPpi
);
ASSERT_EFI_ERROR (Status);
Thunk = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();
return Thunk->PeCoffGetEntryPoint (Pe32Data, EntryPoint);
}
/**
Returns the machine type of PE/COFF image.
This is copied from MDE BasePeCoffGetEntryPointLib, the code should be sync with it.
The reason is Emu package needs to load the image to memory to support source
level debug.
@param Pe32Data Pointer to a PE/COFF header
@return Machine type or zero if not a valid iamge
**/
UINT16
EFIAPI
PeCoffLoaderGetMachineType (
IN VOID *Pe32Data
)
{
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
EFI_IMAGE_DOS_HEADER *DosHdr;
ASSERT (Pe32Data != NULL);
DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));
} else {
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)(Pe32Data);
}
if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
return Hdr.Te->Machine;
} else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
return Hdr.Pe32->FileHeader.Machine;
}
return 0x0000;
}
/**
Returns a pointer to the PDB file name for a PE/COFF image that has been
loaded into system memory with the PE/COFF Loader Library functions.
Returns the PDB file name for the PE/COFF image specified by Pe32Data. If
the PE/COFF image specified by Pe32Data is not a valid, then NULL is
returned. If the PE/COFF image specified by Pe32Data does not contain a
debug directory entry, then NULL is returned. If the debug directory entry
in the PE/COFF image specified by Pe32Data does not contain a PDB file name,
then NULL is returned.
If Pe32Data is NULL, then ASSERT().
@param Pe32Data Pointer to the PE/COFF image that is loaded in system
memory.
@return The PDB file name for the PE/COFF image specified by Pe32Data or NULL
if it cannot be retrieved.
**/
VOID *
EFIAPI
PeCoffLoaderGetPdbPointer (
IN VOID *Pe32Data
)
{
EFI_IMAGE_DOS_HEADER *DosHdr;
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry;
EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry;
UINTN DirCount;
VOID *CodeViewEntryPointer;
INTN TEImageAdjust;
UINT32 NumberOfRvaAndSizes;
UINT16 Magic;
ASSERT (Pe32Data != NULL);
TEImageAdjust = 0;
DirectoryEntry = NULL;
DebugEntry = NULL;
NumberOfRvaAndSizes = 0;
DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
//
// DOS image header is present, so read the PE header after the DOS image header.
//
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));
} else {
//
// DOS image header is not present, so PE header is at the image base.
//
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;
}
if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
if (Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress != 0) {
DirectoryEntry = &Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG];
TEImageAdjust = sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize;
DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN) Hdr.Te +
Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +
TEImageAdjust);
}
} else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
//
// NOTE: We use Machine field to identify PE32/PE32+, instead of Magic.
// It is due to backward-compatibility, for some system might
// generate PE32+ image with PE32 Magic.
//
switch (Hdr.Pe32->FileHeader.Machine) {
case EFI_IMAGE_MACHINE_IA32:
//
// Assume PE32 image with IA32 Machine field.
//
Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;
break;
case EFI_IMAGE_MACHINE_X64:
case EFI_IMAGE_MACHINE_IA64:
//
// Assume PE32+ image with X64 or IA64 Machine field
//
Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;
break;
default:
//
// For unknow Machine field, use Magic in optional Header
//
Magic = Hdr.Pe32->OptionalHeader.Magic;
}
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
//
// Use PE32 offset get Debug Directory Entry
//
NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);
} else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
//
// Use PE32+ offset get Debug Directory Entry
//
NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);
}
if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {
DirectoryEntry = NULL;
DebugEntry = NULL;
}
} else {
return NULL;
}
if (DebugEntry == NULL || DirectoryEntry == NULL) {
return NULL;
}
for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY), DebugEntry++) {
if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {
if (DebugEntry->SizeOfData > 0) {
CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + ((UINTN)Pe32Data) + (UINTN)TEImageAdjust);
switch (* (UINT32 *) CodeViewEntryPointer) {
case CODEVIEW_SIGNATURE_NB10:
return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY));
case CODEVIEW_SIGNATURE_RSDS:
return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY));
case CODEVIEW_SIGNATURE_MTOC:
return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY));
default:
break;
}
}
}
}
return NULL;
}
/**
Returns the size of the PE/COFF headers
Returns the size of the PE/COFF header specified by Pe32Data.
If Pe32Data is NULL, then ASSERT().
@param Pe32Data Pointer to the PE/COFF image that is loaded in system
memory.
@return Size of PE/COFF header in bytes or zero if not a valid image.
**/
UINT32
EFIAPI
PeCoffGetSizeOfHeaders (
IN VOID *Pe32Data
)
{
EFI_IMAGE_DOS_HEADER *DosHdr;
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
UINTN SizeOfHeaders;
ASSERT (Pe32Data != NULL);
DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
//
// DOS image header is present, so read the PE header after the DOS image header.
//
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));
} else {
//
// DOS image header is not present, so PE header is at the image base.
//
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;
}
if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
SizeOfHeaders = sizeof (EFI_TE_IMAGE_HEADER) + (UINTN)Hdr.Te->BaseOfCode - (UINTN)Hdr.Te->StrippedSize;
} else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
SizeOfHeaders = Hdr.Pe32->OptionalHeader.SizeOfHeaders;
} else {
SizeOfHeaders = 0;
}
return SizeOfHeaders;
}

View File

@@ -0,0 +1,49 @@
## @file
# Component description file for the EdkNt32PeiPeCoffGetEntryPointLib library.
#
# PeCoffGetEntryPointLib library class for NT32 instance implemented by use NTPeiLoadFile PPI.
# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = PeiEmuPeCoffGetEntryPointLib
FILE_GUID = 1CBED347-7DE6-BC48-AC68-3758598124D2
MODULE_TYPE = PEIM
VERSION_STRING = 1.0
LIBRARY_CLASS = PeCoffGetEntryPointLib
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
PeiEmuPeCoffGetEntryPointLib.c
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
PeiServicesLib
DebugLib
[Ppis]
gEmuThunkPpiGuid # PPI ALWAYS_CONSUMED

View File

@@ -0,0 +1,140 @@
/** @file
Serial Port Lib that thunks back to Emulator services to write to StdErr.
All read functions are stubed out. There is no constructor so this lib can
be linked with PEI Core.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiPei.h>
#include <Library/SerialPortLib.h>
#include <Library/PeiServicesLib.h>
#include <Ppi/EmuThunk.h>
#include <Protocol/EmuThunk.h>
/**
Initialize the serial device hardware.
If no initialization is required, then return RETURN_SUCCESS.
If the serial device was successfully initialized, then return RETURN_SUCCESS.
If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.
@retval RETURN_SUCCESS The serial device was initialized.
@retval RETURN_DEVICE_ERROR The serial device could not be initialized.
**/
RETURN_STATUS
EFIAPI
SerialPortInitialize (
VOID
)
{
return RETURN_SUCCESS;
}
/**
Write data from buffer to serial device.
Writes NumberOfBytes data bytes from Buffer to the serial device.
The number of bytes actually written to the serial device is returned.
If the return value is less than NumberOfBytes, then the write operation failed.
If Buffer is NULL, then ASSERT().
If NumberOfBytes is zero, then return 0.
@param Buffer The pointer to the data buffer to be written.
@param NumberOfBytes The number of bytes to written to the serial device.
@retval 0 NumberOfBytes is 0.
@retval >0 The number of bytes written to the serial device.
If this value is less than NumberOfBytes, then the read operation failed.
**/
UINTN
EFIAPI
SerialPortWrite (
IN UINT8 *Buffer,
IN UINTN NumberOfBytes
)
{
EMU_THUNK_PPI *ThunkPpi;
EFI_STATUS Status;
EMU_THUNK_PROTOCOL *Thunk;
//
// Locate EmuThunkPpi for retrieving standard output handle
//
Status = PeiServicesLocatePpi (
&gEmuThunkPpiGuid,
0,
NULL,
(VOID **) &ThunkPpi
);
if (!EFI_ERROR (Status)) {
Thunk = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();
return Thunk->WriteStdErr (Buffer, NumberOfBytes);
}
return 0;
}
/**
Read data from serial device and save the datas in buffer.
Reads NumberOfBytes data bytes from a serial device into the buffer
specified by Buffer. The number of bytes actually read is returned.
If the return value is less than NumberOfBytes, then the rest operation failed.
If Buffer is NULL, then ASSERT().
If NumberOfBytes is zero, then return 0.
@param Buffer The pointer to the data buffer to store the data read from the serial device.
@param NumberOfBytes The number of bytes which will be read.
@retval 0 Read data failed; No data is to be read.
@retval >0 The actual number of bytes read from serial device.
**/
UINTN
EFIAPI
SerialPortRead (
OUT UINT8 *Buffer,
IN UINTN NumberOfBytes
)
{
return 0;
}
/**
Polls a serial device to see if there is any data waiting to be read.
Polls a serial device to see if there is any data waiting to be read.
If there is data waiting to be read from the serial device, then TRUE is returned.
If there is no data waiting to be read from the serial device, then FALSE is returned.
@retval TRUE Data is waiting to be read from the serial device.
@retval FALSE There is no data waiting to be read from the serial device.
**/
BOOLEAN
EFIAPI
SerialPortPoll (
VOID
)
{
return FALSE;
}

View File

@@ -0,0 +1,45 @@
## @file
# Write only instance of Serial Port Library with empty functions.
#
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = PeiEmuSerialPortLibNull
FILE_GUID = E4541241-8897-411a-91F8-7D7E45837146
MODULE_TYPE = PEIM
VERSION_STRING = 1.0
LIBRARY_CLASS = SerialPortLib| PEI_CORE PEIM SEC
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
PeiEmuSerialPortLib.c
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
PeiServicesLib
[Ppis]
gEmuThunkPpiGuid # PPI ALWAYS_CONSUMED

View File

@@ -0,0 +1,136 @@
/** @file
PEI Services Table Pointer Library.
This library is used for PEIM which does executed from flash device directly but
executed in memory.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Portiions copyrigth (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiPei.h>
#include <Library/PeiServicesTablePointerLib.h>
#include <Library/DebugLib.h>
#include <Ppi/MemoryDiscovered.h>
CONST EFI_PEI_SERVICES **gPeiServices = NULL;
/**
Caches a pointer PEI Services Table.
Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer
in a CPU specific manner as specified in the CPU binding section of the Platform Initialization
Pre-EFI Initialization Core Interface Specification.
If PeiServicesTablePointer is NULL, then ASSERT().
@param PeiServicesTablePointer The address of PeiServices pointer.
**/
VOID
EFIAPI
SetPeiServicesTablePointer (
IN CONST EFI_PEI_SERVICES ** PeiServicesTablePointer
)
{
ASSERT (PeiServicesTablePointer != NULL);
ASSERT (*PeiServicesTablePointer != NULL);
gPeiServices = PeiServicesTablePointer;
}
/**
Retrieves the cached value of the PEI Services Table pointer.
Returns the cached value of the PEI Services Table pointer in a CPU specific manner
as specified in the CPU binding section of the Platform Initialization Pre-EFI
Initialization Core Interface Specification.
If the cached PEI Services Table pointer is NULL, then ASSERT().
@return The pointer to PeiServices.
**/
CONST EFI_PEI_SERVICES **
EFIAPI
GetPeiServicesTablePointer (
VOID
)
{
ASSERT (gPeiServices != NULL);
ASSERT (*gPeiServices != NULL);
return gPeiServices;
}
/**
Notification service to be called when gEmuThunkPpiGuid is installed.
@param PeiServices Indirect reference to the PEI Services Table.
@param NotifyDescriptor Address of the notification descriptor data structure. Type
EFI_PEI_NOTIFY_DESCRIPTOR is defined above.
@param Ppi Address of the PPI that was installed.
@retval EFI_STATUS This function will install a PPI to PPI database. The status
code will be the code for (*PeiServices)->InstallPpi.
**/
EFI_STATUS
EFIAPI
PeiServicesTablePointerNotifyCallback (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
IN VOID *Ppi
)
{
gPeiServices = (CONST EFI_PEI_SERVICES **)PeiServices;
return EFI_SUCCESS;
}
EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnThunkList = {
(EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiPeiMemoryDiscoveredPpiGuid,
PeiServicesTablePointerNotifyCallback
};
/**
Constructor register notification on when PPI updates. If PPI is
alreay installed registering the notify will cause the handle to
run.
@param FileHandle The handle of FFS header the loaded driver.
@param PeiServices The pointer to the PEI services.
@retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
**/
EFI_STATUS
EFIAPI
PeiServicesTablePointerLibConstructor (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
{
EFI_STATUS Status;
gPeiServices = (CONST EFI_PEI_SERVICES **)PeiServices;
// register to be told when PeiServices pointer is updated
Status = (*PeiServices)->NotifyPpi (PeiServices, &mNotifyOnThunkList);
ASSERT_EFI_ERROR (Status);
return Status;
}

View File

@@ -0,0 +1,46 @@
## @file
# Instance of PEI Services Table Pointer Library using global variable for the table pointer.
#
# PEI Services Table Pointer Library implementation that retrieves a pointer to the
# PEI Services Table from a global variable. Not available to modules that execute from
# read-only memory.
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = EmulatorPkgPeiServicesTablePointerLib
FILE_GUID = 5FD8B4ED-D66F-C144-9953-AC557C649925
MODULE_TYPE = PEIM
VERSION_STRING = 1.0
LIBRARY_CLASS = PeiServicesTablePointerLib|PEIM
CONSTRUCTOR = PeiServicesTablePointerLibConstructor
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC (EBC is for build only)
#
[Sources]
PeiServicesTablePointer.c
[Packages]
MdePkg/MdePkg.dec
[LibraryClasses]
DebugLib
[Ppis]
gEfiPeiMemoryDiscoveredPpiGuid

View File

@@ -0,0 +1,75 @@
/** @file
PEI Services Table Pointer Library.
Store PEI Services Table pointer via gEmulatorPkgTokenSpaceGuid.PcdPeiServicesTablePage.
This emulates a platform SRAM. The PI mechaism does not work in the emulator due to
lack of privledge.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Portiions copyrigth (c) 2011, Apple Inc. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiPei.h>
#include <Library/PeiServicesTablePointerLib.h>
#include <Library/DebugLib.h>
#include <Library/EmuMagicPageLib.h>
/**
Caches a pointer PEI Services Table.
Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer
in a CPU specific manner as specified in the CPU binding section of the Platform Initialization
Pre-EFI Initialization Core Interface Specification.
If PeiServicesTablePointer is NULL, then ASSERT().
@param PeiServicesTablePointer The address of PeiServices pointer.
**/
VOID
EFIAPI
SetPeiServicesTablePointer (
IN CONST EFI_PEI_SERVICES ** PeiServicesTablePointer
)
{
ASSERT (PeiServicesTablePointer != NULL);
ASSERT (*PeiServicesTablePointer != NULL);
EMU_MAGIC_PAGE()->PeiServicesTablePointer = PeiServicesTablePointer;
}
/**
Retrieves the cached value of the PEI Services Table pointer.
Returns the cached value of the PEI Services Table pointer in a CPU specific manner
as specified in the CPU binding section of the Platform Initialization Pre-EFI
Initialization Core Interface Specification.
If the cached PEI Services Table pointer is NULL, then ASSERT().
@return The pointer to PeiServices.
**/
CONST EFI_PEI_SERVICES **
EFIAPI
GetPeiServicesTablePointer (
VOID
)
{
CONST EFI_PEI_SERVICES **PeiServicesTablePointer;
PeiServicesTablePointer = EMU_MAGIC_PAGE()->PeiServicesTablePointer;
ASSERT (PeiServicesTablePointer != NULL);
ASSERT (*PeiServicesTablePointer != NULL);
return PeiServicesTablePointer;
}

View File

@@ -0,0 +1,44 @@
## @file
# PEI Services Table Pointer Library.
#
# Store PEI Services Table pointer via gEmulatorPkgTokenSpaceGuid.PcdPeiServicesTablePage.
# This emulates a platform SRAM. The PI mechaism does not work in the emulator due to
# lack of privledge.
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = EmulatorPkgPeiServicesTablePointerLib
FILE_GUID = 7488FC06-370A-1C41-B05C-7395559A535A
MODULE_TYPE = PEIM
VERSION_STRING = 1.0
LIBRARY_CLASS = PeiServicesTablePointerLib|PEIM PEI_CORE SEC
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC (EBC is for build only)
#
[Sources]
PeiServicesTablePointer.c
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
DebugLib
[Pcd]
gEmulatorPkgTokenSpaceGuid.PcdPeiServicesTablePage

View File

@@ -0,0 +1,174 @@
/** @file
A non-functional instance of the Timer Library.
Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiPei.h>
#include <Library/TimerLib.h>
#include <Library/DebugLib.h>
#include <Library/PeiServicesLib.h>
#include <Ppi/EmuThunk.h>
#include <Protocol/EmuThunk.h>
/**
Stalls the CPU for at least the given number of microseconds.
Stalls the CPU for the number of microseconds specified by MicroSeconds.
@param MicroSeconds The minimum number of microseconds to delay.
@return The value of MicroSeconds inputted.
**/
UINTN
EFIAPI
MicroSecondDelay (
IN UINTN MicroSeconds
)
{
return NanoSecondDelay (MicroSeconds * 1000);
}
/**
Stalls the CPU for at least the given number of nanoseconds.
Stalls the CPU for the number of nanoseconds specified by NanoSeconds.
@param NanoSeconds The minimum number of nanoseconds to delay.
@return The value of NanoSeconds inputted.
**/
UINTN
EFIAPI
NanoSecondDelay (
IN UINTN NanoSeconds
)
{
EMU_THUNK_PPI *ThunkPpi;
EFI_STATUS Status;
EMU_THUNK_PROTOCOL *Thunk;
//
// Locate EmuThunkPpi for
//
Status = PeiServicesLocatePpi (
&gEmuThunkPpiGuid,
0,
NULL,
(VOID **) &ThunkPpi
);
if (!EFI_ERROR (Status)) {
Thunk = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();
Thunk->Sleep (NanoSeconds * 100);
return NanoSeconds;
}
return 0;
}
/**
Retrieves the current value of a 64-bit free running performance counter.
The counter can either count up by 1 or count down by 1. If the physical
performance counter counts by a larger increment, then the counter values
must be translated. The properties of the counter can be retrieved from
GetPerformanceCounterProperties().
@return The current value of the free running performance counter.
**/
UINT64
EFIAPI
GetPerformanceCounter (
VOID
)
{
EMU_THUNK_PPI *ThunkPpi;
EFI_STATUS Status;
EMU_THUNK_PROTOCOL *Thunk;
//
// Locate EmuThunkPpi for
//
Status = PeiServicesLocatePpi (
&gEmuThunkPpiGuid,
0,
NULL,
(VOID **) &ThunkPpi
);
if (!EFI_ERROR (Status)) {
Thunk = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();
return Thunk->QueryPerformanceCounter ();
}
return 0;
}
/**
Retrieves the 64-bit frequency in Hz and the range of performance counter
values.
If StartValue is not NULL, then the value that the performance counter starts
with immediately after is it rolls over is returned in StartValue. If
EndValue is not NULL, then the value that the performance counter end with
immediately before it rolls over is returned in EndValue. The 64-bit
frequency of the performance counter in Hz is always returned. If StartValue
is less than EndValue, then the performance counter counts up. If StartValue
is greater than EndValue, then the performance counter counts down. For
example, a 64-bit free running counter that counts up would have a StartValue
of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter
that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.
@param StartValue The value the performance counter starts with when it
rolls over.
@param EndValue The value that the performance counter ends with before
it rolls over.
@return The frequency in Hz.
**/
UINT64
EFIAPI
GetPerformanceCounterProperties (
OUT UINT64 *StartValue, OPTIONAL
OUT UINT64 *EndValue OPTIONAL
)
{
EMU_THUNK_PPI *ThunkPpi;
EFI_STATUS Status;
EMU_THUNK_PROTOCOL *Thunk;
//
// Locate EmuThunkPpi for
//
Status = PeiServicesLocatePpi (
&gEmuThunkPpiGuid,
0,
NULL,
(VOID **) &ThunkPpi
);
if (!EFI_ERROR (Status)) {
if (StartValue != NULL) {
*StartValue = 0ULL;
}
if (EndValue != NULL) {
*EndValue = (UINT64)-1LL;
}
Thunk = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();
return Thunk->QueryPerformanceFrequency ();
}
return 0;
}

View File

@@ -0,0 +1,47 @@
## @file
# NULL instance of Timer Library as a template.
#
# A non-functional instance of the Timer Library that can be used as a template
# for the implementation of a functional timer library instance. This library instance can
# also be used to test build DXE, Runtime, DXE SAL, and DXE SMM modules that require timer
# services as well as EBC modules that require timer services.
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = EmuPeiTimerLib
FILE_GUID = 6ABE5FDC-AE4B-474E-8E52-9546C96AE536
MODULE_TYPE = BASE
VERSION_STRING = 1.0
LIBRARY_CLASS = TimerLib|PEIM PEI_CORE SEC
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
PeiTimerLib.c
[Packages]
MdePkg/MdePkg.dec
EmulatorPkg/EmulatorPkg.dec
[LibraryClasses]
DebugLib
PeiServicesLib
[Ppis]
gEmuThunkPpiGuid

View File

@@ -0,0 +1,281 @@
/*++ @file
A simple FV stack so the SEC can extract the SEC Core from an
FV.
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiPei.h>
#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \
(ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1))
EFI_FFS_FILE_STATE
GetFileState (
IN UINT8 ErasePolarity,
IN EFI_FFS_FILE_HEADER *FfsHeader
)
/*++
Routine Description:
Returns the highest bit set of the State field
Arguments:
ErasePolarity - Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY
in the Attributes field.
FfsHeader - Pointer to FFS File Header.
Returns:
Returns the highest bit in the State field
**/
{
EFI_FFS_FILE_STATE FileState;
EFI_FFS_FILE_STATE HighestBit;
FileState = FfsHeader->State;
if (ErasePolarity != 0) {
FileState = (EFI_FFS_FILE_STATE)~FileState;
}
HighestBit = 0x80;
while (HighestBit != 0 && (HighestBit & FileState) == 0) {
HighestBit >>= 1;
}
return HighestBit;
}
UINT8
CalculateHeaderChecksum (
IN EFI_FFS_FILE_HEADER *FileHeader
)
/*++
Routine Description:
Calculates the checksum of the header of a file.
Arguments:
FileHeader - Pointer to FFS File Header.
Returns:
Checksum of the header.
**/
{
UINT8 *ptr;
UINTN Index;
UINT8 Sum;
Sum = 0;
ptr = (UINT8 *) FileHeader;
for (Index = 0; Index < sizeof (EFI_FFS_FILE_HEADER) - 3; Index += 4) {
Sum = (UINT8) (Sum + ptr[Index]);
Sum = (UINT8) (Sum + ptr[Index + 1]);
Sum = (UINT8) (Sum + ptr[Index + 2]);
Sum = (UINT8) (Sum + ptr[Index + 3]);
}
for (; Index < sizeof (EFI_FFS_FILE_HEADER); Index++) {
Sum = (UINT8) (Sum + ptr[Index]);
}
//
// State field (since this indicates the different state of file).
//
Sum = (UINT8) (Sum - FileHeader->State);
//
// Checksum field of the file is not part of the header checksum.
//
Sum = (UINT8) (Sum - FileHeader->IntegrityCheck.Checksum.File);
return Sum;
}
EFI_STATUS
SecFfsFindNextFile (
IN EFI_FV_FILETYPE SearchType,
IN EFI_PEI_FV_HANDLE FvHandle,
IN OUT EFI_PEI_FILE_HANDLE *FileHandle
)
/*++
Routine Description:
Given the input file pointer, search for the next matching file in the
FFS volume as defined by SearchType. The search starts from FileHeader inside
the Firmware Volume defined by FwVolHeader.
Arguments:
SearchType - Filter to find only files of this type.
Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
FwVolHeader - Pointer to the FV header of the volume to search.
This parameter must point to a valid FFS volume.
FileHeader - Pointer to the current file from which to begin searching.
This pointer will be updated upon return to reflect the file
found.
Returns:
EFI_NOT_FOUND - No files matching the search criteria were found
EFI_SUCCESS
**/
{
EFI_FFS_FILE_HEADER *FfsFileHeader;
UINT32 FileLength;
UINT32 FileOccupiedSize;
UINT32 FileOffset;
UINT64 FvLength;
UINT8 ErasePolarity;
UINT8 FileState;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
EFI_FFS_FILE_HEADER **FileHeader;
//
// Convert the handle of FV to FV header for memory-mapped firmware volume
//
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) FvHandle;
FileHeader = (EFI_FFS_FILE_HEADER **)FileHandle;
FvLength = FwVolHeader->FvLength;
if (FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) {
ErasePolarity = 1;
} else {
ErasePolarity = 0;
}
//
// If FileHeader is not specified (NULL) start with the first file in the
// firmware volume. Otherwise, start from the FileHeader.
//
if (*FileHeader == NULL) {
FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FwVolHeader + FwVolHeader->HeaderLength);
} else {
//
// Length is 24 bits wide so mask upper 8 bits
// FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.
//
FileLength = *(UINT32 *) (*FileHeader)->Size & 0x00FFFFFF;
FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) *FileHeader + FileOccupiedSize);
}
FileOffset = (UINT32) ((UINT8 *) FfsFileHeader - (UINT8 *) FwVolHeader);
while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) {
//
// Get FileState which is the highest bit of the State
//
FileState = GetFileState (ErasePolarity, FfsFileHeader);
switch (FileState) {
case EFI_FILE_HEADER_INVALID:
FileOffset += sizeof (EFI_FFS_FILE_HEADER);
FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER));
break;
case EFI_FILE_DATA_VALID:
case EFI_FILE_MARKED_FOR_UPDATE:
if (CalculateHeaderChecksum (FfsFileHeader) == 0) {
FileLength = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;
FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
if ((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) {
*FileHeader = FfsFileHeader;
return EFI_SUCCESS;
}
FileOffset += FileOccupiedSize;
FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize);
} else {
return EFI_NOT_FOUND;
}
break;
case EFI_FILE_DELETED:
FileLength = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;
FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
FileOffset += FileOccupiedSize;
FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize);
break;
default:
return EFI_NOT_FOUND;
}
}
return EFI_NOT_FOUND;
}
EFI_STATUS
SecFfsFindSectionData (
IN EFI_SECTION_TYPE SectionType,
IN EFI_FFS_FILE_HEADER *FfsFileHeader,
IN OUT VOID **SectionData
)
/*++
Routine Description:
Given the input file pointer, search for the next matching section in the
FFS volume.
Arguments:
SearchType - Filter to find only sections of this type.
FfsFileHeader - Pointer to the current file to search.
SectionData - Pointer to the Section matching SectionType in FfsFileHeader.
NULL if section not found
Returns:
EFI_NOT_FOUND - No files matching the search criteria were found
EFI_SUCCESS
**/
{
UINT32 FileSize;
EFI_COMMON_SECTION_HEADER *Section;
UINT32 SectionLength;
UINT32 ParsedLength;
//
// Size is 24 bits wide so mask upper 8 bits.
// Does not include FfsFileHeader header size
// FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned.
//
Section = (EFI_COMMON_SECTION_HEADER *) (FfsFileHeader + 1);
FileSize = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;
FileSize -= sizeof (EFI_FFS_FILE_HEADER);
*SectionData = NULL;
ParsedLength = 0;
while (ParsedLength < FileSize) {
if (Section->Type == SectionType) {
*SectionData = (VOID *) (Section + 1);
return EFI_SUCCESS;
}
//
// Size is 24 bits wide so mask upper 8 bits.
// SectionLength is adjusted it is 4 byte aligned.
// Go to the next section
//
SectionLength = *(UINT32 *) Section->Size & 0x00FFFFFF;
SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);
ParsedLength += SectionLength;
Section = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) Section + SectionLength);
}
return EFI_NOT_FOUND;
}

View File

@@ -0,0 +1,567 @@
/** @file
Implementation for PEI Services Library.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiPei.h>
#include <Library/EmuMagicPageLib.h>
#include <Library/PeiServicesLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
EFI_STATUS
SecFfsFindNextFile (
IN EFI_FV_FILETYPE SearchType,
IN EFI_PEI_FV_HANDLE VolumeHandle,
IN OUT EFI_PEI_FILE_HANDLE *FileHandle
);
EFI_STATUS
SecFfsFindSectionData (
IN EFI_SECTION_TYPE SectionType,
IN EFI_PEI_FILE_HANDLE FileHandle,
OUT VOID **SectionData
);
/**
This service enables a given PEIM to register an interface into the PEI Foundation.
@param PpiList A pointer to the list of interfaces that the caller shall install.
@retval EFI_SUCCESS The interface was successfully installed.
@retval EFI_INVALID_PARAMETER The PpiList pointer is NULL.
@retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
@retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
**/
EFI_STATUS
EFIAPI
PeiServicesInstallPpi (
IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList
)
{
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
/**
This service enables PEIMs to replace an entry in the PPI database with an alternate entry.
@param OldPpi The pointer to the old PEI PPI Descriptors.
@param NewPpi The pointer to the new PEI PPI Descriptors.
@retval EFI_SUCCESS The interface was successfully installed.
@retval EFI_INVALID_PARAMETER The OldPpi or NewPpi is NULL.
@retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
@retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
@retval EFI_NOT_FOUND The PPI for which the reinstallation was requested has not been
installed.
**/
EFI_STATUS
EFIAPI
PeiServicesReInstallPpi (
IN CONST EFI_PEI_PPI_DESCRIPTOR *OldPpi,
IN CONST EFI_PEI_PPI_DESCRIPTOR *NewPpi
)
{
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
/**
This service enables PEIMs to discover a given instance of an interface.
So this is, well a hack, so we can reuse the same libraries as the PEI Core
for XIP modules....
@param Guid A pointer to the GUID whose corresponding interface needs to be
found.
@param Instance The N-th instance of the interface that is required.
@param PpiDescriptor A pointer to instance of the EFI_PEI_PPI_DESCRIPTOR.
@param Ppi A pointer to the instance of the interface.
@retval EFI_SUCCESS The interface was successfully returned.
@retval EFI_NOT_FOUND The PPI descriptor is not found in the database.
**/
EFI_STATUS
EFIAPI
PeiServicesLocatePpi (
IN CONST EFI_GUID *Guid,
IN UINTN Instance,
IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
IN OUT VOID **Ppi
)
{
EFI_PEI_PPI_DESCRIPTOR *PpiList;
if (Instance != 0) {
return EFI_NOT_FOUND;
}
for (PpiList = EMU_MAGIC_PAGE()->PpiList; ; PpiList++) {
if (CompareGuid (PpiList->Guid, Guid)) {
if (PpiDescriptor != NULL) {
*PpiDescriptor = PpiList;
}
if (Ppi != NULL) {
*Ppi = PpiList->Ppi;
}
return EFI_SUCCESS;
}
if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) == EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) {
break;
}
}
return EFI_NOT_FOUND;
}
/**
This service enables PEIMs to register a given service to be invoked when another service is
installed or reinstalled.
@param NotifyList A pointer to the list of notification interfaces
that the caller shall install.
@retval EFI_SUCCESS The interface was successfully installed.
@retval EFI_INVALID_PARAMETER The NotifyList pointer is NULL.
@retval EFI_INVALID_PARAMETER Any of the PEI notify descriptors in the list do
not have the EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES
bit set in the Flags field.
@retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
**/
EFI_STATUS
EFIAPI
PeiServicesNotifyPpi (
IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList
)
{
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
/**
This service enables PEIMs to ascertain the present value of the boot mode.
@param BootMode A pointer to contain the value of the boot mode.
@retval EFI_SUCCESS The boot mode was returned successfully.
@retval EFI_INVALID_PARAMETER BootMode is NULL.
**/
EFI_STATUS
EFIAPI
PeiServicesGetBootMode (
OUT EFI_BOOT_MODE *BootMode
)
{
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
/**
This service enables PEIMs to update the boot mode variable.
@param BootMode The value of the boot mode to set.
@retval EFI_SUCCESS The value was successfully updated
**/
EFI_STATUS
EFIAPI
PeiServicesSetBootMode (
IN EFI_BOOT_MODE BootMode
)
{
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
/**
This service enables a PEIM to ascertain the address of the list of HOBs in memory.
@param HobList A pointer to the list of HOBs that the PEI Foundation
will initialize.
@retval EFI_SUCCESS The list was successfully returned.
@retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published.
**/
EFI_STATUS
EFIAPI
PeiServicesGetHobList (
OUT VOID **HobList
)
{
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
/**
This service enables PEIMs to create various types of HOBs.
@param Type The type of HOB to be installed.
@param Length The length of the HOB to be added.
@param Hob The address of a pointer that will contain the
HOB header.
@retval EFI_SUCCESS The HOB was successfully created.
@retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
**/
EFI_STATUS
EFIAPI
PeiServicesCreateHob (
IN UINT16 Type,
IN UINT16 Length,
OUT VOID **Hob
)
{
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
/**
This service enables PEIMs to discover additional firmware volumes.
@param Instance This instance of the firmware volume to find. The
value 0 is the Boot Firmware Volume (BFV).
@param VolumeHandle Handle of the firmware volume header of the volume
to return.
@retval EFI_SUCCESS The volume was found.
@retval EFI_NOT_FOUND The volume was not found.
@retval EFI_INVALID_PARAMETER FwVolHeader is NULL.
**/
EFI_STATUS
EFIAPI
PeiServicesFfsFindNextVolume (
IN UINTN Instance,
IN OUT EFI_PEI_FV_HANDLE *VolumeHandle
)
{
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
/**
This service enables PEIMs to discover additional firmware files.
@param SearchType A filter to find files only of this type.
@param VolumeHandle The pointer to the firmware volume header of the
volume to search. This parameter must point to a
valid FFS volume.
@param FileHandle Handle of the current file from which to begin searching.
@retval EFI_SUCCESS The file was found.
@retval EFI_NOT_FOUND The file was not found.
@retval EFI_NOT_FOUND The header checksum was not zero.
**/
EFI_STATUS
EFIAPI
PeiServicesFfsFindNextFile (
IN EFI_FV_FILETYPE SearchType,
IN EFI_PEI_FV_HANDLE VolumeHandle,
IN OUT EFI_PEI_FILE_HANDLE *FileHandle
)
{
return SecFfsFindNextFile (SearchType, VolumeHandle, FileHandle);
}
/**
This service enables PEIMs to discover sections of a given type within a valid FFS file.
@param SectionType The value of the section type to find.
@param FileHandle A pointer to the file header that contains the set
of sections to be searched.
@param SectionData A pointer to the discovered section, if successful.
@retval EFI_SUCCESS The section was found.
@retval EFI_NOT_FOUND The section was not found.
**/
EFI_STATUS
EFIAPI
PeiServicesFfsFindSectionData (
IN EFI_SECTION_TYPE SectionType,
IN EFI_PEI_FILE_HANDLE FileHandle,
OUT VOID **SectionData
)
{
return SecFfsFindSectionData (SectionType, FileHandle, SectionData);
}
/**
This service enables PEIMs to register the permanent memory configuration
that has been initialized with the PEI Foundation.
@param MemoryBegin The value of a region of installed memory.
@param MemoryLength The corresponding length of a region of installed memory.
@retval EFI_SUCCESS The region was successfully installed in a HOB.
@retval EFI_INVALID_PARAMETER MemoryBegin and MemoryLength are illegal for this system.
@retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
**/
EFI_STATUS
EFIAPI
PeiServicesInstallPeiMemory (
IN EFI_PHYSICAL_ADDRESS MemoryBegin,
IN UINT64 MemoryLength
)
{
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
/**
This service enables PEIMs to allocate memory after the permanent memory has been
installed by a PEIM.
@param MemoryType Type of memory to allocate.
@param Pages The number of pages to allocate.
@param Memory Pointer of memory allocated.
@retval EFI_SUCCESS The memory range was successfully allocated.
@retval EFI_INVALID_PARAMETER Type is not equal to AllocateAnyPages.
@retval EFI_NOT_AVAILABLE_YET Called with permanent memory not available.
@retval EFI_OUT_OF_RESOURCES The pages could not be allocated.
**/
EFI_STATUS
EFIAPI
PeiServicesAllocatePages (
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN Pages,
OUT EFI_PHYSICAL_ADDRESS *Memory
)
{
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
/**
This service allocates memory from the Hand-Off Block (HOB) heap.
@param Size The number of bytes to allocate from the pool.
@param Buffer If the call succeeds, a pointer to a pointer to
the allocate buffer; otherwise, undefined.
@retval EFI_SUCCESS The allocation was successful
@retval EFI_OUT_OF_RESOURCES There is not enough heap to allocate the requested size.
**/
EFI_STATUS
EFIAPI
PeiServicesAllocatePool (
IN UINTN Size,
OUT VOID **Buffer
)
{
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
/**
Resets the entire platform.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_NOT_AVAILABLE_YET The service has not been installed yet.
**/
EFI_STATUS
EFIAPI
PeiServicesResetSystem (
VOID
)
{
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
/**
This service is a wrapper for the PEI Service RegisterForShadow(), except the
pointer to the PEI Services Table has been removed. See the Platform
Initialization Pre-EFI Initialization Core Interface Specification for details.
@param FileHandle PEIM's file handle. Must be the currently
executing PEIM.
@retval EFI_SUCCESS The PEIM was successfully registered for
shadowing.
@retval EFI_ALREADY_STARTED The PEIM was previously
registered for shadowing.
@retval EFI_NOT_FOUND The FileHandle does not refer to a
valid file handle.
**/
EFI_STATUS
EFIAPI
PeiServicesRegisterForShadow (
IN EFI_PEI_FILE_HANDLE FileHandle
)
{
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
/**
This service is a wrapper for the PEI Service FfsGetFileInfo(), except the pointer to the PEI Services
Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
Specification for details.
@param FileHandle The handle of the file.
@param FileInfo Upon exit, points to the file's
information.
@retval EFI_SUCCESS File information returned.
@retval EFI_INVALID_PARAMETER If FileHandle does not
represent a valid file.
@retval EFI_INVALID_PARAMETER FileInfo is NULL.
**/
EFI_STATUS
EFIAPI
PeiServicesFfsGetFileInfo (
IN CONST EFI_PEI_FILE_HANDLE FileHandle,
OUT EFI_FV_FILE_INFO *FileInfo
)
{
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
/**
This service is a wrapper for the PEI Service FfsFindByName(), except the pointer to the PEI Services
Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
Specification for details.
@param FileName A pointer to the name of the file to
find within the firmware volume.
@param VolumeHandle The firmware volume to search FileHandle
Upon exit, points to the found file's
handle or NULL if it could not be found.
@param FileHandle The pointer to found file handle
@retval EFI_SUCCESS File was found.
@retval EFI_NOT_FOUND File was not found.
@retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or
FileName was NULL.
**/
EFI_STATUS
EFIAPI
PeiServicesFfsFindFileByName (
IN CONST EFI_GUID *FileName,
IN CONST EFI_PEI_FV_HANDLE VolumeHandle,
OUT EFI_PEI_FILE_HANDLE *FileHandle
)
{
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
/**
This service is a wrapper for the PEI Service FfsGetVolumeInfo(), except the pointer to the PEI Services
Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
Specification for details.
@param VolumeHandle Handle of the volume.
@param VolumeInfo Upon exit, points to the volume's
information.
@retval EFI_SUCCESS File information returned.
@retval EFI_INVALID_PARAMETER If FileHandle does not
represent a valid file.
@retval EFI_INVALID_PARAMETER If FileInfo is NULL.
**/
EFI_STATUS
EFIAPI
PeiServicesFfsGetVolumeInfo (
IN EFI_PEI_FV_HANDLE VolumeHandle,
OUT EFI_FV_INFO *VolumeInfo
)
{
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
/**
Install a EFI_PEI_FIRMWARE_VOLUME_INFO_PPI instance so the PEI Core will be notified about a new firmware volume.
This function allocates, initializes, and installs a new EFI_PEI_FIRMWARE_VOLUME_INFO_PPI using
the parameters passed in to initialize the fields of the EFI_PEI_FIRMWARE_VOLUME_INFO_PPI instance.
If the resources can not be allocated for EFI_PEI_FIRMWARE_VOLUME_INFO_PPI, then ASSERT().
If the EFI_PEI_FIRMWARE_VOLUME_INFO_PPI can not be installed, then ASSERT().
@param FvFormat Unique identifier of the format of the memory-mapped
firmware volume. This parameter is optional and
may be NULL. If NULL is specified, the
EFI_FIRMWARE_FILE_SYSTEM2_GUID format is assumed.
@param FvInfo Points to a buffer which allows the
EFI_PEI_FIRMWARE_VOLUME_PPI to process the volume.
The format of this buffer is specific to the FvFormat.
For memory-mapped firmware volumes, this typically
points to the first byte of the firmware volume.
@param FvInfoSize The size, in bytes, of FvInfo. For memory-mapped
firmware volumes, this is typically the size of
the firmware volume.
@param ParentFvName If the new firmware volume originated from a file
in a different firmware volume, then this parameter
specifies the GUID name of the originating firmware
volume. Otherwise, this parameter must be NULL.
@param ParentFileName If the new firmware volume originated from a file
in a different firmware volume, then this parameter
specifies the GUID file name of the originating
firmware file. Otherwise, this parameter must be NULL.
**/
VOID
EFIAPI
PeiServicesInstallFvInfoPpi (
IN CONST EFI_GUID *FvFormat, OPTIONAL
IN CONST VOID *FvInfo,
IN UINT32 FvInfoSize,
IN CONST EFI_GUID *ParentFvName, OPTIONAL
IN CONST EFI_GUID *ParentFileName OPTIONAL
)
{
ASSERT (FALSE);
return;
}

Some files were not shown because too many files have changed in this diff Show More