Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2013 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 | /* |
| 7 | * TPM Lightweight Command Library. |
| 8 | * |
| 9 | * A low-level library for interfacing to TPM hardware or an emulator. |
| 10 | */ |
| 11 | |
| 12 | #ifndef TPM_LITE_TLCL_H_ |
| 13 | #define TPM_LITE_TLCL_H_ |
| 14 | #include <stdint.h> |
Vadim Bendebury | 245d457 | 2016-04-05 16:01:57 -0700 | [diff] [blame] | 15 | #include <types.h> |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 16 | |
| 17 | #include "tss_constants.h" |
| 18 | |
| 19 | /*****************************************************************************/ |
| 20 | /* Functions implemented in tlcl.c */ |
| 21 | |
| 22 | /** |
| 23 | * Call this first. Returns 0 if success, nonzero if error. |
| 24 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 25 | uint32_t tlcl_lib_init(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Perform a raw TPM request/response transaction. |
| 29 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 30 | uint32_t tlcl_send_receive(const uint8_t *request, uint8_t *response, |
Lee Leahy | 708fc27 | 2017-03-07 12:18:53 -0800 | [diff] [blame] | 31 | int max_length); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 32 | |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 33 | /* Commands */ |
| 34 | |
| 35 | /** |
| 36 | * Send a TPM_Startup(ST_CLEAR). The TPM error code is returned (0 for |
| 37 | * success). |
| 38 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 39 | uint32_t tlcl_startup(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Resume by sending a TPM_Startup(ST_STATE). The TPM error code is returned |
| 43 | * (0 for success). |
| 44 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 45 | uint32_t tlcl_resume(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * Run the self test. |
| 49 | * |
| 50 | * Note---this is synchronous. To run this in parallel with other firmware, |
| 51 | * use ContinueSelfTest(). The TPM error code is returned. |
| 52 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 53 | uint32_t tlcl_self_test_full(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * Run the self test in the background. |
| 57 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 58 | uint32_t tlcl_continue_self_test(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 59 | |
Vadim Bendebury | 245d457 | 2016-04-05 16:01:57 -0700 | [diff] [blame] | 60 | #if IS_ENABLED(CONFIG_TPM) |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 61 | /** |
| 62 | * Define a space with permission [perm]. [index] is the index for the space, |
| 63 | * [size] the usable data size. The TPM error code is returned. |
| 64 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 65 | uint32_t tlcl_define_space(uint32_t index, uint32_t perm, uint32_t size); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 66 | |
Vadim Bendebury | 245d457 | 2016-04-05 16:01:57 -0700 | [diff] [blame] | 67 | #elif IS_ENABLED(CONFIG_TPM2) |
| 68 | |
| 69 | /* |
Vadim Bendebury | 7ee057c | 2016-07-03 15:24:23 -0700 | [diff] [blame] | 70 | * Define a TPM space. The define space command TPM command used by the tlcl |
| 71 | * layer is enforcing the policy which would not allow to delete the created |
| 72 | * space after any PCR0 change from its initial value. |
Vadim Bendebury | 245d457 | 2016-04-05 16:01:57 -0700 | [diff] [blame] | 73 | */ |
Vadim Bendebury | 7ee057c | 2016-07-03 15:24:23 -0700 | [diff] [blame] | 74 | uint32_t tlcl_define_space(uint32_t space_index, size_t space_size); |
Vadim Bendebury | 245d457 | 2016-04-05 16:01:57 -0700 | [diff] [blame] | 75 | #endif |
| 76 | |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 77 | /** |
| 78 | * Write [length] bytes of [data] to space at [index]. The TPM error code is |
| 79 | * returned. |
| 80 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 81 | uint32_t tlcl_write(uint32_t index, const void *data, uint32_t length); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * Read [length] bytes from space at [index] into [data]. The TPM error code |
| 85 | * is returned. |
| 86 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 87 | uint32_t tlcl_read(uint32_t index, void *data, uint32_t length); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * Assert physical presence in software. The TPM error code is returned. |
| 91 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 92 | uint32_t tlcl_assert_physical_presence(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * Enable the physical presence command. The TPM error code is returned. |
| 96 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 97 | uint32_t tlcl_physical_presence_cmd_enable(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 98 | |
| 99 | /** |
| 100 | * Finalize the physical presence settings: sofware PP is enabled, hardware PP |
| 101 | * is disabled, and the lifetime lock is set. The TPM error code is returned. |
| 102 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 103 | uint32_t tlcl_finalize_physical_presence(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * Set the nvLocked bit. The TPM error code is returned. |
| 107 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 108 | uint32_t tlcl_set_nv_locked(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * Issue a ForceClear. The TPM error code is returned. |
| 112 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 113 | uint32_t tlcl_force_clear(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 114 | |
| 115 | /** |
| 116 | * Issue a PhysicalEnable. The TPM error code is returned. |
| 117 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 118 | uint32_t tlcl_set_enable(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * Issue a SetDeactivated. Pass 0 to activate. Returns result code. |
| 122 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 123 | uint32_t tlcl_set_deactivated(uint8_t flag); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 124 | |
| 125 | /** |
| 126 | * Get flags of interest. Pointers for flags you aren't interested in may |
| 127 | * be NULL. The TPM error code is returned. |
| 128 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 129 | uint32_t tlcl_get_flags(uint8_t *disable, uint8_t *deactivated, |
Lee Leahy | 708fc27 | 2017-03-07 12:18:53 -0800 | [diff] [blame] | 130 | uint8_t *nvlocked); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 131 | |
| 132 | /** |
| 133 | * Set the bGlobalLock flag, which only a reboot can clear. The TPM error |
| 134 | * code is returned. |
| 135 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 136 | uint32_t tlcl_set_global_lock(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 137 | |
| 138 | /** |
Vadim Bendebury | 4c0851c | 2016-07-03 17:08:10 -0700 | [diff] [blame] | 139 | * Make an NV Ram location read_only. The TPM error code is returned. |
| 140 | */ |
| 141 | uint32_t tlcl_lock_nv_write(uint32_t index); |
| 142 | |
| 143 | /** |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 144 | * Perform a TPM_Extend. |
| 145 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 146 | uint32_t tlcl_extend(int pcr_num, const uint8_t *in_digest, |
Lee Leahy | 708fc27 | 2017-03-07 12:18:53 -0800 | [diff] [blame] | 147 | uint8_t *out_digest); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * Get the entire set of permanent flags. |
| 151 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 152 | uint32_t tlcl_get_permanent_flags(TPM_PERMANENT_FLAGS *pflags); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 153 | |
Aaron Durbin | f56c778 | 2017-01-10 17:44:42 -0600 | [diff] [blame] | 154 | /** |
| 155 | * Disable platform hierarchy. Specific to TPM2. The TPM error code is returned. |
| 156 | */ |
| 157 | uint32_t tlcl_disable_platform_hierarchy(void); |
| 158 | |
Aaron Durbin | eeb7737 | 2017-03-08 11:23:11 -0600 | [diff] [blame] | 159 | /** |
| 160 | * CR50 specific tpm command to enable nvmem commits before internal timeout |
| 161 | * expires. |
| 162 | */ |
| 163 | uint32_t tlcl_cr50_enable_nvcommits(void); |
| 164 | |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 165 | #endif /* TPM_LITE_TLCL_H_ */ |