• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 other
22  *  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 
36 // This file contains the instance data for the Platform module. It is collected
37 // in this file so that the state of the module is easier to manage.
38 
39 #ifndef _PLATFORM_DATA_H_
40 #define _PLATFORM_DATA_H_
41 
42 
43 #include      "Implementation.h"
44 
45 // From Cancel.c
46 // Cancel flag.  It is initialized as FALSE, which indicate the command is not
47 // being canceled
48 extern int     s_isCanceled;
49 
50 #include    <time.h>
51 
52 #ifndef HARDWARE_CLOCK
53 // This is the value returned the last time that the system clock was read. This
54 // is only relevant for a simulator or virtual TPM.
55 extern clock_t        s_realTimePrevious;
56 // This is the rate adjusted value that is the equivalent of what would be read from
57 // a hardware register that produced rate adjusted time.
58 extern clock_t        s_tpmTime;
59 #endif // HARDWARE_CLOCK
60 
61 // This value indicates that the timer was reset
62 extern BOOL              s_timerReset;
63 // This value indicates that the timer was stopped. It causes a clock discontinuity.
64 extern BOOL              s_timerStopped;
65 
66 // CLOCK_NOMINAL is the number of hardware ticks per mS. A value of 300000 means
67 // that the nominal clock rate used to drive the hardware clock is 30 MHz. The
68 // adjustment rates are used to determine the conversion of the hardware ticks to
69 // internal hardware clock value. In practice, we would expect that there woudl be
70 // a hardware register will accumulated mS. It would be incremented by the output
71 // of a pre-scaler. The pre-scaler would divide the ticks from the clock by some
72 // value that would compensate for the difference between clock time and real time.
73 // The code in Clock does the emulation of this function.
74 #define     CLOCK_NOMINAL           30000
75 // A 1% change in rate is 300 counts
76 #define     CLOCK_ADJUST_COARSE     300
77 // A 0.1% change in rate is 30 counts
78 #define     CLOCK_ADJUST_MEDIUM     30
79 // A minimum change in rate is 1 count
80 #define     CLOCK_ADJUST_FINE       1
81 // The clock tolerance is +/-15% (4500 counts)
82 // Allow some guard band (16.7%)
83 #define     CLOCK_ADJUST_LIMIT      5000
84 
85 // This variable records the time when _plat__TimerReset is called.  This mechanism
86 // allow us to subtract the time when TPM is power off from the total
87 // time reported by clock() function
88 extern uint64_t        s_initClock;
89 
90 // This variable records the timer adjustment factor.
91 extern unsigned int         s_adjustRate;
92 
93 // From LocalityPlat.c
94 // Locality of current command
95 extern unsigned char s_locality;
96 
97 // From NVMem.c
98 // Choose if the NV memory should be backed by RAM or by file.
99 // If this macro is defined, then a file is used as NV.  If it is not defined,
100 // then RAM is used to back NV memory. Comment out to use RAM.
101 #define FILE_BACKED_NV
102 #if defined FILE_BACKED_NV
103 #include <stdio.h>
104 // A file to emulate NV storage
105 extern FILE*             s_NVFile;
106 #endif
107 extern unsigned char     s_NV[NV_MEMORY_SIZE];
108 extern BOOL              s_NvIsAvailable;
109 extern BOOL              s_NV_unrecoverable;
110 extern BOOL              s_NV_recoverable;
111 
112 
113 // From PPPlat.c
114 // Physical presence.  It is initialized to FALSE
115 extern BOOL     s_physicalPresence;
116 
117 // From Power
118 extern BOOL        s_powerLost;
119 
120 // From Entropy.c
121 extern uint32_t        lastEntropy;
122 
123 extern int             firstValue;
124 
125 
126 #endif // _PLATFORM_DATA_H_
127