EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

DuetPkg/FSVariable/MemStorage.c

Go to the documentation of this file.
00001 /*++
00002 
00003 Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
00004 This program and the accompanying materials
00005 are licensed and made available under the terms and conditions of the BSD License
00006 which accompanies this distribution.  The full text of the license may be found at
00007 http://opensource.org/licenses/bsd-license.php
00008 
00009 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
00010 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
00011 
00012 Module Name:
00013 
00014     MemStorage.c
00015 
00016 Abstract:
00017 
00018     handles variable store/reads with emulated memory
00019 
00020 Revision History
00021 
00022 --*/
00023 #include "FSVariable.h"
00024 
00025 VOID
00026 EFIAPI
00027 OnVirtualAddressChangeMs (
00028   IN EFI_EVENT            Event,
00029   IN VOID                 *Context
00030   );
00031 
00032 EFI_STATUS
00033 EFIAPI
00034 MemEraseStore(
00035   IN VARIABLE_STORAGE   *This
00036   );
00037 
00038 EFI_STATUS
00039 EFIAPI
00040 MemWriteStore (
00041   IN VARIABLE_STORAGE   *This,
00042   IN UINTN                Offset,
00043   IN UINTN                BufferSize,
00044   IN VOID                 *Buffer
00045   );
00046 
00047 EFI_STATUS
00048 MemStorageConstructor (
00049   OUT VARIABLE_STORAGE          **VarStore,
00050   OUT EFI_EVENT_NOTIFY          *GoVirtualEvent,
00051   IN  UINTN                     Size
00052   )
00053 {
00054   EFI_STATUS                  Status;
00055   VS_DEV                      *Dev;
00056 
00057   Status = gBS->AllocatePool (EfiRuntimeServicesData, sizeof(VS_DEV), (VOID **) &Dev);
00058   ASSERT_EFI_ERROR (Status);
00059 
00060   ZeroMem (Dev, sizeof(VS_DEV));
00061 
00062   Dev->Signature   = VS_DEV_SIGNATURE;
00063   Dev->Size        = Size;
00064 
00065   Dev->VarStore.Erase    = MemEraseStore;
00066   Dev->VarStore.Write    = MemWriteStore;
00067 
00068   Status = gBS->AllocatePool (EfiRuntimeServicesData, Size, (VOID **) &VAR_DATA_PTR (Dev));
00069   ASSERT_EFI_ERROR (Status);
00070 
00071   DEBUG ((EFI_D_ERROR, "VStorage: Size = 0x%x\n", Size));
00072   
00073   *VarStore       = &Dev->VarStore;
00074   *GoVirtualEvent = OnVirtualAddressChangeMs;
00075 
00076   return EFI_SUCCESS;
00077 }
00078 
00079 VOID
00080 EFIAPI
00081 OnVirtualAddressChangeMs (
00082   IN EFI_EVENT            Event,
00083   IN VOID                 *Context
00084   )
00085 {
00086   VS_DEV                  *Dev;
00087 
00088   Dev = DEV_FROM_THIS (Context);
00089 
00090   EfiConvertPointer (0, (VOID **)&VAR_DATA_PTR (Dev));
00091   EfiConvertPointer (0, (VOID **)&Dev->VarStore.Erase);
00092   EfiConvertPointer (0, (VOID **)&Dev->VarStore.Write);
00093 }
00094 
00095 EFI_STATUS
00096 EFIAPI
00097 MemEraseStore(
00098   IN VARIABLE_STORAGE   *This
00099   )
00100 {
00101   VS_DEV              *Dev;
00102 
00103   Dev = DEV_FROM_THIS(This);
00104   SetMem (VAR_DATA_PTR (Dev), Dev->Size, VAR_DEFAULT_VALUE);
00105   return EFI_SUCCESS;
00106 }
00107 
00108 
00109 EFI_STATUS
00110 EFIAPI
00111 MemWriteStore (
00112   IN VARIABLE_STORAGE     *This,
00113   IN UINTN                Offset,
00114   IN UINTN                BufferSize,
00115   IN VOID                 *UserBuffer
00116   )
00117 {
00118   VS_DEV              *Dev;
00119 
00120   Dev = DEV_FROM_THIS(This);
00121 
00122   ASSERT (Offset + BufferSize < Dev->Size);
00123 
00124   // For better performance
00125   if (VAR_DATA_PTR (Dev) + Offset != UserBuffer) {
00126     CopyMem (VAR_DATA_PTR (Dev) + Offset, UserBuffer, BufferSize);
00127   }
00128   return EFI_SUCCESS;
00129 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines