2008-04-09 09:07:50 +02:00
|
|
|
/** @file
|
2007-07-19 12:09:07 +02:00
|
|
|
|
2008-04-09 09:07:50 +02:00
|
|
|
Implment all four UEFI runtime variable services and
|
|
|
|
install variable architeture protocol.
|
|
|
|
|
2010-04-24 11:33:45 +02:00
|
|
|
Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
|
|
|
|
This program and the accompanying materials
|
2007-07-19 12:09:07 +02:00
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
2008-04-09 09:07:50 +02:00
|
|
|
**/
|
2007-07-19 12:09:07 +02:00
|
|
|
|
|
|
|
#include "Variable.h"
|
|
|
|
|
2008-05-30 01:07:46 +02:00
|
|
|
EFI_EVENT mVirtualAddressChangeEvent = NULL;
|
|
|
|
|
2008-12-10 10:35:04 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
This code finds variable in storage blocks (Volatile or Non-Volatile).
|
|
|
|
|
|
|
|
@param VariableName Name of Variable to be found.
|
|
|
|
@param VendorGuid Variable vendor GUID.
|
|
|
|
@param Attributes Attribute value of the variable found.
|
|
|
|
@param DataSize Size of Data found. If size is less than the
|
|
|
|
data, this value contains the required size.
|
|
|
|
@param Data Data pointer.
|
|
|
|
|
|
|
|
@return EFI_INVALID_PARAMETER Invalid parameter
|
|
|
|
@return EFI_SUCCESS Find the specified variable
|
|
|
|
@return EFI_NOT_FOUND Not found
|
|
|
|
@return EFI_BUFFER_TO_SMALL DataSize is too small for the result
|
|
|
|
|
|
|
|
**/
|
2007-07-19 12:09:07 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
RuntimeServiceGetVariable (
|
|
|
|
IN CHAR16 *VariableName,
|
2008-12-10 10:35:04 +01:00
|
|
|
IN EFI_GUID *VendorGuid,
|
2007-07-19 12:09:07 +02:00
|
|
|
OUT UINT32 *Attributes OPTIONAL,
|
|
|
|
IN OUT UINTN *DataSize,
|
|
|
|
OUT VOID *Data
|
|
|
|
)
|
|
|
|
{
|
2009-03-24 19:42:18 +01:00
|
|
|
return EmuGetVariable (
|
2007-07-19 12:09:07 +02:00
|
|
|
VariableName,
|
|
|
|
VendorGuid,
|
|
|
|
Attributes OPTIONAL,
|
|
|
|
DataSize,
|
|
|
|
Data,
|
2009-04-27 09:06:01 +02:00
|
|
|
&mVariableModuleGlobal->VariableGlobal[Physical]
|
2007-07-19 12:09:07 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-12-10 10:35:04 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
This code Finds the Next available variable.
|
|
|
|
|
|
|
|
@param VariableNameSize Size of the variable name
|
|
|
|
@param VariableName Pointer to variable name
|
|
|
|
@param VendorGuid Variable Vendor Guid
|
|
|
|
|
|
|
|
@return EFI_INVALID_PARAMETER Invalid parameter
|
|
|
|
@return EFI_SUCCESS Find the specified variable
|
|
|
|
@return EFI_NOT_FOUND Not found
|
|
|
|
@return EFI_BUFFER_TO_SMALL DataSize is too small for the result
|
|
|
|
|
|
|
|
**/
|
2007-07-19 12:09:07 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
RuntimeServiceGetNextVariableName (
|
|
|
|
IN OUT UINTN *VariableNameSize,
|
|
|
|
IN OUT CHAR16 *VariableName,
|
|
|
|
IN OUT EFI_GUID *VendorGuid
|
|
|
|
)
|
|
|
|
{
|
2009-03-24 19:42:18 +01:00
|
|
|
return EmuGetNextVariableName (
|
2007-07-19 12:09:07 +02:00
|
|
|
VariableNameSize,
|
|
|
|
VariableName,
|
|
|
|
VendorGuid,
|
2009-04-27 09:06:01 +02:00
|
|
|
&mVariableModuleGlobal->VariableGlobal[Physical]
|
2007-07-19 12:09:07 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-12-10 10:35:04 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
This code sets variable in storage blocks (Volatile or Non-Volatile).
|
|
|
|
|
|
|
|
@param VariableName Name of Variable to be found
|
|
|
|
@param VendorGuid Variable vendor GUID
|
|
|
|
@param Attributes Attribute value of the variable found
|
|
|
|
@param DataSize Size of Data found. If size is less than the
|
|
|
|
data, this value contains the required size.
|
|
|
|
@param Data Data pointer
|
|
|
|
|
|
|
|
@return EFI_INVALID_PARAMETER Invalid parameter
|
|
|
|
@return EFI_SUCCESS Set successfully
|
|
|
|
@return EFI_OUT_OF_RESOURCES Resource not enough to set variable
|
|
|
|
@return EFI_NOT_FOUND Not found
|
|
|
|
@return EFI_WRITE_PROTECTED Variable is read-only
|
|
|
|
|
|
|
|
**/
|
2007-07-19 12:09:07 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
RuntimeServiceSetVariable (
|
|
|
|
IN CHAR16 *VariableName,
|
|
|
|
IN EFI_GUID *VendorGuid,
|
|
|
|
IN UINT32 Attributes,
|
|
|
|
IN UINTN DataSize,
|
|
|
|
IN VOID *Data
|
|
|
|
)
|
|
|
|
{
|
2009-03-24 19:42:18 +01:00
|
|
|
return EmuSetVariable (
|
2007-07-19 12:09:07 +02:00
|
|
|
VariableName,
|
|
|
|
VendorGuid,
|
|
|
|
Attributes,
|
|
|
|
DataSize,
|
|
|
|
Data,
|
|
|
|
&mVariableModuleGlobal->VariableGlobal[Physical],
|
|
|
|
&mVariableModuleGlobal->VolatileLastVariableOffset,
|
2009-04-27 09:06:01 +02:00
|
|
|
&mVariableModuleGlobal->NonVolatileLastVariableOffset
|
2007-07-19 12:09:07 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-12-10 10:35:04 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
This code returns information about the EFI variables.
|
|
|
|
|
|
|
|
@param Attributes Attributes bitmask to specify the type of variables
|
|
|
|
on which to return information.
|
|
|
|
@param MaximumVariableStorageSize Pointer to the maximum size of the storage space available
|
|
|
|
for the EFI variables associated with the attributes specified.
|
|
|
|
@param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
|
|
|
|
for EFI variables associated with the attributes specified.
|
|
|
|
@param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
|
|
|
|
associated with the attributes specified.
|
|
|
|
|
|
|
|
@return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
|
|
|
|
@return EFI_SUCCESS Query successfully.
|
|
|
|
@return EFI_UNSUPPORTED The attribute is not supported on this platform.
|
|
|
|
|
|
|
|
**/
|
2007-07-19 12:09:07 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
RuntimeServiceQueryVariableInfo (
|
|
|
|
IN UINT32 Attributes,
|
|
|
|
OUT UINT64 *MaximumVariableStorageSize,
|
|
|
|
OUT UINT64 *RemainingVariableStorageSize,
|
|
|
|
OUT UINT64 *MaximumVariableSize
|
|
|
|
)
|
|
|
|
{
|
2009-03-24 19:42:18 +01:00
|
|
|
return EmuQueryVariableInfo (
|
2007-07-19 12:09:07 +02:00
|
|
|
Attributes,
|
|
|
|
MaximumVariableStorageSize,
|
|
|
|
RemainingVariableStorageSize,
|
|
|
|
MaximumVariableSize,
|
2009-04-27 09:06:01 +02:00
|
|
|
&mVariableModuleGlobal->VariableGlobal[Physical]
|
2007-07-19 12:09:07 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-12-10 10:35:04 +01:00
|
|
|
/**
|
|
|
|
Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
|
|
|
|
|
|
|
|
This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
|
|
|
|
It convers pointer to new virtual address.
|
|
|
|
|
|
|
|
@param Event Event whose notification function is being invoked.
|
|
|
|
@param Context Pointer to the notification function's context.
|
|
|
|
|
|
|
|
**/
|
2007-07-19 12:09:07 +02:00
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
VariableClassAddressChangeEvent (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EfiConvertPointer (
|
|
|
|
0x0,
|
|
|
|
(VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase
|
|
|
|
);
|
|
|
|
EfiConvertPointer (
|
|
|
|
0x0,
|
|
|
|
(VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].VolatileVariableBase
|
|
|
|
);
|
|
|
|
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);
|
|
|
|
}
|
|
|
|
|
2008-12-10 10:35:04 +01:00
|
|
|
/**
|
2008-12-12 10:27:17 +01:00
|
|
|
EmuVariable Driver main entry point. The Variable driver places the 4 EFI
|
|
|
|
runtime services in the EFI System Table and installs arch protocols
|
|
|
|
for variable read and write services being availible. It also registers
|
2008-12-10 10:35:04 +01:00
|
|
|
notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
|
|
|
|
|
2008-12-12 10:27:17 +01:00
|
|
|
@param[in] ImageHandle The firmware allocated handle for the EFI image.
|
|
|
|
@param[in] SystemTable A pointer to the EFI System Table.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Variable service successfully initialized.
|
2008-12-10 10:35:04 +01:00
|
|
|
|
|
|
|
**/
|
2007-07-19 12:09:07 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
VariableServiceInitialize (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_HANDLE NewHandle;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
Status = VariableCommonInitialize (ImageHandle, SystemTable);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
SystemTable->RuntimeServices->GetVariable = RuntimeServiceGetVariable;
|
|
|
|
SystemTable->RuntimeServices->GetNextVariableName = RuntimeServiceGetNextVariableName;
|
|
|
|
SystemTable->RuntimeServices->SetVariable = RuntimeServiceSetVariable;
|
|
|
|
SystemTable->RuntimeServices->QueryVariableInfo = RuntimeServiceQueryVariableInfo;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now install the Variable Runtime Architectural Protocol on a new handle
|
|
|
|
//
|
|
|
|
NewHandle = NULL;
|
|
|
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
|
|
|
&NewHandle,
|
|
|
|
&gEfiVariableArchProtocolGuid,
|
|
|
|
NULL,
|
|
|
|
&gEfiVariableWriteArchProtocolGuid,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
2009-02-03 12:09:53 +01:00
|
|
|
Status = gBS->CreateEventEx (
|
|
|
|
EVT_NOTIFY_SIGNAL,
|
2008-05-30 01:07:46 +02:00
|
|
|
TPL_NOTIFY,
|
|
|
|
VariableClassAddressChangeEvent,
|
|
|
|
NULL,
|
2009-02-03 12:09:53 +01:00
|
|
|
&gEfiEventVirtualAddressChangeGuid,
|
2008-05-30 01:07:46 +02:00
|
|
|
&mVirtualAddressChangeEvent
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
2007-07-19 12:09:07 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|