1// This file was extracted from the TCG Published
2// Trusted Platform Module Library
3// Part 4: Supporting Routines
4// Family "2.0"
5// Level 00 Revision 01.16
6// October 30, 2014
7
8#ifndef        PLATFORM_H
9#define        PLATFORM_H
10//
11//
12//          Includes and Defines
13//
14#include "bool.h"
15#include "stdint.h"
16#include "TpmError.h"
17#include "TpmBuildSwitches.h"
18#define UNREFERENCED(a) ((void)(a))
19//
20//
21//          Power Functions
22//
23//          _plat__Signal_PowerOn
24//
25//     Signal power on This signal is simulate by a RPC call
26//
27LIB_EXPORT int
28_plat__Signal_PowerOn(void);
29//
30//
31//          _plat__Signal_Reset
32//
33//     Signal reset This signal is simulate by a RPC call
34//
35LIB_EXPORT int
36_plat__Signal_Reset(void);
37//
38//
39//          _plat__WasPowerLost()
40//
41//     Indicates if the power was lost before a _TPM__Init().
42//
43LIB_EXPORT BOOL
44_plat__WasPowerLost(BOOL clear);
45//
46//
47//          _plat__Signal_PowerOff()
48//
49//     Signal power off This signal is simulate by a RPC call
50//
51LIB_EXPORT void
52_plat__Signal_PowerOff(void);
53//
54//
55//          Physical Presence Functions
56//
57//          _plat__PhysicalPresenceAsserted()
58//
59//     Check if physical presence is signaled
60//
61//
62//
63//
64//     Return Value                      Meaning
65//
66//     TRUE                              if physical presence is signaled
67//     FALSE                             if physical presence is not signaled
68//
69LIB_EXPORT BOOL
70_plat__PhysicalPresenceAsserted(void);
71//
72//
73//         _plat__Signal_PhysicalPresenceOn
74//
75//     Signal physical presence on This signal is simulate by a RPC call
76//
77LIB_EXPORT void
78_plat__Signal_PhysicalPresenceOn(void);
79//
80//
81//         _plat__Signal_PhysicalPresenceOff()
82//
83//     Signal physical presence off This signal is simulate by a RPC call
84//
85LIB_EXPORT void
86_plat__Signal_PhysicalPresenceOff(void);
87//
88//
89//          Command Canceling Functions
90//
91//         _plat__IsCanceled()
92//
93//     Check if the cancel flag is set
94//
95//     Return Value                      Meaning
96//
97//     TRUE                              if cancel flag is set
98//     FALSE                             if cancel flag is not set
99//
100LIB_EXPORT BOOL
101_plat__IsCanceled(void);
102//
103//
104//         _plat__SetCancel()
105//
106//     Set cancel flag.
107//
108LIB_EXPORT void
109_plat__SetCancel(void);
110//
111//
112//         _plat__ClearCancel()
113//
114//     Clear cancel flag
115//
116LIB_EXPORT void
117_plat__ClearCancel( void);
118//
119//
120//
121//          NV memory functions
122//
123//         _plat__NvErrors()
124//
125//     This function is used by the simulator to set the error flags in the NV subsystem to simulate an error in the
126//     NV loading process
127//
128LIB_EXPORT void
129_plat__NvErrors(
130    BOOL           recoverable,
131    BOOL           unrecoverable
132    );
133//
134//
135//         _plat__NVEnable()
136//
137//     Enable platform NV memory NV memory is automatically enabled at power on event. This function is
138//     mostly for TPM_Manufacture() to access NV memory without a power on event
139//
140//     Return Value                     Meaning
141//
142//     0                                if success
143//     non-0                            if fail
144//
145LIB_EXPORT int
146_plat__NVEnable(
147    void      *platParameter                       // IN: platform specific parameters
148);
149//
150//
151//         _plat__NVDisable()
152//
153//     Disable platform NV memory NV memory is automatically disabled at power off event. This function is
154//     mostly for TPM_Manufacture() to disable NV memory without a power off event
155//
156LIB_EXPORT void
157_plat__NVDisable(void);
158//
159//
160//         _plat__IsNvAvailable()
161//
162//     Check if NV is available
163//
164//     Return Value                     Meaning
165//
166//     0                                NV is available
167//     1                                NV is not available due to write failure
168//     2                                NV is not available due to rate limit
169//
170LIB_EXPORT int
171_plat__IsNvAvailable(void);
172//
173//
174//         _plat__NvCommit()
175//
176//     Update NV chip
177//
178//
179//
180//
181//     Return Value                      Meaning
182//
183//     0                                 NV write success
184//     non-0                             NV write fail
185//
186LIB_EXPORT int
187_plat__NvCommit(void);
188//
189//
190//         _plat__NvMemoryRead()
191//
192//     Read a chunk of NV memory
193//
194LIB_EXPORT void
195_plat__NvMemoryRead(
196    unsigned int              startOffset,                 // IN: read start
197    unsigned int              size,                        // IN: size of bytes to read
198    void                      *data                        // OUT: data buffer
199);
200//
201//
202//         _plat__NvIsDifferent()
203//
204//     This function checks to see if the NV is different from the test value. This is so that NV will not be written if
205//     it has not changed.
206//
207//     Return Value                      Meaning
208//
209//     TRUE                              the NV location is different from the test value
210//     FALSE                             the NV location is the same as the test value
211//
212LIB_EXPORT BOOL
213_plat__NvIsDifferent(
214    unsigned int               startOffset,                 // IN: read start
215    unsigned int               size,                        // IN: size of bytes to compare
216    void                      *data                         // IN: data buffer
217    );
218//
219//
220//         _plat__NvMemoryWrite()
221//
222//     Write a chunk of NV memory
223//
224LIB_EXPORT void
225_plat__NvMemoryWrite(
226    unsigned int              startOffset,                 // IN: read start
227    unsigned int              size,                        // IN: size of bytes to read
228    void                      *data                        // OUT: data buffer
229);
230//
231//
232//         _plat__NvMemoryMove()
233//
234//     Move a chunk of NV memory from source to destination This function should ensure that if there overlap,
235//     the original data is copied before it is written
236//
237LIB_EXPORT void
238_plat__NvMemoryMove(
239    unsigned int              sourceOffset,                 // IN: source offset
240    unsigned int              destOffset,                   // IN: destination offset
241    unsigned int              size                          // IN: size of data being moved
242);
243//
244//
245//      _plat__SetNvAvail()
246//
247//     Set the current NV state to available. This function is for testing purposes only. It is not part of the
248//     platform NV logic
249//
250LIB_EXPORT void
251_plat__SetNvAvail(void);
252//
253//
254//      _plat__ClearNvAvail()
255//
256//     Set the current NV state to unavailable. This function is for testing purposes only. It is not part of the
257//     platform NV logic
258//
259LIB_EXPORT void
260_plat__ClearNvAvail(void);
261//
262//
263//          Locality Functions
264//
265//          _plat__LocalityGet()
266//
267//     Get the most recent command locality in locality value form
268//
269LIB_EXPORT unsigned char
270_plat__LocalityGet(void);
271//
272//
273//          _plat__LocalitySet()
274//
275//     Set the most recent command locality in locality value form
276//
277LIB_EXPORT void
278_plat__LocalitySet(
279    unsigned char      locality
280);
281//
282//
283//          _plat__IsRsaKeyCacheEnabled()
284//
285//     This function is used to check if the RSA key cache is enabled or not.
286//
287LIB_EXPORT int
288_plat__IsRsaKeyCacheEnabled(
289    void
290    );
291//
292//
293//          Clock Constants and Functions
294//
295//     Assume that the nominal divisor is 30000
296//
297#define        CLOCK_NOMINAL                30000
298//
299//     A 1% change in rate is 300 counts
300//
301#define        CLOCK_ADJUST_COARSE          300
302//
303//
304//     A .1 change in rate is 30 counts
305//
306#define        CLOCK_ADJUST_MEDIUM            30
307//
308//     A minimum change in rate is 1 count
309//
310#define        CLOCK_ADJUST_FINE              1
311//
312//     The clock tolerance is +/-15% (4500 counts) Allow some guard band (16.7%)
313//
314#define        CLOCK_ADJUST_LIMIT             5000
315//
316//
317//         _plat__ClockReset()
318//
319//     This function sets the current clock time as initial time. This function is called at a power on event to reset
320//     the clock
321//
322LIB_EXPORT void
323_plat__ClockReset(void);
324//
325//
326//         _plat__ClockTimeFromStart()
327//
328//     Function returns the compensated                  time   from   the    start   of     the   command      when
329//     _plat__ClockTimeFromStart() was called.
330//
331LIB_EXPORT unsigned long long
332_plat__ClockTimeFromStart(
333    void
334    );
335//
336//
337//         _plat__ClockTimeElapsed()
338//
339//     Get the time elapsed from current to the last time the _plat__ClockTimeElapsed() is called. For the first
340//     _plat__ClockTimeElapsed() call after a power on event, this call report the elapsed time from power on to
341//     the current call
342//
343LIB_EXPORT unsigned long long
344_plat__ClockTimeElapsed(void);
345//
346//
347//         _plat__ClockAdjustRate()
348//
349//     Adjust the clock rate
350//
351LIB_EXPORT void
352_plat__ClockAdjustRate(
353    int            adjust                    // IN: the adjust number.         It could be
354                                             // positive or negative
355    );
356//
357//
358//
359//           Single Function Files
360//
361//           _plat__GetEntropy()
362//
363//      This function is used to get available hardware entropy. In a hardware implementation of this function,
364//      there would be no call to the system to get entropy. If the caller does not ask for any entropy, then this is
365//      a startup indication and firstValue should be reset.
366//
367//      Return Value                     Meaning
368//
369//      <0                               hardware failure of the entropy generator, this is sticky
370//      >= 0                             the returned amount of entropy (bytes)
371//
372LIB_EXPORT int32_t
373_plat__GetEntropy(
374      unsigned char          *entropy,                  // output buffer
375      uint32_t                amount                    // amount requested
376);
377
378int uart_printf(const char *format, ...);
379#define ecprintf(format, args...) uart_printf(format, ## args);
380
381#endif
382