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