Coverage Report

Created: 2025-11-24 06:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ibmswtpm2/src/PowerPlat.c
Line
Count
Source
1
/********************************************************************************/
2
/*                    */
3
/*                  */
4
/*           Written by Ken Goldman       */
5
/*           IBM Thomas J. Watson Research Center     */
6
/*            $Id: PowerPlat.c 809 2016-11-16 18:31:54Z kgoldman $      */
7
/*                    */
8
/*  Licenses and Notices              */
9
/*                    */
10
/*  1. Copyright Licenses:              */
11
/*                    */
12
/*  - Trusted Computing Group (TCG) grants to the user of the source code in  */
13
/*    this specification (the "Source Code") a worldwide, irrevocable,    */
14
/*    nonexclusive, royalty free, copyright license to reproduce, create  */
15
/*    derivative works, distribute, display and perform the Source Code and */
16
/*    derivative works thereof, and to grant others the rights granted herein.  */
17
/*                    */
18
/*  - The TCG grants to the user of the other parts of the specification  */
19
/*    (other than the Source Code) the rights to reproduce, distribute,   */
20
/*    display, and perform the specification solely for the purpose of    */
21
/*    developing products based on such documents.        */
22
/*                    */
23
/*  2. Source Code Distribution Conditions:         */
24
/*                    */
25
/*  - Redistributions of Source Code must retain the above copyright licenses,  */
26
/*    this list of conditions and the following disclaimers.      */
27
/*                    */
28
/*  - Redistributions in binary form must reproduce the above copyright   */
29
/*    licenses, this list of conditions and the following disclaimers in the  */
30
/*    documentation and/or other materials provided with the distribution.  */
31
/*                    */
32
/*  3. Disclaimers:               */
33
/*                    */
34
/*  - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */
35
/*  LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */
36
/*  RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */
37
/*  THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE.   */
38
/*  Contact TCG Administration (admin@trustedcomputinggroup.org) for    */
39
/*  information on specification licensing rights available through TCG   */
40
/*  membership agreements.              */
41
/*                    */
42
/*  - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED   */
43
/*    WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR   */
44
/*    FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR    */
45
/*    NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY    */
46
/*    OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE.   */
47
/*                    */
48
/*  - Without limitation, TCG and its members and licensors disclaim all  */
49
/*    liability, including liability for infringement of any proprietary  */
50
/*    rights, relating to use of information in this specification and to the */
51
/*    implementation of this specification, and TCG disclaims all liability for */
52
/*    cost of procurement of substitute goods or services, lost profits, loss   */
53
/*    of use, loss of data or any incidental, consequential, direct, indirect,  */
54
/*    or special damages, whether under contract, tort, warranty or otherwise,  */
55
/*    arising in any way out of use or reliance upon this specification or any  */
56
/*    information herein.             */
57
/*                    */
58
/*  (c) Copyright IBM Corp. and others, 2016          */
59
/*                    */
60
/********************************************************************************/
61
62
/* C.7 PowerPlat.c */
63
/* C.7.1. Includes and Function Prototypes */
64
#include    "PlatformData.h"
65
#include    "Platform_fp.h"
66
#include    "_TPM_Init_fp.h"
67
/* C.7.2. Functions */
68
/* C.7.2.1. _plat__Signal_PowerOn() */
69
/* Signal platform power on */
70
LIB_EXPORT int
71
_plat__Signal_PowerOn(
72
          void
73
          )
74
1
{
75
    // Reset the timer
76
1
    _plat__TimerReset();
77
    // Need to indicate that we lost power
78
1
    s_powerLost = TRUE;
79
1
    return 0;
80
1
}
81
/* C.7.2.2. _plat__WasPowerLost() */
82
/* Test whether power was lost before a _TPM_Init(). */
83
/* This function will clear the hardware indication of power loss before return. This means that
84
   there can only be one spot in the TPM code where this value gets read. This method is used here
85
   as it is the most difficult to manage in the TPM code and, if the hardware actually works this
86
   way, it is hard to make it look like anything else. So, the burden is placed on the TPM code
87
   rather than the platform code */
88
/* Return Values Meaning */
89
/* TRUE(1) power was lost */
90
/* FALSE(0) power was not lost */
91
LIB_EXPORT int
92
_plat__WasPowerLost(
93
        void
94
        )
95
1
{
96
1
    BOOL        retVal = s_powerLost;
97
1
    s_powerLost = FALSE;
98
1
    return retVal;
99
1
}
100
/* C.7.2.3. _plat_Signal_Reset() */
101
/* This a TPM reset without a power loss. */
102
LIB_EXPORT int
103
_plat__Signal_Reset(
104
        void
105
        )
106
1
{
107
    // Initialize locality
108
1
    s_locality = 0;
109
    // Command cancel
110
1
    s_isCanceled = FALSE;
111
1
    _TPM_Init();
112
    // if we are doing reset but did not have a power failure, then we should
113
    // not need to reload NV ...
114
1
    return 0;
115
1
}
116
/* C.7.2.4. _plat__Signal_PowerOff() */
117
/* Signal platform power off */
118
LIB_EXPORT void
119
_plat__Signal_PowerOff(
120
           void
121
           )
122
0
{
123
    // Prepare NV memory for power off
124
0
    _plat__NVDisable();
125
0
    return;
126
0
}