xref: /aosp_15_r20/external/ms-tpm-20-ref/TPMCmd/Platform/include/PlatformData.h (revision 5c591343844d1f9da7da26467c4bf7efc8a7a413)
1 /* Microsoft Reference Implementation for TPM 2.0
2  *
3  *  The copyright in this software is being made available under the BSD License,
4  *  included below. This software may be subject to other third party and
5  *  contributor rights, including patent rights, and no such rights are granted
6  *  under this license.
7  *
8  *  Copyright (c) Microsoft Corporation
9  *
10  *  All rights reserved.
11  *
12  *  BSD License
13  *
14  *  Redistribution and use in source and binary forms, with or without modification,
15  *  are permitted provided that the following conditions are met:
16  *
17  *  Redistributions of source code must retain the above copyright notice, this list
18  *  of conditions and the following disclaimer.
19  *
20  *  Redistributions in binary form must reproduce the above copyright notice, this
21  *  list of conditions and the following disclaimer in the documentation and/or
22  *  other materials provided with the distribution.
23  *
24  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
25  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28  *  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31  *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 // This file contains the instance data for the Platform module. It is collected
36 // in this file so that the state of the module is easier to manage.
37 
38 #ifndef _PLATFORM_DATA_H_
39 #define _PLATFORM_DATA_H_
40 
41 #ifdef  _PLATFORM_DATA_C_
42 #define EXTERN
43 #else
44 #define EXTERN  extern
45 #endif
46 
47 // From Cancel.c
48 // Cancel flag.  It is initialized as FALSE, which indicate the command is not
49 // being canceled
50 EXTERN int     s_isCanceled;
51 
52 #ifndef HARDWARE_CLOCK
53 typedef uint64_t     clock64_t;
54 // This is the value returned the last time that the system clock was read. This
55 // is only relevant for a simulator or virtual TPM.
56 EXTERN clock64_t       s_realTimePrevious;
57 
58 // These values are used to try to synthesize a long lived version of clock().
59 EXTERN clock64_t        s_lastSystemTime;
60 EXTERN clock64_t        s_lastReportedTime;
61 
62 // This is the rate adjusted value that is the equivalent of what would be read from
63 // a hardware register that produced rate adjusted time.
64 EXTERN clock64_t        s_tpmTime;
65 #endif // HARDWARE_CLOCK
66 
67 // This value indicates that the timer was reset
68 EXTERN int               s_timerReset;
69 // This value indicates that the timer was stopped. It causes a clock discontinuity.
70 EXTERN int               s_timerStopped;
71 
72 // This variable records the time when _plat__TimerReset is called.  This mechanism
73 // allow us to subtract the time when TPM is power off from the total
74 // time reported by clock() function
75 EXTERN uint64_t        s_initClock;
76 
77 // This variable records the timer adjustment factor.
78 EXTERN unsigned int         s_adjustRate;
79 
80 // For LocalityPlat.c
81 // Locality of current command
82 EXTERN unsigned char s_locality;
83 
84 // For NVMem.c
85 // Choose if the NV memory should be backed by RAM or by file.
86 // If this macro is defined, then a file is used as NV.  If it is not defined,
87 // then RAM is used to back NV memory. Comment out to use RAM.
88 
89 #if (!defined VTPM) || ((VTPM != NO) && (VTPM != YES))
90 #   undef VTPM
91 #   define      VTPM            YES                 // Default: Either YES or NO
92 #endif
93 
94 // For a simulation, use a file to back up the NV
95 #if (!defined FILE_BACKED_NV) || ((FILE_BACKED_NV != NO) && (FILE_BACKED_NV != YES))
96 #   undef   FILE_BACKED_NV
97 #   define  FILE_BACKED_NV          (VTPM && YES)     // Default: Either YES or NO
98 #endif
99 
100 #if SIMULATION
101 #   undef       FILE_BACKED_NV
102 #   define      FILE_BACKED_NV          YES
103 #endif // SIMULATION
104 
105 EXTERN unsigned char     s_NV[NV_MEMORY_SIZE];
106 EXTERN int               s_NvIsAvailable;
107 EXTERN int               s_NV_unrecoverable;
108 EXTERN int               s_NV_recoverable;
109 
110 // For PPPlat.c
111 // Physical presence.  It is initialized to FALSE
112 EXTERN int              s_physicalPresence;
113 
114 // From Power
115 EXTERN int              s_powerLost;
116 
117 // For Entropy.c
118 EXTERN uint32_t         lastEntropy;
119 
120 #define DEFINE_ACT(N)   EXTERN ACT_DATA ACT_##N;
121     FOR_EACH_ACT(DEFINE_ACT)
122 
123 EXTERN int              actTicksAllowed;
124 
125 #endif // _PLATFORM_DATA_H_
126