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