xref: /aosp_15_r20/external/ms-tpm-20-ref/TPMCmd/Platform/src/PowerPlat.c (revision 5c591343844d1f9da7da26467c4bf7efc8a7a413)
1*5c591343SA. Cody Schuffelen /* Microsoft Reference Implementation for TPM 2.0
2*5c591343SA. Cody Schuffelen  *
3*5c591343SA. Cody Schuffelen  *  The copyright in this software is being made available under the BSD License,
4*5c591343SA. Cody Schuffelen  *  included below. This software may be subject to other third party and
5*5c591343SA. Cody Schuffelen  *  contributor rights, including patent rights, and no such rights are granted
6*5c591343SA. Cody Schuffelen  *  under this license.
7*5c591343SA. Cody Schuffelen  *
8*5c591343SA. Cody Schuffelen  *  Copyright (c) Microsoft Corporation
9*5c591343SA. Cody Schuffelen  *
10*5c591343SA. Cody Schuffelen  *  All rights reserved.
11*5c591343SA. Cody Schuffelen  *
12*5c591343SA. Cody Schuffelen  *  BSD License
13*5c591343SA. Cody Schuffelen  *
14*5c591343SA. Cody Schuffelen  *  Redistribution and use in source and binary forms, with or without modification,
15*5c591343SA. Cody Schuffelen  *  are permitted provided that the following conditions are met:
16*5c591343SA. Cody Schuffelen  *
17*5c591343SA. Cody Schuffelen  *  Redistributions of source code must retain the above copyright notice, this list
18*5c591343SA. Cody Schuffelen  *  of conditions and the following disclaimer.
19*5c591343SA. Cody Schuffelen  *
20*5c591343SA. Cody Schuffelen  *  Redistributions in binary form must reproduce the above copyright notice, this
21*5c591343SA. Cody Schuffelen  *  list of conditions and the following disclaimer in the documentation and/or
22*5c591343SA. Cody Schuffelen  *  other materials provided with the distribution.
23*5c591343SA. Cody Schuffelen  *
24*5c591343SA. Cody Schuffelen  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
25*5c591343SA. Cody Schuffelen  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26*5c591343SA. Cody Schuffelen  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27*5c591343SA. Cody Schuffelen  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28*5c591343SA. Cody Schuffelen  *  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29*5c591343SA. Cody Schuffelen  *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30*5c591343SA. Cody Schuffelen  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31*5c591343SA. Cody Schuffelen  *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32*5c591343SA. Cody Schuffelen  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33*5c591343SA. Cody Schuffelen  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34*5c591343SA. Cody Schuffelen  */
35*5c591343SA. Cody Schuffelen //** Includes and Function Prototypes
36*5c591343SA. Cody Schuffelen 
37*5c591343SA. Cody Schuffelen #include    "Platform.h"
38*5c591343SA. Cody Schuffelen #include    "_TPM_Init_fp.h"
39*5c591343SA. Cody Schuffelen 
40*5c591343SA. Cody Schuffelen //** Functions
41*5c591343SA. Cody Schuffelen 
42*5c591343SA. Cody Schuffelen //***_plat__Signal_PowerOn()
43*5c591343SA. Cody Schuffelen // Signal platform power on
44*5c591343SA. Cody Schuffelen LIB_EXPORT int
_plat__Signal_PowerOn(void)45*5c591343SA. Cody Schuffelen _plat__Signal_PowerOn(
46*5c591343SA. Cody Schuffelen     void
47*5c591343SA. Cody Schuffelen     )
48*5c591343SA. Cody Schuffelen {
49*5c591343SA. Cody Schuffelen     // Reset the timer
50*5c591343SA. Cody Schuffelen     _plat__TimerReset();
51*5c591343SA. Cody Schuffelen 
52*5c591343SA. Cody Schuffelen    // Need to indicate that we lost power
53*5c591343SA. Cody Schuffelen     s_powerLost = TRUE;
54*5c591343SA. Cody Schuffelen 
55*5c591343SA. Cody Schuffelen     return 0;
56*5c591343SA. Cody Schuffelen }
57*5c591343SA. Cody Schuffelen 
58*5c591343SA. Cody Schuffelen //*** _plat__WasPowerLost()
59*5c591343SA. Cody Schuffelen // Test whether power was lost before a _TPM_Init.
60*5c591343SA. Cody Schuffelen //
61*5c591343SA. Cody Schuffelen // This function will clear the "hardware" indication of power loss before return.
62*5c591343SA. Cody Schuffelen // This means that there can only be one spot in the TPM code where this value
63*5c591343SA. Cody Schuffelen // gets read. This method is used here as it is the most difficult to manage in the
64*5c591343SA. Cody Schuffelen // TPM code and, if the hardware actually works this way, it is hard to make it
65*5c591343SA. Cody Schuffelen // look like anything else. So, the burden is placed on the TPM code rather than the
66*5c591343SA. Cody Schuffelen // platform code
67*5c591343SA. Cody Schuffelen //  Return Type: int
68*5c591343SA. Cody Schuffelen //      TRUE(1)         power was lost
69*5c591343SA. Cody Schuffelen //      FALSE(0)        power was not lost
70*5c591343SA. Cody Schuffelen LIB_EXPORT int
_plat__WasPowerLost(void)71*5c591343SA. Cody Schuffelen _plat__WasPowerLost(
72*5c591343SA. Cody Schuffelen     void
73*5c591343SA. Cody Schuffelen     )
74*5c591343SA. Cody Schuffelen {
75*5c591343SA. Cody Schuffelen     int         retVal = s_powerLost;
76*5c591343SA. Cody Schuffelen     s_powerLost = FALSE;
77*5c591343SA. Cody Schuffelen     return retVal;
78*5c591343SA. Cody Schuffelen }
79*5c591343SA. Cody Schuffelen 
80*5c591343SA. Cody Schuffelen //*** _plat_Signal_Reset()
81*5c591343SA. Cody Schuffelen // This a TPM reset without a power loss.
82*5c591343SA. Cody Schuffelen LIB_EXPORT int
_plat__Signal_Reset(void)83*5c591343SA. Cody Schuffelen _plat__Signal_Reset(
84*5c591343SA. Cody Schuffelen     void
85*5c591343SA. Cody Schuffelen     )
86*5c591343SA. Cody Schuffelen {
87*5c591343SA. Cody Schuffelen     // Initialize locality
88*5c591343SA. Cody Schuffelen     s_locality = 0;
89*5c591343SA. Cody Schuffelen 
90*5c591343SA. Cody Schuffelen     // Command cancel
91*5c591343SA. Cody Schuffelen     s_isCanceled = FALSE;
92*5c591343SA. Cody Schuffelen 
93*5c591343SA. Cody Schuffelen     _TPM_Init();
94*5c591343SA. Cody Schuffelen 
95*5c591343SA. Cody Schuffelen     // if we are doing reset but did not have a power failure, then we should
96*5c591343SA. Cody Schuffelen     // not need to reload NV ...
97*5c591343SA. Cody Schuffelen 
98*5c591343SA. Cody Schuffelen     return 0;
99*5c591343SA. Cody Schuffelen }
100*5c591343SA. Cody Schuffelen 
101*5c591343SA. Cody Schuffelen //***_plat__Signal_PowerOff()
102*5c591343SA. Cody Schuffelen // Signal platform power off
103*5c591343SA. Cody Schuffelen LIB_EXPORT void
_plat__Signal_PowerOff(void)104*5c591343SA. Cody Schuffelen _plat__Signal_PowerOff(
105*5c591343SA. Cody Schuffelen     void
106*5c591343SA. Cody Schuffelen     )
107*5c591343SA. Cody Schuffelen {
108*5c591343SA. Cody Schuffelen     // Prepare NV memory for power off
109*5c591343SA. Cody Schuffelen     _plat__NVDisable(0);
110*5c591343SA. Cody Schuffelen 
111*5c591343SA. Cody Schuffelen     // Disable tick ACT tick processing
112*5c591343SA. Cody Schuffelen     _plat__ACT_EnableTicks(FALSE);
113*5c591343SA. Cody Schuffelen 
114*5c591343SA. Cody Schuffelen     return;
115*5c591343SA. Cody Schuffelen }