blob: e0b56262d4c17081bdd4651d6488e2912b7d781c [file] [log] [blame]
Luigi Semenzatofb1379d2010-02-18 17:50:33 -08001/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6/* TPM Lightweight Command Library.
7 *
8 * A low-level library for interfacing to TPM hardware or an emulator.
9 */
10
11#ifndef TPM_LITE_TLCL_H_
12#define TPM_LITE_TLCL_H_
13
Luigi Semenzato37826c22010-03-12 15:16:23 -080014#include <stdarg.h>
Luigi Semenzatofb1379d2010-02-18 17:50:33 -080015#include <stdint.h>
Luigi Semenzato37826c22010-03-12 15:16:23 -080016#include <stdio.h>
17#include <stdlib.h>
18
19#define POSSIBLY_UNUSED __attribute__((unused))
20
21#ifdef __STRICT_ANSI__
22#define INLINE
23#else
24#define INLINE inline
25#endif
26
27/* Outputs an error message and quits the program.
28 */
Luigi Semenzatofdb8e122010-03-17 16:28:23 -070029POSSIBLY_UNUSED
Luigi Semenzato37826c22010-03-12 15:16:23 -080030static void error(const char *format, ...) {
31 va_list ap;
32 va_start(ap, format);
33 fprintf(stderr, "ERROR: ");
34 vfprintf(stderr, format, ap);
35 va_end(ap);
36 exit(1);
37}
38
39/* Outputs a warning and continues.
40 */
41POSSIBLY_UNUSED
42static void warning(const char *format, ...) {
43 va_list ap;
44 va_start(ap, format);
45 fprintf(stderr, "WARNING: ");
46 vfprintf(stderr, format, ap);
47 va_end(ap);
48}
49
50#define assert(expr) do { if (!(expr)) { \
51 error("assert fail: %s at %s:%d\n", \
52 #expr, __FILE__, __LINE__); }} while(0)
Luigi Semenzatofb1379d2010-02-18 17:50:33 -080053
54/* Call this first.
55 */
56void TlclLibinit(void);
57
58/* Sends a TPM_Startup(ST_CLEAR). Note that this is a no-op for the emulator,
59 * because it runs this command during initialization.
60 */
61void TlclStartup(void);
62
63/* Run the self test. Note---this is synchronous. To run this in parallel
64 * with other firmware, use ContinueSelfTest.
65 */
66void TlclSelftestfull(void);
67
68/* Defines a space with permission [perm]. [index] is the index for the space,
69 * [size] the usable data size. Errors are ignored.
70 */
71void TlclDefineSpace(uint32_t index, uint32_t perm, uint32_t size);
72
73/* Writes [length] bytes of [data] to space at [index]. The TPM error code is
74 * returned (0 for success).
75 */
76uint32_t TlclWrite(uint32_t index, uint8_t *data, uint32_t length);
77
78/* Reads [length] bytes from space at [index] into [data]. The TPM error code
79 * is returned (0 for success).
80 */
81uint32_t TlclRead(uint32_t index, uint8_t *data, uint32_t length);
82
83/* Write-locks space at [index].
84 */
85void TlclWriteLock(uint32_t index);
86
87/* Read-locks space at [index].
88 */
89void TlclReadLock(uint32_t index);
90
91/* Asserts physical presence in software.
92 */
93void TlclAssertPhysicalPresence(void);
94
95/* Sets the nvLocked bit.
96 */
97void TlclSetNvLocked(void);
98
Luigi Semenzato37826c22010-03-12 15:16:23 -080099/* Returns 1 if the TPM is owned, 0 otherwise.
100 */
101int TlclIsOwned(void);
102
Luigi Semenzatofdb8e122010-03-17 16:28:23 -0700103/* Issues a ForceClear.
104 */
105void TlclForceClear(void);
106
107/* Issues a PhysicalEnable.
108 */
109void TlclPhysicalEnable(void);
110
111/* Issues a PhysicalSetDeactivated. Pass 0 to activate. Returns result code.
112 */
113int TlclPhysicalSetDeactivated(uint8_t flag);
114
115/* Gets some permanent flags of interest. (Add more here as needed.)
116 */
117int TlclGetFlags(uint8_t* disable, uint8_t* deactivated);
118
Luigi Semenzatofb1379d2010-02-18 17:50:33 -0800119#endif /* TPM_LITE_TLCL_H_ */