Debian Codegraph @

simulator/ms-tpm-20-ref/Samples/Google/PlatformData.h

raw
1 /* Microsoft Reference Implementation for TPM 2.0
2 *
3 * The copyright in this software is being made available under the BSD
4 * License, included below. This software may be subject to other third party
5 * and contributor rights, including patent rights, and no such rights are
6 * granted 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
15 * modification, are permitted provided that the following conditions are met:
16 *
17 * Redistributions of source code must retain the above copyright notice, this
18 * list of conditions and the following disclaimer.
19 *
20 * Redistributions in binary form must reproduce the above copyright notice,
21 * this list of conditions and the following disclaimer in the documentation
22 * and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS
25 * IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
31 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 #include <stdbool.h>
43 #include <stdint.h>
44
45 #include "TpmProfile.h" // For NV_MEMORY_SIZE
46
47 typedef uint64_t clock64_t;
48 // This is the value returned the last time that the system clock was read. This
49 // is only relevant for a simulator or virtual TPM.
50 extern clock64_t s_realTimePrevious;
51
52 // These values are used to try to synthesize a long lived version of clock().
53 extern clock64_t s_lastSystemTime;
54 extern clock64_t s_lastReportedTime;
55
56 // This is the rate adjusted value that is the equivalent of what would be read
57 // from a hardware register that produced rate adjusted time.
58 extern clock64_t s_tpmTime;
59
60 // This value indicates that the timer was reset
61 extern bool s_timerReset;
62 // This variable records the timer adjustment factor.
63 extern unsigned int s_adjustRate;
64
65 // CLOCK_NOMINAL is the number of hardware ticks per mS. A value of 300000 means
66 // that the nominal clock rate used to drive the hardware clock is 30 MHz. The
67 // adjustment rates are used to determine the conversion of the hardware ticks
68 // to internal hardware clock value. In practice, we would expect that there
69 // would be a hardware register with accumulated mS. It would be incremented by
70 // the output of a prescaler. The prescaler would divide the ticks from the
71 // clock by some value that would compensate for the difference between clock
72 // time and real time. The code in Clock does the emulation of this function.
73 #define CLOCK_NOMINAL 30000
74 // A 1% change in rate is 300 counts
75 #define CLOCK_ADJUST_COARSE 300
76 // A 0.1% change in rate is 30 counts
77 #define CLOCK_ADJUST_MEDIUM 30
78 // A minimum change in rate is 1 count
79 #define CLOCK_ADJUST_FINE 1
80 // The clock tolerance is +/-15% (4500 counts)
81 // Allow some guard band (16.7%)
82 #define CLOCK_ADJUST_LIMIT 5000
83
84 extern unsigned char s_NV[NV_MEMORY_SIZE];
85
86 #endif // _PLATFORM_DATA_H_