Home | History | Annotate | Download | only in Guid
      1 /** @file
      2   The variable data structures are related to EDK II-specific implementation of UEFI variables.
      3   VariableFormat.h defines variable data headers and variable storage region headers.
      4 
      5 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
      6 This program and the accompanying materials are licensed and made available under
      7 the terms and conditions of the BSD License that accompanies this distribution.
      8 The full text of the license may be found at
      9 http://opensource.org/licenses/bsd-license.php.
     10 
     11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     13 
     14 **/
     15 
     16 #ifndef __VARIABLE_FORMAT_H__
     17 #define __VARIABLE_FORMAT_H__
     18 
     19 #define EFI_VARIABLE_GUID \
     20   { 0xddcf3616, 0x3275, 0x4164, { 0x98, 0xb6, 0xfe, 0x85, 0x70, 0x7f, 0xfe, 0x7d } }
     21 
     22 #define EFI_AUTHENTICATED_VARIABLE_GUID \
     23   { 0xaaf32c78, 0x947b, 0x439a, { 0xa1, 0x80, 0x2e, 0x14, 0x4e, 0xc3, 0x77, 0x92 } }
     24 
     25 extern EFI_GUID gEfiVariableGuid;
     26 extern EFI_GUID gEfiAuthenticatedVariableGuid;
     27 
     28 ///
     29 /// Alignment of variable name and data, according to the architecture:
     30 /// * For IA-32 and Intel(R) 64 architectures: 1.
     31 /// * For IA-64 architecture: 8.
     32 ///
     33 #if defined (MDE_CPU_IPF)
     34 #define ALIGNMENT         8
     35 #else
     36 #define ALIGNMENT         1
     37 #endif
     38 
     39 //
     40 // GET_PAD_SIZE calculates the miminal pad bytes needed to make the current pad size satisfy the alignment requirement.
     41 //
     42 #if (ALIGNMENT == 1)
     43 #define GET_PAD_SIZE(a) (0)
     44 #else
     45 #define GET_PAD_SIZE(a) (((~a) + 1) & (ALIGNMENT - 1))
     46 #endif
     47 
     48 ///
     49 /// Alignment of Variable Data Header in Variable Store region.
     50 ///
     51 #define HEADER_ALIGNMENT  4
     52 #define HEADER_ALIGN(Header)  (((UINTN) (Header) + HEADER_ALIGNMENT - 1) & (~(HEADER_ALIGNMENT - 1)))
     53 
     54 ///
     55 /// Status of Variable Store Region.
     56 ///
     57 typedef enum {
     58   EfiRaw,
     59   EfiValid,
     60   EfiInvalid,
     61   EfiUnknown
     62 } VARIABLE_STORE_STATUS;
     63 
     64 #pragma pack(1)
     65 
     66 #define VARIABLE_STORE_SIGNATURE  EFI_VARIABLE_GUID
     67 #define AUTHENTICATED_VARIABLE_STORE_SIGNATURE  EFI_AUTHENTICATED_VARIABLE_GUID
     68 
     69 ///
     70 /// Variable Store Header Format and State.
     71 ///
     72 #define VARIABLE_STORE_FORMATTED          0x5a
     73 #define VARIABLE_STORE_HEALTHY            0xfe
     74 
     75 ///
     76 /// Variable Store region header.
     77 ///
     78 typedef struct {
     79   ///
     80   /// Variable store region signature.
     81   ///
     82   EFI_GUID  Signature;
     83   ///
     84   /// Size of entire variable store,
     85   /// including size of variable store header but not including the size of FvHeader.
     86   ///
     87   UINT32  Size;
     88   ///
     89   /// Variable region format state.
     90   ///
     91   UINT8   Format;
     92   ///
     93   /// Variable region healthy state.
     94   ///
     95   UINT8   State;
     96   UINT16  Reserved;
     97   UINT32  Reserved1;
     98 } VARIABLE_STORE_HEADER;
     99 
    100 ///
    101 /// Variable data start flag.
    102 ///
    103 #define VARIABLE_DATA                     0x55AA
    104 
    105 ///
    106 /// Variable State flags.
    107 ///
    108 #define VAR_IN_DELETED_TRANSITION     0xfe  ///< Variable is in obsolete transition.
    109 #define VAR_DELETED                   0xfd  ///< Variable is obsolete.
    110 #define VAR_HEADER_VALID_ONLY         0x7f  ///< Variable header has been valid.
    111 #define VAR_ADDED                     0x3f  ///< Variable has been completely added.
    112 
    113 ///
    114 /// Variable Attribute combinations.
    115 ///
    116 #define VARIABLE_ATTRIBUTE_NV_BS        (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS)
    117 #define VARIABLE_ATTRIBUTE_BS_RT        (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS)
    118 #define VARIABLE_ATTRIBUTE_AT_AW        (EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS)
    119 #define VARIABLE_ATTRIBUTE_NV_BS_RT     (VARIABLE_ATTRIBUTE_BS_RT | EFI_VARIABLE_NON_VOLATILE)
    120 #define VARIABLE_ATTRIBUTE_NV_BS_RT_HR  (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_HARDWARE_ERROR_RECORD)
    121 #define VARIABLE_ATTRIBUTE_NV_BS_RT_AT  (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)
    122 #define VARIABLE_ATTRIBUTE_NV_BS_RT_AW  (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS)
    123 #define VARIABLE_ATTRIBUTE_NV_BS_RT_HR_AT_AW    (VARIABLE_ATTRIBUTE_NV_BS_RT_HR | VARIABLE_ATTRIBUTE_AT_AW)
    124 
    125 ///
    126 /// Single Variable Data Header Structure.
    127 ///
    128 typedef struct {
    129   ///
    130   /// Variable Data Start Flag.
    131   ///
    132   UINT16      StartId;
    133   ///
    134   /// Variable State defined above.
    135   ///
    136   UINT8       State;
    137   UINT8       Reserved;
    138   ///
    139   /// Attributes of variable defined in UEFI specification.
    140   ///
    141   UINT32      Attributes;
    142   ///
    143   /// Size of variable null-terminated Unicode string name.
    144   ///
    145   UINT32      NameSize;
    146   ///
    147   /// Size of the variable data without this header.
    148   ///
    149   UINT32      DataSize;
    150   ///
    151   /// A unique identifier for the vendor that produces and consumes this varaible.
    152   ///
    153   EFI_GUID    VendorGuid;
    154 } VARIABLE_HEADER;
    155 
    156 ///
    157 /// Single Authenticated Variable Data Header Structure.
    158 ///
    159 typedef struct {
    160   ///
    161   /// Variable Data Start Flag.
    162   ///
    163   UINT16      StartId;
    164   ///
    165   /// Variable State defined above.
    166   ///
    167   UINT8       State;
    168   UINT8       Reserved;
    169   ///
    170   /// Attributes of variable defined in UEFI specification.
    171   ///
    172   UINT32      Attributes;
    173   ///
    174   /// Associated monotonic count value against replay attack.
    175   ///
    176   UINT64      MonotonicCount;
    177   ///
    178   /// Associated TimeStamp value against replay attack.
    179   ///
    180   EFI_TIME    TimeStamp;
    181   ///
    182   /// Index of associated public key in database.
    183   ///
    184   UINT32      PubKeyIndex;
    185   ///
    186   /// Size of variable null-terminated Unicode string name.
    187   ///
    188   UINT32      NameSize;
    189   ///
    190   /// Size of the variable data without this header.
    191   ///
    192   UINT32      DataSize;
    193   ///
    194   /// A unique identifier for the vendor that produces and consumes this varaible.
    195   ///
    196   EFI_GUID    VendorGuid;
    197 } AUTHENTICATED_VARIABLE_HEADER;
    198 
    199 typedef struct {
    200   EFI_GUID    *Guid;
    201   CHAR16      *Name;
    202   UINTN       VariableSize;
    203 } VARIABLE_ENTRY_CONSISTENCY;
    204 
    205 #pragma pack()
    206 
    207 typedef struct _VARIABLE_INFO_ENTRY  VARIABLE_INFO_ENTRY;
    208 
    209 ///
    210 /// This structure contains the variable list that is put in EFI system table.
    211 /// The variable driver collects all variables that were used at boot service time and produces this list.
    212 /// This is an optional feature to dump all used variables in shell environment.
    213 ///
    214 struct _VARIABLE_INFO_ENTRY {
    215   VARIABLE_INFO_ENTRY *Next;       ///< Pointer to next entry.
    216   EFI_GUID            VendorGuid;  ///< Guid of Variable.
    217   CHAR16              *Name;       ///< Name of Variable.
    218   UINT32              Attributes;  ///< Attributes of variable defined in UEFI specification.
    219   UINT32              ReadCount;   ///< Number of times to read this variable.
    220   UINT32              WriteCount;  ///< Number of times to write this variable.
    221   UINT32              DeleteCount; ///< Number of times to delete this variable.
    222   UINT32              CacheCount;  ///< Number of times that cache hits this variable.
    223   BOOLEAN             Volatile;    ///< TRUE if volatile, FALSE if non-volatile.
    224 };
    225 
    226 #endif // _EFI_VARIABLE_H_
    227