3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
24 #include <Protocol/VariableWrite.h>
25 #include <Protocol/FaultTolerantWriteLite.h>
26 #include <Protocol/FirmwareVolumeBlock.h>
27 #include <Protocol/Variable.h>
28 #include <Library/PcdLib.h>
29 #include <Library/UefiDriverEntryPoint.h>
30 #include <Library/DxeServicesTableLib.h>
31 #include <Library/UefiRuntimeLib.h>
32 #include <Library/DebugLib.h>
33 #include <Library/BaseMemoryLib.h>
34 #include <Library/FvbServiceLib.h>
35 #include <Library/UefiBootServicesTableLib.h>
36 #include <Library/UefiLib.h>
37 #include <Library/BaseLib.h>
38 #include <Library/MemoryAllocationLib.h>
39 #include <Library/HobLib.h>
40 #include <Guid/VariableInfo.h>
41 #include <Guid/GlobalVariable.h>
42 #include <VariableFormat.h>
46 #define VARIABLE_RECLAIM_THRESHOLD (1024)
48 #define VARIABLE_STORE_SIZE FixedPcdGet32(PcdVariableStoreSize)
49 #define SCRATCH_SIZE FixedPcdGet32(PcdMaxVariableSize)
52 // Define GET_PAD_SIZE to optimize compiler
54 #if ((ALIGNMENT == 0) || (ALIGNMENT == 1))
55 #define GET_PAD_SIZE(a) (0)
57 #define GET_PAD_SIZE(a) (((~a) + 1) & (ALIGNMENT - 1))
60 #define HEADER_ALIGN(Header) (((UINTN) (Header) + HEADER_ALIGNMENT - 1) & (~(HEADER_ALIGNMENT - 1)))
62 #define NAMESIZE_OF_VARIABLE(Variable) \
63 ((((Variable)->DataSize == (UINT32) -1) || \
64 ((Variable)->Attributes == (UINT32) -1) || \
65 ((Variable)->NameSize == (UINT32) -1)) ? \
67 (Variable)->NameSize \
70 #define DATASIZE_OF_VARIABLE(Variable) \
71 ((((Variable)->DataSize == (UINT32) -1) || \
72 ((Variable)->Attributes == (UINT32) -1) || \
73 ((Variable)->NameSize == (UINT32) -1)) ? \
75 (Variable)->DataSize \
78 #define GET_VARIABLE_NAME_PTR(a) (CHAR16 *) ((UINTN) (a) + sizeof (VARIABLE_HEADER))
82 VARIABLE_HEADER
*CurrPtr
;
83 VARIABLE_HEADER
*EndPtr
;
84 VARIABLE_HEADER
*StartPtr
;
86 } VARIABLE_POINTER_TRACK
;
89 EFI_PHYSICAL_ADDRESS VolatileVariableBase
;
90 EFI_PHYSICAL_ADDRESS NonVolatileVariableBase
;
91 EFI_LOCK VariableServicesLock
;
92 UINT32 ReentrantState
;
96 VARIABLE_GLOBAL VariableGlobal
;
97 UINTN VolatileLastVariableOffset
;
98 UINTN NonVolatileLastVariableOffset
;
100 } VARIABLE_MODULE_GLOBAL
;
108 } VARIABLE_CACHE_ENTRY
;
117 VariableServiceInitialize (
118 IN EFI_HANDLE ImageHandle
,
119 IN EFI_SYSTEM_TABLE
*SystemTable
125 IN EFI_PHYSICAL_ADDRESS VariableBaseAddress
,