blob: 966ce824571e2386370752e7e0f2fed4cccf75a3 [file] [log] [blame]
Vadim Bendebury56797522015-05-20 10:32:25 -07001// 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//
Louis Collard5cb743a2018-06-26 20:07:49 +0800263// _plat__NvGetHandleVirtualOffset()
264//
265// If the specified handle represents a virtual NV index, this function returns
266// the corresponding virtual offset. For all other handles, 0 is returned.
267//
268LIB_EXPORT uint32_t
269_plat__NvGetHandleVirtualOffset(uint32_t handle);
270//
271//
272// _plat__NvOffsetIsVirtual()
273//
274//
275// Returns true iff the specified offset corresponds to virtual NV memory; if
276// so, this offset must only be read using the _plat__NvVirtualMemoryRead()
277// function below.
278//
279LIB_EXPORT BOOL
280_plat__NvOffsetIsVirtual(unsigned int startOffset);
281//
282//
283// _plat__NvVirtualMemoryRead()
284//
285//
286// Equivalent of _plat__NvMemoryRead, but for virtual NV memory. Only offsets
287// for which _plat__NvOffsetIsVirtual() returns true should be passed to this
288// function.
289//
290LIB_EXPORT void
291_plat__NvVirtualMemoryRead(
292 unsigned int startOffset,
293 unsigned int size,
294 void *data
295);
296//
297//
Vadim Bendebury56797522015-05-20 10:32:25 -0700298// Locality Functions
299//
300// _plat__LocalityGet()
301//
302// Get the most recent command locality in locality value form
303//
304LIB_EXPORT unsigned char
305_plat__LocalityGet(void);
306//
307//
308// _plat__LocalitySet()
309//
310// Set the most recent command locality in locality value form
311//
312LIB_EXPORT void
313_plat__LocalitySet(
314 unsigned char locality
315);
316//
317//
318// _plat__IsRsaKeyCacheEnabled()
319//
320// This function is used to check if the RSA key cache is enabled or not.
321//
322LIB_EXPORT int
323_plat__IsRsaKeyCacheEnabled(
324 void
325 );
326//
327//
328// Clock Constants and Functions
329//
330// Assume that the nominal divisor is 30000
331//
332#define CLOCK_NOMINAL 30000
333//
334// A 1% change in rate is 300 counts
335//
336#define CLOCK_ADJUST_COARSE 300
337//
338//
339// A .1 change in rate is 30 counts
340//
341#define CLOCK_ADJUST_MEDIUM 30
342//
343// A minimum change in rate is 1 count
344//
345#define CLOCK_ADJUST_FINE 1
346//
347// The clock tolerance is +/-15% (4500 counts) Allow some guard band (16.7%)
348//
349#define CLOCK_ADJUST_LIMIT 5000
350//
351//
352// _plat__ClockReset()
353//
354// This function sets the current clock time as initial time. This function is called at a power on event to reset
355// the clock
356//
357LIB_EXPORT void
358_plat__ClockReset(void);
359//
360//
361// _plat__ClockTimeFromStart()
362//
363// Function returns the compensated time from the start of the command when
364// _plat__ClockTimeFromStart() was called.
365//
366LIB_EXPORT unsigned long long
367_plat__ClockTimeFromStart(
368 void
369 );
370//
371//
372// _plat__ClockTimeElapsed()
373//
374// Get the time elapsed from current to the last time the _plat__ClockTimeElapsed() is called. For the first
375// _plat__ClockTimeElapsed() call after a power on event, this call report the elapsed time from power on to
376// the current call
377//
378LIB_EXPORT unsigned long long
379_plat__ClockTimeElapsed(void);
380//
381//
382// _plat__ClockAdjustRate()
383//
384// Adjust the clock rate
385//
386LIB_EXPORT void
387_plat__ClockAdjustRate(
388 int adjust // IN: the adjust number. It could be
389 // positive or negative
390 );
391//
392//
393//
394// Single Function Files
395//
396// _plat__GetEntropy()
397//
398// This function is used to get available hardware entropy. In a hardware implementation of this function,
399// there would be no call to the system to get entropy. If the caller does not ask for any entropy, then this is
400// a startup indication and firstValue should be reset.
401//
402// Return Value Meaning
403//
404// <0 hardware failure of the entropy generator, this is sticky
405// >= 0 the returned amount of entropy (bytes)
406//
407LIB_EXPORT int32_t
408_plat__GetEntropy(
409 unsigned char *entropy, // output buffer
410 uint32_t amount // amount requested
411);
Vadim Bendebury7878aef2015-08-12 12:57:26 -0700412
Vadim Bendebury15d53c32016-10-25 14:14:38 -0700413//
414// Get firmware version numbers from the platform.
415//
416LIB_EXPORT void
417_plat__GetFwVersion(
418 uint32_t *fw1,
419 uint32_t *fw2
420);
421
Allen Webb536744f2018-07-18 15:20:13 -0700422// A function to call after every successful TPM2_Startup.
Vadim Bendeburyae8d0442017-12-01 12:58:58 -0800423LIB_EXPORT void
Allen Webb536744f2018-07-18 15:20:13 -0700424_plat__StartupCallback(
Vadim Bendeburyae8d0442017-12-01 12:58:58 -0800425 void
426);
427
Andrey Pronin45fa7902018-08-01 21:14:41 -0700428//
429// Check if a non-PLATFORMCREATE index shall nevertheless be retained when
430// performing TPM2_Clear.
431//
432LIB_EXPORT BOOL
433_plat__ShallSurviveOwnerClear(
434 uint32_t index
435);
436
Louis Collard4dcbc722018-10-31 11:44:39 +0800437// A function to call as part of every TPM2_Clear.
438LIB_EXPORT void
439_plat__OwnerClearCallback(
440 void
441);
442
Vadim Bendebury7878aef2015-08-12 12:57:26 -0700443int uart_printf(const char *format, ...);
444#define ecprintf(format, args...) uart_printf(format, ## args);
445
Vadim Bendebury56797522015-05-20 10:32:25 -0700446#endif