2008-04-18 05:09:54 +02:00
|
|
|
/*++
|
|
|
|
|
2014-10-15 07:19:08 +02:00
|
|
|
Caution: This file is used for Duet platform only, do not use them in real platform.
|
|
|
|
All variable code, variable metadata, and variable data used by Duet platform are on
|
|
|
|
disk. They can be changed by user. BIOS is not able to protoect those.
|
|
|
|
Duet trusts all meta data from disk. If variable code, variable metadata and variable
|
|
|
|
data is modified in inproper way, the behavior is undefined.
|
|
|
|
|
|
|
|
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
|
2010-04-28 14:39:50 +02:00
|
|
|
This program and the accompanying materials
|
2008-04-18 05:09:54 +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.
|
|
|
|
|
|
|
|
Module Name:
|
|
|
|
|
|
|
|
MemStorage.c
|
|
|
|
|
|
|
|
Abstract:
|
|
|
|
|
|
|
|
handles variable store/reads with emulated memory
|
|
|
|
|
|
|
|
Revision History
|
|
|
|
|
|
|
|
--*/
|
|
|
|
#include "FSVariable.h"
|
|
|
|
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
2008-10-30 07:17:19 +01:00
|
|
|
OnVirtualAddressChangeMs (
|
2008-04-18 05:09:54 +02:00
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
|
|
|
);
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
MemEraseStore(
|
|
|
|
IN VARIABLE_STORAGE *This
|
|
|
|
);
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
MemWriteStore (
|
|
|
|
IN VARIABLE_STORAGE *This,
|
|
|
|
IN UINTN Offset,
|
|
|
|
IN UINTN BufferSize,
|
|
|
|
IN VOID *Buffer
|
|
|
|
);
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
MemStorageConstructor (
|
|
|
|
OUT VARIABLE_STORAGE **VarStore,
|
|
|
|
OUT EFI_EVENT_NOTIFY *GoVirtualEvent,
|
|
|
|
IN UINTN Size
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
VS_DEV *Dev;
|
|
|
|
|
2008-11-24 00:57:13 +01:00
|
|
|
Status = gBS->AllocatePool (EfiRuntimeServicesData, sizeof(VS_DEV), (VOID **) &Dev);
|
2008-04-18 05:09:54 +02:00
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
ZeroMem (Dev, sizeof(VS_DEV));
|
|
|
|
|
2009-02-28 19:15:09 +01:00
|
|
|
Dev->Signature = VS_DEV_SIGNATURE;
|
2008-04-18 05:09:54 +02:00
|
|
|
Dev->Size = Size;
|
|
|
|
|
|
|
|
Dev->VarStore.Erase = MemEraseStore;
|
|
|
|
Dev->VarStore.Write = MemWriteStore;
|
|
|
|
|
2008-11-24 00:57:13 +01:00
|
|
|
Status = gBS->AllocatePool (EfiRuntimeServicesData, Size, (VOID **) &VAR_DATA_PTR (Dev));
|
2008-04-18 05:09:54 +02:00
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
DEBUG ((EFI_D_ERROR, "VStorage: Size = 0x%x\n", Size));
|
|
|
|
|
|
|
|
*VarStore = &Dev->VarStore;
|
2008-10-30 07:17:19 +01:00
|
|
|
*GoVirtualEvent = OnVirtualAddressChangeMs;
|
2008-04-18 05:09:54 +02:00
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
2008-10-30 07:17:19 +01:00
|
|
|
OnVirtualAddressChangeMs (
|
2008-04-18 05:09:54 +02:00
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
|
|
|
VS_DEV *Dev;
|
|
|
|
|
|
|
|
Dev = DEV_FROM_THIS (Context);
|
|
|
|
|
2008-11-24 00:57:13 +01:00
|
|
|
EfiConvertPointer (0, (VOID **)&VAR_DATA_PTR (Dev));
|
|
|
|
EfiConvertPointer (0, (VOID **)&Dev->VarStore.Erase);
|
|
|
|
EfiConvertPointer (0, (VOID **)&Dev->VarStore.Write);
|
2008-04-18 05:09:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
MemEraseStore(
|
|
|
|
IN VARIABLE_STORAGE *This
|
|
|
|
)
|
|
|
|
{
|
|
|
|
VS_DEV *Dev;
|
|
|
|
|
|
|
|
Dev = DEV_FROM_THIS(This);
|
|
|
|
SetMem (VAR_DATA_PTR (Dev), Dev->Size, VAR_DEFAULT_VALUE);
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
MemWriteStore (
|
|
|
|
IN VARIABLE_STORAGE *This,
|
|
|
|
IN UINTN Offset,
|
|
|
|
IN UINTN BufferSize,
|
|
|
|
IN VOID *UserBuffer
|
|
|
|
)
|
|
|
|
{
|
|
|
|
VS_DEV *Dev;
|
|
|
|
|
|
|
|
Dev = DEV_FROM_THIS(This);
|
|
|
|
|
|
|
|
ASSERT (Offset + BufferSize < Dev->Size);
|
|
|
|
|
|
|
|
// For better performance
|
|
|
|
if (VAR_DATA_PTR (Dev) + Offset != UserBuffer) {
|
|
|
|
CopyMem (VAR_DATA_PTR (Dev) + Offset, UserBuffer, BufferSize);
|
|
|
|
}
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|