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 //** Includes and Function Prototypes
36
37 #include "Platform.h"
38 #include "_TPM_Init_fp.h"
39
40 //** Functions
41
42 //***_plat__Signal_PowerOn()
43 // Signal platform power on
44 LIB_EXPORT int
_plat__Signal_PowerOn(void)45 _plat__Signal_PowerOn(
46 void
47 )
48 {
49 // Reset the timer
50 _plat__TimerReset();
51
52 // Need to indicate that we lost power
53 s_powerLost = TRUE;
54
55 return 0;
56 }
57
58 //*** _plat__WasPowerLost()
59 // Test whether power was lost before a _TPM_Init.
60 //
61 // This function will clear the "hardware" indication of power loss before return.
62 // This means that there can only be one spot in the TPM code where this value
63 // gets read. This method is used here as it is the most difficult to manage in the
64 // TPM code and, if the hardware actually works this way, it is hard to make it
65 // look like anything else. So, the burden is placed on the TPM code rather than the
66 // platform code
67 // Return Type: int
68 // TRUE(1) power was lost
69 // FALSE(0) power was not lost
70 LIB_EXPORT int
_plat__WasPowerLost(void)71 _plat__WasPowerLost(
72 void
73 )
74 {
75 int retVal = s_powerLost;
76 s_powerLost = FALSE;
77 return retVal;
78 }
79
80 //*** _plat_Signal_Reset()
81 // This a TPM reset without a power loss.
82 LIB_EXPORT int
_plat__Signal_Reset(void)83 _plat__Signal_Reset(
84 void
85 )
86 {
87 // Initialize locality
88 s_locality = 0;
89
90 // Command cancel
91 s_isCanceled = FALSE;
92
93 _TPM_Init();
94
95 // if we are doing reset but did not have a power failure, then we should
96 // not need to reload NV ...
97
98 return 0;
99 }
100
101 //***_plat__Signal_PowerOff()
102 // Signal platform power off
103 LIB_EXPORT void
_plat__Signal_PowerOff(void)104 _plat__Signal_PowerOff(
105 void
106 )
107 {
108 // Prepare NV memory for power off
109 _plat__NVDisable(0);
110
111 // Disable tick ACT tick processing
112 _plat__ACT_EnableTicks(FALSE);
113
114 return;
115 }