summaryrefslogtreecommitdiff
path: root/Silicon/BroxtonSoC/BroxtonSiPkg/Include/VariableNvmStorageFormat.h
blob: 4e372428574b818643c50f92cbdb82728195f0f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/** @file
  This file contains common declarations for Variable Storage data structures.

  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>

  This program and the accompanying materials
  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.

**/

#ifndef _VARIABLE_STORAGE_FORMAT_H_
#define _VARIABLE_STORAGE_FORMAT_H_

#define VARIABLE_NVM_STORE_REVISION_1_0   0x1

#define NVM_HEADER_ALIGNMENT  4
#define NVM_HEADER_ALIGN(a)   (((UINTN) (a) + NVM_HEADER_ALIGNMENT - 1) & (~(UINTN)(NVM_HEADER_ALIGNMENT - 1)))

//
// Calculates the minimal pad bytes needed to make the current pad size satisfy the alignment requirement.
//
#define NVM_GET_PAD_SIZE(a)    (((~a) + 1) & (NVM_HEADER_ALIGNMENT - 1)) ///< Bytes for alignment padding higher in memory
#define NVM_GET_PAD_SIZE_N(a)  (((~a) - 1) & (NVM_HEADER_ALIGNMENT - 1)) ///< Bytes for alignment padding lower in memory

#pragma pack (push, 1)

//
// Variable Store Header
//
// This table is at the beginning of every variable store.
//
typedef struct {
  EFI_GUID  Signature;                   ///< Signature to identify this table
  UINT32    Size;                        ///< Length in bytes of this entire header
  UINT8     Revision;                    ///< Revision of this header
  UINT8     Checksum;                    ///< Checksum of this header
  UINT8     Format;                      ///< Format of the variable store
  UINT8     State;                       ///< Indicates the current state of the variable store
  UINT32    VariableDataTotalLength;     ///< Length in bytes of all variable data in this store
  UINT32    VariableHeaderTotalEntries;  ///< Total number of variable headers in this store
  UINT32    VariableHeaderTotalLength;   ///< Length in bytes of all variable headers in this store
  UINT32    VariableHeaderOffset;        ///< Offset, in bytes, from the beginning of this header
                                         ///< to the first variable header
} VARIABLE_NVM_STORE_HEADER;

//
// Variable Header
//
// This header maintains all meta data associated with a variable.
//
typedef struct {
  UINT16      StartId;     ///< Variable data section start identifier
  UINT8       Reserved;    ///< Reserved field
  UINT8       State;       ///< State of the variable
  UINT32      Attributes;  ///< Variable attributes
  UINT32      NameSize;    ///< Length in bytes of the variable name string
  UINT32      DataSize;    ///< Length in bytes of the variable data region
  UINT32      DataOffset;  ///< Offset in bytes from the beginning of this
                           ///< structure to the corresponding data section
  EFI_GUID    VendorGuid;  ///< Unique identifier for the variable vendor
} VARIABLE_NVM_HEADER;

//
// Authenticated Variable Header
//
typedef struct {
  UINT16      StartId;         ///< Variable data section start identifier
  UINT8       Reserved;        ///< Reserved field
  UINT8       State;           ///< State of the variable
  UINT32      Attributes;      ///< Variable attributes
  UINT32      NameSize;        ///< Length in bytes of the variable name string
  UINT32      DataSize;        ///< Length in bytes of the variable data region
  UINT32      DataOffset;      ///< Offset in bytes from the beginning of this
                               ///< structure to the corresponding data section
  EFI_GUID    VendorGuid;      ///< Unique identifier for the variable vendor
  UINT64      MonotonicCount;  ///< Associated monotonic count value to protect against replay attack
  EFI_TIME    TimeStamp;       ///< Associated TimeStamp value to protect against replay attack
  UINT32      PubKeyIndex;     ///< Index of associated public key in database
} AUTHENTICATED_VARIABLE_NVM_HEADER;

//
// Variable Index Table
//
// This table tracks distance between variable headers.
//
typedef struct {
  UINT16               Length;       ///< Length of the index table
  UINT16               GoneThrough;  ///< Entries gone through when searching
  VARIABLE_NVM_HEADER  *EndPtr;      ///< Last variable in the variable header region
  VARIABLE_NVM_HEADER  *StartPtr;    ///< First variable in the variable header region
  //
  // This field is used to store the distance
  // of two neighboring VAR_ADDED type variables.
  // The meaning of this field is implementation-
  // dependent.
  //
} VARIABLE_NVM_INDEX_TABLE;

//
// Variable Store Info
//
// Associates an index table with a corresponding variable store.
//
typedef struct {
  VARIABLE_NVM_STORE_HEADER  *VariableStoreHeader;  ///< Header for the NVM variable store
  VARIABLE_NVM_INDEX_TABLE   *IndexTable;           ///< Pointer to the variable header region index table
  BOOLEAN                    AuthFlag;              ///< Indicates if the store contains authenticated variables
} VARIABLE_NVM_STORE_INFO;

//
// Variable Pointer Tracking Structure
//
// This structure is used to track variable header pointers and information.
//
typedef struct {
  VARIABLE_NVM_HEADER        *CurrPtr;
  VARIABLE_NVM_HEADER        *StartPtr;
  VARIABLE_NVM_HEADER        *EndPtr;
  VARIABLE_NVM_HEADER        *InDeletedTransitionPtr;
} VARIABLE_NVM_POINTER_TRACK;

#pragma pack (pop)

#endif