Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * The code in this file has been heavily based on the article "Writing a TPM |
| 5 | * Device Driver" published on http://ptgmedia.pearsoncmg.com and the |
| 6 | * submission by Stefan Berger on Qemu-devel mailing list. |
| 7 | * |
| 8 | * One principal difference is that in the simplest config the other than 0 |
| 9 | * TPM localities do not get mapped by some devices (for instance, by |
| 10 | * Infineon slb9635), so this driver provides access to locality 0 only. |
| 11 | */ |
| 12 | |
Elyes HAOUAS | 361a935 | 2019-12-18 21:26:33 +0100 | [diff] [blame] | 13 | #include <commonlib/helpers.h> |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 14 | #include <string.h> |
| 15 | #include <delay.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 16 | #include <device/mmio.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 17 | #include <acpi/acpi.h> |
| 18 | #include <acpi/acpigen.h> |
| 19 | #include <acpi/acpi_device.h> |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 20 | #include <device/device.h> |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 21 | #include <console/console.h> |
Philipp Deppenwiese | d88fb36 | 2017-10-18 20:26:18 +0200 | [diff] [blame] | 22 | #include <security/tpm/tis.h> |
Sergii Dmytruk | 0a89d52 | 2022-10-29 16:57:07 +0300 | [diff] [blame] | 23 | #include <security/tpm/tss.h> |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 24 | #include <device/pnp.h> |
Patrick Rudolph | d8d8be1 | 2020-09-21 09:48:53 +0200 | [diff] [blame] | 25 | #include <drivers/tpm/tpm_ppi.h> |
Werner Zeh | 92ab611 | 2021-10-11 15:27:12 +0200 | [diff] [blame] | 26 | #include <timer.h> |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 27 | #include "chip.h" |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 28 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 29 | #define PREFIX "lpc_tpm: " |
Patrick Rudolph | d8d8be1 | 2020-09-21 09:48:53 +0200 | [diff] [blame] | 30 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 31 | /* coreboot wrapper for TPM driver (start) */ |
| 32 | #define TPM_DEBUG(fmt, args...) \ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 33 | if (CONFIG(DEBUG_TPM)) { \ |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 34 | printk(BIOS_DEBUG, PREFIX); \ |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 35 | printk(BIOS_DEBUG, fmt, ##args); \ |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 36 | } |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 37 | #define TPM_DEBUG_IO_READ(reg_, val_) \ |
Jon Murphy | 53fc667 | 2023-09-26 21:05:37 -0600 | [diff] [blame] | 38 | TPM_DEBUG("Read reg %#x returns %#x\n", (reg_), (val_)) |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 39 | #define TPM_DEBUG_IO_WRITE(reg_, val_) \ |
Jon Murphy | 53fc667 | 2023-09-26 21:05:37 -0600 | [diff] [blame] | 40 | TPM_DEBUG("Write reg %#x with %#x\n", (reg_), (val_)) |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 41 | #define printf(x...) printk(BIOS_ERR, x) |
| 42 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 43 | /* coreboot wrapper for TPM driver (end) */ |
| 44 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 45 | /* the macro accepts the locality value, but only locality 0 is operational */ |
| 46 | #define TIS_REG(LOCALITY, REG) \ |
Patrick Rudolph | 56fdafb | 2020-07-01 20:07:08 +0200 | [diff] [blame] | 47 | (void *)(uintptr_t)(CONFIG_TPM_TIS_BASE_ADDRESS + (LOCALITY << 12) + REG) |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 48 | |
| 49 | /* hardware registers' offsets */ |
| 50 | #define TIS_REG_ACCESS 0x0 |
| 51 | #define TIS_REG_INT_ENABLE 0x8 |
| 52 | #define TIS_REG_INT_VECTOR 0xc |
| 53 | #define TIS_REG_INT_STATUS 0x10 |
| 54 | #define TIS_REG_INTF_CAPABILITY 0x14 |
| 55 | #define TIS_REG_STS 0x18 |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 56 | #define TIS_REG_BURST_COUNT 0x19 |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 57 | #define TIS_REG_DATA_FIFO 0x24 |
| 58 | #define TIS_REG_DID_VID 0xf00 |
| 59 | #define TIS_REG_RID 0xf04 |
| 60 | |
| 61 | /* Some registers' bit field definitions */ |
| 62 | #define TIS_STS_VALID (1 << 7) /* 0x80 */ |
| 63 | #define TIS_STS_COMMAND_READY (1 << 6) /* 0x40 */ |
| 64 | #define TIS_STS_TPM_GO (1 << 5) /* 0x20 */ |
| 65 | #define TIS_STS_DATA_AVAILABLE (1 << 4) /* 0x10 */ |
| 66 | #define TIS_STS_EXPECT (1 << 3) /* 0x08 */ |
| 67 | #define TIS_STS_RESPONSE_RETRY (1 << 1) /* 0x02 */ |
| 68 | |
| 69 | #define TIS_ACCESS_TPM_REG_VALID_STS (1 << 7) /* 0x80 */ |
| 70 | #define TIS_ACCESS_ACTIVE_LOCALITY (1 << 5) /* 0x20 */ |
| 71 | #define TIS_ACCESS_BEEN_SEIZED (1 << 4) /* 0x10 */ |
| 72 | #define TIS_ACCESS_SEIZE (1 << 3) /* 0x08 */ |
| 73 | #define TIS_ACCESS_PENDING_REQUEST (1 << 2) /* 0x04 */ |
| 74 | #define TIS_ACCESS_REQUEST_USE (1 << 1) /* 0x02 */ |
| 75 | #define TIS_ACCESS_TPM_ESTABLISHMENT (1 << 0) /* 0x01 */ |
| 76 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 77 | /* 1 second is plenty for anything TPM does.*/ |
Werner Zeh | 92ab611 | 2021-10-11 15:27:12 +0200 | [diff] [blame] | 78 | #define MAX_DELAY_US USECS_PER_SEC |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 79 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 80 | /* |
| 81 | * Structures defined below allow creating descriptions of TPM vendor/device |
Sergii Dmytruk | 025d20e | 2022-12-22 19:34:16 +0200 | [diff] [blame] | 82 | * ID information for run time discovery. The only device the system knows |
| 83 | * about at this time is Infineon slb9635 |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 84 | */ |
| 85 | struct device_name { |
| 86 | u16 dev_id; |
Elyes HAOUAS | b0b0c8c | 2018-07-08 12:33:47 +0200 | [diff] [blame] | 87 | const char *const dev_name; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | struct vendor_name { |
| 91 | u16 vendor_id; |
Elyes HAOUAS | b0b0c8c | 2018-07-08 12:33:47 +0200 | [diff] [blame] | 92 | const char *vendor_name; |
| 93 | const struct device_name *dev_names; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 96 | static const struct device_name atmel_devices[] = { |
Sergii Dmytruk | 025d20e | 2022-12-22 19:34:16 +0200 | [diff] [blame] | 97 | {0x3204, "AT97SC3204"}, |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 98 | {0xffff} |
| 99 | }; |
| 100 | |
Stefan Reinauer | c668af7 | 2011-10-27 21:28:25 +0000 | [diff] [blame] | 101 | static const struct device_name infineon_devices[] = { |
Sergii Dmytruk | 025d20e | 2022-12-22 19:34:16 +0200 | [diff] [blame] | 102 | {0x000b, "SLB9635 TT 1.2"}, |
| 103 | #if CONFIG(TPM2) |
| 104 | {0x001a, "SLB9665 TT 2.0"}, |
| 105 | {0x001b, "SLB9670 TT 2.0"}, |
Tim Crawford | 6466281 | 2023-06-12 11:44:08 -0600 | [diff] [blame] | 106 | {0x001d, "SLB9672 TT 2.0"}, |
Sergii Dmytruk | 025d20e | 2022-12-22 19:34:16 +0200 | [diff] [blame] | 107 | #else |
| 108 | {0x001a, "SLB9660 TT 1.2"}, |
| 109 | {0x001b, "SLB9670 TT 1.2"}, |
| 110 | #endif |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 111 | {0xffff} |
| 112 | }; |
| 113 | |
| 114 | static const struct device_name nuvoton_devices[] = { |
Sergii Dmytruk | 025d20e | 2022-12-22 19:34:16 +0200 | [diff] [blame] | 115 | {0x00fe, "NPCT420AA V2"}, |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 116 | {0xffff} |
| 117 | }; |
| 118 | |
| 119 | static const struct device_name stmicro_devices[] = { |
Sergii Dmytruk | 025d20e | 2022-12-22 19:34:16 +0200 | [diff] [blame] | 120 | {0x0000, "ST33ZP24" }, |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 121 | {0xffff} |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
Tsung Ho Wu | 804a043 | 2019-06-07 15:03:49 -0700 | [diff] [blame] | 124 | static const struct device_name swtpm_devices[] = { |
Sergii Dmytruk | 025d20e | 2022-12-22 19:34:16 +0200 | [diff] [blame] | 125 | #if CONFIG(TPM2) |
| 126 | {0x0001, "SwTPM 2.0" }, |
| 127 | #endif |
Tsung Ho Wu | 804a043 | 2019-06-07 15:03:49 -0700 | [diff] [blame] | 128 | {0xffff} |
| 129 | }; |
| 130 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 131 | static const struct vendor_name vendor_names[] = { |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 132 | {0x1114, "Atmel", atmel_devices}, |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 133 | {0x15d1, "Infineon", infineon_devices}, |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 134 | {0x1050, "Nuvoton", nuvoton_devices}, |
Tsung Ho Wu | 804a043 | 2019-06-07 15:03:49 -0700 | [diff] [blame] | 135 | {0x1014, "TPM Emulator", swtpm_devices}, |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 136 | {0x104a, "ST Microelectronics", stmicro_devices}, |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | /* |
| 140 | * Cached vendor/device ID pair to indicate that the device has been already |
| 141 | * discovered |
| 142 | */ |
Arthur Heymans | 0ca944b | 2019-11-20 19:51:06 +0100 | [diff] [blame] | 143 | static u32 vendor_dev_id; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 144 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 145 | static inline u8 tpm_read_status(int locality) |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 146 | { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 147 | u8 value = read8(TIS_REG(locality, TIS_REG_STS)); |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 148 | TPM_DEBUG_IO_READ(TIS_REG_STS, value); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 149 | return value; |
| 150 | } |
| 151 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 152 | static inline void tpm_write_status(u8 sts, int locality) |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 153 | { |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 154 | TPM_DEBUG_IO_WRITE(TIS_REG_STS, sts); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 155 | write8(TIS_REG(locality, TIS_REG_STS), sts); |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 156 | } |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 157 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 158 | static inline u8 tpm_read_data(int locality) |
| 159 | { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 160 | u8 value = read8(TIS_REG(locality, TIS_REG_DATA_FIFO)); |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 161 | TPM_DEBUG_IO_READ(TIS_REG_DATA_FIFO, value); |
| 162 | return value; |
| 163 | } |
| 164 | |
| 165 | static inline void tpm_write_data(u8 data, int locality) |
| 166 | { |
Werner Zeh | a31d6cd | 2021-10-07 07:15:38 +0200 | [diff] [blame] | 167 | TPM_DEBUG_IO_WRITE(TIS_REG_DATA_FIFO, data); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 168 | write8(TIS_REG(locality, TIS_REG_DATA_FIFO), data); |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | static inline u16 tpm_read_burst_count(int locality) |
| 172 | { |
| 173 | u16 count; |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 174 | count = read8(TIS_REG(locality, TIS_REG_BURST_COUNT)); |
| 175 | count |= read8(TIS_REG(locality, TIS_REG_BURST_COUNT + 1)) << 8; |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 176 | TPM_DEBUG_IO_READ(TIS_REG_BURST_COUNT, count); |
| 177 | return count; |
| 178 | } |
| 179 | |
| 180 | static inline u8 tpm_read_access(int locality) |
| 181 | { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 182 | u8 value = read8(TIS_REG(locality, TIS_REG_ACCESS)); |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 183 | TPM_DEBUG_IO_READ(TIS_REG_ACCESS, value); |
| 184 | return value; |
| 185 | } |
| 186 | |
| 187 | static inline void tpm_write_access(u8 data, int locality) |
| 188 | { |
| 189 | TPM_DEBUG_IO_WRITE(TIS_REG_ACCESS, data); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 190 | write8(TIS_REG(locality, TIS_REG_ACCESS), data); |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | static inline u32 tpm_read_did_vid(int locality) |
| 194 | { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 195 | u32 value = read32(TIS_REG(locality, TIS_REG_DID_VID)); |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 196 | TPM_DEBUG_IO_READ(TIS_REG_DID_VID, value); |
| 197 | return value; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 200 | static inline void tpm_write_int_vector(int vector, int locality) |
| 201 | { |
| 202 | TPM_DEBUG_IO_WRITE(TIS_REG_INT_VECTOR, vector); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 203 | write8(TIS_REG(locality, TIS_REG_INT_VECTOR), vector & 0xf); |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 206 | static inline u8 tpm_read_int_vector(int locality) |
| 207 | { |
| 208 | u8 value = read8(TIS_REG(locality, TIS_REG_INT_VECTOR)); |
| 209 | TPM_DEBUG_IO_READ(TIS_REG_INT_VECTOR, value); |
| 210 | return value; |
| 211 | } |
| 212 | |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 213 | static inline void tpm_write_int_polarity(int polarity, int locality) |
| 214 | { |
| 215 | /* Set polarity and leave all other bits at 0 */ |
| 216 | u32 value = (polarity & 0x3) << 3; |
| 217 | TPM_DEBUG_IO_WRITE(TIS_REG_INT_ENABLE, value); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 218 | write32(TIS_REG(locality, TIS_REG_INT_ENABLE), value); |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 221 | static inline u32 tpm_read_int_polarity(int locality) |
| 222 | { |
| 223 | /* Get polarity and leave all other bits */ |
| 224 | u32 value = read8(TIS_REG(locality, TIS_REG_INT_ENABLE)); |
| 225 | value = (value >> 3) & 0x3; |
| 226 | TPM_DEBUG_IO_READ(TIS_REG_INT_ENABLE, value); |
| 227 | return value; |
| 228 | } |
| 229 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 230 | /* |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 231 | * tis_wait_sts() |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 232 | * |
Werner Zeh | 92ab611 | 2021-10-11 15:27:12 +0200 | [diff] [blame] | 233 | * Wait for at most a second for a status to change its state to match the |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 234 | * expected state. Normally the transition happens within microseconds. |
| 235 | * |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 236 | * @locality - locality |
| 237 | * @mask - bitmask for the bitfield(s) to watch |
| 238 | * @expected - value the field(s) are supposed to be set to |
| 239 | * |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 240 | * Returns TPM_SUCCESS on success or TPM_CB_TIMEOUT on timeout. |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 241 | */ |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 242 | static tpm_result_t tis_wait_sts(int locality, u8 mask, u8 expected) |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 243 | { |
Werner Zeh | 92ab611 | 2021-10-11 15:27:12 +0200 | [diff] [blame] | 244 | struct stopwatch sw; |
| 245 | |
| 246 | stopwatch_init_usecs_expire(&sw, MAX_DELAY_US); |
| 247 | do { |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 248 | u8 value = tpm_read_status(locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 249 | if ((value & mask) == expected) |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 250 | return TPM_SUCCESS; |
Werner Zeh | 92ab611 | 2021-10-11 15:27:12 +0200 | [diff] [blame] | 251 | udelay(1); |
| 252 | } while (!stopwatch_expired(&sw)); |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 253 | return TPM_CB_TIMEOUT; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 256 | static inline tpm_result_t tis_wait_ready(int locality) |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 257 | { |
| 258 | return tis_wait_sts(locality, TIS_STS_COMMAND_READY, |
| 259 | TIS_STS_COMMAND_READY); |
| 260 | } |
| 261 | |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 262 | static inline tpm_result_t tis_wait_valid(int locality) |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 263 | { |
| 264 | return tis_wait_sts(locality, TIS_STS_VALID, TIS_STS_VALID); |
| 265 | } |
| 266 | |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 267 | static inline tpm_result_t tis_wait_valid_data(int locality) |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 268 | { |
| 269 | const u8 has_data = TIS_STS_DATA_AVAILABLE | TIS_STS_VALID; |
| 270 | return tis_wait_sts(locality, has_data, has_data); |
| 271 | } |
| 272 | |
| 273 | static inline int tis_has_valid_data(int locality) |
| 274 | { |
| 275 | const u8 has_data = TIS_STS_DATA_AVAILABLE | TIS_STS_VALID; |
| 276 | return (tpm_read_status(locality) & has_data) == has_data; |
| 277 | } |
| 278 | |
| 279 | static inline int tis_expect_data(int locality) |
| 280 | { |
| 281 | return !!(tpm_read_status(locality) & TIS_STS_EXPECT); |
| 282 | } |
| 283 | |
| 284 | /* |
| 285 | * tis_wait_access() |
| 286 | * |
Werner Zeh | 92ab611 | 2021-10-11 15:27:12 +0200 | [diff] [blame] | 287 | * Wait for at most a second for a access to change its state to match the |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 288 | * expected state. Normally the transition happens within microseconds. |
| 289 | * |
| 290 | * @locality - locality |
| 291 | * @mask - bitmask for the bitfield(s) to watch |
| 292 | * @expected - value the field(s) are supposed to be set to |
| 293 | * |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 294 | * Returns TPM_SUCCESS on success or TPM_CB_TIMEOUT on timeout. |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 295 | */ |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 296 | static tpm_result_t tis_wait_access(int locality, u8 mask, u8 expected) |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 297 | { |
Werner Zeh | 92ab611 | 2021-10-11 15:27:12 +0200 | [diff] [blame] | 298 | struct stopwatch sw; |
| 299 | |
| 300 | stopwatch_init_usecs_expire(&sw, MAX_DELAY_US); |
| 301 | do { |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 302 | u8 value = tpm_read_access(locality); |
| 303 | if ((value & mask) == expected) |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 304 | return TPM_SUCCESS; |
Werner Zeh | 92ab611 | 2021-10-11 15:27:12 +0200 | [diff] [blame] | 305 | udelay(1); |
| 306 | } while (!stopwatch_expired(&sw)); |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 307 | return TPM_CB_TIMEOUT; |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 308 | } |
| 309 | |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 310 | static inline tpm_result_t tis_wait_received_access(int locality) |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 311 | { |
| 312 | return tis_wait_access(locality, TIS_ACCESS_ACTIVE_LOCALITY, |
| 313 | TIS_ACCESS_ACTIVE_LOCALITY); |
| 314 | } |
| 315 | |
| 316 | static inline int tis_has_access(int locality) |
| 317 | { |
| 318 | return !!(tpm_read_access(locality) & TIS_ACCESS_ACTIVE_LOCALITY); |
| 319 | } |
| 320 | |
| 321 | static inline void tis_request_access(int locality) |
| 322 | { |
| 323 | tpm_write_access(TIS_ACCESS_REQUEST_USE, locality); |
| 324 | } |
| 325 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 326 | /* |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 327 | * PC Client Specific TPM Interface Specification section 11.2.12: |
| 328 | * |
| 329 | * Software must be prepared to send two writes of a "1" to command ready |
| 330 | * field: the first to indicate successful read of all the data, thus |
| 331 | * clearing the data from the ReadFIFO and freeing the TPM's resources, |
| 332 | * and the second to indicate to the TPM it is about to send a new command. |
| 333 | * |
| 334 | * In practice not all TPMs behave the same so it is necessary to be |
| 335 | * flexible when trying to set command ready. |
| 336 | * |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 337 | */ |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 338 | static tpm_result_t tis_command_ready(u8 locality) |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 339 | { |
| 340 | u32 status; |
| 341 | |
| 342 | /* 1st attempt to set command ready */ |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 343 | tpm_write_status(TIS_STS_COMMAND_READY, locality); |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 344 | |
| 345 | /* Wait for response */ |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 346 | status = tpm_read_status(locality); |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 347 | |
| 348 | /* Check if command ready is set yet */ |
| 349 | if (status & TIS_STS_COMMAND_READY) |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 350 | return TPM_SUCCESS; |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 351 | |
| 352 | /* 2nd attempt to set command ready */ |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 353 | tpm_write_status(TIS_STS_COMMAND_READY, locality); |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 354 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 355 | return tis_wait_ready(locality); |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | /* |
Sergii Dmytruk | 963f7b9 | 2022-10-29 20:42:28 +0300 | [diff] [blame^] | 359 | * pc80_tis_probe() |
Jon Murphy | a7c64d7 | 2023-09-15 07:58:08 -0600 | [diff] [blame] | 360 | * |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 361 | * Probe the TPM device and try determining its manufacturer/device name. |
| 362 | * |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 363 | * Returns TPM_SUCCESS on success (the device is found or was found during |
| 364 | * an earlier invocation) or TPM_CB_FAIL if the device is not found. |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 365 | */ |
Sergii Dmytruk | 963f7b9 | 2022-10-29 20:42:28 +0300 | [diff] [blame^] | 366 | static tpm_result_t pc80_tis_probe(void) |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 367 | { |
Sergii Dmytruk | 025d20e | 2022-12-22 19:34:16 +0200 | [diff] [blame] | 368 | const char *device_name = "unknown"; |
| 369 | const char *vendor_name = device_name; |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 370 | const struct device_name *dev; |
Sergii Dmytruk | 025d20e | 2022-12-22 19:34:16 +0200 | [diff] [blame] | 371 | u32 didvid; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 372 | u16 vid, did; |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 373 | int i; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 374 | |
Arthur Heymans | 0ca944b | 2019-11-20 19:51:06 +0100 | [diff] [blame] | 375 | if (vendor_dev_id) |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 376 | return TPM_SUCCESS; /* Already probed. */ |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 377 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 378 | didvid = tpm_read_did_vid(0); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 379 | if (!didvid || (didvid == 0xffffffff)) { |
Angel Pons | 08e8cab | 2020-06-18 15:20:37 +0200 | [diff] [blame] | 380 | printf("%s: No TPM device found\n", __func__); |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 381 | return TPM_CB_FAIL; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Arthur Heymans | 0ca944b | 2019-11-20 19:51:06 +0100 | [diff] [blame] | 384 | vendor_dev_id = didvid; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 385 | |
| 386 | vid = didvid & 0xffff; |
| 387 | did = (didvid >> 16) & 0xffff; |
| 388 | for (i = 0; i < ARRAY_SIZE(vendor_names); i++) { |
| 389 | int j = 0; |
Sergii Dmytruk | 025d20e | 2022-12-22 19:34:16 +0200 | [diff] [blame] | 390 | u16 known_did; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 391 | if (vid == vendor_names[i].vendor_id) { |
| 392 | vendor_name = vendor_names[i].vendor_name; |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 393 | } else { |
| 394 | continue; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 395 | } |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 396 | dev = &vendor_names[i].dev_names[j]; |
Sergii Dmytruk | 025d20e | 2022-12-22 19:34:16 +0200 | [diff] [blame] | 397 | while ((known_did = dev->dev_id) != 0xffff) { |
| 398 | if (known_did == did) { |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 399 | device_name = dev->dev_name; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 400 | break; |
| 401 | } |
| 402 | j++; |
Subrata | 41b08d9 | 2015-05-14 14:38:07 +0530 | [diff] [blame] | 403 | dev = &vendor_names[i].dev_names[j]; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 404 | } |
| 405 | break; |
| 406 | } |
Sergii Dmytruk | 025d20e | 2022-12-22 19:34:16 +0200 | [diff] [blame] | 407 | /* this will have to be converted into debug printout */ |
| 408 | printk(BIOS_INFO, "Found TPM %s by %s\n", device_name, vendor_name); |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 409 | return TPM_SUCCESS; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | /* |
| 413 | * tis_senddata() |
| 414 | * |
| 415 | * send the passed in data to the TPM device. |
| 416 | * |
| 417 | * @data - address of the data to send, byte by byte |
| 418 | * @len - length of the data to send |
| 419 | * |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 420 | * Returns TPM_SUCCESS on success, TPM_CB_FAIL on error (in case the device does |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 421 | * not accept the entire command). |
| 422 | */ |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 423 | static tpm_result_t tis_senddata(const u8 *const data, u32 len) |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 424 | { |
| 425 | u32 offset = 0; |
| 426 | u16 burst = 0; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 427 | u8 locality = 0; |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 428 | tpm_result_t rc = TPM_SUCCESS; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 429 | |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 430 | rc = tis_wait_ready(locality); |
| 431 | if (rc) { |
| 432 | printf("%s:%d - failed to get 'command_ready' status with error %#x\n", |
| 433 | __FILE__, __LINE__, rc); |
| 434 | return rc; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 435 | } |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 436 | burst = tpm_read_burst_count(locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 437 | |
| 438 | while (1) { |
Martin Roth | 38ddbfb | 2019-10-23 21:41:00 -0600 | [diff] [blame] | 439 | unsigned int count; |
Werner Zeh | 92ab611 | 2021-10-11 15:27:12 +0200 | [diff] [blame] | 440 | struct stopwatch sw; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 441 | |
| 442 | /* Wait till the device is ready to accept more data. */ |
Werner Zeh | 92ab611 | 2021-10-11 15:27:12 +0200 | [diff] [blame] | 443 | stopwatch_init_usecs_expire(&sw, MAX_DELAY_US); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 444 | while (!burst) { |
Werner Zeh | 92ab611 | 2021-10-11 15:27:12 +0200 | [diff] [blame] | 445 | if (stopwatch_expired(&sw)) { |
Werner Zeh | 66b2f20 | 2021-10-12 15:14:22 +0200 | [diff] [blame] | 446 | printf("%s:%d failed to feed %u bytes of %u\n", |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 447 | __FILE__, __LINE__, len - offset, len); |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 448 | return TPM_CB_TIMEOUT; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 449 | } |
| 450 | udelay(1); |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 451 | burst = tpm_read_burst_count(locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 454 | /* |
| 455 | * Calculate number of bytes the TPM is ready to accept in one |
| 456 | * shot. |
| 457 | * |
| 458 | * We want to send the last byte outside of the loop (hence |
| 459 | * the -1 below) to make sure that the 'expected' status bit |
| 460 | * changes to zero exactly after the last byte is fed into the |
| 461 | * FIFO. |
| 462 | */ |
Elyes HAOUAS | 361a935 | 2019-12-18 21:26:33 +0100 | [diff] [blame] | 463 | count = MIN(burst, len - offset - 1); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 464 | while (count--) |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 465 | tpm_write_data(data[offset++], locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 466 | |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 467 | rc = tis_wait_valid(locality); |
| 468 | if (rc || !tis_expect_data(locality)) { |
| 469 | printf("%s:%d TPM command feed overflow with error %#x\n", |
| 470 | __FILE__, __LINE__, rc); |
| 471 | return rc ? rc : TPM_CB_FAIL; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 474 | burst = tpm_read_burst_count(locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 475 | if ((offset == (len - 1)) && burst) |
| 476 | /* |
| 477 | * We need to be able to send the last byte to the |
| 478 | * device, so burst size must be nonzero before we |
| 479 | * break out. |
| 480 | */ |
| 481 | break; |
| 482 | } |
| 483 | |
| 484 | /* Send the last byte. */ |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 485 | tpm_write_data(data[offset++], locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 486 | |
| 487 | /* |
| 488 | * Verify that TPM does not expect any more data as part of this |
| 489 | * command. |
| 490 | */ |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 491 | rc = tis_wait_valid(locality); |
| 492 | if (rc || tis_expect_data(locality)) { |
| 493 | printf("%s:%d unexpected TPM error %#x with status %#x\n", |
| 494 | __FILE__, __LINE__, rc, tpm_read_status(locality)); |
| 495 | return rc ? rc : TPM_CB_FAIL; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | /* OK, sitting pretty, let's start the command execution. */ |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 499 | tpm_write_status(TIS_STS_TPM_GO, locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 500 | |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 501 | return TPM_SUCCESS; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /* |
| 505 | * tis_readresponse() |
| 506 | * |
| 507 | * read the TPM device response after a command was issued. |
| 508 | * |
| 509 | * @buffer - address where to read the response, byte by byte. |
| 510 | * @len - pointer to the size of buffer |
| 511 | * |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 512 | * On success stores the number of received bytes to len and returns |
| 513 | * TPM_SUCCESS. On errors (misformatted TPM data or synchronization |
| 514 | * problems) returns TPM_CB_FAIL. |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 515 | */ |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 516 | static tpm_result_t tis_readresponse(u8 *buffer, size_t *len) |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 517 | { |
| 518 | u16 burst_count; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 519 | u32 offset = 0; |
| 520 | u8 locality = 0; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 521 | u32 expected_count = *len; |
| 522 | int max_cycles = 0; |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 523 | tpm_result_t rc = TPM_SUCCESS; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 524 | |
| 525 | /* Wait for the TPM to process the command */ |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 526 | rc = tis_wait_valid_data(locality); |
| 527 | if (rc) { |
| 528 | printf("%s:%d failed processing command with error %#x\n", |
| 529 | __FILE__, __LINE__, rc); |
| 530 | return rc; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | do { |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 534 | while ((burst_count = tpm_read_burst_count(locality)) == 0) { |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 535 | if (max_cycles++ == MAX_DELAY_US) { |
| 536 | printf("%s:%d TPM stuck on read\n", |
| 537 | __FILE__, __LINE__); |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 538 | return TPM_CB_FAIL; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 539 | } |
| 540 | udelay(1); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | max_cycles = 0; |
| 544 | |
| 545 | while (burst_count-- && (offset < expected_count)) { |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 546 | buffer[offset++] = tpm_read_data(locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 547 | if (offset == 6) { |
| 548 | /* |
| 549 | * We got the first six bytes of the reply, |
| 550 | * let's figure out how many bytes to expect |
| 551 | * total - it is stored as a 4 byte number in |
| 552 | * network order, starting with offset 2 into |
| 553 | * the body of the reply. |
| 554 | */ |
| 555 | u32 real_length; |
| 556 | memcpy(&real_length, |
| 557 | buffer + 2, |
| 558 | sizeof(real_length)); |
| 559 | expected_count = be32_to_cpu(real_length); |
| 560 | |
| 561 | if ((expected_count < offset) || |
| 562 | (expected_count > *len)) { |
Werner Zeh | 66b2f20 | 2021-10-12 15:14:22 +0200 | [diff] [blame] | 563 | printf("%s:%d bad response size %u\n", |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 564 | __FILE__, __LINE__, |
| 565 | expected_count); |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 566 | return TPM_CB_FAIL; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | /* Wait for the next portion */ |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 572 | rc = tis_wait_valid(locality); |
| 573 | if (rc) { |
| 574 | printf("%s:%d failed to read response with error %#x\n", |
| 575 | __FILE__, __LINE__, rc); |
| 576 | return rc; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | if (offset == expected_count) |
| 580 | break; /* We got all we need */ |
| 581 | |
Bill XIE | a4bf0b7 | 2018-03-22 17:07:43 +0800 | [diff] [blame] | 582 | /* |
| 583 | * Certain TPMs seem to need some delay between tis_wait_valid() |
| 584 | * and tis_has_valid_data(), or some race-condition-related |
| 585 | * issue will occur. |
| 586 | */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 587 | if (CONFIG(TPM_RDRESP_NEED_DELAY)) |
Bill XIE | a4bf0b7 | 2018-03-22 17:07:43 +0800 | [diff] [blame] | 588 | udelay(10); |
| 589 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 590 | } while (tis_has_valid_data(locality)); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 591 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 592 | /* * Make sure we indeed read all there was. */ |
| 593 | if (tis_has_valid_data(locality)) { |
Jon Murphy | 53fc667 | 2023-09-26 21:05:37 -0600 | [diff] [blame] | 594 | printf("%s:%d wrong receive status: %#x %u bytes left\n", |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 595 | __FILE__, __LINE__, tpm_read_status(locality), |
| 596 | tpm_read_burst_count(locality)); |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 597 | return TPM_CB_FAIL; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | /* Tell the TPM that we are done. */ |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 601 | rc = tis_command_ready(locality); |
| 602 | if (rc) |
| 603 | return rc; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 604 | |
| 605 | *len = offset; |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 606 | return TPM_SUCCESS; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | /* |
Sergii Dmytruk | 963f7b9 | 2022-10-29 20:42:28 +0300 | [diff] [blame^] | 610 | * pc80_tis_open() |
Sergii Dmytruk | 4ee0317 | 2022-12-22 19:35:25 +0200 | [diff] [blame] | 611 | * |
Sergii Dmytruk | 0a89d52 | 2022-10-29 16:57:07 +0300 | [diff] [blame] | 612 | * Requests access to locality 0 for the caller. |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 613 | * |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 614 | * Returns TPM_SUCCESS on success, TSS Error on failure. |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 615 | */ |
Sergii Dmytruk | 963f7b9 | 2022-10-29 20:42:28 +0300 | [diff] [blame^] | 616 | static tpm_result_t pc80_tis_open(void) |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 617 | { |
| 618 | u8 locality = 0; /* we use locality zero for everything */ |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 619 | tpm_result_t rc = TPM_SUCCESS; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 620 | |
Sergii Dmytruk | 0a89d52 | 2022-10-29 16:57:07 +0300 | [diff] [blame] | 621 | if (!tis_has_access(locality)) { |
| 622 | /* request access to locality */ |
| 623 | tis_request_access(locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 624 | |
Sergii Dmytruk | 0a89d52 | 2022-10-29 16:57:07 +0300 | [diff] [blame] | 625 | /* did we get a lock? */ |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 626 | rc = tis_wait_received_access(locality); |
| 627 | if (rc) { |
| 628 | printf("%s:%d - failed to lock locality %u with error %#x\n", |
| 629 | __FILE__, __LINE__, locality, rc); |
| 630 | return rc; |
Sergii Dmytruk | 0a89d52 | 2022-10-29 16:57:07 +0300 | [diff] [blame] | 631 | } |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 632 | |
Sergii Dmytruk | 0a89d52 | 2022-10-29 16:57:07 +0300 | [diff] [blame] | 633 | /* Certain TPMs seem to need some delay here or they hang... */ |
| 634 | udelay(10); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 637 | return tis_command_ready(locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | /* |
Sergii Dmytruk | 4ee0317 | 2022-12-22 19:35:25 +0200 | [diff] [blame] | 641 | * tis_sendrecv() |
| 642 | * |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 643 | * Send the requested data to the TPM and then try to get its response |
| 644 | * |
| 645 | * @sendbuf - buffer of the data to send |
| 646 | * @send_size size of the data to send |
| 647 | * @recvbuf - memory to save the response to |
| 648 | * @recv_len - pointer to the size of the response buffer |
| 649 | * |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 650 | * Returns TPM_SUCCESS on success (and places the number of response bytes |
| 651 | * at recv_len) or TPM_CB_FAIL on failure. |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 652 | */ |
Sergii Dmytruk | 963f7b9 | 2022-10-29 20:42:28 +0300 | [diff] [blame^] | 653 | static tpm_result_t pc80_tpm_sendrecv(const uint8_t *sendbuf, size_t send_size, |
| 654 | uint8_t *recvbuf, size_t *recv_len) |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 655 | { |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 656 | tpm_result_t rc = tis_senddata(sendbuf, send_size); |
| 657 | if (rc) { |
| 658 | printf("%s:%d failed sending data to TPM with error %#x\n", |
| 659 | __FILE__, __LINE__, rc); |
| 660 | return rc; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | return tis_readresponse(recvbuf, recv_len); |
| 664 | } |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 665 | |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 666 | /* |
Sergii Dmytruk | 963f7b9 | 2022-10-29 20:42:28 +0300 | [diff] [blame^] | 667 | * tis_probe() |
| 668 | * |
| 669 | * Probe for the TPM device and set it up for use within locality 0. Returns |
| 670 | * pointer to send-receive function on success or NULL on failure. |
| 671 | */ |
| 672 | tis_sendrecv_fn tis_probe(void) |
| 673 | { |
| 674 | if (pc80_tis_probe()) |
| 675 | return NULL; |
| 676 | |
| 677 | if (pc80_tis_open()) |
| 678 | return NULL; |
| 679 | |
| 680 | return &pc80_tpm_sendrecv; |
| 681 | } |
| 682 | |
| 683 | /* |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 684 | * tis_setup_interrupt() |
| 685 | * |
| 686 | * Set up the interrupt vector and polarity for locality 0 and |
| 687 | * disable all interrupts so they are unused in firmware but can |
| 688 | * be enabled by the OS. |
| 689 | * |
| 690 | * The values used here must match what is passed in the TPM ACPI |
| 691 | * device if ACPI is used on the platform. |
| 692 | * |
| 693 | * @vector - TPM interrupt vector |
| 694 | * @polarity - TPM interrupt polarity |
| 695 | * |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 696 | * Returns TPM_SUCCESS on success, TPM_CB_FAIL on failure. |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 697 | */ |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 698 | static tpm_result_t tis_setup_interrupt(int vector, int polarity) |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 699 | { |
| 700 | u8 locality = 0; |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 701 | tpm_result_t rc = tlcl_lib_init(); |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 702 | |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 703 | if (rc) |
| 704 | return rc; |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 705 | |
| 706 | /* Set TPM interrupt vector */ |
| 707 | tpm_write_int_vector(vector, locality); |
| 708 | |
Elyes HAOUAS | 1895838 | 2018-08-07 12:23:16 +0200 | [diff] [blame] | 709 | /* Set TPM interrupt polarity and disable interrupts */ |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 710 | tpm_write_int_polarity(polarity, locality); |
| 711 | |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 712 | return TPM_SUCCESS; |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | static void lpc_tpm_read_resources(struct device *dev) |
| 716 | { |
| 717 | /* Static 5K memory region specified in Kconfig */ |
Arthur Heymans | e05693e | 2023-07-05 11:43:09 +0200 | [diff] [blame] | 718 | mmio_range(dev, 0, CONFIG_TPM_TIS_BASE_ADDRESS, 0x5000); |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | static void lpc_tpm_set_resources(struct device *dev) |
| 722 | { |
| 723 | tpm_config_t *config = (tpm_config_t *)dev->chip_info; |
Kyösti Mälkki | baa16e9 | 2019-11-05 18:38:00 +0200 | [diff] [blame] | 724 | DEVTREE_CONST struct resource *res; |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 725 | |
| 726 | for (res = dev->resource_list; res; res = res->next) { |
| 727 | if (!(res->flags & IORESOURCE_ASSIGNED)) |
| 728 | continue; |
| 729 | |
| 730 | if (res->flags & IORESOURCE_IRQ) { |
| 731 | /* Set interrupt vector */ |
| 732 | tis_setup_interrupt((int)res->base, |
| 733 | config->irq_polarity); |
| 734 | } else { |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 735 | continue; |
| 736 | } |
| 737 | |
Kyösti Mälkki | baa16e9 | 2019-11-05 18:38:00 +0200 | [diff] [blame] | 738 | #if !DEVTREE_EARLY |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 739 | res->flags |= IORESOURCE_STORED; |
| 740 | report_resource_stored(dev, res, " <tpm>"); |
Kyösti Mälkki | baa16e9 | 2019-11-05 18:38:00 +0200 | [diff] [blame] | 741 | #endif |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 745 | #if CONFIG(HAVE_ACPI_TABLES) |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 746 | static void lpc_tpm_fill_ssdt(const struct device *dev) |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 747 | { |
Michał Kopeć | a691cbd | 2022-02-22 12:30:22 +0100 | [diff] [blame] | 748 | /* Windows 11 requires the following path for TPM to be detected */ |
| 749 | const char *path = "\\_SB_.PCI0"; |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 750 | |
| 751 | /* Device */ |
| 752 | acpigen_write_scope(path); |
| 753 | acpigen_write_device(acpi_device_name(dev)); |
| 754 | |
Michał Żygowski | 7b28801 | 2020-03-20 15:41:44 +0100 | [diff] [blame] | 755 | if (CONFIG(TPM2)) { |
| 756 | acpigen_write_name_string("_HID", "MSFT0101"); |
| 757 | acpigen_write_name_string("_CID", "MSFT0101"); |
| 758 | } else { |
| 759 | acpigen_write_name("_HID"); |
| 760 | acpigen_emit_eisaid("PNP0C31"); |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 761 | |
Michał Żygowski | 7b28801 | 2020-03-20 15:41:44 +0100 | [diff] [blame] | 762 | acpigen_write_name("_CID"); |
| 763 | acpigen_emit_eisaid("PNP0C31"); |
| 764 | } |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 765 | |
Patrick Rudolph | c83bab6 | 2019-12-13 12:16:06 +0100 | [diff] [blame] | 766 | acpi_device_write_uid(dev); |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 767 | |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 768 | u32 did_vid = tpm_read_did_vid(0); |
| 769 | if (did_vid > 0 && did_vid < 0xffffffff) |
| 770 | acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON); |
| 771 | else |
| 772 | acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_OFF); |
| 773 | |
Kevin Cody-Little | c97b5af | 2018-05-09 14:14:59 -0400 | [diff] [blame] | 774 | u16 port = dev->path.pnp.port; |
| 775 | |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 776 | /* Resources */ |
| 777 | acpigen_write_name("_CRS"); |
| 778 | acpigen_write_resourcetemplate_header(); |
| 779 | acpigen_write_mem32fixed(1, CONFIG_TPM_TIS_BASE_ADDRESS, 0x5000); |
Frans Hendriks | 6cc937e | 2018-10-29 14:30:58 +0100 | [diff] [blame] | 780 | if (port) |
| 781 | acpigen_write_io16(port, port, 1, 2, 1); |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 782 | |
| 783 | if (CONFIG_TPM_PIRQ) { |
| 784 | /* |
| 785 | * PIRQ: Update interrupt vector with configured PIRQ |
| 786 | * Active-Low Level-Triggered Shared |
| 787 | */ |
Furquan Shaikh | 5b9b593 | 2017-02-21 13:16:30 -0800 | [diff] [blame] | 788 | struct acpi_irq tpm_irq_a = ACPI_IRQ_LEVEL_LOW(CONFIG_TPM_PIRQ); |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 789 | acpi_device_write_interrupt(&tpm_irq_a); |
| 790 | } else if (tpm_read_int_vector(0) > 0) { |
| 791 | u8 int_vec = tpm_read_int_vector(0); |
| 792 | u8 int_pol = tpm_read_int_polarity(0); |
Furquan Shaikh | 5b9b593 | 2017-02-21 13:16:30 -0800 | [diff] [blame] | 793 | struct acpi_irq tpm_irq = ACPI_IRQ_LEVEL_LOW(int_vec); |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 794 | |
| 795 | if (int_pol & 1) |
Furquan Shaikh | 5b9b593 | 2017-02-21 13:16:30 -0800 | [diff] [blame] | 796 | tpm_irq.polarity = ACPI_IRQ_ACTIVE_LOW; |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 797 | else |
Furquan Shaikh | 5b9b593 | 2017-02-21 13:16:30 -0800 | [diff] [blame] | 798 | tpm_irq.polarity = ACPI_IRQ_ACTIVE_HIGH; |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 799 | |
| 800 | if (int_pol & 2) |
Furquan Shaikh | 5b9b593 | 2017-02-21 13:16:30 -0800 | [diff] [blame] | 801 | tpm_irq.mode = ACPI_IRQ_EDGE_TRIGGERED; |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 802 | else |
Furquan Shaikh | 5b9b593 | 2017-02-21 13:16:30 -0800 | [diff] [blame] | 803 | tpm_irq.mode = ACPI_IRQ_LEVEL_TRIGGERED; |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 804 | |
| 805 | acpi_device_write_interrupt(&tpm_irq); |
| 806 | } |
| 807 | |
Patrick Rudolph | d8d8be1 | 2020-09-21 09:48:53 +0200 | [diff] [blame] | 808 | |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 809 | acpigen_write_resourcetemplate_footer(); |
| 810 | |
Patrick Rudolph | d8d8be1 | 2020-09-21 09:48:53 +0200 | [diff] [blame] | 811 | if (!CONFIG(CHROMEOS)) |
| 812 | tpm_ppi_acpi_fill_ssdt(dev); |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 813 | |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 814 | acpigen_pop_len(); /* Device */ |
| 815 | acpigen_pop_len(); /* Scope */ |
| 816 | |
Kyösti Mälkki | baa16e9 | 2019-11-05 18:38:00 +0200 | [diff] [blame] | 817 | #if !DEVTREE_EARLY |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 818 | printk(BIOS_INFO, "%s.%s: %s %s\n", path, acpi_device_name(dev), |
| 819 | dev->chip_ops->name, dev_path(dev)); |
Kyösti Mälkki | baa16e9 | 2019-11-05 18:38:00 +0200 | [diff] [blame] | 820 | #endif |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 821 | } |
| 822 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 823 | static const char *lpc_tpm_acpi_name(const struct device *dev) |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 824 | { |
| 825 | return "TPM"; |
| 826 | } |
| 827 | #endif |
| 828 | |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 829 | static struct device_operations lpc_tpm_ops = { |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 830 | .read_resources = lpc_tpm_read_resources, |
| 831 | .set_resources = lpc_tpm_set_resources, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 832 | #if CONFIG(HAVE_ACPI_TABLES) |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 833 | .acpi_name = lpc_tpm_acpi_name, |
| 834 | .acpi_fill_ssdt = lpc_tpm_fill_ssdt, |
Naresh G Solanki | 80ff038 | 2016-11-15 11:01:33 +0530 | [diff] [blame] | 835 | #endif |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 836 | }; |
| 837 | |
Arthur Heymans | 04c49a5 | 2023-08-22 13:16:40 +0200 | [diff] [blame] | 838 | static struct device_operations noop_tpm_ops = { |
| 839 | .read_resources = noop_read_resources, |
| 840 | .set_resources = noop_set_resources, |
| 841 | }; |
| 842 | |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 843 | static struct pnp_info pnp_dev_info[] = { |
| 844 | { .flags = PNP_IRQ0 } |
| 845 | }; |
| 846 | |
| 847 | static void enable_dev(struct device *dev) |
| 848 | { |
Kyösti Mälkki | d2b2a18 | 2021-04-29 15:33:07 +0300 | [diff] [blame] | 849 | if (CONFIG(TPM)) |
Kyösti Mälkki | 9cc6493 | 2020-05-29 19:42:07 +0300 | [diff] [blame] | 850 | pnp_enable_devices(dev, &lpc_tpm_ops, |
| 851 | ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
Arthur Heymans | 04c49a5 | 2023-08-22 13:16:40 +0200 | [diff] [blame] | 852 | else |
| 853 | pnp_enable_devices(dev, &noop_tpm_ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | struct chip_operations drivers_pc80_tpm_ops = { |
| 857 | CHIP_NAME("LPC TPM") |
| 858 | .enable_dev = enable_dev |
| 859 | }; |