Luigi Semenzato | fb1379d | 2010-02-18 17:50:33 -0800 | [diff] [blame] | 1 | /* 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 Semenzato | 37826c2 | 2010-03-12 15:16:23 -0800 | [diff] [blame] | 14 | #include <stdarg.h> |
Luigi Semenzato | fb1379d | 2010-02-18 17:50:33 -0800 | [diff] [blame] | 15 | #include <stdint.h> |
Luigi Semenzato | 37826c2 | 2010-03-12 15:16:23 -0800 | [diff] [blame] | 16 | #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 Semenzato | fdb8e12 | 2010-03-17 16:28:23 -0700 | [diff] [blame^] | 29 | POSSIBLY_UNUSED |
Luigi Semenzato | 37826c2 | 2010-03-12 15:16:23 -0800 | [diff] [blame] | 30 | static 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 | */ |
| 41 | POSSIBLY_UNUSED |
| 42 | static 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 Semenzato | fb1379d | 2010-02-18 17:50:33 -0800 | [diff] [blame] | 53 | |
| 54 | /* Call this first. |
| 55 | */ |
| 56 | void 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 | */ |
| 61 | void TlclStartup(void); |
| 62 | |
| 63 | /* Run the self test. Note---this is synchronous. To run this in parallel |
| 64 | * with other firmware, use ContinueSelfTest. |
| 65 | */ |
| 66 | void 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 | */ |
| 71 | void 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 | */ |
| 76 | uint32_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 | */ |
| 81 | uint32_t TlclRead(uint32_t index, uint8_t *data, uint32_t length); |
| 82 | |
| 83 | /* Write-locks space at [index]. |
| 84 | */ |
| 85 | void TlclWriteLock(uint32_t index); |
| 86 | |
| 87 | /* Read-locks space at [index]. |
| 88 | */ |
| 89 | void TlclReadLock(uint32_t index); |
| 90 | |
| 91 | /* Asserts physical presence in software. |
| 92 | */ |
| 93 | void TlclAssertPhysicalPresence(void); |
| 94 | |
| 95 | /* Sets the nvLocked bit. |
| 96 | */ |
| 97 | void TlclSetNvLocked(void); |
| 98 | |
Luigi Semenzato | 37826c2 | 2010-03-12 15:16:23 -0800 | [diff] [blame] | 99 | /* Returns 1 if the TPM is owned, 0 otherwise. |
| 100 | */ |
| 101 | int TlclIsOwned(void); |
| 102 | |
Luigi Semenzato | fdb8e12 | 2010-03-17 16:28:23 -0700 | [diff] [blame^] | 103 | /* Issues a ForceClear. |
| 104 | */ |
| 105 | void TlclForceClear(void); |
| 106 | |
| 107 | /* Issues a PhysicalEnable. |
| 108 | */ |
| 109 | void TlclPhysicalEnable(void); |
| 110 | |
| 111 | /* Issues a PhysicalSetDeactivated. Pass 0 to activate. Returns result code. |
| 112 | */ |
| 113 | int TlclPhysicalSetDeactivated(uint8_t flag); |
| 114 | |
| 115 | /* Gets some permanent flags of interest. (Add more here as needed.) |
| 116 | */ |
| 117 | int TlclGetFlags(uint8_t* disable, uint8_t* deactivated); |
| 118 | |
Luigi Semenzato | fb1379d | 2010-02-18 17:50:33 -0800 | [diff] [blame] | 119 | #endif /* TPM_LITE_TLCL_H_ */ |